Skip to content

Commit a0bab75

Browse files
committed
Add support for exteranal nested compose
1 parent 383421b commit a0bab75

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
@@ -142,6 +142,22 @@ export const composedAndFlat = Object.freeze({
142142
composes: plain;
143143
color: blue;
144144
}
145+
146+
.nested {
147+
composes: extra from './utils.css';
148+
color: green;
149+
}
150+
`,
151+
152+
'utils.css': outdent`
153+
.base {
154+
color: red;
155+
}
156+
157+
.extra {
158+
composes: base;
159+
color: blue;
160+
}
145161
`,
146162

147163
'postcss.config.js': postcssConfig,

tests/specs/patched/postcss.spec.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -583,11 +583,13 @@ export default testSuite(({ describe }) => {
583583
style: {
584584
plain: expect.stringMatching(/_plain_\w+/),
585585
composed: expect.stringMatching(/_composed_\w+ _plain_\w+/),
586+
nested: expect.stringMatching(/_nested_\w+ _extra_\w+ _base_\w+/),
586587
},
587588
});
588589
const dts = await fixture.readFile('style.module.css.d.ts', 'utf8');
589590
expect(dts).toMatch('const plain: string;');
590591
expect(dts).toMatch('const composed: string;');
592+
expect(dts).toMatch('const nested: string;');
591593
});
592594

593595
test('array', async () => {
@@ -607,11 +609,13 @@ export default testSuite(({ describe }) => {
607609
style: {
608610
plain: expect.stringMatching(/_plain_\w+/),
609611
composed: [expect.stringMatching(/_composed_\w+/), expect.stringMatching(/_plain_\w+/)],
612+
nested: [expect.stringMatching(/_nested_\w+/), expect.stringMatching(/_extra_\w+/), expect.stringMatching(/_base_\w+/)],
610613
},
611614
});
612615
const dts = await fixture.readFile('style.module.css.d.ts', 'utf8');
613616
expect(dts).toMatch('const plain: string;');
614617
expect(dts).toMatch('const composed: string[];');
618+
expect(dts).toMatch('const nested: string[];');
615619
});
616620

617621
test('all-array', async () => {
@@ -631,11 +635,13 @@ export default testSuite(({ describe }) => {
631635
style: {
632636
plain: [expect.stringMatching(/_plain_\w+/)],
633637
composed: [expect.stringMatching(/_composed_\w+/), expect.stringMatching(/_plain_\w+/)],
638+
nested: [expect.stringMatching(/_nested_\w+/), expect.stringMatching(/_extra_\w+/), expect.stringMatching(/_base_\w+/)],
634639
},
635640
});
636641
const dts = await fixture.readFile('style.module.css.d.ts', 'utf8');
637642
expect(dts).toMatch('const plain: string[];');
638643
expect(dts).toMatch('const composed: string[];');
644+
expect(dts).toMatch('const nested: string[];');
639645
});
640646
});
641647

0 commit comments

Comments
 (0)