Skip to content

Commit ea6a0e9

Browse files
authored
fix: rename & deconflict together (#820)
@Morklympious found a bug where if you exercise both the renaming & deconflicting logic the rename (via `identifierfy`) gets lost and the resulting variable name is no longer valid. So now it's fixed.
1 parent 2c69783 commit ea6a0e9

5 files changed

Lines changed: 47 additions & 4 deletions

File tree

packages/css-to-js/css-to-js.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,16 @@ const {
3030
isValue,
3131
} = Processor;
3232

33-
const deconflict = (map, ident) => {
34-
let proposal = identifierfy(ident);
33+
const deconflict = (map, source) => {
34+
const safe = identifierfy(source);
3535
let idx = 0;
36+
let proposal = safe;
3637

3738
while(map.has(proposal)) {
38-
proposal = `${ident}${++idx}`;
39+
proposal = `${safe}${++idx}`;
3940
}
4041

41-
map.set(proposal, ident);
42+
map.set(proposal, source);
4243

4344
return proposal;
4445
};

packages/rollup/test/__snapshots__/rollup.test.js.snap

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,27 @@ console.log(css);
426426
}
427427
`;
428428
429+
exports[`/rollup.js should support @value camelCase overlap 1`] = `
430+
Object {
431+
"assets/value-camel-overlap.css": "
432+
/* packages/rollup/test/specimens/value-camel-overlap.css */
433+
",
434+
"value-camel-overlap.js": "
435+
const colorBlack = \\"#000\\";
436+
const colorBlack1 = \\"#000\\";
437+
const $values = {
438+
colorBlack,
439+
\\"color-black\\" : colorBlack1,
440+
};
441+
var css = {
442+
$values
443+
};
444+
445+
console.log(css);
446+
",
447+
}
448+
`;
449+
429450
exports[`/rollup.js should support external @value aliases 1`] = `
430451
Object {
431452
"assets/external-value-aliasing.css": "

packages/rollup/test/rollup.test.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,22 @@ describe("/rollup.js", () => {
346346
).toMatchRollupSnapshot();
347347
});
348348

349+
it("should support @value camelCase overlap", async () => {
350+
const bundle = await rollup({
351+
input : require.resolve("./specimens/value-camel-overlap.js"),
352+
plugins : [
353+
createPlugin(),
354+
],
355+
});
356+
357+
expect(
358+
await bundle.generate({
359+
format,
360+
assetFileNames,
361+
})
362+
).toMatchRollupSnapshot();
363+
});
364+
349365
it("should output classes in topological order", async () => {
350366
const bundle = await rollup({
351367
input : require.resolve("./specimens/topological-order/topological-order.js"),
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
@value colorBlack: #000;
2+
@value color-black: #000;
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import css from "./value-camel-overlap.css";
2+
3+
console.log(css);

0 commit comments

Comments
 (0)