@vanilla-extract/babel-plugin-debug-ids
Advanced tools
Comparing version 1.0.0 to 1.0.1
@@ -1,2 +0,11 @@ | ||
export * from "./declarations/src/index"; | ||
export { default } from "./declarations/src/index"; | ||
import { PluginObj, PluginPass } from '@babel/core'; | ||
declare const styleFunctions: readonly [...("style" | "createTheme" | "styleVariants" | "fontFace" | "keyframes" | "createVar" | "recipe" | "createContainer")[], "globalStyle", "createGlobalTheme", "createThemeContract", "globalFontFace", "globalKeyframes", "recipe"]; | ||
type StyleFunction = typeof styleFunctions[number]; | ||
type Context = PluginPass & { | ||
namespaceImport: string; | ||
importIdentifiers: Map<string, StyleFunction>; | ||
}; | ||
declare function export_default(): PluginObj<Context>; | ||
export { export_default as default }; |
@@ -16,3 +16,6 @@ 'use strict'; | ||
styleVariants: { | ||
maxParams: 3 | ||
maxParams: 3, | ||
hasDebugId: ({ | ||
arguments: args | ||
}) => core.types.isStringLiteral(args.at(-1)) || core.types.isTemplateLiteral(args.at(-1)) | ||
}, | ||
@@ -36,3 +39,2 @@ fontFace: { | ||
const styleFunctions = [...Object.keys(debuggableFunctionConfig), 'globalStyle', 'createGlobalTheme', 'createThemeContract', 'globalFontFace', 'globalKeyframes', 'recipe']; | ||
const extractName = node => { | ||
@@ -49,3 +51,2 @@ if (core.types.isObjectProperty(node) && core.types.isIdentifier(node.key)) { | ||
}; | ||
const getDebugId = path => { | ||
@@ -55,6 +56,7 @@ const firstRelevantParentPath = path.findParent(({ | ||
}) => !(core.types.isCallExpression(node) || core.types.isSequenceExpression(node))); | ||
if (!firstRelevantParentPath) { | ||
return; | ||
} // Special case: Handle `export const [themeClass, vars] = createTheme({});` | ||
} | ||
// Special case: Handle `export const [themeClass, vars] = createTheme({});` | ||
// when it's already been compiled into this: | ||
@@ -66,7 +68,4 @@ // | ||
// vars = _createTheme2[1]; | ||
if (core.types.isVariableDeclaration(firstRelevantParentPath.parent) && firstRelevantParentPath.parent.declarations.length === 4) { | ||
const [themeDeclarator,, classNameDeclarator] = firstRelevantParentPath.parent.declarations; | ||
if (core.types.isCallExpression(themeDeclarator.init) && core.types.isIdentifier(themeDeclarator.init.callee, { | ||
@@ -78,5 +77,3 @@ name: 'createTheme' | ||
} | ||
const relevantParent = firstRelevantParentPath.node; | ||
if (core.types.isObjectProperty(relevantParent) || core.types.isReturnStatement(relevantParent) || core.types.isArrowFunctionExpression(relevantParent) || core.types.isArrayExpression(relevantParent) || core.types.isSpreadElement(relevantParent)) { | ||
@@ -88,8 +85,6 @@ const names = []; | ||
const name = extractName(node); | ||
if (name) { | ||
names.unshift(name); | ||
} // Traverse all the way to the root | ||
} | ||
// Traverse all the way to the root | ||
return false; | ||
@@ -102,3 +97,2 @@ }); | ||
}; | ||
const getRelevantCall = (node, namespaceImport, importIdentifiers) => { | ||
@@ -108,3 +102,2 @@ const { | ||
} = node; | ||
if (namespaceImport && core.types.isMemberExpression(callee) && core.types.isIdentifier(callee.object, { | ||
@@ -120,3 +113,2 @@ name: namespaceImport | ||
})); | ||
if (importInfo) { | ||
@@ -127,3 +119,2 @@ return importInfo[1]; | ||
}; | ||
function index () { | ||
@@ -135,3 +126,2 @@ return { | ||
}, | ||
visitor: { | ||
@@ -149,3 +139,2 @@ ImportDeclaration(path) { | ||
const importName = core.types.isIdentifier(imported) ? imported.name : imported.value; | ||
if (styleFunctions.includes(importName)) { | ||
@@ -158,3 +147,2 @@ this.importIdentifiers.set(local.name, importName); | ||
}, | ||
CallExpression(path) { | ||
@@ -165,7 +153,9 @@ const { | ||
const usedExport = getRelevantCall(node, this.namespaceImport, this.importIdentifiers); | ||
if (usedExport && usedExport in debuggableFunctionConfig) { | ||
if (node.arguments.length < debuggableFunctionConfig[usedExport].maxParams) { | ||
const { | ||
maxParams, | ||
hasDebugId | ||
} = debuggableFunctionConfig[usedExport]; | ||
if (node.arguments.length < maxParams && !(hasDebugId !== null && hasDebugId !== void 0 && hasDebugId(node))) { | ||
const debugIdent = getDebugId(path); | ||
if (debugIdent) { | ||
@@ -177,3 +167,2 @@ node.arguments.push(core.types.stringLiteral(debugIdent)); | ||
} | ||
} | ||
@@ -180,0 +169,0 @@ }; |
@@ -16,3 +16,6 @@ 'use strict'; | ||
styleVariants: { | ||
maxParams: 3 | ||
maxParams: 3, | ||
hasDebugId: ({ | ||
arguments: args | ||
}) => core.types.isStringLiteral(args.at(-1)) || core.types.isTemplateLiteral(args.at(-1)) | ||
}, | ||
@@ -36,3 +39,2 @@ fontFace: { | ||
const styleFunctions = [...Object.keys(debuggableFunctionConfig), 'globalStyle', 'createGlobalTheme', 'createThemeContract', 'globalFontFace', 'globalKeyframes', 'recipe']; | ||
const extractName = node => { | ||
@@ -49,3 +51,2 @@ if (core.types.isObjectProperty(node) && core.types.isIdentifier(node.key)) { | ||
}; | ||
const getDebugId = path => { | ||
@@ -55,6 +56,7 @@ const firstRelevantParentPath = path.findParent(({ | ||
}) => !(core.types.isCallExpression(node) || core.types.isSequenceExpression(node))); | ||
if (!firstRelevantParentPath) { | ||
return; | ||
} // Special case: Handle `export const [themeClass, vars] = createTheme({});` | ||
} | ||
// Special case: Handle `export const [themeClass, vars] = createTheme({});` | ||
// when it's already been compiled into this: | ||
@@ -66,7 +68,4 @@ // | ||
// vars = _createTheme2[1]; | ||
if (core.types.isVariableDeclaration(firstRelevantParentPath.parent) && firstRelevantParentPath.parent.declarations.length === 4) { | ||
const [themeDeclarator,, classNameDeclarator] = firstRelevantParentPath.parent.declarations; | ||
if (core.types.isCallExpression(themeDeclarator.init) && core.types.isIdentifier(themeDeclarator.init.callee, { | ||
@@ -78,5 +77,3 @@ name: 'createTheme' | ||
} | ||
const relevantParent = firstRelevantParentPath.node; | ||
if (core.types.isObjectProperty(relevantParent) || core.types.isReturnStatement(relevantParent) || core.types.isArrowFunctionExpression(relevantParent) || core.types.isArrayExpression(relevantParent) || core.types.isSpreadElement(relevantParent)) { | ||
@@ -88,8 +85,6 @@ const names = []; | ||
const name = extractName(node); | ||
if (name) { | ||
names.unshift(name); | ||
} // Traverse all the way to the root | ||
} | ||
// Traverse all the way to the root | ||
return false; | ||
@@ -102,3 +97,2 @@ }); | ||
}; | ||
const getRelevantCall = (node, namespaceImport, importIdentifiers) => { | ||
@@ -108,3 +102,2 @@ const { | ||
} = node; | ||
if (namespaceImport && core.types.isMemberExpression(callee) && core.types.isIdentifier(callee.object, { | ||
@@ -120,3 +113,2 @@ name: namespaceImport | ||
})); | ||
if (importInfo) { | ||
@@ -127,3 +119,2 @@ return importInfo[1]; | ||
}; | ||
function index () { | ||
@@ -135,3 +126,2 @@ return { | ||
}, | ||
visitor: { | ||
@@ -149,3 +139,2 @@ ImportDeclaration(path) { | ||
const importName = core.types.isIdentifier(imported) ? imported.name : imported.value; | ||
if (styleFunctions.includes(importName)) { | ||
@@ -158,3 +147,2 @@ this.importIdentifiers.set(local.name, importName); | ||
}, | ||
CallExpression(path) { | ||
@@ -165,7 +153,9 @@ const { | ||
const usedExport = getRelevantCall(node, this.namespaceImport, this.importIdentifiers); | ||
if (usedExport && usedExport in debuggableFunctionConfig) { | ||
if (node.arguments.length < debuggableFunctionConfig[usedExport].maxParams) { | ||
const { | ||
maxParams, | ||
hasDebugId | ||
} = debuggableFunctionConfig[usedExport]; | ||
if (node.arguments.length < maxParams && !(hasDebugId !== null && hasDebugId !== void 0 && hasDebugId(node))) { | ||
const debugIdent = getDebugId(path); | ||
if (debugIdent) { | ||
@@ -177,3 +167,2 @@ node.arguments.push(core.types.stringLiteral(debugIdent)); | ||
} | ||
} | ||
@@ -180,0 +169,0 @@ }; |
@@ -12,3 +12,6 @@ import { types } from '@babel/core'; | ||
styleVariants: { | ||
maxParams: 3 | ||
maxParams: 3, | ||
hasDebugId: ({ | ||
arguments: args | ||
}) => types.isStringLiteral(args.at(-1)) || types.isTemplateLiteral(args.at(-1)) | ||
}, | ||
@@ -32,3 +35,2 @@ fontFace: { | ||
const styleFunctions = [...Object.keys(debuggableFunctionConfig), 'globalStyle', 'createGlobalTheme', 'createThemeContract', 'globalFontFace', 'globalKeyframes', 'recipe']; | ||
const extractName = node => { | ||
@@ -45,3 +47,2 @@ if (types.isObjectProperty(node) && types.isIdentifier(node.key)) { | ||
}; | ||
const getDebugId = path => { | ||
@@ -51,6 +52,7 @@ const firstRelevantParentPath = path.findParent(({ | ||
}) => !(types.isCallExpression(node) || types.isSequenceExpression(node))); | ||
if (!firstRelevantParentPath) { | ||
return; | ||
} // Special case: Handle `export const [themeClass, vars] = createTheme({});` | ||
} | ||
// Special case: Handle `export const [themeClass, vars] = createTheme({});` | ||
// when it's already been compiled into this: | ||
@@ -62,7 +64,4 @@ // | ||
// vars = _createTheme2[1]; | ||
if (types.isVariableDeclaration(firstRelevantParentPath.parent) && firstRelevantParentPath.parent.declarations.length === 4) { | ||
const [themeDeclarator,, classNameDeclarator] = firstRelevantParentPath.parent.declarations; | ||
if (types.isCallExpression(themeDeclarator.init) && types.isIdentifier(themeDeclarator.init.callee, { | ||
@@ -74,5 +73,3 @@ name: 'createTheme' | ||
} | ||
const relevantParent = firstRelevantParentPath.node; | ||
if (types.isObjectProperty(relevantParent) || types.isReturnStatement(relevantParent) || types.isArrowFunctionExpression(relevantParent) || types.isArrayExpression(relevantParent) || types.isSpreadElement(relevantParent)) { | ||
@@ -84,8 +81,6 @@ const names = []; | ||
const name = extractName(node); | ||
if (name) { | ||
names.unshift(name); | ||
} // Traverse all the way to the root | ||
} | ||
// Traverse all the way to the root | ||
return false; | ||
@@ -98,3 +93,2 @@ }); | ||
}; | ||
const getRelevantCall = (node, namespaceImport, importIdentifiers) => { | ||
@@ -104,3 +98,2 @@ const { | ||
} = node; | ||
if (namespaceImport && types.isMemberExpression(callee) && types.isIdentifier(callee.object, { | ||
@@ -116,3 +109,2 @@ name: namespaceImport | ||
})); | ||
if (importInfo) { | ||
@@ -123,3 +115,2 @@ return importInfo[1]; | ||
}; | ||
function index () { | ||
@@ -131,3 +122,2 @@ return { | ||
}, | ||
visitor: { | ||
@@ -145,3 +135,2 @@ ImportDeclaration(path) { | ||
const importName = types.isIdentifier(imported) ? imported.name : imported.value; | ||
if (styleFunctions.includes(importName)) { | ||
@@ -154,3 +143,2 @@ this.importIdentifiers.set(local.name, importName); | ||
}, | ||
CallExpression(path) { | ||
@@ -161,7 +149,9 @@ const { | ||
const usedExport = getRelevantCall(node, this.namespaceImport, this.importIdentifiers); | ||
if (usedExport && usedExport in debuggableFunctionConfig) { | ||
if (node.arguments.length < debuggableFunctionConfig[usedExport].maxParams) { | ||
const { | ||
maxParams, | ||
hasDebugId | ||
} = debuggableFunctionConfig[usedExport]; | ||
if (node.arguments.length < maxParams && !(hasDebugId !== null && hasDebugId !== void 0 && hasDebugId(node))) { | ||
const debugIdent = getDebugId(path); | ||
if (debugIdent) { | ||
@@ -173,3 +163,2 @@ node.arguments.push(types.stringLiteral(debugIdent)); | ||
} | ||
} | ||
@@ -176,0 +165,0 @@ }; |
{ | ||
"name": "@vanilla-extract/babel-plugin-debug-ids", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "Zero-runtime Stylesheets-in-TypeScript", | ||
@@ -17,3 +17,3 @@ "main": "dist/vanilla-extract-babel-plugin-debug-ids.cjs.js", | ||
"type": "git", | ||
"url": "https://github.com/seek-oss/vanilla-extract.git", | ||
"url": "https://github.com/vanilla-extract-css/vanilla-extract.git", | ||
"directory": "packages/babel-plugin-debug-ids" | ||
@@ -24,7 +24,7 @@ }, | ||
"dependencies": { | ||
"@babel/core": "^7.13.10" | ||
"@babel/core": "^7.20.7" | ||
}, | ||
"devDependencies": { | ||
"@types/babel__core": "^7.1.19" | ||
"@types/babel__core": "^7.1.20" | ||
} | ||
} |
@@ -37,3 +37,3 @@ # π§ vanilla-extract | ||
π₯ [Try it out for yourself in CodeSandbox.](https://codesandbox.io/s/github/seek-oss/vanilla-extract/tree/master/examples/webpack-react?file=/src/App.css.ts) | ||
π₯ [Try it out for yourself in CodeSandbox.](https://codesandbox.io/s/github/vanilla-extract-css/vanilla-extract/tree/master/examples/webpack-react?file=/src/App.css.ts) | ||
@@ -40,0 +40,0 @@ --- |
21398
466
8
Updated@babel/core@^7.20.7