Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(core): css-custom-property feature overall #2216

Merged
merged 23 commits into from
Jan 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
5553e90
empty `css-custom-property` feature file to open the PR
idoros Dec 21, 2021
e7f06c0
Merge branch 'master' of github.com:wix/stylable into ido/css-custom-…
idoros Jan 10, 2022
c249470
chore: init `css-custom-property` feature
idoros Jan 10, 2022
498c3a8
refactor: `validate-at-property.ts` -> `helpers/css-custom-property.ts`
idoros Jan 10, 2022
3067265
refactor: processor `css-custom-property` feature extract
idoros Jan 10, 2022
4deced9
refactor: extract helpers
idoros Jan 10, 2022
b5ddb8f
refactor: move more code from processor to feature
idoros Jan 10, 2022
e088a45
refactor: transformer `css-custom-property` feature extract
idoros Jan 10, 2022
648230b
refactor: move transform value `var()` to feature
idoros Jan 10, 2022
7ea1051
refactor: `--X: ` declaration prop transform to feature
idoros Jan 10, 2022
e38fe8a
Merge branch 'master' of github.com:wix/stylable into ido/css-custom-…
idoros Jan 16, 2022
f596744
test: move tests from `css-vars.spec` to feature spec
idoros Jan 16, 2022
f61a55e
test: move more tests to feature spec
idoros Jan 16, 2022
495482f
test: add expectations for symbols & exports
idoros Jan 17, 2022
f7a04f3
test: move `at-property.spec` -> feature spec
idoros Jan 18, 2022
ea9d2f9
fix(core-test-kit): fix parse of multiline diagnostic expectation
idoros Jan 19, 2022
67ea1b5
refactor: reorder and cleanups
idoros Jan 19, 2022
7f120e8
chore: deprecate `meta.cssVars`
idoros Jan 19, 2022
8b5eda4
test: fix `scopeCSSVar` unit test
idoros Jan 19, 2022
8d7113a
fix: empty `var()` crush
idoros Jan 19, 2022
a235be6
fix: empty keyframes name crush
idoros Jan 19, 2022
02760af
chore: fix review comments
idoros Jan 23, 2022
df4946e
Merge branch 'master' of github.com:wix/stylable into ido/css-custom-…
idoros Jan 23, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions packages/cli/src/base-generator.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { IFileSystem } from '@file-services/types';
import type { Stylable } from '@stylable/core';
import { CSSKeyframes } from '@stylable/core/dist/features';
import { STSymbol } from '@stylable/core/dist/features';
import camelcase from 'lodash.camelcase';
import upperfirst from 'lodash.upperfirst';
import { basename, relative } from 'path';
Expand Down Expand Up @@ -108,17 +108,19 @@ export function reExportsAllSymbols(filePath: string, generator: IndexGenerator)
acc[name] = `${rootExport}__${name}`;
return acc;
}, {});
const vars = Object.keys(meta.cssVars).reduce<Record<string, string>>((acc, varName) => {
acc[varName] = `--${rootExport}__${varName.slice(2)}`;
return acc;
}, {});
const keyframes = Object.keys(CSSKeyframes.getAll(meta)).reduce<Record<string, string>>(
(acc, keyframe) => {
acc[keyframe] = `${rootExport}__${keyframe}`;
const vars = Object.keys(STSymbol.getAllByType(meta, `cssVar`)).reduce<Record<string, string>>(
(acc, varName) => {
acc[varName] = `--${rootExport}__${varName.slice(2)}`;
return acc;
},
{}
);
const keyframes = Object.keys(STSymbol.getAllByType(meta, `keyframes`)).reduce<
Record<string, string>
>((acc, keyframe) => {
acc[keyframe] = `${rootExport}__${keyframe}`;
return acc;
}, {});
return {
root: rootExport,
classes,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
import {
CSSVarSymbol,
Diagnostics,
isCSSVarProp,
paramMapping,
processorWarnings,
} from '@stylable/core';
import { CSSVarSymbol, Diagnostics, isCSSVarProp } from '@stylable/core';
import { CSSCustomProperty } from '@stylable/core/dist/features';
import type { AtRule } from 'postcss';
import type { CodeMod } from './types';

Expand All @@ -18,7 +13,7 @@ export const stGlobalCustomPropertyToAtProperty: CodeMod = ({ ast, diagnostics,
atRule.before(
postcss.atRule({
name: 'property',
params: `${paramMapping.global}(${property.name})`,
params: `st-global(${property.name})`,
})
);
}
Expand All @@ -41,9 +36,13 @@ function parseStGlobalCustomProperty(atRule: AtRule, diagnostics: Diagnostics):
.filter((s) => s !== ',');

if (cssVarsBySpacing.length > cssVarsByComma.length) {
diagnostics.warn(atRule, processorWarnings.GLOBAL_CSS_VAR_MISSING_COMMA(atRule.params), {
word: atRule.params,
});
diagnostics.warn(
atRule,
CSSCustomProperty.diagnostics.GLOBAL_CSS_VAR_MISSING_COMMA(atRule.params),
{
word: atRule.params,
}
);
return cssVars;
}

Expand All @@ -55,9 +54,10 @@ function parseStGlobalCustomProperty(atRule: AtRule, diagnostics: Diagnostics):
_kind: 'cssVar',
name: cssVar,
global: true,
alias: undefined,
});
} else {
diagnostics.warn(atRule, processorWarnings.ILLEGAL_GLOBAL_CSS_VAR(cssVar), {
diagnostics.warn(atRule, CSSCustomProperty.diagnostics.ILLEGAL_GLOBAL_CSS_VAR(cssVar), {
word: cssVar,
});
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { processorWarnings } from '@stylable/core';
import { CSSCustomProperty } from '@stylable/core/dist/features';
import { expect } from 'chai';
import { createTempDirectory, ITempDirectory } from 'create-temp-directory';
import { populateDirectorySync, loadDirSync, runCliCodeMod } from '@stylable/e2e-test-kit';
Expand Down Expand Up @@ -68,7 +68,7 @@ describe('CLI Codemods st-global-custom-property-to-at-property', () => {

expect(stdout).to.match(
new RegExp(
`style.st.css: ${processorWarnings.GLOBAL_CSS_VAR_MISSING_COMMA(
`style.st.css: ${CSSCustomProperty.diagnostics.GLOBAL_CSS_VAR_MISSING_COMMA(
'--myVar --mySecondVar'
)}`
)
Expand Down
2 changes: 1 addition & 1 deletion packages/core-test-kit/src/inline-expectation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ function diagnosticTest(
errors: [],
};
const matchResult = expectation.match(
/-(?<severity>\w+)(?<label>\([^)]*\))?\s?(?:word\((?<word>[^)]*)\))?\s?(?<message>.*)/
/-(?<severity>\w+)(?<label>\([^)]*\))?\s?(?:word\((?<word>[^)]*)\))?\s?(?<message>[\s\S]*)/
);
if (!matchResult) {
result.errors.push(testInlineExpectsErrors.diagnosticsMalformed(type, expectation));
Expand Down
17 changes: 15 additions & 2 deletions packages/core-test-kit/test/inline-expectations.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -651,8 +651,15 @@ describe('inline-expectations', () => {
'/style.st.css': {
namespace: 'entry',
content: `
/* @analyze-warn ${CSSType.diagnostics.UNSCOPED_TYPE_SELECTOR(`div`)} */
/* @analyze-warn(1 line) ${CSSType.diagnostics.UNSCOPED_TYPE_SELECTOR(
`div`
)} */
div {}

/* @analyze-warn(multi line) word(span)
${CSSType.diagnostics.UNSCOPED_TYPE_SELECTOR(`span`)}
*/
span {}
`,
},
},
Expand Down Expand Up @@ -935,11 +942,17 @@ describe('inline-expectations', () => {
@st-import [unknown] from './other.st.css';

.root {
/* @transform-error ${CSSClass.diagnostics.CANNOT_EXTEND_UNKNOWN_SYMBOL(
/* @transform-error(1 line) ${CSSClass.diagnostics.CANNOT_EXTEND_UNKNOWN_SYMBOL(
`unknown`
)}*/
-st-extends: unknown;
}

.part {
/* @transform-error(multi line)
${CSSClass.diagnostics.CANNOT_EXTEND_UNKNOWN_SYMBOL(`unknown`)}*/
-st-extends: unknown;
}
`,
},
'/other.st.css': {
Expand Down
Loading