Skip to content

Commit

Permalink
test: reserved js keywords
Browse files Browse the repository at this point in the history
  • Loading branch information
privatenumber committed Mar 8, 2024
1 parent c02aefe commit 9fdfa5b
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 0 deletions.
30 changes: 30 additions & 0 deletions tests/fixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,36 @@ export const multiCssModules = Object.freeze({
'postcss.config.js': postcssConfig,
});

export const reservedKeywords = Object.freeze({
'index.js': outdent`
export * as style from './style.module.css';
`,

'style.module.css': outdent`
.import {
composes: if from './utils.css';
color: red;
}
.export {
composes: with from './utils.css';
}
`,

'utils.css': outdent`
.if {
--name: 'foo';
color: blue;
}
.with {
color: yellow;
}
`,

'postcss.config.js': postcssConfig,
});

export const cssModulesValues = Object.freeze({
'index.js': outdent`
export * from './style.module.css';
Expand Down
25 changes: 25 additions & 0 deletions tests/specs/patched/lightningcss.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,31 @@ export default testSuite(({ describe }) => {
expect(css).toBe('\n');
});

test('reserved keywords', async ({ onTestFinish }) => {
const fixture = await createFixture(fixtures.reservedKeywords);
onTestFinish(() => fixture.rm());

const { js } = await viteBuild(fixture.path, {
plugins: [
patchCssModules(),
],
css: {
transformer: 'lightningcss',
},
});
const exported = await import(base64Module(js));
expect(exported).toMatchObject({
style: {
default: {
export: 'fk9XWG_export V_YH-W_with',
import: 'fk9XWG_import V_YH-W_if',
},
export: 'fk9XWG_export V_YH-W_with',
import: 'fk9XWG_import V_YH-W_if',
},
});
});

describe('Custom property dependencies', ({ test }) => {
test('build', async ({ onTestFinish }) => {
const fixture = await createFixture(fixtures.lightningCustomPropertiesFrom);
Expand Down
22 changes: 22 additions & 0 deletions tests/specs/patched/postcss.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,28 @@ export default testSuite(({ describe }) => {
expect(exported.default).toMatch(/--file: "style.module.css\?inline"/);
});

test('reserved keywords', async ({ onTestFinish }) => {
const fixture = await createFixture(fixtures.reservedKeywords);
onTestFinish(() => fixture.rm());

const { js } = await viteBuild(fixture.path, {
plugins: [
patchCssModules(),
],
});
const exported = await import(base64Module(js));
expect(exported).toMatchObject({
style: {
default: {
import: '_import_1f0f104 _if_36a6377',
export: '_export_31ef8f2 _with_779bcbb',
},
export: '_export_31ef8f2 _with_779bcbb',
import: '_import_1f0f104 _if_36a6377',
},
});
});

test('dev server', async ({ onTestFinish }) => {
const fixture = await createFixture(fixtures.multiCssModules);
onTestFinish(() => fixture.rm());
Expand Down
21 changes: 21 additions & 0 deletions tests/specs/reproductions.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,27 @@ export default testSuite(({ describe }) => {
expect(error?.reason).toBe('Unexpected \'/\'. Escaping special characters with \\ may help.');
});

// https://github.com/vitejs/vite/issues/14050
test('reserved keywords', async ({ onTestFinish }) => {
const fixture = await createFixture(fixtures.reservedKeywords);
onTestFinish(() => fixture.rm());

const { js } = await viteBuild(fixture.path);
const exported = await import(base64Module(js));

expect(exported).toMatchObject({
style: {
default: {
import: '_import_3y4f1_1 _if_1bsbm_1',
export: '_export_3y4f1_6 _with_1bsbm_6',
},
},
});

expect(exported.import).toBeUndefined();
expect(exported.export).toBeUndefined();
});

// This one is more for understanding expected behavior
test('@values', async ({ onTestFinish }) => {
const fixture = await createFixture(fixtures.cssModulesValues);
Expand Down

0 comments on commit 9fdfa5b

Please sign in to comment.