Skip to content

Commit

Permalink
fix: flaws in cloning state and reverse mutating array
Browse files Browse the repository at this point in the history
  • Loading branch information
Yash-Singh1 committed May 18, 2024
1 parent 095b64e commit c5e9533
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 16 deletions.
25 changes: 12 additions & 13 deletions server/src/capabilities/hover.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ async function onHover({
isStyleXPropertyType(node.callee, stateManager)
) {
state.propertyType = dashify(node.callee.property.value);
return;
return state;
}

state.callInside = null;
Expand Down Expand Up @@ -306,19 +306,19 @@ async function onHover({

let cssLines: string[] = [];

classLine.reverse();
const propertyName =
(state.callInside === "create" || state.callInside === "keyframes"
? classLine
.reverse()
.find(
(className) =>
!(
className.startsWith(":") ||
className.startsWith("@") ||
className === "default"
),
)
? classLine.find(
(className) =>
!(
className.startsWith(":") ||
className.startsWith("@") ||
className === "default"
),
)
: `--${state.parentClass[0] || key}`) || "unknown";
classLine.reverse();
const dashifyPropertyKey = dashify(propertyName);

if (propertyType) {
Expand All @@ -341,8 +341,7 @@ async function onHover({
.slice(0)
.filter(
(className, index) =>
index === 0 ||
(className !== "default" && className.startsWith(":")),
index === 0 || className.startsWith(":"),
)
.sort()
.reverse()
Expand Down
11 changes: 8 additions & 3 deletions server/src/lib/walk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -435,12 +435,17 @@ export async function _walk<StateType>(
let result;

if ("type" in child) {
result = await _walk<StateType>(child, visitor, { ...state }, node);
result = await _walk<StateType>(
child,
visitor,
JSON.parse(JSON.stringify(state)),
node,
);
} else if ("expression" in child) {
result = await _walk<StateType>(
child.expression,
visitor,
{ ...state },
JSON.parse(JSON.stringify(state)),
node,
);
}
Expand All @@ -456,7 +461,7 @@ export async function _walk<StateType>(
const result = await _walk<StateType>(
node[key as keyof typeof node] as unknown as NodeType,
visitor,
{ ...state },
JSON.parse(JSON.stringify(state)),
node,
);
if (result === States.EXIT) {
Expand Down

0 comments on commit c5e9533

Please sign in to comment.