Skip to content

Commit 00e84c8

Browse files
authored
fix: don't move composed classes early (#856)
Because it can cause invalid output if they get moved ahead of their dependencies, and we don't need to handle them at this point anyways
1 parent dc476ef commit 00e84c8

File tree

6 files changed

+66
-9
lines changed

6 files changed

+66
-9
lines changed

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

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ const DEFAULTS = {
2626
const {
2727
selectorKey,
2828
isFile,
29-
isSelector,
3029
isValue,
3130
} = Processor;
3231

@@ -108,14 +107,8 @@ exports.transform = (file, processor, opts = {}) => {
108107

109108
const imported = importsMap.get(depFile);
110109

111-
// File we're transforming
110+
// Local deps are ignored at this point
112111
if(depFile === id) {
113-
// Track this selector as part of the keys to be exported, adding
114-
// here so it'll be sorted topologically
115-
if(isSelector(depKey)) {
116-
exportedKeys.add(data.selector);
117-
}
118-
119112
return;
120113
}
121114

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

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,9 +268,38 @@ Object {
268268
}
269269
`;
270270
271+
exports[`/rollup.js should express local & remote-composed classes correctly 1`] = `
272+
Object {
273+
"assets/multiple-composition.css": "
274+
/* packages/rollup/test/specimens/multiple-composition/other.css */
275+
.mc_other {
276+
color: green;
277+
}
278+
/* packages/rollup/test/specimens/multiple-composition/multiple-composition.css */
279+
.mc_one {
280+
color: red;
281+
}
282+
.mc_two {
283+
background: blue;
284+
}",
285+
"multiple-composition.js": "
286+
const other = \\"mc_other\\";
287+
288+
const one = \\"mc_one\\";
289+
const two = other + \\" \\" + one + \\" \\" + \\"mc_two\\";
290+
var css = {
291+
one,
292+
two
293+
};
294+
295+
console.log(css);
296+
",
297+
}
298+
`;
299+
271300
exports[`/rollup.js should express locally-composed classes correctly 1`] = `
272301
Object {
273-
"assets/local-composition-1485bb4a.css": "
302+
"assets/local-composition.css": "
274303
/* packages/rollup/test/specimens/local-composition.css */
275304
.mc_one {
276305
color: red;

packages/rollup/test/rollup.test.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ describe("/rollup.js", () => {
5151
expect(
5252
await bundle.generate({
5353
format,
54+
assetFileNames,
5455
})
5556
).toMatchRollupCodeSnapshot();
5657
});
@@ -66,6 +67,23 @@ describe("/rollup.js", () => {
6667
expect(
6768
await bundle.generate({
6869
format,
70+
assetFileNames,
71+
})
72+
).toMatchRollupSnapshot();
73+
});
74+
75+
it("should express local & remote-composed classes correctly", async () => {
76+
const bundle = await rollup({
77+
input : require.resolve(`./specimens/multiple-composition/multiple-composition.js`),
78+
plugins : [
79+
createPlugin(),
80+
],
81+
});
82+
83+
expect(
84+
await bundle.generate({
85+
format,
86+
assetFileNames,
6987
})
7088
).toMatchRollupSnapshot();
7189
});
@@ -81,6 +99,7 @@ describe("/rollup.js", () => {
8199
expect(
82100
await bundle.generate({
83101
format,
102+
assetFileNames,
84103
})
85104
).toMatchRollupCodeSnapshot();
86105
});
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
.one {
2+
color: red;
3+
}
4+
5+
.two {
6+
composes: other from "./other.css";
7+
composes: one;
8+
9+
background: blue;
10+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import css from "./multiple-composition.css";
2+
3+
console.log(css);
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.other {
2+
color: green;
3+
}

0 commit comments

Comments
 (0)