Skip to content

Commit d3421bf

Browse files
committed
Add support for exteranal nested compose
1 parent 321cfe2 commit d3421bf

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

src/plugin/generate-esm.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ const exportsToCode = (
5757
if (composedClassesMode === 'string' || (composedClassesMode === 'array' && !value.includes(' '))) {
5858
variables.add(`const ${jsVariable} = \`${value}\`;`);
5959
} else {
60-
variables.add(`const ${jsVariable} = [${value.split(' ').map(v => `\`${v}\``).join(', ')}];`);
60+
variables.add(`const ${jsVariable} = [${value.split(' ').map(v => (v.search(/^\$\{.*\}$/) === 0 ? v.slice(2, -1) : `\`${v}\``)).join(', ')}].flat();`);
6161
}
6262

6363
return Array.from(exportAs).map((exportAsName) => {

tests/fixtures.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,22 @@ export const composedAndFlat = Object.freeze({
140140
composes: plain;
141141
color: blue;
142142
}
143+
144+
.nested {
145+
composes: extra from './utils.css';
146+
color: green;
147+
}
148+
`,
149+
150+
'utils.css': outdent`
151+
.base {
152+
color: red;
153+
}
154+
155+
.extra {
156+
composes: base;
157+
color: blue;
158+
}
143159
`,
144160

145161
'postcss.config.js': postcssConfig,

tests/specs/patched/postcss.spec.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -564,11 +564,13 @@ export default testSuite(({ describe }) => {
564564
style: {
565565
plain: expect.stringMatching(/_plain_\w+/),
566566
composed: expect.stringMatching(/_composed_\w+ _plain_\w+/),
567+
nested: expect.stringMatching(/_nested_\w+ _extra_\w+ _base_\w+/),
567568
},
568569
});
569570
const dts = await fixture.readFile('style.module.css.d.ts', 'utf8');
570571
expect(dts).toMatch('const plain: string;');
571572
expect(dts).toMatch('const composed: string;');
573+
expect(dts).toMatch('const nested: string;');
572574
});
573575

574576
test('array', async () => {
@@ -588,11 +590,13 @@ export default testSuite(({ describe }) => {
588590
style: {
589591
plain: expect.stringMatching(/_plain_\w+/),
590592
composed: [expect.stringMatching(/_composed_\w+/), expect.stringMatching(/_plain_\w+/)],
593+
nested: [expect.stringMatching(/_nested_\w+/), expect.stringMatching(/_extra_\w+/), expect.stringMatching(/_base_\w+/)],
591594
},
592595
});
593596
const dts = await fixture.readFile('style.module.css.d.ts', 'utf8');
594597
expect(dts).toMatch('const plain: string;');
595598
expect(dts).toMatch('const composed: string[];');
599+
expect(dts).toMatch('const nested: string[];');
596600
});
597601

598602
test('all-array', async () => {
@@ -612,11 +616,13 @@ export default testSuite(({ describe }) => {
612616
style: {
613617
plain: [expect.stringMatching(/_plain_\w+/)],
614618
composed: [expect.stringMatching(/_composed_\w+/), expect.stringMatching(/_plain_\w+/)],
619+
nested: [expect.stringMatching(/_nested_\w+/), expect.stringMatching(/_extra_\w+/), expect.stringMatching(/_base_\w+/)],
615620
},
616621
});
617622
const dts = await fixture.readFile('style.module.css.d.ts', 'utf8');
618623
expect(dts).toMatch('const plain: string[];');
619624
expect(dts).toMatch('const composed: string[];');
625+
expect(dts).toMatch('const nested: string[];');
620626
});
621627
});
622628

0 commit comments

Comments
 (0)