@tamagui/static 1.0.1-beta.68 → 1.0.1-beta.71
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/extractor/createEvaluator.js +1 -1
- package/dist/cjs/extractor/createEvaluator.js.map +2 -2
- package/dist/cjs/extractor/createExtractor.js +227 -115
- package/dist/cjs/extractor/createExtractor.js.map +2 -2
- package/dist/cjs/extractor/extractToClassNames.js +17 -31
- package/dist/cjs/extractor/extractToClassNames.js.map +2 -2
- package/dist/cjs/index.js +1 -1
- package/dist/cjs/index.js.map +2 -2
- package/dist/cjs/types.js.map +1 -1
- package/dist/esm/extractor/createEvaluator.js +1 -1
- package/dist/esm/extractor/createEvaluator.js.map +2 -2
- package/dist/esm/extractor/createExtractor.js +232 -119
- package/dist/esm/extractor/createExtractor.js.map +2 -2
- package/dist/esm/extractor/extractToClassNames.js +17 -31
- package/dist/esm/extractor/extractToClassNames.js.map +2 -2
- package/dist/esm/index.js +1 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/jsx/extractor/createEvaluator.js +1 -1
- package/dist/jsx/extractor/createExtractor.js +232 -119
- package/dist/jsx/extractor/extractToClassNames.js +17 -31
- package/dist/jsx/index.js +1 -1
- package/package.json +19 -13
- package/src/extractor/createEvaluator.ts +2 -1
- package/src/extractor/createExtractor.ts +356 -161
- package/src/extractor/extractToClassNames.ts +20 -50
- package/src/index.ts +1 -1
- package/src/types.ts +6 -8
- package/types/constants.d.ts +0 -0
- package/types/constants.d.ts.map +0 -0
- package/types/extractor/accessSafe.d.ts +0 -0
- package/types/extractor/accessSafe.d.ts.map +0 -0
- package/types/extractor/babelParse.d.ts +0 -0
- package/types/extractor/babelParse.d.ts.map +0 -0
- package/types/extractor/buildClassName.d.ts +0 -0
- package/types/extractor/buildClassName.d.ts.map +0 -0
- package/types/extractor/createEvaluator.d.ts +1 -1
- package/types/extractor/createEvaluator.d.ts.map +1 -1
- package/types/extractor/createExtractor.d.ts +2 -1
- package/types/extractor/createExtractor.d.ts.map +1 -1
- package/types/extractor/ensureImportingConcat.d.ts +0 -0
- package/types/extractor/ensureImportingConcat.d.ts.map +0 -0
- package/types/extractor/evaluateAstNode.d.ts +0 -0
- package/types/extractor/evaluateAstNode.d.ts.map +0 -0
- package/types/extractor/extractHelpers.d.ts +0 -0
- package/types/extractor/extractHelpers.d.ts.map +0 -0
- package/types/extractor/extractMediaStyle.d.ts +0 -0
- package/types/extractor/extractMediaStyle.d.ts.map +0 -0
- package/types/extractor/extractToClassNames.d.ts +1 -6
- package/types/extractor/extractToClassNames.d.ts.map +1 -1
- package/types/extractor/findTopmostFunction.d.ts +0 -0
- package/types/extractor/findTopmostFunction.d.ts.map +0 -0
- package/types/extractor/generatedUid.d.ts +0 -0
- package/types/extractor/generatedUid.d.ts.map +0 -0
- package/types/extractor/getPrefixLogs.d.ts +0 -0
- package/types/extractor/getPrefixLogs.d.ts.map +0 -0
- package/types/extractor/getPropValueFromAttributes.d.ts +0 -0
- package/types/extractor/getPropValueFromAttributes.d.ts.map +0 -0
- package/types/extractor/getSourceModule.d.ts +0 -0
- package/types/extractor/getSourceModule.d.ts.map +0 -0
- package/types/extractor/getStaticBindingsForScope.d.ts +0 -0
- package/types/extractor/getStaticBindingsForScope.d.ts.map +0 -0
- package/types/extractor/hoistClassNames.d.ts +0 -0
- package/types/extractor/hoistClassNames.d.ts.map +0 -0
- package/types/extractor/literalToAst.d.ts +0 -0
- package/types/extractor/literalToAst.d.ts.map +0 -0
- package/types/extractor/loadTamagui.d.ts +0 -0
- package/types/extractor/loadTamagui.d.ts.map +0 -0
- package/types/extractor/logLines.d.ts +0 -0
- package/types/extractor/logLines.d.ts.map +0 -0
- package/types/extractor/normalizeTernaries.d.ts +0 -0
- package/types/extractor/normalizeTernaries.d.ts.map +0 -0
- package/types/extractor/removeUnusedHooks.d.ts +0 -0
- package/types/extractor/removeUnusedHooks.d.ts.map +0 -0
- package/types/extractor/timer.d.ts +0 -0
- package/types/extractor/timer.d.ts.map +0 -0
- package/types/extractor/validHTMLAttributes.d.ts +0 -0
- package/types/extractor/validHTMLAttributes.d.ts.map +0 -0
- package/types/index.d.ts +1 -1
- package/types/index.d.ts.map +1 -1
- package/types/types.d.ts +4 -7
- package/types/types.d.ts.map +1 -1
- package/dist/cjs/patchReactNativeWeb.js +0 -167
- package/dist/cjs/patchReactNativeWeb.js.map +0 -7
- package/dist/esm/patchReactNativeWeb.js +0 -142
- package/dist/esm/patchReactNativeWeb.js.map +0 -7
- package/dist/jsx/patchReactNativeWeb.js +0 -141
- package/src/patchReactNativeWeb.ts +0 -165
- package/types/patchReactNativeWeb.d.ts +0 -2
- package/types/patchReactNativeWeb.d.ts.map +0 -1
|
@@ -41,7 +41,7 @@ function createEvaluator({
|
|
|
41
41
|
shouldPrintDebug
|
|
42
42
|
}) {
|
|
43
43
|
const evalFn = /* @__PURE__ */ __name((n) => {
|
|
44
|
-
if (t.isMemberExpression(n) && t.isIdentifier(n.property) && (0, import_extractHelpers.isValidThemeHook)(traversePath, n, sourcePath)) {
|
|
44
|
+
if (t.isMemberExpression(n) && t.isIdentifier(n.property) && traversePath && (0, import_extractHelpers.isValidThemeHook)(traversePath, n, sourcePath)) {
|
|
45
45
|
const key = n.property.name;
|
|
46
46
|
if (shouldPrintDebug) {
|
|
47
47
|
console.log(" > found theme prop", key);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/extractor/createEvaluator.ts"],
|
|
4
|
-
"sourcesContent": ["import vm from 'vm'\n\nimport generate from '@babel/generator'\nimport { NodePath } from '@babel/traverse'\nimport * as t from '@babel/types'\nimport type { TamaguiConfig } from '@tamagui/core'\nimport { createCSSVariable } from '@tamagui/core-node'\nimport esbuild from 'esbuild'\n\nimport { FAILED_EVAL } from '../constants'\nimport { evaluateAstNode } from './evaluateAstNode'\nimport { isValidThemeHook } from './extractHelpers'\n\nexport function createEvaluator({\n tamaguiConfig,\n staticNamespace,\n sourcePath,\n traversePath,\n shouldPrintDebug,\n}: {\n tamaguiConfig: TamaguiConfig\n staticNamespace: Record<string, any>\n sourcePath: string\n traversePath
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,gBAAe;AAEf,uBAAqB;AAErB,QAAmB;AAEnB,uBAAkC;AAClC,qBAAoB;AAEpB,uBAA4B;AAC5B,6BAAgC;AAChC,4BAAiC;AAE1B,yBAAyB;AAAA,EAC9B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,GAOC;AAED,QAAM,SAAS,wBAAC,MAAc;AAE5B,QACE,EAAE,mBAAmB,CAAC,KACtB,EAAE,aAAa,EAAE,QAAQ,KACzB,4CAAiB,cAAc,GAAG,UAAU,GAC5C;AACA,YAAM,MAAM,EAAE,SAAS;AACvB,UAAI,kBAAkB;AACpB,gBAAQ,IAAI,0BAA0B,GAAG;AAAA,MAC3C;AACA,cAAQ,IAAI,kCAAkC,GAAG;AAIjD,aAAO,wCAAkB,GAAG;AAAA,IAC9B;AAEA,QAAI,EAAE,aAAa,CAAC,KAAK,gBAAgB,eAAe,EAAE,IAAI,GAAG;AAC/D,aAAO,gBAAgB,EAAE;AAAA,IAC3B;AACA,UAAM,cAAc,kBAAG,cAAc,eAAe;AACpD,UAAM,gCAAgC,IAAI,8BAAS,CAAQ,EAAE;AAC7D,UAAM,OAAO,uBACV,cAAc,+BAA+B,EAAE,QAAQ,MAAM,CAAC,EAC9D,KAAK,QAAQ,QAAQ,EAAE;AAE1B,QAAI,kBAAkB;AACpB,cAAQ,IAAI,cAAc,IAAI;AAAA,IAChC;AACA,WAAO,kBAAG,aAAa,MAAM,WAAW;AAAA,EAC1C,
|
|
4
|
+
"sourcesContent": ["import vm from 'vm'\n\nimport generate from '@babel/generator'\nimport { NodePath } from '@babel/traverse'\nimport * as t from '@babel/types'\nimport type { TamaguiConfig } from '@tamagui/core'\nimport { createCSSVariable } from '@tamagui/core-node'\nimport esbuild from 'esbuild'\n\nimport { FAILED_EVAL } from '../constants'\nimport { evaluateAstNode } from './evaluateAstNode'\nimport { isValidThemeHook } from './extractHelpers'\n\nexport function createEvaluator({\n tamaguiConfig,\n staticNamespace,\n sourcePath,\n traversePath,\n shouldPrintDebug,\n}: {\n tamaguiConfig: TamaguiConfig\n staticNamespace: Record<string, any>\n sourcePath: string\n traversePath?: NodePath<t.JSXElement>\n shouldPrintDebug: boolean | 'verbose'\n}) {\n // called when evaluateAstNode encounters a dynamic-looking prop\n const evalFn = (n: t.Node) => {\n // themes\n if (\n t.isMemberExpression(n) &&\n t.isIdentifier(n.property) &&\n traversePath &&\n isValidThemeHook(traversePath, n, sourcePath)\n ) {\n const key = n.property.name\n if (shouldPrintDebug) {\n console.log(' > found theme prop', key)\n }\n console.log('SHOULD FIND THEME (NESTED NOW)', key) // tamaguiConfig.themes)\n // if (!themeKeys.has(key)) {\n // throw new Error(` > accessing non-existent theme key: ${key}`)\n // }\n return createCSSVariable(key)\n }\n // variable\n if (t.isIdentifier(n) && staticNamespace.hasOwnProperty(n.name)) {\n return staticNamespace[n.name]\n }\n const evalContext = vm.createContext(staticNamespace)\n const codeWithTypescriptAnnotations = `(${generate(n as any).code})`\n const code = esbuild\n .transformSync(codeWithTypescriptAnnotations, { loader: 'tsx' })\n .code.replace(/;\\n$/, '')\n\n if (shouldPrintDebug) {\n console.log('evaluating', code)\n }\n return vm.runInContext(code, evalContext)\n }\n\n return (n: t.Node) => {\n return evaluateAstNode(n, evalFn)\n }\n}\n\nexport function createSafeEvaluator(attemptEval: (n: t.Node) => any) {\n return (n: t.Node) => {\n try {\n return attemptEval(n)\n } catch (err) {\n return FAILED_EVAL\n }\n }\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,gBAAe;AAEf,uBAAqB;AAErB,QAAmB;AAEnB,uBAAkC;AAClC,qBAAoB;AAEpB,uBAA4B;AAC5B,6BAAgC;AAChC,4BAAiC;AAE1B,yBAAyB;AAAA,EAC9B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,GAOC;AAED,QAAM,SAAS,wBAAC,MAAc;AAE5B,QACE,EAAE,mBAAmB,CAAC,KACtB,EAAE,aAAa,EAAE,QAAQ,KACzB,gBACA,4CAAiB,cAAc,GAAG,UAAU,GAC5C;AACA,YAAM,MAAM,EAAE,SAAS;AACvB,UAAI,kBAAkB;AACpB,gBAAQ,IAAI,0BAA0B,GAAG;AAAA,MAC3C;AACA,cAAQ,IAAI,kCAAkC,GAAG;AAIjD,aAAO,wCAAkB,GAAG;AAAA,IAC9B;AAEA,QAAI,EAAE,aAAa,CAAC,KAAK,gBAAgB,eAAe,EAAE,IAAI,GAAG;AAC/D,aAAO,gBAAgB,EAAE;AAAA,IAC3B;AACA,UAAM,cAAc,kBAAG,cAAc,eAAe;AACpD,UAAM,gCAAgC,IAAI,8BAAS,CAAQ,EAAE;AAC7D,UAAM,OAAO,uBACV,cAAc,+BAA+B,EAAE,QAAQ,MAAM,CAAC,EAC9D,KAAK,QAAQ,QAAQ,EAAE;AAE1B,QAAI,kBAAkB;AACpB,cAAQ,IAAI,cAAc,IAAI;AAAA,IAChC;AACA,WAAO,kBAAG,aAAa,MAAM,WAAW;AAAA,EAC1C,GAhCe;AAkCf,SAAO,CAAC,MAAc;AACpB,WAAO,4CAAgB,GAAG,MAAM;AAAA,EAClC;AACF;AAnDgB;AAqDT,6BAA6B,aAAiC;AACnE,SAAO,CAAC,MAAc;AACpB,QAAI;AACF,aAAO,YAAY,CAAC;AAAA,IACtB,SAAS,KAAP;AACA,aAAO;AAAA,IACT;AAAA,EACF;AACF;AARgB;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -99,6 +99,11 @@ function createExtractor() {
|
|
|
99
99
|
const shouldAddDebugProp = !process.env.npm_package_dependencies_next && process.env.TAMAGUI_TARGET !== "native" && process.env.IDENTIFY_TAGS !== "false" && (process.env.NODE_ENV === "development" || process.env.DEBUG || process.env.IDENTIFY_TAGS);
|
|
100
100
|
let loadedTamaguiConfig;
|
|
101
101
|
let hasLogged = false;
|
|
102
|
+
function isValidStyleKey(name, staticConfig) {
|
|
103
|
+
var _a;
|
|
104
|
+
return !!(!!((_a = staticConfig.validStyles) == null ? void 0 : _a[name]) || !!import_core_node.pseudos[name] || loadedTamaguiConfig.shorthands[name] || (name[0] === "$" ? !!import_core_node.mediaQueryConfig[name.slice(1)] : false));
|
|
105
|
+
}
|
|
106
|
+
__name(isValidStyleKey, "isValidStyleKey");
|
|
102
107
|
return {
|
|
103
108
|
getTamagui() {
|
|
104
109
|
return loadedTamaguiConfig;
|
|
@@ -111,12 +116,14 @@ function createExtractor() {
|
|
|
111
116
|
shouldPrintDebug = false,
|
|
112
117
|
sourcePath = "",
|
|
113
118
|
onExtractTag,
|
|
119
|
+
onStyleRule,
|
|
114
120
|
getFlattenedNode,
|
|
115
121
|
disable,
|
|
116
122
|
disableExtraction,
|
|
117
123
|
disableExtractInlineMedia,
|
|
118
124
|
disableExtractVariables,
|
|
119
125
|
disableDebugAttr,
|
|
126
|
+
extractStyledDefinitions,
|
|
120
127
|
prefixLogs,
|
|
121
128
|
excludeProps,
|
|
122
129
|
target
|
|
@@ -127,12 +134,14 @@ function createExtractor() {
|
|
|
127
134
|
"shouldPrintDebug",
|
|
128
135
|
"sourcePath",
|
|
129
136
|
"onExtractTag",
|
|
137
|
+
"onStyleRule",
|
|
130
138
|
"getFlattenedNode",
|
|
131
139
|
"disable",
|
|
132
140
|
"disableExtraction",
|
|
133
141
|
"disableExtractInlineMedia",
|
|
134
142
|
"disableExtractVariables",
|
|
135
143
|
"disableDebugAttr",
|
|
144
|
+
"extractStyledDefinitions",
|
|
136
145
|
"prefixLogs",
|
|
137
146
|
"excludeProps",
|
|
138
147
|
"target"
|
|
@@ -189,6 +198,16 @@ function createExtractor() {
|
|
|
189
198
|
continue;
|
|
190
199
|
const node = "node" in bodyPath ? bodyPath.node : bodyPath;
|
|
191
200
|
const from = node.source.value;
|
|
201
|
+
if (extractStyledDefinitions) {
|
|
202
|
+
if (from === "@tamagui/core" || from === "tamagui") {
|
|
203
|
+
if (node.specifiers.some((specifier) => {
|
|
204
|
+
return specifier.local.name === "styled";
|
|
205
|
+
})) {
|
|
206
|
+
doesUseValidImport = true;
|
|
207
|
+
break;
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
}
|
|
192
211
|
const isValidImport = props.components.includes(from) || isInternalImport(from);
|
|
193
212
|
if (isValidImport) {
|
|
194
213
|
const isValidComponent = node.specifiers.some((specifier) => {
|
|
@@ -219,6 +238,7 @@ function createExtractor() {
|
|
|
219
238
|
}, "callTraverse");
|
|
220
239
|
let programPath;
|
|
221
240
|
const res = {
|
|
241
|
+
styled: 0,
|
|
222
242
|
flattened: 0,
|
|
223
243
|
optimized: 0,
|
|
224
244
|
modified: 0,
|
|
@@ -230,8 +250,88 @@ function createExtractor() {
|
|
|
230
250
|
programPath = path;
|
|
231
251
|
}
|
|
232
252
|
},
|
|
253
|
+
CallExpression(path) {
|
|
254
|
+
if (disable || disableExtraction) {
|
|
255
|
+
return;
|
|
256
|
+
}
|
|
257
|
+
if (!t.isIdentifier(path.node.callee) || path.node.callee.name !== "styled") {
|
|
258
|
+
return;
|
|
259
|
+
}
|
|
260
|
+
const name = t.isVariableDeclarator(path.parent) && t.isIdentifier(path.parent.id) ? path.parent.id.name : "unknown";
|
|
261
|
+
const definition = path.node.arguments[1];
|
|
262
|
+
if (!name || !definition || !t.isObjectExpression(definition)) {
|
|
263
|
+
return;
|
|
264
|
+
}
|
|
265
|
+
const Component = validComponents[name];
|
|
266
|
+
if (!Component) {
|
|
267
|
+
if (shouldPrintDebug) {
|
|
268
|
+
console.log(`Didn't recognize styled(${name}), ${name} isn't in design system provided to tamagui.config.ts`);
|
|
269
|
+
}
|
|
270
|
+
return;
|
|
271
|
+
}
|
|
272
|
+
const componentSkipProps = /* @__PURE__ */ new Set([
|
|
273
|
+
...Component.staticConfig.inlineWhenUnflattened || [],
|
|
274
|
+
...Component.staticConfig.inlineProps || [],
|
|
275
|
+
...Component.staticConfig.deoptProps || []
|
|
276
|
+
]);
|
|
277
|
+
const skipped = [];
|
|
278
|
+
const styles = {};
|
|
279
|
+
const skipProps = {
|
|
280
|
+
variants: true,
|
|
281
|
+
defaultVariants: true,
|
|
282
|
+
name: true
|
|
283
|
+
};
|
|
284
|
+
const staticNamespace = (0, import_getStaticBindingsForScope.getStaticBindingsForScope)(path.scope, importsWhitelist, sourcePath, bindingCache, shouldPrintDebug);
|
|
285
|
+
const attemptEval = !evaluateVars ? import_evaluateAstNode.evaluateAstNode : (0, import_createEvaluator.createEvaluator)({
|
|
286
|
+
tamaguiConfig,
|
|
287
|
+
staticNamespace,
|
|
288
|
+
sourcePath,
|
|
289
|
+
shouldPrintDebug
|
|
290
|
+
});
|
|
291
|
+
const attemptEvalSafe = (0, import_createEvaluator.createSafeEvaluator)(attemptEval);
|
|
292
|
+
for (const property of definition.properties) {
|
|
293
|
+
if (!t.isObjectProperty(property) || !t.isIdentifier(property.key) || skipProps[property.key.name] || !isValidStyleKey(property.key.name, Component.staticConfig) || componentSkipProps.has(property.key.name)) {
|
|
294
|
+
skipped.push(property);
|
|
295
|
+
continue;
|
|
296
|
+
}
|
|
297
|
+
const out2 = attemptEvalSafe(property.value);
|
|
298
|
+
if (out2 === import_constants.FAILED_EVAL) {
|
|
299
|
+
skipped.push(property);
|
|
300
|
+
} else {
|
|
301
|
+
styles[property.key.name] = out2;
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
const out = (0, import_core_node.getSplitStyles)(styles, Component.staticConfig, defaultTheme, {
|
|
305
|
+
focus: false,
|
|
306
|
+
hover: false,
|
|
307
|
+
mounted: false,
|
|
308
|
+
press: false,
|
|
309
|
+
pressIn: false,
|
|
310
|
+
resolveVariablesAs: "variable"
|
|
311
|
+
});
|
|
312
|
+
const classNames = __spreadValues({}, out.classNames);
|
|
313
|
+
const atomics = (0, import_core_node.getStylesAtomic)(out.style);
|
|
314
|
+
for (const atomic of atomics) {
|
|
315
|
+
for (const rule of atomic.rules) {
|
|
316
|
+
out.rulesToInsert.push([atomic.identifier, rule]);
|
|
317
|
+
}
|
|
318
|
+
classNames[atomic.property] = atomic.identifier;
|
|
319
|
+
}
|
|
320
|
+
definition.properties = skipped;
|
|
321
|
+
for (const cn in classNames) {
|
|
322
|
+
const val = classNames[cn];
|
|
323
|
+
definition.properties.push(t.objectProperty(t.stringLiteral(cn), t.stringLiteral(val)));
|
|
324
|
+
}
|
|
325
|
+
for (const [identifier, rule] of out.rulesToInsert) {
|
|
326
|
+
onStyleRule == null ? void 0 : onStyleRule(identifier, [rule]);
|
|
327
|
+
}
|
|
328
|
+
res.styled++;
|
|
329
|
+
if (shouldPrintDebug) {
|
|
330
|
+
console.log(`Extracted styled(${name}) props:`, styles);
|
|
331
|
+
}
|
|
332
|
+
},
|
|
233
333
|
JSXElement(traversePath) {
|
|
234
|
-
var _a2, _b2, _c;
|
|
334
|
+
var _a2, _b2, _c, _d, _e;
|
|
235
335
|
tm.mark("jsx-element", shouldPrintDebug === "verbose");
|
|
236
336
|
const node = traversePath.node.openingElement;
|
|
237
337
|
const ogAttributes = node.attributes;
|
|
@@ -273,10 +373,7 @@ function createExtractor() {
|
|
|
273
373
|
shouldPrintDebug = debugPropValue;
|
|
274
374
|
}
|
|
275
375
|
try {
|
|
276
|
-
let
|
|
277
|
-
var _a3;
|
|
278
|
-
return !!(!!validStyles[name] || !!import_core_node.pseudos[name] || ((_a3 = staticConfig.variants) == null ? void 0 : _a3[name]) || tamaguiConfig.shorthands[name] || (name[0] === "$" ? !!import_core_node.mediaQueryConfig[name.slice(1)] : false));
|
|
279
|
-
}, evaluateAttribute = function(path) {
|
|
376
|
+
let evaluateAttribute = function(path) {
|
|
280
377
|
const attribute = path.node;
|
|
281
378
|
const attr = { type: "attr", value: attribute };
|
|
282
379
|
if (t.isJSXSpreadAttribute(attribute)) {
|
|
@@ -399,36 +496,35 @@ function createExtractor() {
|
|
|
399
496
|
return attr;
|
|
400
497
|
}
|
|
401
498
|
const styleValue = attemptEvalSafe(value);
|
|
402
|
-
if (!isValidStyleKey(name)) {
|
|
499
|
+
if (!variants[name] && !isValidStyleKey(name, staticConfig)) {
|
|
403
500
|
let keys = [name];
|
|
404
501
|
let out = null;
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
if (out) {
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
out = Object.fromEntries(out);
|
|
414
|
-
}
|
|
415
|
-
}
|
|
416
|
-
if (out) {
|
|
417
|
-
if (isTargetingHTML) {
|
|
418
|
-
out = import_core_node.rnw.createDOMProps(isTextView ? "span" : "div", out);
|
|
419
|
-
delete out.className;
|
|
420
|
-
}
|
|
502
|
+
out = staticConfig.propMapper(name, styleValue, defaultTheme, staticConfig.defaultProps, { resolveVariablesAs: "auto" }, void 0, shouldPrintDebug);
|
|
503
|
+
if (out) {
|
|
504
|
+
if (!Array.isArray(out)) {
|
|
505
|
+
console.warn(`Error expected array but got`, out);
|
|
506
|
+
couldntParse = true;
|
|
507
|
+
shouldDeopt = true;
|
|
508
|
+
} else {
|
|
509
|
+
out = Object.fromEntries(out);
|
|
421
510
|
keys = Object.keys(out);
|
|
422
511
|
}
|
|
423
512
|
}
|
|
513
|
+
if (out) {
|
|
514
|
+
if (isTargetingHTML) {
|
|
515
|
+
out = import_core_node.rnw.createDOMProps(isTextView ? "span" : "div", out);
|
|
516
|
+
delete out.className;
|
|
517
|
+
}
|
|
518
|
+
keys = Object.keys(out);
|
|
519
|
+
}
|
|
424
520
|
let didInline = false;
|
|
425
521
|
const attributes = keys.map((key) => {
|
|
426
522
|
const val = out[key];
|
|
427
|
-
if (isValidStyleKey(key)) {
|
|
523
|
+
if (isValidStyleKey(key, staticConfig)) {
|
|
428
524
|
return {
|
|
429
525
|
type: "style",
|
|
430
|
-
value: { [
|
|
431
|
-
name,
|
|
526
|
+
value: { [key]: styleValue },
|
|
527
|
+
name: key,
|
|
432
528
|
attr: path.node
|
|
433
529
|
};
|
|
434
530
|
}
|
|
@@ -454,7 +550,7 @@ function createExtractor() {
|
|
|
454
550
|
if (inlineWhenUnflattened.has(name)) {
|
|
455
551
|
inlineWhenUnflattenedOGVals[name] = { styleValue, attr };
|
|
456
552
|
}
|
|
457
|
-
if (isValidStyleKey(name)) {
|
|
553
|
+
if (isValidStyleKey(name, staticConfig)) {
|
|
458
554
|
if (shouldPrintDebug) {
|
|
459
555
|
console.log(` style: ${name} =`, styleValue);
|
|
460
556
|
}
|
|
@@ -471,6 +567,9 @@ function createExtractor() {
|
|
|
471
567
|
attr: path.node
|
|
472
568
|
};
|
|
473
569
|
} else {
|
|
570
|
+
if (variants[name]) {
|
|
571
|
+
variantValues.set(name, styleValue);
|
|
572
|
+
}
|
|
474
573
|
inlined.set(name, true);
|
|
475
574
|
return attr;
|
|
476
575
|
}
|
|
@@ -595,7 +694,7 @@ function createExtractor() {
|
|
|
595
694
|
return false;
|
|
596
695
|
}
|
|
597
696
|
const propName = prop.key["name"];
|
|
598
|
-
if (!isValidStyleKey(propName) && propName !== "tag") {
|
|
697
|
+
if (!isValidStyleKey(propName, staticConfig) && propName !== "tag") {
|
|
599
698
|
if (shouldPrintDebug) {
|
|
600
699
|
console.log(" not a valid style prop!", propName);
|
|
601
700
|
}
|
|
@@ -695,7 +794,6 @@ function createExtractor() {
|
|
|
695
794
|
}
|
|
696
795
|
}
|
|
697
796
|
};
|
|
698
|
-
__name(isValidStyleKey, "isValidStyleKey");
|
|
699
797
|
__name(evaluateAttribute, "evaluateAttribute");
|
|
700
798
|
__name(isExtractable, "isExtractable");
|
|
701
799
|
__name(createTernariesFromObjectProperties, "createTernariesFromObjectProperties");
|
|
@@ -713,14 +811,16 @@ function createExtractor() {
|
|
|
713
811
|
}
|
|
714
812
|
const shouldLog = !hasLogged;
|
|
715
813
|
if (shouldLog) {
|
|
814
|
+
console.log(` 1\uFE0F\u20E3 Inline optimized 2\uFE0F\u20E3 Inline flattened 3\uFE0F\u20E3 styled() extracted`);
|
|
716
815
|
const prefix = " |";
|
|
717
|
-
console.log(prefixLogs || prefix, "
|
|
816
|
+
console.log(prefixLogs || prefix, " total \xB7 1\uFE0F\u20E3 \xB7 2\uFE0F\u20E3 \xB7 3\uFE0F\u20E3");
|
|
718
817
|
hasLogged = true;
|
|
719
818
|
}
|
|
720
819
|
if (disableExtraction) {
|
|
721
820
|
return;
|
|
722
821
|
}
|
|
723
822
|
const { staticConfig } = component;
|
|
823
|
+
const variants = staticConfig.variants || {};
|
|
724
824
|
const isTextView = staticConfig.isText || false;
|
|
725
825
|
const validStyles = (staticConfig == null ? void 0 : staticConfig.validStyles) ?? {};
|
|
726
826
|
let tagName = ((_a2 = staticConfig.defaultProps) == null ? void 0 : _a2.tag) ?? (isTextView ? "span" : "div");
|
|
@@ -803,26 +903,10 @@ function createExtractor() {
|
|
|
803
903
|
}
|
|
804
904
|
tm.mark("jsx-element-flattened", shouldPrintDebug === "verbose");
|
|
805
905
|
node.attributes = flattenedAttrs;
|
|
806
|
-
if (staticConfig.defaultProps) {
|
|
807
|
-
for (const key in staticConfig.defaultProps) {
|
|
808
|
-
if (isValidStyleKey(key)) {
|
|
809
|
-
continue;
|
|
810
|
-
}
|
|
811
|
-
const serialize = require("babel-literal-to-ast");
|
|
812
|
-
const val = staticConfig.defaultProps[key];
|
|
813
|
-
try {
|
|
814
|
-
const serializedDefaultProp = serialize(val);
|
|
815
|
-
node.attributes.unshift(t.jsxAttribute(t.jsxIdentifier(key), typeof val === "string" ? t.stringLiteral(val) : t.jsxExpressionContainer(serializedDefaultProp)));
|
|
816
|
-
} catch (err) {
|
|
817
|
-
console.warn(`\u26A0\uFE0F Error evaluating default prop for component ${node.name.name}, prop ${key}
|
|
818
|
-
error: ${err}
|
|
819
|
-
value:`, val, "\n defaultProps:", staticConfig.defaultProps);
|
|
820
|
-
}
|
|
821
|
-
}
|
|
822
|
-
}
|
|
823
906
|
let attrs = [];
|
|
824
907
|
let shouldDeopt = false;
|
|
825
908
|
const inlined = /* @__PURE__ */ new Map();
|
|
909
|
+
const variantValues = /* @__PURE__ */ new Map();
|
|
826
910
|
let hasSetOptimized = false;
|
|
827
911
|
const inlineWhenUnflattenedOGVals = {};
|
|
828
912
|
attrs = traversePath.get("openingElement").get("attributes").flatMap((path) => {
|
|
@@ -896,10 +980,14 @@ function createExtractor() {
|
|
|
896
980
|
const hasOnlyStringChildren = !hasSpread && (node.selfClosing || traversePath.node.children && traversePath.node.children.every((x) => x.type === "JSXText"));
|
|
897
981
|
let themeVal = inlined.get("theme");
|
|
898
982
|
inlined.delete("theme");
|
|
899
|
-
const
|
|
900
|
-
|
|
901
|
-
|
|
983
|
+
for (const [key] of [...inlined]) {
|
|
984
|
+
if (INLINE_EXTRACTABLE[key] || ((_b2 = staticConfig.variants) == null ? void 0 : _b2[key])) {
|
|
985
|
+
inlined.delete(key);
|
|
986
|
+
}
|
|
987
|
+
}
|
|
988
|
+
const canFlattenProps = inlined.size === 0;
|
|
902
989
|
let shouldFlatten = !shouldDeopt && canFlattenProps && !hasSpread && staticConfig.neverFlatten !== true && (staticConfig.neverFlatten === "jsx" ? hasOnlyStringChildren : true);
|
|
990
|
+
const shouldWrapTheme = shouldFlatten && themeVal;
|
|
903
991
|
if (disableExtractVariables) {
|
|
904
992
|
themeAccessListeners.add((key) => {
|
|
905
993
|
shouldFlatten = false;
|
|
@@ -909,11 +997,11 @@ function createExtractor() {
|
|
|
909
997
|
});
|
|
910
998
|
}
|
|
911
999
|
if (shouldPrintDebug) {
|
|
912
|
-
console.log(" - flatten?", (0, import_extractHelpers.objToStr)({ hasSpread, shouldDeopt, shouldFlatten, canFlattenProps,
|
|
1000
|
+
console.log(" - flatten?", (0, import_extractHelpers.objToStr)({ hasSpread, shouldDeopt, shouldFlatten, canFlattenProps, shouldWrapTheme, hasOnlyStringChildren }), "inlined", [...inlined]);
|
|
913
1001
|
}
|
|
914
|
-
if (shouldFlatten &&
|
|
1002
|
+
if (shouldFlatten && shouldWrapTheme) {
|
|
915
1003
|
if (shouldPrintDebug) {
|
|
916
|
-
console.log(" - wrapping theme",
|
|
1004
|
+
console.log(" - wrapping theme", themeVal);
|
|
917
1005
|
}
|
|
918
1006
|
attrs = attrs.filter((x) => x.type === "attr" && t.isJSXAttribute(x.value) && x.value.name.name === "theme" ? false : true);
|
|
919
1007
|
if (!hasImportedTheme) {
|
|
@@ -926,7 +1014,7 @@ function createExtractor() {
|
|
|
926
1014
|
}
|
|
927
1015
|
if (shouldFlatten && staticConfig.defaultProps) {
|
|
928
1016
|
const defaultStyleAttrs = Object.keys(staticConfig.defaultProps).flatMap((key) => {
|
|
929
|
-
if (!isValidStyleKey(key)) {
|
|
1017
|
+
if (!isValidStyleKey(key, staticConfig)) {
|
|
930
1018
|
return [];
|
|
931
1019
|
}
|
|
932
1020
|
const value = staticConfig.defaultProps[key];
|
|
@@ -956,10 +1044,10 @@ function createExtractor() {
|
|
|
956
1044
|
for (const cur of attrs) {
|
|
957
1045
|
if (cur.type === "style") {
|
|
958
1046
|
for (const key in cur.value) {
|
|
959
|
-
const shouldEnsureOverridden = !!((
|
|
1047
|
+
const shouldEnsureOverridden = !!((_c = staticConfig.ensureOverriddenProp) == null ? void 0 : _c[key]);
|
|
960
1048
|
const isSetInAttrsAlready = attrs.some((x) => x.type === "attr" && x.value.type === "JSXAttribute" && x.value.name.name === key);
|
|
961
1049
|
if (!isSetInAttrsAlready) {
|
|
962
|
-
const isVariant = !!((
|
|
1050
|
+
const isVariant = !!((_d = staticConfig.variants) == null ? void 0 : _d[cur.name || ""]);
|
|
963
1051
|
if (isVariant || shouldEnsureOverridden) {
|
|
964
1052
|
ensureOverridden[key] = true;
|
|
965
1053
|
}
|
|
@@ -972,13 +1060,84 @@ function createExtractor() {
|
|
|
972
1060
|
console.log(" - attrs (flattened): \n", (0, import_logLines.logLines)(attrs.map(import_extractHelpers.attrStr).join(", ")));
|
|
973
1061
|
console.log(" - ensureOverriden:", Object.keys(ensureOverridden).join(", "));
|
|
974
1062
|
}
|
|
1063
|
+
const state = {
|
|
1064
|
+
noClassNames: false,
|
|
1065
|
+
focus: false,
|
|
1066
|
+
hover: false,
|
|
1067
|
+
mounted: true,
|
|
1068
|
+
press: false,
|
|
1069
|
+
pressIn: false
|
|
1070
|
+
};
|
|
1071
|
+
let foundStaticProps = {};
|
|
1072
|
+
for (const key in attrs) {
|
|
1073
|
+
const cur = attrs[key];
|
|
1074
|
+
if (cur.type === "style") {
|
|
1075
|
+
(0, import_core_node.normalizeStyleObject)(cur.value);
|
|
1076
|
+
foundStaticProps = __spreadValues(__spreadValues({}, foundStaticProps), (0, import_core_node.expandStyles)(cur.value));
|
|
1077
|
+
continue;
|
|
1078
|
+
}
|
|
1079
|
+
if (cur.type === "attr") {
|
|
1080
|
+
if (t.isJSXSpreadAttribute(cur.value)) {
|
|
1081
|
+
continue;
|
|
1082
|
+
}
|
|
1083
|
+
if (!t.isJSXIdentifier(cur.value.name)) {
|
|
1084
|
+
continue;
|
|
1085
|
+
}
|
|
1086
|
+
const key2 = cur.value.name.name;
|
|
1087
|
+
const value = attemptEvalSafe(cur.value.value || t.booleanLiteral(true));
|
|
1088
|
+
if (value !== import_constants.FAILED_EVAL) {
|
|
1089
|
+
foundStaticProps = __spreadProps(__spreadValues({}, foundStaticProps), {
|
|
1090
|
+
[key2]: value
|
|
1091
|
+
});
|
|
1092
|
+
}
|
|
1093
|
+
}
|
|
1094
|
+
}
|
|
1095
|
+
const completeProps = {};
|
|
1096
|
+
for (const key in staticConfig.defaultProps) {
|
|
1097
|
+
if (!(key in foundStaticProps)) {
|
|
1098
|
+
completeProps[key] = staticConfig.defaultProps[key];
|
|
1099
|
+
}
|
|
1100
|
+
}
|
|
1101
|
+
for (const key in foundStaticProps) {
|
|
1102
|
+
completeProps[key] = foundStaticProps[key];
|
|
1103
|
+
}
|
|
975
1104
|
attrs = attrs.reduce((acc, cur) => {
|
|
976
1105
|
if (!cur)
|
|
977
1106
|
return acc;
|
|
978
1107
|
if (cur.type === "attr" && !t.isJSXSpreadAttribute(cur.value)) {
|
|
979
1108
|
if (shouldFlatten) {
|
|
980
|
-
|
|
981
|
-
|
|
1109
|
+
const name = cur.value.name.name;
|
|
1110
|
+
if (typeof name === "string") {
|
|
1111
|
+
if (name === "tag") {
|
|
1112
|
+
return acc;
|
|
1113
|
+
}
|
|
1114
|
+
if (variants[name] && variantValues.has(name)) {
|
|
1115
|
+
let out = Object.fromEntries(staticConfig.propMapper(name, variantValues.get(name), defaultTheme, completeProps, __spreadProps(__spreadValues({}, state), { resolveVariablesAs: "auto" }), void 0, shouldPrintDebug) || []);
|
|
1116
|
+
if (out && isTargetingHTML) {
|
|
1117
|
+
const cn = out.className;
|
|
1118
|
+
out = import_core_node.rnw.createDOMProps(isTextView ? "span" : "div", out);
|
|
1119
|
+
out.className = cn;
|
|
1120
|
+
}
|
|
1121
|
+
if (shouldPrintDebug) {
|
|
1122
|
+
console.log(" - expanded variant", name, out);
|
|
1123
|
+
}
|
|
1124
|
+
for (const key2 in out) {
|
|
1125
|
+
const value2 = out[key2];
|
|
1126
|
+
if (isValidStyleKey(key2, staticConfig)) {
|
|
1127
|
+
acc.push({
|
|
1128
|
+
type: "style",
|
|
1129
|
+
value: { [key2]: value2 },
|
|
1130
|
+
name: key2,
|
|
1131
|
+
attr: cur.value
|
|
1132
|
+
});
|
|
1133
|
+
} else {
|
|
1134
|
+
acc.push({
|
|
1135
|
+
type: "attr",
|
|
1136
|
+
value: t.jsxAttribute(t.jsxIdentifier(key2), t.jsxExpressionContainer(typeof value2 === "string" ? t.stringLiteral(value2) : (0, import_literalToAst.literalToAst)(value2)))
|
|
1137
|
+
});
|
|
1138
|
+
}
|
|
1139
|
+
}
|
|
1140
|
+
}
|
|
982
1141
|
}
|
|
983
1142
|
}
|
|
984
1143
|
}
|
|
@@ -1045,47 +1204,6 @@ function createExtractor() {
|
|
|
1045
1204
|
acc.push(cur);
|
|
1046
1205
|
return acc;
|
|
1047
1206
|
}, []);
|
|
1048
|
-
const state = {
|
|
1049
|
-
noClassNames: true,
|
|
1050
|
-
focus: false,
|
|
1051
|
-
hover: false,
|
|
1052
|
-
mounted: true,
|
|
1053
|
-
press: false,
|
|
1054
|
-
pressIn: false
|
|
1055
|
-
};
|
|
1056
|
-
let foundStaticProps = {};
|
|
1057
|
-
for (const key in attrs) {
|
|
1058
|
-
const cur = attrs[key];
|
|
1059
|
-
if (cur.type === "style") {
|
|
1060
|
-
(0, import_core_node.normalizeStyleObject)(cur.value);
|
|
1061
|
-
foundStaticProps = __spreadValues(__spreadValues({}, foundStaticProps), (0, import_core_node.expandStyles)(cur.value));
|
|
1062
|
-
continue;
|
|
1063
|
-
}
|
|
1064
|
-
if (cur.type === "attr") {
|
|
1065
|
-
if (t.isJSXSpreadAttribute(cur.value)) {
|
|
1066
|
-
continue;
|
|
1067
|
-
}
|
|
1068
|
-
if (!t.isJSXIdentifier(cur.value.name)) {
|
|
1069
|
-
continue;
|
|
1070
|
-
}
|
|
1071
|
-
const key2 = cur.value.name.name;
|
|
1072
|
-
const value = attemptEvalSafe(cur.value.value || t.booleanLiteral(true));
|
|
1073
|
-
if (value !== import_constants.FAILED_EVAL) {
|
|
1074
|
-
foundStaticProps = __spreadProps(__spreadValues({}, foundStaticProps), {
|
|
1075
|
-
[key2]: value
|
|
1076
|
-
});
|
|
1077
|
-
}
|
|
1078
|
-
}
|
|
1079
|
-
}
|
|
1080
|
-
const completeProps = {};
|
|
1081
|
-
for (const key in staticConfig.defaultProps) {
|
|
1082
|
-
if (!(key in foundStaticProps)) {
|
|
1083
|
-
completeProps[key] = staticConfig.defaultProps[key];
|
|
1084
|
-
}
|
|
1085
|
-
}
|
|
1086
|
-
for (const key in foundStaticProps) {
|
|
1087
|
-
completeProps[key] = foundStaticProps[key];
|
|
1088
|
-
}
|
|
1089
1207
|
if (shouldPrintDebug) {
|
|
1090
1208
|
console.log(" - attrs (combined \u{1F500}): \n", (0, import_logLines.logLines)(attrs.map(import_extractHelpers.attrStr).join(", ")));
|
|
1091
1209
|
console.log(" - defaultProps: \n", (0, import_logLines.logLines)((0, import_extractHelpers.objToStr)(staticConfig.defaultProps)));
|
|
@@ -1112,15 +1230,6 @@ function createExtractor() {
|
|
|
1112
1230
|
fallbackProps: completeProps
|
|
1113
1231
|
}), void 0, props2["debug"]);
|
|
1114
1232
|
const outStyle = __spreadValues(__spreadValues({}, out.style), out.pseudos);
|
|
1115
|
-
omitInvalidStyles(outStyle);
|
|
1116
|
-
if (shouldPrintDebug) {
|
|
1117
|
-
console.log(` getStyles ${debugName} (props):
|
|
1118
|
-
`, (0, import_logLines.logLines)((0, import_extractHelpers.objToStr)(props2)));
|
|
1119
|
-
console.log(` getStyles ${debugName} (out.viewProps):
|
|
1120
|
-
`, (0, import_logLines.logLines)((0, import_extractHelpers.objToStr)(out.viewProps)));
|
|
1121
|
-
console.log(` getStyles ${debugName} (out.style):
|
|
1122
|
-
`, (0, import_logLines.logLines)((0, import_extractHelpers.objToStr)(outStyle || {}), true));
|
|
1123
|
-
}
|
|
1124
1233
|
return outStyle;
|
|
1125
1234
|
} catch (err) {
|
|
1126
1235
|
console.log("error", err.message, err.stack);
|
|
@@ -1146,8 +1255,8 @@ function createExtractor() {
|
|
|
1146
1255
|
}
|
|
1147
1256
|
}
|
|
1148
1257
|
if (shouldPrintDebug) {
|
|
1149
|
-
|
|
1150
|
-
|
|
1258
|
+
if (shouldFlatten)
|
|
1259
|
+
console.log(" -- addInitialStyleKeys", addInitialStyleKeys.join(", "));
|
|
1151
1260
|
}
|
|
1152
1261
|
let getStyleError = null;
|
|
1153
1262
|
for (const attr of attrs) {
|
|
@@ -1164,14 +1273,14 @@ function createExtractor() {
|
|
|
1164
1273
|
console.log(" => tern ", (0, import_extractHelpers.attrStr)(attr));
|
|
1165
1274
|
continue;
|
|
1166
1275
|
case "style":
|
|
1167
|
-
if (shouldPrintDebug)
|
|
1168
|
-
console.log(" * styles in", attr.value);
|
|
1169
1276
|
const styles = getStyles(attr.value, "style");
|
|
1170
|
-
if (shouldPrintDebug)
|
|
1171
|
-
console.log(" * styles out", (0, import_logLines.logLines)((0, import_extractHelpers.objToStr)(styles)));
|
|
1172
1277
|
if (styles) {
|
|
1173
|
-
attr.value =
|
|
1278
|
+
attr.value = styles;
|
|
1174
1279
|
}
|
|
1280
|
+
if (shouldPrintDebug)
|
|
1281
|
+
console.log(" * styles (in)", (0, import_logLines.logLines)((0, import_extractHelpers.objToStr)(attr.value)));
|
|
1282
|
+
if (shouldPrintDebug)
|
|
1283
|
+
console.log(" * styles (out)", (0, import_logLines.logLines)((0, import_extractHelpers.objToStr)(styles)));
|
|
1175
1284
|
continue;
|
|
1176
1285
|
}
|
|
1177
1286
|
} catch (err) {
|
|
@@ -1190,7 +1299,7 @@ function createExtractor() {
|
|
|
1190
1299
|
const existingStyleKeys = /* @__PURE__ */ new Set();
|
|
1191
1300
|
for (let i = attrs.length - 1; i >= 0; i--) {
|
|
1192
1301
|
const attr = attrs[i];
|
|
1193
|
-
if (shouldFlatten
|
|
1302
|
+
if (shouldFlatten) {
|
|
1194
1303
|
if (attr.type === "attr") {
|
|
1195
1304
|
if (t.isJSXAttribute(attr.value)) {
|
|
1196
1305
|
if (t.isJSXIdentifier(attr.value.name)) {
|
|
@@ -1198,6 +1307,9 @@ function createExtractor() {
|
|
|
1198
1307
|
if (INLINE_EXTRACTABLE[name]) {
|
|
1199
1308
|
attr.value.name.name = INLINE_EXTRACTABLE[name];
|
|
1200
1309
|
}
|
|
1310
|
+
if ((_e = staticConfig.variants) == null ? void 0 : _e[name]) {
|
|
1311
|
+
const expanded = getStyles({});
|
|
1312
|
+
}
|
|
1201
1313
|
}
|
|
1202
1314
|
}
|
|
1203
1315
|
}
|