-
Notifications
You must be signed in to change notification settings - Fork 221
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
feat: Allow stencil modifiers-in-selectors #2741
Changes from all commits
48b19a1
bdf13d9
07fe9b8
18fa1a3
bfbf744
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,7 +20,8 @@ export interface StyleTransformerOptions extends TransformerContext { | |
transformers?: NodeTransformer[]; | ||
} | ||
|
||
let vars: TransformerContext['variables'] = {}; | ||
let vars: TransformerContext['names'] = {}; | ||
let extractedNames: TransformerContext['extractedNames'] = {}; | ||
Comment on lines
+23
to
+24
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
For example: const foo = createStencil({
modifiers: {
size: {
small: {},
large: {}
}
}
})
const bar = createStencil({
base: {
// The type of `foo.modifiers.size.small` is `string` which the static
// transform doesn't like. It will now be added to `names` so that
// static resolution uses the actual class name
[`.${foo.modifiers.size.small} :where(&)`]: {
}
}
}) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
let styles: TransformerContext['styles'] = {}; | ||
let cache: TransformerContext['cache'] = {}; | ||
let loadedFallbacks = false; | ||
|
@@ -32,6 +33,7 @@ let config: Config = {}; | |
*/ | ||
export function _reset() { | ||
vars = {}; | ||
extractedNames = {}; | ||
styles = {}; | ||
cache = {}; | ||
loadedFallbacks = false; | ||
|
@@ -63,7 +65,7 @@ export default function styleTransformer( | |
configLoaded = true; | ||
} | ||
|
||
const {variables, ...transformContext} = withDefaultContext(program.getTypeChecker(), { | ||
const {names, ...transformContext} = withDefaultContext(program.getTypeChecker(), { | ||
...config, | ||
...options, | ||
}); | ||
|
@@ -83,8 +85,10 @@ export default function styleTransformer( | |
const fallbackVars = getVariablesFromFiles(files); | ||
console.log(`Found ${Object.keys(fallbackVars).length} variables.`); | ||
|
||
// eslint-disable-next-line no-param-reassign | ||
vars = {...variables, ...fallbackVars}; | ||
// eslint-disable-next-line guard-for-in | ||
for (const key in fallbackVars) { | ||
names[key] = fallbackVars[key]; | ||
} | ||
Comment on lines
+88
to
+91
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a bug where passing in |
||
loadedFallbacks = true; | ||
} | ||
|
||
|
@@ -108,7 +112,7 @@ export default function styleTransformer( | |
} | ||
|
||
const newNode = transformContext.transform(node, { | ||
variables: vars, | ||
names, | ||
...transformContext, | ||
}); | ||
|
||
|
@@ -126,7 +130,8 @@ export function withDefaultContext( | |
return { | ||
prefix: 'css', | ||
getPrefix: path => input.prefix || 'css', | ||
variables: {}, | ||
names: vars, | ||
extractedNames, | ||
styles, | ||
cache, | ||
checker, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The build process automates the syncing of these version strings.