Skip to content

Commit

Permalink
Fix variable orders inside @svg()
Browse files Browse the repository at this point in the history
  • Loading branch information
yuanchuan committed Sep 11, 2023
1 parent e56213a commit 52f31b5
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/parser/parse-svg.js
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,11 @@ function skipHeadSVG(block) {
}
}
if (headSVG && Array.isArray(headSVG.value)) {
headSVG.value.push(...headVariables);
for (let variable of headVariables) {
if (!headSVG.value.find(n => n.name == variable.name)) {
headSVG.value.unshift(variable);
}
}
return headSVG;
}
return block;
Expand Down
30 changes: 30 additions & 0 deletions test/parse-svg.js
Original file line number Diff line number Diff line change
Expand Up @@ -438,3 +438,33 @@ test('svg variable', t => {
}]
});
});


test('svg variable order', t => {
compare(t, '--a: 1; svg { --a: 2 }', {
name: 'svg',
type: 'block',
value: [{
type: 'statement',
name: '--a',
value: '2',
variable: true
}]
});

compare(t, '--b: 1; svg { --a: 2 }', {
name: 'svg',
type: 'block',
value: [{
type: 'statement',
name: '--b',
value: '1',
variable: true
}, {
type: 'statement',
name: '--a',
value: '2',
variable: true
}]
});
});

0 comments on commit 52f31b5

Please sign in to comment.