diff --git a/packages/example/01-basic/1.css b/packages/example/01-basic/1.css index 9c11707d..103d710f 100644 --- a/packages/example/01-basic/1.css +++ b/packages/example/01-basic/1.css @@ -33,8 +33,3 @@ } :local(.local_class_name_4) { } -.composes_target { -} -.composes { - composes: composes_target; -} diff --git a/packages/example/01-basic/1.css.d.ts b/packages/example/01-basic/1.css.d.ts index 02e276f5..a4f5be4e 100644 --- a/packages/example/01-basic/1.css.d.ts +++ b/packages/example/01-basic/1.css.d.ts @@ -16,8 +16,6 @@ declare const styles: & Readonly<{ "local_class_name_2": string }> & Readonly<{ "local_class_name_3": string }> & Readonly<{ "local_class_name_4": string }> - & Readonly<{ "composes_target": string }> - & Readonly<{ "composes": string }> ; export default styles; //# sourceMappingURL=./1.css.d.ts.map diff --git a/packages/example/01-basic/1.css.d.ts.map b/packages/example/01-basic/1.css.d.ts.map index 598bd335..582e7508 100644 --- a/packages/example/01-basic/1.css.d.ts.map +++ b/packages/example/01-basic/1.css.d.ts.map @@ -1 +1 @@ -{"version":3,"sources":["./1.css"],"names":["basic","cascading","pseudo_class_1","pseudo_class_2","pseudo_class_3","multiple_selector_1","multiple_selector_2","combinator_1","combinator_2","at_rule","selector_list_1","selector_list_2","local_class_name_1","local_class_name_2","local_class_name_3","local_class_name_4","composes_target","composes"],"mappings":"AAAA;AAAA,E,aAAAA,O,WAAA;AAAA,E,aAEAC,W,WAFA;AAAA,E,aAIAA,W,WAJA;AAAA,E,aAMAC,gB,WANA;AAAA,E,aAQAC,gB,WARA;AAAA,E,aAUAC,gB,WAVA;AAAA,E,aAYAC,qB,WAZA;AAAA,E,aAYAC,qB,WAZA;AAAA,E,aAcAC,c,WAdA;AAAA,E,aAcAC,c,WAdA;AAAA,E,aAkBIC,S,WAlBJ;AAAA,E,aAsBAC,iB,WAtBA;AAAA,E,aAAAC,iB,WAAA;AAAA,E,aAyBAC,oB,WAzBA;AAAA,E,aA4BEC,oB,WA5BF;AAAA,E,aA8BEC,oB,WA9BF;AAAA,E,aAiCAC,oB,WAjCA;AAAA,E,aAmCAC,iB,WAnCA;AAAA,E,aAqCAC,U,WArCA;AAAA;AAAA","file":"1.css.d.ts","sourceRoot":""} \ No newline at end of file +{"version":3,"sources":["./1.css"],"names":["basic","cascading","pseudo_class_1","pseudo_class_2","pseudo_class_3","multiple_selector_1","multiple_selector_2","combinator_1","combinator_2","at_rule","selector_list_1","selector_list_2","local_class_name_1","local_class_name_2","local_class_name_3","local_class_name_4"],"mappings":"AAAA;AAAA,E,aAAAA,O,WAAA;AAAA,E,aAEAC,W,WAFA;AAAA,E,aAIAA,W,WAJA;AAAA,E,aAMAC,gB,WANA;AAAA,E,aAQAC,gB,WARA;AAAA,E,aAUAC,gB,WAVA;AAAA,E,aAYAC,qB,WAZA;AAAA,E,aAYAC,qB,WAZA;AAAA,E,aAcAC,c,WAdA;AAAA,E,aAcAC,c,WAdA;AAAA,E,aAkBIC,S,WAlBJ;AAAA,E,aAsBAC,iB,WAtBA;AAAA,E,aAAAC,iB,WAAA;AAAA,E,aAyBAC,oB,WAzBA;AAAA,E,aA4BEC,oB,WA5BF;AAAA,E,aA8BEC,oB,WA9BF;AAAA,E,aAiCAC,oB,WAjCA;AAAA;AAAA","file":"1.css.d.ts","sourceRoot":""} \ No newline at end of file diff --git a/packages/example/03-composes/2.css b/packages/example/03-composes/2.css index 765777b3..651b7d82 100644 --- a/packages/example/03-composes/2.css +++ b/packages/example/03-composes/2.css @@ -1,3 +1,2 @@ .b { - composes: c from './3.css'; } diff --git a/packages/example/03-composes/3.css b/packages/example/03-composes/3.css deleted file mode 100644 index 5d1515ab..00000000 --- a/packages/example/03-composes/3.css +++ /dev/null @@ -1,2 +0,0 @@ -.c { -} diff --git a/packages/example/03-composes/3.css.d.ts b/packages/example/03-composes/3.css.d.ts deleted file mode 100644 index ebd17526..00000000 --- a/packages/example/03-composes/3.css.d.ts +++ /dev/null @@ -1,5 +0,0 @@ -declare const styles: - & Readonly<{ "c": string }> -; -export default styles; -//# sourceMappingURL=./3.css.d.ts.map diff --git a/packages/example/03-composes/3.css.d.ts.map b/packages/example/03-composes/3.css.d.ts.map deleted file mode 100644 index 5a2ffb55..00000000 --- a/packages/example/03-composes/3.css.d.ts.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"sources":["./3.css"],"names":["c"],"mappings":"AAAA;AAAA,E,aAAAA,G,WAAA;AAAA;AAAA","file":"3.css.d.ts","sourceRoot":""} \ No newline at end of file diff --git a/packages/example/04-sass/1.scss b/packages/example/04-sass/1.scss index fd39fe06..daa47e7e 100644 --- a/packages/example/04-sass/1.scss +++ b/packages/example/04-sass/1.scss @@ -13,6 +13,4 @@ &_2 { dummy: ''; } - composes: a_1; // css module feature test (composes) - composes: d from './4.scss'; // css module feature test (composes from other file) } diff --git a/packages/example/05-less/1.less b/packages/example/05-less/1.less index 94dcdd07..58d1be3e 100644 --- a/packages/example/05-less/1.less +++ b/packages/example/05-less/1.less @@ -14,6 +14,4 @@ } .b_1(); .b_2(); - composes: a_1; // css module feature test (composes) - composes: c from './3.less'; // css module feature test (composes from other file) } diff --git a/packages/example/app.ts b/packages/example/app.ts index 6c869792..95d1cff6 100644 --- a/packages/example/app.ts +++ b/packages/example/app.ts @@ -22,8 +22,6 @@ console.log(styles1.local_class_name_1); console.log(styles1.local_class_name_2); console.log(styles1.local_class_name_3); console.log(styles1.local_class_name_4); -console.log(styles1.composes_target); -console.log(styles1.composes); console.log(styles2.a); console.log(styles2.b); diff --git a/packages/happy-css-modules/src/integration-test/go-to-definition.test.ts b/packages/happy-css-modules/src/integration-test/go-to-definition.test.ts index 13f4d908..28134dbb 100644 --- a/packages/happy-css-modules/src/integration-test/go-to-definition.test.ts +++ b/packages/happy-css-modules/src/integration-test/go-to-definition.test.ts @@ -41,10 +41,6 @@ test('basic', async () => { .local_class_name_3 {} } :local(.local_class_name_4) {} - .composes_target {} - .composes { - composes: composes_target; - } `, }); await run({ ...defaultOptions }); @@ -65,8 +61,6 @@ test('basic', async () => { 'local_class_name_2', 'local_class_name_3', 'local_class_name_4', - 'composes_target', - 'composes', ]); // FIXME: Fix an issue where the text at definition destination was incorrect. expect(results).toMatchInlineSnapshot(` @@ -208,23 +202,6 @@ test('basic', async () => { ], "identifier": "local_class_name_4", }, - { - "definitions": [ - { - file: "/test/1.css", - text: ".composes_target ", - start: { line: 21, offset: 1 }, - end: { line: 21, offset: 18 }, - }, - ], - "identifier": "composes_target", - }, - { - "definitions": [ - { file: "/test/1.css", text: ".composes ", start: { line: 22, offset: 1 }, end: { line: 22, offset: 11 } }, - ], - "identifier": "composes", - }, ] `); const moduleDefinitions = await server.getModuleDefinitions(getFixturePath('/test/1.css')); @@ -295,8 +272,6 @@ test('with transformer', async () => { // sass feature test (nesting) .nesting_1 { dummy: ''; } &_2 { dummy: ''; } - composes: basic; // css module feature test (composes) - composes: d from './4.scss'; // css module feature test (composes from other file) } `, '/test/2.scss': dedent` @@ -306,9 +281,6 @@ test('with transformer', async () => { '/test/3.scss': dedent` .c { dummy: ''; } `, - '/test/4.scss': dedent` - .d { dummy: ''; } - `, }); await run({ ...defaultOptions }); const results = await server.getMultipleIdentifierDefinitions(getFixturePath(`/test/1.scss`), [ @@ -319,7 +291,6 @@ test('with transformer', async () => { 'b_1', 'b_2', 'c', - 'd', ]); expect(results).toMatchInlineSnapshot(` [ @@ -364,10 +335,6 @@ test('with transformer', async () => { ], "identifier": "c", }, - { - "definitions": [], - "identifier": "d", - }, ] `); }); diff --git a/packages/happy-css-modules/src/locator/index.test.ts b/packages/happy-css-modules/src/locator/index.test.ts index 7ce89162..fd5b9901 100644 --- a/packages/happy-css-modules/src/locator/index.test.ts +++ b/packages/happy-css-modules/src/locator/index.test.ts @@ -117,25 +117,17 @@ test('tracks other files when `@import` is present', async () => { `); }); -test('tracks other files when `composes` is present', async () => { +test('does not track other files by `composes`', async () => { createFixtures({ '/test/1.css': dedent` .a { composes: b from './2.css'; - composes: c d from './3.css'; - composes: e from '${getFixturePath('/test/4.css')}'; + composes: c from './3.css'; /* non-existent file */ } `, '/test/2.css': dedent` .b {} `, - '/test/3.css': dedent` - .c {} - .d {} - `, - '/test/4.css': dedent` - .e {} - `, }); const result = await locator.load(getFixturePath('/test/1.css')); expect(result).toMatchInlineSnapshot(` @@ -159,14 +151,7 @@ test('normalizes tokens', async () => { /* duplicate import */ @import './2.css'; @import '2.css'; - .a { - /* duplicate composes */ - composes: c from './3.css'; - composes: c from '3.css'; - composes: c c from './3.css'; - /* duplicate import and composes */ - composes: b from './2.css'; - } + .a {} .a {} /* duplicate class selector */ `, '/test/2.css': dedent` @@ -187,7 +172,7 @@ test('normalizes tokens', async () => { originalLocations: [ { filePath: "/test/2.css", start: { line: 1, column: 1 }, end: { line: 1, column: 2 } }, { filePath: "/test/1.css", start: { line: 4, column: 1 }, end: { line: 4, column: 2 } }, - { filePath: "/test/1.css", start: { line: 12, column: 1 }, end: { line: 12, column: 2 } }, + { filePath: "/test/1.css", start: { line: 5, column: 1 }, end: { line: 5, column: 2 } }, ], }, { @@ -205,12 +190,7 @@ test.failing('returns the result from the cache when the file has not been modif createFixtures({ '/test/1.css': dedent` @import './2.css'; - @import './2.css'; - .a { - composes: b from './2.css'; - composes: c from './3.css'; - composes: d from './3.css'; - } + @import './3.css'; `, '/test/2.css': dedent` .b {} @@ -246,25 +226,6 @@ test.failing('returns the result from the cache when the file has not been modif expect(readFileSpy).toHaveBeenCalledTimes(2); }); -test('ignores the composition of non-existent tokens', async () => { - // In css-loader and postcss-modules, compositions of non-existent tokens are simply ignored. - // Therefore, happy-css-modules follows suit. - // It may be preferable to warn rather than ignore, but for now, we will focus on compatibility. - // ref: https://github.com/css-modules/css-modules/issues/356 - createFixtures({ - '/test/1.css': dedent` - .a { - composes: b c from './2.css'; - } - `, - '/test/2.css': dedent` - .b {} - `, - }); - const result = await locator.load(getFixturePath('/test/1.css')); - expect(result.tokens.map((t) => t.name)).toStrictEqual(['a']); -}); - describe('supports sourcemap', () => { test('restores original locations from sourcemap', async () => { const transformer = createDefaultTransformer(); diff --git a/packages/happy-css-modules/src/locator/index.ts b/packages/happy-css-modules/src/locator/index.ts index 97f54754..25af1157 100644 --- a/packages/happy-css-modules/src/locator/index.ts +++ b/packages/happy-css-modules/src/locator/index.ts @@ -31,7 +31,7 @@ type CacheEntry = { /** The result of `Locator#load`. */ export type LoadResult = { - /** The path of the file imported from the source file with `@import` or `composes`. */ + /** The path of the file imported from the source file with `@import`. */ dependencies: string[]; /** The tokens exported by the source file. */ tokens: Token[]; diff --git a/packages/happy-css-modules/src/locator/postcss.test.ts b/packages/happy-css-modules/src/locator/postcss.test.ts index a6fb2949..7516f8ce 100644 --- a/packages/happy-css-modules/src/locator/postcss.test.ts +++ b/packages/happy-css-modules/src/locator/postcss.test.ts @@ -27,10 +27,6 @@ describe('generateLocalTokenNames', () => { .local_class_name_3 {} } :local(.local_class_name_4) {} - .composes_target {} - .composes { - composes: composes_target; - } `), ), ).toStrictEqual([ @@ -50,8 +46,6 @@ describe('generateLocalTokenNames', () => { 'local_class_name_2', 'local_class_name_3', 'local_class_name_4', - 'composes_target', - 'composes', ]); }); test('does not track styles imported by @import in other file because it is not a local token', async () => { @@ -224,23 +218,6 @@ describe('getOriginalLocation', () => { `{ filePath: "/test/test.css", start: { line: 6, column: 8 }, end: { line: 6, column: 26 } }`, ); }); - test('composes', () => { - // eslint-disable-next-line @typescript-eslint/naming-convention - const [composes_target, composes] = createClassSelectors( - createRoot(dedent` - .composes_target {} - .composes { - composes: composes_target; - } - `), - ); - expect(getOriginalLocation(composes_target!.rule, composes_target!.classSelector)).toMatchInlineSnapshot( - `{ filePath: "/test/test.css", start: { line: 1, column: 1 }, end: { line: 1, column: 16 } }`, - ); - expect(getOriginalLocation(composes!.rule, composes!.classSelector)).toMatchInlineSnapshot( - `{ filePath: "/test/test.css", start: { line: 2, column: 1 }, end: { line: 2, column: 9 } }`, - ); - }); test('with_newline', () => { // eslint-disable-next-line @typescript-eslint/naming-convention const [with_newline_1, with_newline_2, with_newline_3] = createClassSelectors( @@ -268,8 +245,8 @@ test('collectNodes', () => { @import; @import "test.css"; @ignored; - .a { ignored: "ignored"; composes: a; } - .b { ignored: "ignored"; composes: b; } + .a { ignored: "ignored"; } + .b { ignored: "ignored"; } `); const { atImports, classSelectors } = collectNodes(ast); @@ -278,9 +255,9 @@ test('collectNodes', () => { expect(atImports[0]!.toString()).toEqual('@import'); expect(atImports[1]!.toString()).toEqual('@import "test.css"'); expect(classSelectors).toHaveLength(2); - expect(classSelectors[0]!.rule.toString()).toEqual('.a { ignored: "ignored"; composes: a; }'); + expect(classSelectors[0]!.rule.toString()).toEqual('.a { ignored: "ignored"; }'); expect(classSelectors[0]!.classSelector.toString()).toEqual('.a'); - expect(classSelectors[1]!.rule.toString()).toEqual('.b { ignored: "ignored"; composes: b; }'); + expect(classSelectors[1]!.rule.toString()).toEqual('.b { ignored: "ignored"; }'); expect(classSelectors[1]!.classSelector.toString()).toEqual('.b'); }); diff --git a/packages/happy-css-modules/src/locator/postcss.ts b/packages/happy-css-modules/src/locator/postcss.ts index 679bdcb6..a718d0fd 100644 --- a/packages/happy-css-modules/src/locator/postcss.ts +++ b/packages/happy-css-modules/src/locator/postcss.ts @@ -54,9 +54,9 @@ export async function generateLocalTokenNames(ast: Root): Promise { postcss .default() // postcss-modules collects tokens (i.e., includes external tokens) by following - // the dependencies specified in the @import and composes properties. + // the dependencies specified in the @import. // However, we do not want `generateLocalTokenNames` to return external tokens. - // So we remove the @import and composes properties beforehand. + // So we remove the @import beforehand. .use(removeDependenciesPlugin()) .use( modules({ diff --git a/packages/happy-css-modules/src/transformer/less-transformer.test.ts b/packages/happy-css-modules/src/transformer/less-transformer.test.ts index 1bc52b7a..76682ac4 100644 --- a/packages/happy-css-modules/src/transformer/less-transformer.test.ts +++ b/packages/happy-css-modules/src/transformer/less-transformer.test.ts @@ -23,8 +23,6 @@ test('handles less features', async () => { &_2 { dummy: ''; } .b_1(); .b_2(); - composes: a_1; // css module feature test (composes) - composes: c from './3.less'; // css module feature test (composes from other file) } `, '/test/2.less': dedent` diff --git a/packages/happy-css-modules/src/transformer/scss-transformer.test.ts b/packages/happy-css-modules/src/transformer/scss-transformer.test.ts index d5efc260..41525be4 100644 --- a/packages/happy-css-modules/src/transformer/scss-transformer.test.ts +++ b/packages/happy-css-modules/src/transformer/scss-transformer.test.ts @@ -22,8 +22,6 @@ test('handles sass features', async () => { // sass feature test (nesting) .a_2_1 { dummy: ''; } &_2 { dummy: ''; } - composes: a_1; // css module feature test (composes) - composes: d from './4.scss'; // css module feature test (composes from other file) } `, '/test/2.scss': dedent`