@tamagui/static 1.0.0-alpha.6 → 1.0.0-alpha.60
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/constants.js +43 -0
- package/dist/cjs/constants.js.map +7 -0
- package/dist/cjs/extractor/accessSafe.js +39 -0
- package/dist/cjs/extractor/accessSafe.js.map +7 -0
- package/dist/cjs/extractor/babelParse.js +58 -0
- package/dist/cjs/extractor/babelParse.js.map +7 -0
- package/dist/cjs/extractor/buildClassName.js +68 -0
- package/dist/cjs/extractor/buildClassName.js.map +7 -0
- package/dist/cjs/extractor/createEvaluator.js +79 -0
- package/dist/cjs/extractor/createEvaluator.js.map +7 -0
- package/dist/cjs/extractor/createExtractor.js +952 -0
- package/dist/cjs/extractor/createExtractor.js.map +7 -0
- package/dist/cjs/extractor/ensureImportingConcat.js +52 -0
- package/dist/cjs/extractor/ensureImportingConcat.js.map +7 -0
- package/dist/cjs/extractor/evaluateAstNode.js +122 -0
- package/dist/cjs/extractor/evaluateAstNode.js.map +7 -0
- package/dist/cjs/extractor/extractHelpers.js +124 -0
- package/dist/cjs/extractor/extractHelpers.js.map +7 -0
- package/dist/cjs/extractor/extractMediaStyle.js +193 -0
- package/dist/cjs/extractor/extractMediaStyle.js.map +7 -0
- package/dist/cjs/extractor/extractToClassNames.js +291 -0
- package/dist/cjs/extractor/extractToClassNames.js.map +7 -0
- package/dist/cjs/extractor/findTopmostFunction.js +46 -0
- package/dist/cjs/extractor/findTopmostFunction.js.map +7 -0
- package/dist/cjs/extractor/generatedUid.js +56 -0
- package/dist/cjs/extractor/generatedUid.js.map +7 -0
- package/dist/cjs/extractor/getPropValueFromAttributes.js +77 -0
- package/dist/cjs/extractor/getPropValueFromAttributes.js.map +7 -0
- package/dist/cjs/extractor/getSourceModule.js +97 -0
- package/dist/cjs/extractor/getSourceModule.js.map +7 -0
- package/dist/cjs/extractor/getStaticBindingsForScope.js +156 -0
- package/dist/cjs/extractor/getStaticBindingsForScope.js.map +7 -0
- package/dist/cjs/extractor/hoistClassNames.js +72 -0
- package/dist/cjs/extractor/hoistClassNames.js.map +7 -0
- package/dist/cjs/extractor/literalToAst.js +62 -0
- package/dist/cjs/extractor/literalToAst.js.map +7 -0
- package/dist/cjs/extractor/loadTamagui.js +70 -0
- package/dist/cjs/extractor/loadTamagui.js.map +7 -0
- package/dist/cjs/extractor/logLines.js +40 -0
- package/dist/cjs/extractor/logLines.js.map +7 -0
- package/dist/cjs/extractor/normalizeTernaries.js +108 -0
- package/dist/cjs/extractor/normalizeTernaries.js.map +7 -0
- package/dist/cjs/extractor/removeUnusedHooks.js +107 -0
- package/dist/cjs/extractor/removeUnusedHooks.js.map +7 -0
- package/dist/cjs/index.js +38 -0
- package/dist/cjs/index.js.map +7 -0
- package/dist/cjs/patchReactNativeWeb.js +157 -0
- package/dist/cjs/patchReactNativeWeb.js.map +7 -0
- package/dist/cjs/types.js +21 -0
- package/dist/cjs/types.js.map +7 -0
- package/dist/{constants.js → esm/constants.js} +4 -0
- package/dist/{constants.js.map → esm/constants.js.map} +3 -3
- package/dist/{extractor → esm/extractor}/accessSafe.js +0 -0
- package/dist/{extractor → esm/extractor}/accessSafe.js.map +1 -1
- package/dist/{extractor → esm/extractor}/babelParse.js +0 -0
- package/dist/{extractor → esm/extractor}/babelParse.js.map +1 -1
- package/dist/{extractor → esm/extractor}/buildClassName.js +0 -0
- package/dist/{extractor → esm/extractor}/buildClassName.js.map +1 -1
- package/dist/{extractor → esm/extractor}/createEvaluator.js +1 -1
- package/dist/esm/extractor/createEvaluator.js.map +7 -0
- package/dist/{extractor → esm/extractor}/createExtractor.js +151 -79
- package/dist/esm/extractor/createExtractor.js.map +7 -0
- package/dist/{extractor → esm/extractor}/ensureImportingConcat.js +1 -1
- package/dist/esm/extractor/ensureImportingConcat.js.map +7 -0
- package/dist/{extractor → esm/extractor}/evaluateAstNode.js +0 -0
- package/dist/{extractor → esm/extractor}/evaluateAstNode.js.map +1 -1
- package/dist/{extractor → esm/extractor}/extractHelpers.js +6 -4
- package/dist/{extractor → esm/extractor}/extractHelpers.js.map +3 -3
- package/dist/{extractor → esm/extractor}/extractMediaStyle.js +3 -2
- package/dist/{extractor → esm/extractor}/extractMediaStyle.js.map +2 -2
- package/dist/{extractor → esm/extractor}/extractToClassNames.js +35 -22
- package/dist/esm/extractor/extractToClassNames.js.map +7 -0
- package/dist/{extractor → esm/extractor}/findTopmostFunction.js +0 -0
- package/dist/{extractor → esm/extractor}/findTopmostFunction.js.map +1 -1
- package/dist/{extractor → esm/extractor}/generatedUid.js +0 -0
- package/dist/{extractor → esm/extractor}/generatedUid.js.map +1 -1
- package/dist/{extractor → esm/extractor}/getPropValueFromAttributes.js +0 -0
- package/dist/{extractor → esm/extractor}/getPropValueFromAttributes.js.map +1 -1
- package/dist/{extractor → esm/extractor}/getSourceModule.js +0 -0
- package/dist/{extractor → esm/extractor}/getSourceModule.js.map +1 -1
- package/dist/{extractor → esm/extractor}/getStaticBindingsForScope.js +0 -0
- package/dist/{extractor → esm/extractor}/getStaticBindingsForScope.js.map +1 -1
- package/dist/{extractor → esm/extractor}/hoistClassNames.js +0 -0
- package/dist/{extractor → esm/extractor}/hoistClassNames.js.map +1 -1
- package/dist/{extractor → esm/extractor}/literalToAst.js +0 -0
- package/dist/{extractor → esm/extractor}/literalToAst.js.map +1 -1
- package/dist/{extractor → esm/extractor}/loadTamagui.js +8 -2
- package/dist/esm/extractor/loadTamagui.js.map +7 -0
- package/dist/esm/extractor/logLines.js +17 -0
- package/dist/esm/extractor/logLines.js.map +7 -0
- package/dist/{extractor → esm/extractor}/normalizeTernaries.js +3 -2
- package/dist/{extractor → esm/extractor}/normalizeTernaries.js.map +2 -2
- package/dist/{extractor → esm/extractor}/removeUnusedHooks.js +5 -3
- package/dist/{extractor → esm/extractor}/removeUnusedHooks.js.map +2 -2
- package/dist/{index.js → esm/index.js} +0 -0
- package/dist/{index.js.map → esm/index.js.map} +1 -1
- package/dist/{patchReactNativeWeb.js → esm/patchReactNativeWeb.js} +22 -0
- package/dist/esm/patchReactNativeWeb.js.map +7 -0
- package/dist/{types.js → esm/types.js} +0 -0
- package/dist/{types.js.map → esm/types.js.map} +0 -0
- package/dist/jsx/constants.js +13 -0
- package/dist/jsx/extractor/accessSafe.js +10 -0
- package/dist/jsx/extractor/babelParse.js +29 -0
- package/dist/jsx/extractor/buildClassName.js +39 -0
- package/dist/jsx/extractor/createEvaluator.js +50 -0
- package/dist/jsx/extractor/createExtractor.js +890 -0
- package/dist/jsx/extractor/ensureImportingConcat.js +23 -0
- package/dist/jsx/extractor/evaluateAstNode.js +93 -0
- package/dist/jsx/extractor/extractHelpers.js +95 -0
- package/dist/jsx/extractor/extractMediaStyle.js +151 -0
- package/dist/jsx/extractor/extractToClassNames.js +247 -0
- package/dist/jsx/extractor/findTopmostFunction.js +22 -0
- package/dist/jsx/extractor/generatedUid.js +27 -0
- package/dist/jsx/extractor/getPropValueFromAttributes.js +48 -0
- package/dist/jsx/extractor/getSourceModule.js +68 -0
- package/dist/jsx/extractor/getStaticBindingsForScope.js +127 -0
- package/dist/jsx/extractor/hoistClassNames.js +43 -0
- package/dist/jsx/extractor/literalToAst.js +33 -0
- package/dist/jsx/extractor/loadTamagui.js +46 -0
- package/dist/jsx/extractor/logLines.js +16 -0
- package/dist/jsx/extractor/normalizeTernaries.js +52 -0
- package/dist/jsx/extractor/removeUnusedHooks.js +79 -0
- package/dist/jsx/index.js +13 -0
- package/dist/jsx/patchReactNativeWeb.js +128 -0
- package/dist/jsx/types.js +0 -0
- package/package.json +27 -19
- package/types/constants.d.ts +6 -0
- package/types/constants.d.ts.map +1 -0
- package/types/extractor/accessSafe.d.ts +3 -0
- package/types/extractor/accessSafe.d.ts.map +1 -0
- package/types/extractor/babelParse.d.ts +5 -0
- package/types/extractor/babelParse.d.ts.map +1 -0
- package/types/extractor/buildClassName.d.ts +4 -0
- package/types/extractor/buildClassName.d.ts.map +1 -0
- package/types/extractor/createEvaluator.d.ts +12 -0
- package/types/extractor/createEvaluator.d.ts.map +1 -0
- package/types/extractor/createExtractor.d.ts +33 -0
- package/types/extractor/createExtractor.d.ts.map +1 -0
- package/types/extractor/ensureImportingConcat.d.ts +4 -0
- package/types/extractor/ensureImportingConcat.d.ts.map +1 -0
- package/types/extractor/evaluateAstNode.d.ts +3 -0
- package/types/extractor/evaluateAstNode.d.ts.map +1 -0
- package/types/extractor/extractHelpers.d.ts +12 -0
- package/types/extractor/extractHelpers.d.ts.map +1 -0
- package/types/extractor/extractMediaStyle.d.ts +10 -0
- package/types/extractor/extractMediaStyle.d.ts.map +1 -0
- package/types/extractor/extractToClassNames.d.ts +21 -0
- package/types/extractor/extractToClassNames.d.ts.map +1 -0
- package/types/extractor/findTopmostFunction.d.ts +4 -0
- package/types/extractor/findTopmostFunction.d.ts.map +1 -0
- package/types/extractor/generatedUid.d.ts +5 -0
- package/types/extractor/generatedUid.d.ts.map +1 -0
- package/types/extractor/getPropValueFromAttributes.d.ts +3 -0
- package/types/extractor/getPropValueFromAttributes.d.ts.map +1 -0
- package/types/extractor/getSourceModule.d.ts +16 -0
- package/types/extractor/getSourceModule.d.ts.map +1 -0
- package/types/extractor/getStaticBindingsForScope.d.ts +4 -0
- package/types/extractor/getStaticBindingsForScope.d.ts.map +1 -0
- package/types/extractor/hoistClassNames.d.ts +6 -0
- package/types/extractor/hoistClassNames.d.ts.map +1 -0
- package/types/extractor/literalToAst.d.ts +3 -0
- package/types/extractor/literalToAst.d.ts.map +1 -0
- package/types/extractor/loadTamagui.d.ts +9 -0
- package/types/extractor/loadTamagui.d.ts.map +1 -0
- package/types/extractor/logLines.d.ts +2 -0
- package/types/extractor/logLines.d.ts.map +1 -0
- package/types/extractor/normalizeTernaries.d.ts +3 -0
- package/types/extractor/normalizeTernaries.d.ts.map +1 -0
- package/types/extractor/removeUnusedHooks.d.ts +3 -0
- package/types/extractor/removeUnusedHooks.d.ts.map +1 -0
- package/types/index.d.ts +8 -0
- package/types/index.d.ts.map +1 -0
- package/types/patchReactNativeWeb.d.ts +2 -0
- package/types/patchReactNativeWeb.d.ts.map +1 -0
- package/types/types.d.ts +79 -0
- package/types/types.d.ts.map +1 -0
- package/dist/extractor/createEvaluator.js.map +0 -7
- package/dist/extractor/createExtractor.js.map +0 -7
- package/dist/extractor/ensureImportingConcat.js.map +0 -7
- package/dist/extractor/extractToClassNames.js.map +0 -7
- package/dist/extractor/loadTamagui.js.map +0 -7
- package/dist/index.cjs +0 -2107
- package/dist/index.cjs.map +0 -7
- package/dist/patchReactNativeWeb.js.map +0 -7
- package/src/constants.ts +0 -10
- package/src/extractor/accessSafe.ts +0 -18
- package/src/extractor/babelParse.ts +0 -27
- package/src/extractor/buildClassName.ts +0 -61
- package/src/extractor/createEvaluator.ts +0 -68
- package/src/extractor/createExtractor.ts +0 -1132
- package/src/extractor/ensureImportingConcat.ts +0 -33
- package/src/extractor/evaluateAstNode.ts +0 -121
- package/src/extractor/extractHelpers.ts +0 -102
- package/src/extractor/extractMediaStyle.ts +0 -191
- package/src/extractor/extractToClassNames.ts +0 -326
- package/src/extractor/findTopmostFunction.ts +0 -22
- package/src/extractor/generatedUid.ts +0 -43
- package/src/extractor/getPropValueFromAttributes.ts +0 -92
- package/src/extractor/getSourceModule.ts +0 -101
- package/src/extractor/getStaticBindingsForScope.ts +0 -173
- package/src/extractor/hoistClassNames.ts +0 -45
- package/src/extractor/literalToAst.ts +0 -32
- package/src/extractor/loadTamagui.ts +0 -61
- package/src/extractor/normalizeTernaries.ts +0 -60
- package/src/extractor/removeUnusedHooks.ts +0 -76
- package/src/index.ts +0 -9
- package/src/patchReactNativeWeb.ts +0 -123
- package/src/types.ts +0 -83
- package/types.d.ts +0 -215
|
@@ -3,7 +3,7 @@ var __name = (target, value) => __defProp(target, "name", { value, configurable:
|
|
|
3
3
|
import vm from "vm";
|
|
4
4
|
import generate from "@babel/generator";
|
|
5
5
|
import * as t from "@babel/types";
|
|
6
|
-
import { FAILED_EVAL } from "
|
|
6
|
+
import { FAILED_EVAL } from "../constants";
|
|
7
7
|
import { evaluateAstNode } from "./evaluateAstNode";
|
|
8
8
|
import { isValidThemeHook } from "./extractHelpers";
|
|
9
9
|
function createEvaluator({
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 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'\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\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 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 `var(--${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 code = `(${generate(n as any).code})`\n // if (shouldPrintDebug) {\n // console.log('evaluating', { n, code, evalContext })\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;AAEA;AAEA;AAGA;AACA;AACA;AAEO,yBAAyB;AAAA,EAC9B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,GAOC;AAED,QAAM,SAAS,wBAAC,MAAc;AAE5B,QACE,EAAE,mBAAmB,MACrB,EAAE,aAAa,EAAE,aACjB,iBAAiB,cAAc,GAAG,aAClC;AACA,YAAM,MAAM,EAAE,SAAS;AACvB,UAAI,kBAAkB;AACpB,gBAAQ,IAAI,0BAA0B;AAAA;AAExC,cAAQ,IAAI,kCAAkC;AAI9C,aAAO,SAAS;AAAA;AAGlB,QAAI,EAAE,aAAa,MAAM,gBAAgB,eAAe,EAAE,OAAO;AAC/D,aAAO,gBAAgB,EAAE;AAAA;AAE3B,UAAM,cAAc,GAAG,cAAc;AACrC,UAAM,OAAO,IAAI,SAAS,GAAU;AAIpC,WAAO,GAAG,aAAa,MAAM;AAAA,KA1BhB;AA6Bf,SAAO,CAAC,MAAc;AACpB,WAAO,gBAAgB,GAAG;AAAA;AAAA;AA5Cd;AAgDT,6BAA6B,aAAiC;AACnE,SAAO,CAAC,MAAc;AACpB,QAAI;AACF,aAAO,YAAY;AAAA,aACZ,KAAP;AACA,aAAO;AAAA;AAAA;AAAA;AALG;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -2,9 +2,10 @@ var __defProp = Object.defineProperty;
|
|
|
2
2
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
3
|
import traverse from "@babel/traverse";
|
|
4
4
|
import * as t from "@babel/types";
|
|
5
|
-
import
|
|
5
|
+
import { mediaQueryConfig, postProcessStyles, pseudos } from "@tamagui/core-node";
|
|
6
6
|
import { stylePropsTransform } from "@tamagui/helpers";
|
|
7
7
|
import { difference, pick } from "lodash";
|
|
8
|
+
import { FAILED_EVAL } from "../constants";
|
|
8
9
|
import { createEvaluator, createSafeEvaluator } from "./createEvaluator";
|
|
9
10
|
import { evaluateAstNode } from "./evaluateAstNode";
|
|
10
11
|
import { attrStr, findComponentName, isInsideTamagui, isPresent, objToStr } from "./extractHelpers";
|
|
@@ -12,10 +13,9 @@ import { findTopmostFunction } from "./findTopmostFunction";
|
|
|
12
13
|
import { getStaticBindingsForScope } from "./getStaticBindingsForScope";
|
|
13
14
|
import { literalToAst } from "./literalToAst";
|
|
14
15
|
import { loadTamagui } from "./loadTamagui";
|
|
16
|
+
import { logLines } from "./logLines";
|
|
15
17
|
import { normalizeTernaries } from "./normalizeTernaries";
|
|
16
18
|
import { removeUnusedHooks } from "./removeUnusedHooks";
|
|
17
|
-
const { mediaQueryConfig, postProcessStyles, pseudos } = CoreNode;
|
|
18
|
-
const FAILED_EVAL = Symbol("failed_style_eval");
|
|
19
19
|
const UNTOUCHED_PROPS = {
|
|
20
20
|
key: true,
|
|
21
21
|
style: true,
|
|
@@ -36,7 +36,7 @@ function createExtractor() {
|
|
|
36
36
|
let loadedTamaguiConfig;
|
|
37
37
|
let hasLogged = false;
|
|
38
38
|
return {
|
|
39
|
-
|
|
39
|
+
getTamagui() {
|
|
40
40
|
return loadedTamaguiConfig;
|
|
41
41
|
},
|
|
42
42
|
parse: (fileOrPath, {
|
|
@@ -48,6 +48,8 @@ function createExtractor() {
|
|
|
48
48
|
onExtractTag,
|
|
49
49
|
getFlattenedNode,
|
|
50
50
|
disableExtraction,
|
|
51
|
+
disableExtractInlineMedia,
|
|
52
|
+
disableExtractVariables,
|
|
51
53
|
disableDebugAttr,
|
|
52
54
|
...props
|
|
53
55
|
}) => {
|
|
@@ -64,8 +66,13 @@ function createExtractor() {
|
|
|
64
66
|
loadedTamaguiConfig = tamaguiConfig;
|
|
65
67
|
const defaultTheme = tamaguiConfig.themes[Object.keys(tamaguiConfig.themes)[0]];
|
|
66
68
|
const body = fileOrPath.type === "Program" ? fileOrPath.get("body") : fileOrPath.program.body;
|
|
67
|
-
const isInternalImport = /* @__PURE__ */ __name((importStr) =>
|
|
68
|
-
|
|
69
|
+
const isInternalImport = /* @__PURE__ */ __name((importStr) => {
|
|
70
|
+
return isInsideTamagui(sourcePath) && importStr[0] === ".";
|
|
71
|
+
}, "isInternalImport");
|
|
72
|
+
const validComponents = Object.keys(components).filter((key) => {
|
|
73
|
+
var _a;
|
|
74
|
+
return key[0].toUpperCase() === key[0] && !!((_a = components[key]) == null ? void 0 : _a.staticConfig);
|
|
75
|
+
}).reduce((obj, name) => {
|
|
69
76
|
obj[name] = components[name];
|
|
70
77
|
return obj;
|
|
71
78
|
}, {});
|
|
@@ -92,7 +99,7 @@ function createExtractor() {
|
|
|
92
99
|
return null;
|
|
93
100
|
}
|
|
94
101
|
let couldntParse = false;
|
|
95
|
-
const modifiedComponents = new Set();
|
|
102
|
+
const modifiedComponents = /* @__PURE__ */ new Set();
|
|
96
103
|
const bindingCache = {};
|
|
97
104
|
const callTraverse = /* @__PURE__ */ __name((a) => {
|
|
98
105
|
return fileOrPath.type === "File" ? traverse(fileOrPath, a) : fileOrPath.traverse(a);
|
|
@@ -110,11 +117,12 @@ function createExtractor() {
|
|
|
110
117
|
}
|
|
111
118
|
},
|
|
112
119
|
JSXElement(traversePath) {
|
|
120
|
+
var _a, _b, _c, _d, _e, _f;
|
|
113
121
|
const node = traversePath.node.openingElement;
|
|
114
122
|
const ogAttributes = node.attributes;
|
|
115
123
|
const componentName = findComponentName(traversePath.scope);
|
|
116
124
|
const closingElement = traversePath.node.closingElement;
|
|
117
|
-
if (t.isJSXMemberExpression(closingElement
|
|
125
|
+
if (t.isJSXMemberExpression(closingElement == null ? void 0 : closingElement.name) || !t.isJSXIdentifier(node.name)) {
|
|
118
126
|
return;
|
|
119
127
|
}
|
|
120
128
|
const binding = traversePath.scope.getBinding(node.name.name);
|
|
@@ -155,8 +163,8 @@ function createExtractor() {
|
|
|
155
163
|
}
|
|
156
164
|
const { staticConfig } = component;
|
|
157
165
|
const isTextView = staticConfig.isText || false;
|
|
158
|
-
const validStyles = staticConfig
|
|
159
|
-
let tagName = staticConfig.defaultProps
|
|
166
|
+
const validStyles = (_a = staticConfig == null ? void 0 : staticConfig.validStyles) != null ? _a : {};
|
|
167
|
+
let tagName = (_c = (_b = staticConfig.defaultProps) == null ? void 0 : _b.tag) != null ? _c : isTextView ? "span" : "div";
|
|
160
168
|
traversePath.get("openingElement").get("attributes").forEach((path) => {
|
|
161
169
|
const attr = path.node;
|
|
162
170
|
if (t.isJSXSpreadAttribute(attr))
|
|
@@ -169,11 +177,11 @@ function createExtractor() {
|
|
|
169
177
|
tagName = val.value;
|
|
170
178
|
});
|
|
171
179
|
const flatNode = getFlattenedNode({ isTextView, tag: tagName });
|
|
172
|
-
const deoptProps = new Set([
|
|
173
|
-
...props.deoptProps
|
|
174
|
-
...staticConfig.deoptProps
|
|
180
|
+
const deoptProps = /* @__PURE__ */ new Set([
|
|
181
|
+
...(_d = props.deoptProps) != null ? _d : [],
|
|
182
|
+
...(_e = staticConfig.deoptProps) != null ? _e : []
|
|
175
183
|
]);
|
|
176
|
-
const excludeProps = new Set(props.excludeProps
|
|
184
|
+
const excludeProps = new Set((_f = props.excludeProps) != null ? _f : []);
|
|
177
185
|
const isExcludedProp = /* @__PURE__ */ __name((name) => {
|
|
178
186
|
const res2 = excludeProps.has(name);
|
|
179
187
|
if (res2 && shouldPrintDebug)
|
|
@@ -198,9 +206,6 @@ function createExtractor() {
|
|
|
198
206
|
if (shouldPrintDebug) {
|
|
199
207
|
console.log(" staticNamespace", Object.keys(staticNamespace).join(", "));
|
|
200
208
|
}
|
|
201
|
-
const hasDeopt = /* @__PURE__ */ __name((obj) => {
|
|
202
|
-
return Object.keys(obj).some(isDeoptedProp);
|
|
203
|
-
}, "hasDeopt");
|
|
204
209
|
const flattenedAttrs = [];
|
|
205
210
|
traversePath.get("openingElement").get("attributes").forEach((path) => {
|
|
206
211
|
const attr = path.node;
|
|
@@ -247,9 +252,19 @@ function createExtractor() {
|
|
|
247
252
|
node.attributes = flattenedAttrs;
|
|
248
253
|
if (staticConfig.defaultProps) {
|
|
249
254
|
for (const key in staticConfig.defaultProps) {
|
|
255
|
+
if (key === "StyleSheet") {
|
|
256
|
+
continue;
|
|
257
|
+
}
|
|
250
258
|
const serialize = require("babel-literal-to-ast");
|
|
251
259
|
const val = staticConfig.defaultProps[key];
|
|
252
|
-
|
|
260
|
+
try {
|
|
261
|
+
const serializedDefaultProp = serialize(val);
|
|
262
|
+
node.attributes.unshift(t.jsxAttribute(t.jsxIdentifier(key), typeof val === "string" ? t.stringLiteral(val) : t.jsxExpressionContainer(serializedDefaultProp)));
|
|
263
|
+
} catch (err) {
|
|
264
|
+
console.warn(`\u26A0\uFE0F Error evaluating default prop for component ${node.name.name}, prop ${key}
|
|
265
|
+
error: ${err}
|
|
266
|
+
value:`, val, "\n defaultProps:", staticConfig.defaultProps);
|
|
267
|
+
}
|
|
253
268
|
}
|
|
254
269
|
}
|
|
255
270
|
let attrs = [];
|
|
@@ -264,16 +279,22 @@ function createExtractor() {
|
|
|
264
279
|
}
|
|
265
280
|
return res2;
|
|
266
281
|
} catch (err) {
|
|
267
|
-
|
|
268
|
-
|
|
282
|
+
if (shouldPrintDebug) {
|
|
283
|
+
console.log("Error extracting attribute", err.message, err.stack);
|
|
284
|
+
console.log("node", path.node);
|
|
285
|
+
}
|
|
269
286
|
return {
|
|
270
287
|
type: "attr",
|
|
271
288
|
value: path.node
|
|
272
289
|
};
|
|
273
290
|
}
|
|
274
291
|
}).flat(4).filter(isPresent);
|
|
292
|
+
if (shouldPrintDebug) {
|
|
293
|
+
console.log(" - attrs (before):\n", logLines(attrs.map(attrStr).join(", ")));
|
|
294
|
+
}
|
|
275
295
|
function isStaticAttributeName(name) {
|
|
276
|
-
|
|
296
|
+
var _a2, _b2;
|
|
297
|
+
return !!(!!validStyles[name] || ((_a2 = staticConfig.validPropsExtra) == null ? void 0 : _a2[name]) || !!pseudos[name] || ((_b2 = staticConfig.variants) == null ? void 0 : _b2[name]) || tamaguiConfig.shorthands[name] || (name[0] === "$" ? !!mediaQueryConfig[name.slice(1)] : false));
|
|
277
298
|
}
|
|
278
299
|
__name(isStaticAttributeName, "isStaticAttributeName");
|
|
279
300
|
function isExtractable(obj) {
|
|
@@ -384,7 +405,10 @@ function createExtractor() {
|
|
|
384
405
|
if (UNTOUCHED_PROPS[name]) {
|
|
385
406
|
return attr;
|
|
386
407
|
}
|
|
387
|
-
if (name[0] === "$" && t.isJSXExpressionContainer(attribute
|
|
408
|
+
if (name[0] === "$" && t.isJSXExpressionContainer(attribute == null ? void 0 : attribute.value)) {
|
|
409
|
+
if (disableExtractInlineMedia) {
|
|
410
|
+
return attr;
|
|
411
|
+
}
|
|
388
412
|
const shortname = name.slice(1);
|
|
389
413
|
if (mediaQueryConfig[shortname]) {
|
|
390
414
|
const expression = attribute.value.expression;
|
|
@@ -402,7 +426,7 @@ function createExtractor() {
|
|
|
402
426
|
}
|
|
403
427
|
}
|
|
404
428
|
const [value, valuePath] = (() => {
|
|
405
|
-
if (t.isJSXExpressionContainer(attribute
|
|
429
|
+
if (t.isJSXExpressionContainer(attribute == null ? void 0 : attribute.value)) {
|
|
406
430
|
return [attribute.value.expression, path.get("value")];
|
|
407
431
|
} else {
|
|
408
432
|
return [attribute.value, path.get("value")];
|
|
@@ -424,6 +448,17 @@ function createExtractor() {
|
|
|
424
448
|
value: path.node
|
|
425
449
|
};
|
|
426
450
|
}
|
|
451
|
+
if (disableExtractVariables) {
|
|
452
|
+
if (value) {
|
|
453
|
+
if (value.type === "StringLiteral" && value.value[0] === "$") {
|
|
454
|
+
if (shouldPrintDebug) {
|
|
455
|
+
console.log(` native, disable extract: ${name} =`, value.value);
|
|
456
|
+
}
|
|
457
|
+
inlinePropCount++;
|
|
458
|
+
return attr;
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
}
|
|
427
462
|
const styleValue = attemptEvalSafe(value);
|
|
428
463
|
if (!isStaticAttributeName(name)) {
|
|
429
464
|
let keys = [name];
|
|
@@ -433,21 +468,30 @@ function createExtractor() {
|
|
|
433
468
|
keys = Object.keys(out);
|
|
434
469
|
}
|
|
435
470
|
}
|
|
436
|
-
|
|
437
|
-
if (
|
|
438
|
-
|
|
471
|
+
for (const key of keys) {
|
|
472
|
+
if (!isStaticAttributeName(key)) {
|
|
473
|
+
inlinePropCount++;
|
|
439
474
|
}
|
|
440
|
-
|
|
475
|
+
}
|
|
476
|
+
if (inlinePropCount) {
|
|
441
477
|
return attr;
|
|
442
478
|
}
|
|
443
479
|
}
|
|
444
480
|
if (styleValue !== FAILED_EVAL) {
|
|
481
|
+
if (shouldPrintDebug) {
|
|
482
|
+
console.log(` style: ${name} =`, styleValue);
|
|
483
|
+
}
|
|
445
484
|
return {
|
|
446
485
|
type: "style",
|
|
447
|
-
value: { [name]: styleValue }
|
|
486
|
+
value: { [name]: styleValue },
|
|
487
|
+
name,
|
|
488
|
+
attr: path.node
|
|
448
489
|
};
|
|
449
490
|
}
|
|
450
491
|
if (t.isBinaryExpression(value)) {
|
|
492
|
+
if (shouldPrintDebug) {
|
|
493
|
+
console.log(` binary expression ${name} = `, value);
|
|
494
|
+
}
|
|
451
495
|
const { operator, left, right } = value;
|
|
452
496
|
const lVal = attemptEvalSafe(left);
|
|
453
497
|
const rVal = attemptEvalSafe(right);
|
|
@@ -472,16 +516,25 @@ function createExtractor() {
|
|
|
472
516
|
}
|
|
473
517
|
const staticConditional = getStaticConditional(value);
|
|
474
518
|
if (staticConditional) {
|
|
519
|
+
if (shouldPrintDebug) {
|
|
520
|
+
console.log(` static conditional ${name} = `, value);
|
|
521
|
+
}
|
|
475
522
|
return { type: "ternary", value: staticConditional };
|
|
476
523
|
}
|
|
477
524
|
const staticLogical = getStaticLogical(value);
|
|
478
525
|
if (staticLogical) {
|
|
526
|
+
if (shouldPrintDebug) {
|
|
527
|
+
console.log(` static ternary ${name} = `, value);
|
|
528
|
+
}
|
|
479
529
|
return { type: "ternary", value: staticLogical };
|
|
480
530
|
}
|
|
481
531
|
if (shouldPrintDebug) {
|
|
482
532
|
console.log(" ! inline prop via no match", name, value.type);
|
|
483
533
|
}
|
|
484
534
|
inlinePropCount++;
|
|
535
|
+
if (shouldPrintDebug) {
|
|
536
|
+
console.log(` inlining ${name} = `, value);
|
|
537
|
+
}
|
|
485
538
|
return attr;
|
|
486
539
|
function addBinaryConditional(operator, staticExpr, cond) {
|
|
487
540
|
if (getStaticConditional(cond)) {
|
|
@@ -556,9 +609,6 @@ function createExtractor() {
|
|
|
556
609
|
__name(getStaticLogical, "getStaticLogical");
|
|
557
610
|
}
|
|
558
611
|
__name(evaluateAttribute, "evaluateAttribute");
|
|
559
|
-
if (shouldPrintDebug) {
|
|
560
|
-
console.log(" - attrs (before): ", attrs.map(attrStr).join(", "));
|
|
561
|
-
}
|
|
562
612
|
node.attributes = attrs.filter(isAttr).map((x) => x.value);
|
|
563
613
|
if (couldntParse) {
|
|
564
614
|
if (shouldPrintDebug) {
|
|
@@ -631,16 +681,19 @@ function createExtractor() {
|
|
|
631
681
|
const shouldFlatten = !shouldDeopt && inlinePropCount === 0 && !hasSpread && staticConfig.neverFlatten !== true && (staticConfig.neverFlatten === "jsx" ? hasOnlyStringChildren : true);
|
|
632
682
|
if (!shouldFlatten) {
|
|
633
683
|
attrs = attrs.reduce((acc, cur) => {
|
|
684
|
+
var _a2, _b2;
|
|
634
685
|
if (cur.type === "style") {
|
|
635
686
|
for (const key in cur.value) {
|
|
636
|
-
const
|
|
687
|
+
const shouldEnsureOverridden = !!((_a2 = staticConfig.ensureOverriddenProp) == null ? void 0 : _a2[key]);
|
|
637
688
|
const isSetInAttrsAlready = attrs.some((x) => x.type === "attr" && x.value.type === "JSXAttribute" && x.value.name.name === key);
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
689
|
+
if (!isSetInAttrsAlready) {
|
|
690
|
+
const isVariant = !!((_b2 = staticConfig.variants) == null ? void 0 : _b2[cur.name || ""]);
|
|
691
|
+
if (isVariant || shouldEnsureOverridden) {
|
|
692
|
+
acc.push({
|
|
693
|
+
type: "attr",
|
|
694
|
+
value: cur.attr || t.jsxAttribute(t.jsxIdentifier(key), t.jsxExpressionContainer(t.nullLiteral()))
|
|
695
|
+
});
|
|
696
|
+
}
|
|
644
697
|
}
|
|
645
698
|
}
|
|
646
699
|
}
|
|
@@ -649,16 +702,33 @@ function createExtractor() {
|
|
|
649
702
|
}, []);
|
|
650
703
|
}
|
|
651
704
|
if (shouldPrintDebug) {
|
|
652
|
-
console.log(" - attrs (flattened):
|
|
705
|
+
console.log(" - attrs (flattened): \n", logLines(attrs.map(attrStr).join(", ")));
|
|
653
706
|
}
|
|
654
707
|
attrs = attrs.reduce((acc, cur) => {
|
|
655
|
-
if (cur.type
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
708
|
+
if (cur.type === "style") {
|
|
709
|
+
let key = Object.keys(cur.value)[0];
|
|
710
|
+
let value = cur.value[key];
|
|
711
|
+
const nonShortKey = tamaguiConfig.shorthands[key];
|
|
712
|
+
if (nonShortKey) {
|
|
713
|
+
cur.value = { [nonShortKey]: value };
|
|
714
|
+
key = nonShortKey;
|
|
715
|
+
}
|
|
716
|
+
if (!shouldFlatten && stylePropsTransform[key] || !validStyles[key] && !pseudos[key] && !key.startsWith("data-")) {
|
|
717
|
+
acc.push({
|
|
718
|
+
type: "attr",
|
|
719
|
+
value: t.jsxAttribute(t.jsxIdentifier(key), t.jsxExpressionContainer(typeof value === "string" ? t.stringLiteral(value) : literalToAst(value)))
|
|
720
|
+
});
|
|
721
|
+
return acc;
|
|
722
|
+
}
|
|
723
|
+
if (disableExtractVariables) {
|
|
724
|
+
if (value[0] === "$") {
|
|
659
725
|
if (shouldPrintDebug) {
|
|
660
|
-
console.log(
|
|
726
|
+
console.log(` keeping variable inline: ${key} =`, value);
|
|
661
727
|
}
|
|
728
|
+
acc.push({
|
|
729
|
+
type: "attr",
|
|
730
|
+
value: t.jsxAttribute(t.jsxIdentifier(key), t.jsxExpressionContainer(t.stringLiteral(value)))
|
|
731
|
+
});
|
|
662
732
|
return acc;
|
|
663
733
|
}
|
|
664
734
|
}
|
|
@@ -667,12 +737,12 @@ function createExtractor() {
|
|
|
667
737
|
return acc;
|
|
668
738
|
}, []);
|
|
669
739
|
if (shouldPrintDebug) {
|
|
670
|
-
console.log(" - attrs (evaluated
|
|
740
|
+
console.log(" - attrs (evaluated): \n", logLines(attrs.map(attrStr).join(", ")));
|
|
671
741
|
}
|
|
672
742
|
let prev = null;
|
|
673
743
|
attrs = attrs.reduce((acc, cur) => {
|
|
674
744
|
if (cur.type === "style") {
|
|
675
|
-
if (prev
|
|
745
|
+
if ((prev == null ? void 0 : prev.type) === "style") {
|
|
676
746
|
Object.assign(prev.value, cur.value);
|
|
677
747
|
return acc;
|
|
678
748
|
}
|
|
@@ -682,9 +752,10 @@ function createExtractor() {
|
|
|
682
752
|
return acc;
|
|
683
753
|
}, []);
|
|
684
754
|
if (shouldPrintDebug) {
|
|
685
|
-
console.log(" - attrs (combined \u{1F500}):
|
|
755
|
+
console.log(" - attrs (combined \u{1F500}): \n", logLines(attrs.map(attrStr).join(", ")));
|
|
686
756
|
}
|
|
687
757
|
const getStyles = /* @__PURE__ */ __name((props2) => {
|
|
758
|
+
var _a2;
|
|
688
759
|
if (!props2)
|
|
689
760
|
return;
|
|
690
761
|
if (!!excludeProps.size) {
|
|
@@ -694,14 +765,14 @@ function createExtractor() {
|
|
|
694
765
|
}
|
|
695
766
|
}
|
|
696
767
|
const out = postProcessStyles(props2, staticConfig, defaultTheme);
|
|
697
|
-
const next = out
|
|
768
|
+
const next = (_a2 = out == null ? void 0 : out.style) != null ? _a2 : props2;
|
|
698
769
|
if (shouldPrintDebug) {
|
|
699
|
-
console.log("
|
|
700
|
-
console.log("
|
|
701
|
-
console.log("
|
|
770
|
+
console.log(" -- viewProps:\n", logLines(objToStr(out.viewProps)));
|
|
771
|
+
console.log(" -- props:\n", logLines(objToStr(props2)));
|
|
772
|
+
console.log(" -- next:\n", logLines(objToStr(next)));
|
|
702
773
|
}
|
|
703
|
-
|
|
704
|
-
|
|
774
|
+
for (const key in next) {
|
|
775
|
+
if (staticConfig.validStyles) {
|
|
705
776
|
if (!staticConfig.validStyles[key] && !pseudos[key]) {
|
|
706
777
|
delete next[key];
|
|
707
778
|
}
|
|
@@ -709,9 +780,6 @@ function createExtractor() {
|
|
|
709
780
|
}
|
|
710
781
|
return next;
|
|
711
782
|
}, "getStyles");
|
|
712
|
-
if (shouldPrintDebug) {
|
|
713
|
-
console.log(" staticConfig.defaultProps", staticConfig.defaultProps);
|
|
714
|
-
}
|
|
715
783
|
const completeStylesProcessed = getStyles({
|
|
716
784
|
...staticConfig.defaultProps,
|
|
717
785
|
...completeStaticProps
|
|
@@ -721,7 +789,6 @@ function createExtractor() {
|
|
|
721
789
|
const toAdd = pick(completeStylesProcessed, ...stylesToAddToInitialGroup);
|
|
722
790
|
const firstGroup = attrs.find((x) => x.type === "style");
|
|
723
791
|
if (shouldPrintDebug) {
|
|
724
|
-
console.log(" stylesToAddToInitialGroup", stylesToAddToInitialGroup.join(", "));
|
|
725
792
|
console.log(" toAdd", objToStr(toAdd));
|
|
726
793
|
}
|
|
727
794
|
if (!firstGroup) {
|
|
@@ -731,9 +798,10 @@ function createExtractor() {
|
|
|
731
798
|
}
|
|
732
799
|
}
|
|
733
800
|
if (shouldPrintDebug) {
|
|
734
|
-
console.log("
|
|
735
|
-
console.log("
|
|
801
|
+
console.log(" completeStaticProps\n", logLines(objToStr(completeStaticProps)));
|
|
802
|
+
console.log(" completeStylesProcessed\n", logLines(objToStr(completeStylesProcessed)));
|
|
736
803
|
}
|
|
804
|
+
let getStyleError = null;
|
|
737
805
|
for (const attr of attrs) {
|
|
738
806
|
try {
|
|
739
807
|
switch (attr.type) {
|
|
@@ -742,32 +810,37 @@ function createExtractor() {
|
|
|
742
810
|
const c = getStyles(attr.value.consequent);
|
|
743
811
|
attr.value.alternate = a;
|
|
744
812
|
attr.value.consequent = c;
|
|
745
|
-
if (shouldPrintDebug)
|
|
813
|
+
if (shouldPrintDebug)
|
|
746
814
|
console.log(" => tern ", attrStr(attr));
|
|
747
|
-
|
|
748
|
-
break;
|
|
815
|
+
continue;
|
|
749
816
|
case "style":
|
|
750
|
-
const
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
817
|
+
for (const keyIn in attr.value) {
|
|
818
|
+
const [key, value] = (() => {
|
|
819
|
+
var _a2;
|
|
820
|
+
if (keyIn in stylePropsTransform) {
|
|
821
|
+
return ["transform", completeStylesProcessed["transform"]];
|
|
822
|
+
} else {
|
|
823
|
+
return [keyIn, (_a2 = completeStylesProcessed[keyIn]) != null ? _a2 : attr.value[keyIn]];
|
|
824
|
+
}
|
|
825
|
+
})();
|
|
826
|
+
if (shouldPrintDebug)
|
|
827
|
+
console.log("style", { keyIn, key, value });
|
|
828
|
+
delete attr.value[keyIn];
|
|
829
|
+
attr.value[key] = value;
|
|
757
830
|
}
|
|
758
|
-
|
|
759
|
-
break;
|
|
831
|
+
continue;
|
|
760
832
|
}
|
|
761
833
|
} catch (err) {
|
|
762
|
-
|
|
763
|
-
console.log(" postprocessing error, deopt", err);
|
|
764
|
-
node.attributes = ogAttributes;
|
|
765
|
-
return node;
|
|
766
|
-
}
|
|
834
|
+
getStyleError = err;
|
|
767
835
|
}
|
|
768
836
|
}
|
|
837
|
+
if (getStyleError) {
|
|
838
|
+
console.log(" \u26A0\uFE0F postprocessing error, deopt", getStyleError);
|
|
839
|
+
node.attributes = ogAttributes;
|
|
840
|
+
return node;
|
|
841
|
+
}
|
|
769
842
|
if (shouldPrintDebug) {
|
|
770
|
-
console.log(" - attrs (after)
|
|
843
|
+
console.log(" - attrs (after):\n", logLines(attrs.map(attrStr).join(", ")));
|
|
771
844
|
}
|
|
772
845
|
if (shouldFlatten) {
|
|
773
846
|
if (shouldPrintDebug) {
|
|
@@ -782,7 +855,7 @@ function createExtractor() {
|
|
|
782
855
|
}
|
|
783
856
|
if (shouldPrintDebug) {
|
|
784
857
|
console.log(" [\u274A] inline props ", inlinePropCount, shouldDeopt ? " deopted" : "", hasSpread ? " spread" : "", "!flatten", staticConfig.neverFlatten);
|
|
785
|
-
console.log(" - attrs (end)
|
|
858
|
+
console.log(" - attrs (end):\n", logLines(attrs.map(attrStr).join(", ")));
|
|
786
859
|
}
|
|
787
860
|
res.optimized++;
|
|
788
861
|
onExtractTag({
|
|
@@ -813,7 +886,6 @@ function createExtractor() {
|
|
|
813
886
|
}
|
|
814
887
|
__name(createExtractor, "createExtractor");
|
|
815
888
|
export {
|
|
816
|
-
FAILED_EVAL,
|
|
817
889
|
createExtractor
|
|
818
890
|
};
|
|
819
891
|
//# sourceMappingURL=createExtractor.js.map
|