-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
237 additions
and
104 deletions.
There are no files selected for viewing
Binary file not shown.
6 changes: 1 addition & 5 deletions
6
packages/babel-plugin/__tests__/fixtures/inject-global-style/output.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,4 @@ | ||
import { create as _create, props as _props } from "@stylexjs/stylex"; | ||
import { injectGlobalStyle } from "@stylex-extend/core"; | ||
import { expression } from "./expression.stylex"; | ||
export const styles = injectGlobalStyle({ | ||
html: { | ||
fontSize: expression.font, | ||
}, | ||
}); | ||
export const styles = ""; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import fs from 'fs' | ||
import { parseSync, traverse } from '@babel/core' | ||
import { types } from '@babel/core' | ||
import type { NodePath } from '@babel/core' | ||
import { Context, matchesFileSuffix } from '../state-context' | ||
import { getStringValue } from './jsx-attribute' | ||
|
||
const STYLEX_EXTEND = '@stylex-extend/core' | ||
|
||
function isTopLevelCalled(p: NodePath) { | ||
return types.isProgram(p.parent) || types.isExportDefaultDeclaration(p.parent) || types.isExportNamedDeclaration(p.parent) | ||
} | ||
|
||
export function scanImportStmt(stmts: NodePath<types.Statement>[], ctx: Context) { | ||
const matchers = matchesFileSuffix(ctx.options.unstable_moduleResolution.themeFileExtension!) | ||
for (const stmt of stmts) { | ||
if (!stmt.isImportDeclaration()) continue | ||
if (stmt.node.source.value === STYLEX_EXTEND || matchers(stmt.node.source.value)) { | ||
const specs = stmt.node.specifiers.filter((s) => s.type === 'ImportSpecifier') as types.ImportSpecifier[] | ||
if (stmt.node.source.value === STYLEX_EXTEND) { | ||
ctx.addImports(specs.map((s) => s.local.name)) | ||
} else { | ||
const [filePath, fileName] = ctx.importPathResolver(stmt.node.source.value) | ||
const codeContent = fs.readFileSync(filePath, 'utf-8') | ||
const ast = parseSync(codeContent, { babelrc: true }) | ||
const seens = new Set<string>(specs.map((s) => getStringValue(s.imported))) | ||
traverse(ast!, { | ||
VariableDeclaration(path) { | ||
if (isTopLevelCalled(path)) { | ||
const { node } = path | ||
for (const decl of node.declarations) { | ||
if (types.isIdentifier(decl.id) && seens.has(decl.id.name)) { | ||
const varId = decl.id.name | ||
ctx.fileNamesForHashing.set(decl.id.name, { fileName, exportName: varId }) | ||
} | ||
} | ||
} | ||
path.skip() | ||
} | ||
}) | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export { transformStylexAttrs } from './jsx-attribute' | ||
export { transformInjectGlobalStyle } from './global-style' | ||
export { scanImportStmt } from './import-stmt' |
Oops, something went wrong.