Skip to content

Commit

Permalink
fix: handle boolean state as well
Browse files Browse the repository at this point in the history
  • Loading branch information
idoros committed Jul 13, 2023
1 parent a9ba758 commit e9461bf
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 20 deletions.
15 changes: 9 additions & 6 deletions packages/core/src/helpers/custom-state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -861,10 +861,7 @@ export function transformPseudoClassToCustomState(
diagnostics: Diagnostics,
selectorNode?: postcss.Node
) {
if (stateDef === null) {
convertToClass(stateNode).value = createBooleanStateClassName(name, namespace);
delete stateNode.nodes;
} else if (typeof stateDef === 'string') {
if (stateDef === null || typeof stateDef === 'string') {
if (stateNode.nodes && selectorNode) {
diagnostics.report(
stateDiagnostics.NO_PARAM_REQUIRED(name, stringifySelector(stateNode.nodes)),
Expand All @@ -874,8 +871,14 @@ export function transformPseudoClassToCustomState(
}
);
}
// simply concat global mapped selector - ToDo: maybe change to 'selector'
convertToInvalid(stateNode).value = stateDef;
if (stateDef === null) {
// boolean
convertToClass(stateNode).value = createBooleanStateClassName(name, namespace);
} else {
// static template selector
// simply concat global mapped selector - ToDo: maybe change to 'selector'
convertToInvalid(stateNode).value = stateDef;
}
delete stateNode.nodes;
} else if (typeof stateDef === 'object') {
if (isTemplateState(stateDef)) {
Expand Down
44 changes: 30 additions & 14 deletions packages/core/test/features/css-pseudo-class.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,24 +34,40 @@ describe('features/css-pseudo-class', () => {
});
describe('st-custom-state', () => {
it('should transform boolean state', () => {
const { sheets } = testStylableCore(`
.root {
/* @transform-remove(removed decl) */
-st-states: bool,
exBool(boolean);
}
const { sheets } = testStylableCore({
'/valid.st.css': `
.root {
/* @transform-remove(removed decl) */
-st-states: bool,
exBool(boolean);
}
/* @rule(boolean) .entry__root.entry--bool */
.root:bool {}
/* @rule(boolean) .valid__root.valid--bool */
.root:bool {}
/* @rule(explicit boolean) .entry__root.entry--exBool */
.root:exBool {}
/* @rule(explicit boolean) .valid__root.valid--exBool */
.root:exBool {}
/* @rule(nested) .entry__root:not(.entry--bool) */
.root:not(:bool) {}
`);
/* @rule(nested) .valid__root:not(.valid--bool) */
.root:not(:bool) {}
`,
'/invalid.st.css': `
.root {
-st-states: bool;
}
/*
@transform-error ${stCustomStateDiagnostics.NO_PARAM_REQUIRED(
'bool',
'unknown-param'
)}
@rule .invalid__root.invalid--bool
*/
.root:bool(unknown-param) {}
`,
});

const { meta } = sheets['/entry.st.css'];
const { meta } = sheets['/valid.st.css'];
shouldReportNoDiagnostics(meta);
});
describe('string parameter', () => {
Expand Down

0 comments on commit e9461bf

Please sign in to comment.