From f3a8d6699f067b5fb03fb1b73729dcd27c14f34b Mon Sep 17 00:00:00 2001 From: Ido Rosenthal Date: Thu, 28 Sep 2023 18:44:03 +0300 Subject: [PATCH 1/3] feat!: disallow complex global mapping --- packages/core/src/features/css-class.ts | 14 ++++++++++++++ packages/core/test/features/css-class.spec.ts | 17 +++++++---------- 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/packages/core/src/features/css-class.ts b/packages/core/src/features/css-class.ts index f9e33cc63..acff7f24e 100644 --- a/packages/core/src/features/css-class.ts +++ b/packages/core/src/features/css-class.ts @@ -99,6 +99,11 @@ export const diagnostics = { 'error', () => `unsupported multi selector in -st-global` ), + UNSUPPORTED_COMPLEX_SELECTOR: createDiagnosticReporter( + '00010', + 'error', + () => `unsupported complex selector` + ), IMPORT_ISNT_EXTENDABLE: createDiagnosticReporter( '00005', 'error', @@ -663,6 +668,15 @@ function parseStGlobal( context.diagnostics.report(diagnostics.UNSUPPORTED_MULTI_SELECTORS_ST_GLOBAL(), { node: decl, }); + } else { + for (const node of selector[0].nodes) { + if (node.type === 'combinator') { + context.diagnostics.report(diagnostics.UNSUPPORTED_COMPLEX_SELECTOR(), { + node: decl, + }); + return; + } + } } return selector[0].nodes; } diff --git a/packages/core/test/features/css-class.spec.ts b/packages/core/test/features/css-class.spec.ts index a6cb97bb7..43b02660c 100644 --- a/packages/core/test/features/css-class.spec.ts +++ b/packages/core/test/features/css-class.spec.ts @@ -147,12 +147,6 @@ describe(`features/css-class`, () => { /* @transform-remove */ -st-global: "[attr=val]"; } - - /* @rule(complex) .y .z */ - .d { - /* @transform-remove */ - -st-global: ".y .z"; - } /* @rule(not only classes compound) .yy[attr] */ .e { @@ -176,9 +170,6 @@ describe(`features/css-class`, () => { expect(CSSClass.get(meta, `c`), `c symbol`).to.contain({ name: 'c', }); - expect(CSSClass.get(meta, `d`), `d symbol`).to.contain({ - name: 'd', - }); expect(CSSClass.get(meta, `e`), `e symbol`).to.contain({ name: 'e', }); @@ -188,7 +179,6 @@ describe(`features/css-class`, () => { x: true, z: true, zz: true, - y: true, yy: true, }); @@ -213,6 +203,12 @@ describe(`features/css-class`, () => { /* @analyze-error(multi) ${classDiagnostics.UNSUPPORTED_MULTI_SELECTORS_ST_GLOBAL()} */ -st-global: ".y , .z"; } + + /* @rule(complex) .entry__c */ + .c { + /* @analyze-error(complex) ${classDiagnostics.UNSUPPORTED_COMPLEX_SELECTOR()} */ + -st-global: ".y .z"; + } `); const { meta, exports } = sheets['/entry.st.css']; @@ -225,6 +221,7 @@ describe(`features/css-class`, () => { // JS exports expect(exports.classes.a, `a (empty) JS export`).to.eql(`entry__a`); expect(exports.classes.b, `b (multi) JS export`).to.eql(`y`); + expect(exports.classes.c, `c (complex) JS export`).to.eql(`entry__c`); }); it(`should escape`, () => { const { sheets } = testStylableCore( From 2bc9b348121b99da1aaf16f02f6299801ecc4a89 Mon Sep 17 00:00:00 2001 From: Ido Rosenthal Date: Thu, 28 Sep 2023 18:44:52 +0300 Subject: [PATCH 2/3] feat!: no transform or global for multi selector --- packages/core/src/features/css-class.ts | 1 + packages/core/test/features/css-class.spec.ts | 8 +++----- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/packages/core/src/features/css-class.ts b/packages/core/src/features/css-class.ts index acff7f24e..ae9fcabf2 100644 --- a/packages/core/src/features/css-class.ts +++ b/packages/core/src/features/css-class.ts @@ -668,6 +668,7 @@ function parseStGlobal( context.diagnostics.report(diagnostics.UNSUPPORTED_MULTI_SELECTORS_ST_GLOBAL(), { node: decl, }); + return; } else { for (const node of selector[0].nodes) { if (node.type === 'combinator') { diff --git a/packages/core/test/features/css-class.spec.ts b/packages/core/test/features/css-class.spec.ts index 43b02660c..ed091870c 100644 --- a/packages/core/test/features/css-class.spec.ts +++ b/packages/core/test/features/css-class.spec.ts @@ -198,7 +198,7 @@ describe(`features/css-class`, () => { -st-global: ""; } - /* @rule(empty) .y */ + /* @rule(multi) .entry__b */ .b { /* @analyze-error(multi) ${classDiagnostics.UNSUPPORTED_MULTI_SELECTORS_ST_GLOBAL()} */ -st-global: ".y , .z"; @@ -214,13 +214,11 @@ describe(`features/css-class`, () => { const { meta, exports } = sheets['/entry.st.css']; // meta.globals - expect(meta.globals).to.eql({ - y: true, - }); + expect(meta.globals).to.eql({}); // JS exports expect(exports.classes.a, `a (empty) JS export`).to.eql(`entry__a`); - expect(exports.classes.b, `b (multi) JS export`).to.eql(`y`); + expect(exports.classes.b, `b (multi) JS export`).to.eql(`entry__b`); expect(exports.classes.c, `c (complex) JS export`).to.eql(`entry__c`); }); it(`should escape`, () => { From b41981e043d2b88f4b2c8a991e65a0fa35c9fa0c Mon Sep 17 00:00:00 2001 From: Ido Rosenthal Date: Thu, 28 Sep 2023 19:23:17 +0300 Subject: [PATCH 3/3] fix: broken test --- packages/core/test/stylable-transformer/global.spec.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/core/test/stylable-transformer/global.spec.ts b/packages/core/test/stylable-transformer/global.spec.ts index 734cf4d7a..32e4e2bcb 100644 --- a/packages/core/test/stylable-transformer/global.spec.ts +++ b/packages/core/test/stylable-transformer/global.spec.ts @@ -13,7 +13,7 @@ describe('Stylable postcss transform (Global)', () => { @st-import [test] from './imported.st.css'; .root {} .test {} - .x { -st-global: '.a .b'; } + .x { -st-global: '.a.b'; } :global(.c .d) {} :global(.e) {} `, @@ -38,7 +38,7 @@ describe('Stylable postcss transform (Global)', () => { e: true, }); expect((meta.targetAst!.nodes[1] as postcss.Rule).selector).to.equal('.global-test'); - expect((meta.targetAst!.nodes[2] as postcss.Rule).selector).to.equal('.a .b'); + expect((meta.targetAst!.nodes[2] as postcss.Rule).selector).to.equal('.a.b'); expect((meta.targetAst!.nodes[3] as postcss.Rule).selector).to.equal('.c .d'); expect((meta.targetAst!.nodes[4] as postcss.Rule).selector).to.equal('.e'); });