@tamagui/static 1.0.0-alpha.34 → 1.0.0-alpha.38
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/.buildinfo +1 -0
- package/dist/extractor/createEvaluator.js.map +2 -2
- package/dist/extractor/createExtractor.js +86 -105
- package/dist/extractor/createExtractor.js.map +2 -2
- package/dist/extractor/extractHelpers.js +1 -3
- package/dist/extractor/extractHelpers.js.map +2 -2
- package/dist/extractor/extractMediaStyle.js +8 -10
- package/dist/extractor/extractMediaStyle.js.map +2 -2
- package/dist/extractor/extractToClassNames.js +20 -10
- package/dist/extractor/extractToClassNames.js.map +2 -2
- package/dist/extractor/getStaticBindingsForScope.js +7 -0
- package/dist/extractor/getStaticBindingsForScope.js.map +2 -2
- package/dist/forwardPropsList.js +140 -0
- package/dist/forwardPropsList.js.map +7 -0
- package/dist/index.cjs +133 -205
- package/dist/index.cjs.map +3 -3
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/patchReactNativeWeb.js +3 -30
- package/dist/patchReactNativeWeb.js.map +2 -2
- package/package.json +7 -7
- package/dist/cjs/constants.js +0 -33
- package/dist/cjs/constants.js.map +0 -7
- package/dist/cjs/extractor/accessSafe.js +0 -33
- package/dist/cjs/extractor/accessSafe.js.map +0 -7
- package/dist/cjs/extractor/babelParse.js +0 -52
- package/dist/cjs/extractor/babelParse.js.map +0 -7
- package/dist/cjs/extractor/buildClassName.js +0 -62
- package/dist/cjs/extractor/buildClassName.js.map +0 -7
- package/dist/cjs/extractor/createEvaluator.js +0 -73
- package/dist/cjs/extractor/createEvaluator.js.map +0 -7
- package/dist/cjs/extractor/createExtractor.js +0 -903
- package/dist/cjs/extractor/createExtractor.js.map +0 -7
- package/dist/cjs/extractor/ensureImportingConcat.js +0 -46
- package/dist/cjs/extractor/ensureImportingConcat.js.map +0 -7
- package/dist/cjs/extractor/evaluateAstNode.js +0 -116
- package/dist/cjs/extractor/evaluateAstNode.js.map +0 -7
- package/dist/cjs/extractor/extractHelpers.js +0 -118
- package/dist/cjs/extractor/extractHelpers.js.map +0 -7
- package/dist/cjs/extractor/extractMediaStyle.js +0 -187
- package/dist/cjs/extractor/extractMediaStyle.js.map +0 -7
- package/dist/cjs/extractor/extractToClassNames.js +0 -279
- package/dist/cjs/extractor/extractToClassNames.js.map +0 -7
- package/dist/cjs/extractor/findTopmostFunction.js +0 -29
- package/dist/cjs/extractor/findTopmostFunction.js.map +0 -7
- package/dist/cjs/extractor/generatedUid.js +0 -50
- package/dist/cjs/extractor/generatedUid.js.map +0 -7
- package/dist/cjs/extractor/getPropValueFromAttributes.js +0 -71
- package/dist/cjs/extractor/getPropValueFromAttributes.js.map +0 -7
- package/dist/cjs/extractor/getSourceModule.js +0 -91
- package/dist/cjs/extractor/getSourceModule.js.map +0 -7
- package/dist/cjs/extractor/getStaticBindingsForScope.js +0 -150
- package/dist/cjs/extractor/getStaticBindingsForScope.js.map +0 -7
- package/dist/cjs/extractor/hoistClassNames.js +0 -66
- package/dist/cjs/extractor/hoistClassNames.js.map +0 -7
- package/dist/cjs/extractor/literalToAst.js +0 -56
- package/dist/cjs/extractor/literalToAst.js.map +0 -7
- package/dist/cjs/extractor/loadTamagui.js +0 -63
- package/dist/cjs/extractor/loadTamagui.js.map +0 -7
- package/dist/cjs/extractor/logLines.js +0 -23
- package/dist/cjs/extractor/logLines.js.map +0 -7
- package/dist/cjs/extractor/normalizeTernaries.js +0 -102
- package/dist/cjs/extractor/normalizeTernaries.js.map +0 -7
- package/dist/cjs/extractor/removeUnusedHooks.js +0 -101
- package/dist/cjs/extractor/removeUnusedHooks.js.map +0 -7
- package/dist/cjs/index.js +0 -37
- package/dist/cjs/index.js.map +0 -7
- package/dist/cjs/patchReactNativeWeb.js +0 -129
- package/dist/cjs/patchReactNativeWeb.js.map +0 -7
- package/dist/cjs/types.js +0 -4
- package/dist/cjs/types.js.map +0 -7
- package/dist/esm/constants.js +0 -10
- package/dist/esm/constants.js.map +0 -7
- package/dist/esm/extractor/accessSafe.js +0 -11
- package/dist/esm/extractor/accessSafe.js.map +0 -7
- package/dist/esm/extractor/babelParse.js +0 -30
- package/dist/esm/extractor/babelParse.js.map +0 -7
- package/dist/esm/extractor/buildClassName.js +0 -40
- package/dist/esm/extractor/buildClassName.js.map +0 -7
- package/dist/esm/extractor/createEvaluator.js +0 -51
- package/dist/esm/extractor/createEvaluator.js.map +0 -7
- package/dist/esm/extractor/createExtractor.js +0 -840
- package/dist/esm/extractor/createExtractor.js.map +0 -7
- package/dist/esm/extractor/ensureImportingConcat.js +0 -24
- package/dist/esm/extractor/ensureImportingConcat.js.map +0 -7
- package/dist/esm/extractor/evaluateAstNode.js +0 -94
- package/dist/esm/extractor/evaluateAstNode.js.map +0 -7
- package/dist/esm/extractor/extractHelpers.js +0 -94
- package/dist/esm/extractor/extractHelpers.js.map +0 -7
- package/dist/esm/extractor/extractMediaStyle.js +0 -151
- package/dist/esm/extractor/extractMediaStyle.js.map +0 -7
- package/dist/esm/extractor/extractToClassNames.js +0 -240
- package/dist/esm/extractor/extractToClassNames.js.map +0 -7
- package/dist/esm/extractor/findTopmostFunction.js +0 -23
- package/dist/esm/extractor/findTopmostFunction.js.map +0 -7
- package/dist/esm/extractor/generatedUid.js +0 -28
- package/dist/esm/extractor/generatedUid.js.map +0 -7
- package/dist/esm/extractor/getPropValueFromAttributes.js +0 -49
- package/dist/esm/extractor/getPropValueFromAttributes.js.map +0 -7
- package/dist/esm/extractor/getSourceModule.js +0 -69
- package/dist/esm/extractor/getSourceModule.js.map +0 -7
- package/dist/esm/extractor/getStaticBindingsForScope.js +0 -128
- package/dist/esm/extractor/getStaticBindingsForScope.js.map +0 -7
- package/dist/esm/extractor/hoistClassNames.js +0 -44
- package/dist/esm/extractor/hoistClassNames.js.map +0 -7
- package/dist/esm/extractor/literalToAst.js +0 -34
- package/dist/esm/extractor/literalToAst.js.map +0 -7
- package/dist/esm/extractor/loadTamagui.js +0 -41
- package/dist/esm/extractor/loadTamagui.js.map +0 -7
- package/dist/esm/extractor/logLines.js +0 -17
- package/dist/esm/extractor/logLines.js.map +0 -7
- package/dist/esm/extractor/normalizeTernaries.js +0 -52
- package/dist/esm/extractor/normalizeTernaries.js.map +0 -7
- package/dist/esm/extractor/removeUnusedHooks.js +0 -78
- package/dist/esm/extractor/removeUnusedHooks.js.map +0 -7
- package/dist/esm/index.js +0 -14
- package/dist/esm/index.js.map +0 -7
- package/dist/esm/patchReactNativeWeb.js +0 -107
- package/dist/esm/patchReactNativeWeb.js.map +0 -7
- package/dist/esm/types.js +0 -1
- package/dist/esm/types.js.map +0 -7
- package/dist/extractor/loadTamagui.js +0 -41
- package/dist/extractor/loadTamagui.js.map +0 -7
- package/dist/jsx/constants.js +0 -9
- package/dist/jsx/extractor/accessSafe.js +0 -10
- package/dist/jsx/extractor/babelParse.js +0 -29
- package/dist/jsx/extractor/buildClassName.js +0 -39
- package/dist/jsx/extractor/createEvaluator.js +0 -50
- package/dist/jsx/extractor/createExtractor.js +0 -839
- package/dist/jsx/extractor/ensureImportingConcat.js +0 -23
- package/dist/jsx/extractor/evaluateAstNode.js +0 -93
- package/dist/jsx/extractor/extractHelpers.js +0 -93
- package/dist/jsx/extractor/extractMediaStyle.js +0 -150
- package/dist/jsx/extractor/extractToClassNames.js +0 -239
- package/dist/jsx/extractor/findTopmostFunction.js +0 -22
- package/dist/jsx/extractor/generatedUid.js +0 -27
- package/dist/jsx/extractor/getPropValueFromAttributes.js +0 -48
- package/dist/jsx/extractor/getSourceModule.js +0 -68
- package/dist/jsx/extractor/getStaticBindingsForScope.js +0 -127
- package/dist/jsx/extractor/hoistClassNames.js +0 -43
- package/dist/jsx/extractor/literalToAst.js +0 -33
- package/dist/jsx/extractor/loadTamagui.js +0 -40
- package/dist/jsx/extractor/logLines.js +0 -16
- package/dist/jsx/extractor/normalizeTernaries.js +0 -51
- package/dist/jsx/extractor/removeUnusedHooks.js +0 -77
- package/dist/jsx/index.js +0 -13
- package/dist/jsx/patchReactNativeWeb.js +0 -106
- package/dist/jsx/types.js +0 -0
- package/types/constants.d.ts.map +0 -1
- package/types/extractor/accessSafe.d.ts.map +0 -1
- package/types/extractor/babelParse.d.ts.map +0 -1
- package/types/extractor/buildClassName.d.ts.map +0 -1
- package/types/extractor/createEvaluator.d.ts.map +0 -1
- package/types/extractor/createExtractor.d.ts.map +0 -1
- package/types/extractor/ensureImportingConcat.d.ts.map +0 -1
- package/types/extractor/evaluateAstNode.d.ts.map +0 -1
- package/types/extractor/extractHelpers.d.ts.map +0 -1
- package/types/extractor/extractMediaStyle.d.ts.map +0 -1
- package/types/extractor/extractToClassNames.d.ts.map +0 -1
- package/types/extractor/findTopmostFunction.d.ts.map +0 -1
- package/types/extractor/generatedUid.d.ts.map +0 -1
- package/types/extractor/getPropValueFromAttributes.d.ts.map +0 -1
- package/types/extractor/getSourceModule.d.ts.map +0 -1
- package/types/extractor/getStaticBindingsForScope.d.ts.map +0 -1
- package/types/extractor/hoistClassNames.d.ts.map +0 -1
- package/types/extractor/literalToAst.d.ts.map +0 -1
- package/types/extractor/loadTamagui.d.ts.map +0 -1
- package/types/extractor/logLines.d.ts.map +0 -1
- package/types/extractor/normalizeTernaries.d.ts.map +0 -1
- package/types/extractor/removeUnusedHooks.d.ts.map +0 -1
- package/types/index.d.ts.map +0 -1
- package/types/patchReactNativeWeb.d.ts.map +0 -1
- package/types/types.d.ts.map +0 -1
package/dist/.buildinfo
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"at":1636517189925}
|
|
@@ -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 '
|
|
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,
|
|
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'\n\nimport { FAILED_EVAL } from './createExtractor'\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 (t.isMemberExpression(n) && t.isIdentifier(n.property) && isValidThemeHook(traversePath, n, sourcePath)) {\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,QAAI,EAAE,mBAAmB,MAAM,EAAE,aAAa,EAAE,aAAa,iBAAiB,cAAc,GAAG,aAAa;AAC1G,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,KAtBhB;AAyBf,SAAO,CAAC,MAAc;AACpB,WAAO,gBAAgB,GAAG;AAAA;AAAA;AAxCd;AA4CT,6BAA6B,aAAiC;AACnE,SAAO,CAAC,MAAc;AACpB,QAAI;AACF,aAAO,YAAY;AAAA,aACZ,KAAP;AACA,aAAO;AAAA;AAAA;AAAA;AALG;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
var __defProp = Object.defineProperty;
|
|
2
2
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
+
import { join } from "path";
|
|
3
4
|
import traverse from "@babel/traverse";
|
|
4
5
|
import * as t from "@babel/types";
|
|
5
6
|
import * as CoreNode from "@tamagui/core-node";
|
|
6
|
-
import {
|
|
7
|
+
import { pseudos } from "@tamagui/helpers";
|
|
7
8
|
import { difference, pick } from "lodash";
|
|
8
9
|
import { createEvaluator, createSafeEvaluator } from "./createEvaluator";
|
|
9
10
|
import { evaluateAstNode } from "./evaluateAstNode";
|
|
@@ -11,10 +12,9 @@ import { attrStr, findComponentName, isInsideTamagui, isPresent, objToStr } from
|
|
|
11
12
|
import { findTopmostFunction } from "./findTopmostFunction";
|
|
12
13
|
import { getStaticBindingsForScope } from "./getStaticBindingsForScope";
|
|
13
14
|
import { literalToAst } from "./literalToAst";
|
|
14
|
-
import { loadTamagui } from "./loadTamagui";
|
|
15
15
|
import { normalizeTernaries } from "./normalizeTernaries";
|
|
16
16
|
import { removeUnusedHooks } from "./removeUnusedHooks";
|
|
17
|
-
const { mediaQueryConfig, postProcessStyles
|
|
17
|
+
const { mediaQueryConfig, postProcessStyles } = CoreNode;
|
|
18
18
|
const FAILED_EVAL = Symbol("failed_style_eval");
|
|
19
19
|
const UNTOUCHED_PROPS = {
|
|
20
20
|
key: true,
|
|
@@ -27,18 +27,44 @@ const validHooks = {
|
|
|
27
27
|
useTheme: true
|
|
28
28
|
};
|
|
29
29
|
const createTernary = /* @__PURE__ */ __name((x) => x, "createTernary");
|
|
30
|
+
let loadedTamagui = null;
|
|
31
|
+
function loadTamagui(props) {
|
|
32
|
+
if (loadedTamagui) {
|
|
33
|
+
return loadedTamagui;
|
|
34
|
+
}
|
|
35
|
+
process.env.IS_STATIC = "is_static";
|
|
36
|
+
const proxyWorm = require("@dish/proxy-worm");
|
|
37
|
+
const Mod = require("module");
|
|
38
|
+
const og = Mod.prototype.require;
|
|
39
|
+
Mod.prototype.require = function(path) {
|
|
40
|
+
if (path.startsWith("react-native")) {
|
|
41
|
+
return proxyWorm;
|
|
42
|
+
}
|
|
43
|
+
return og.apply(this, arguments);
|
|
44
|
+
};
|
|
45
|
+
const tamaguiConfigExport = require(join(process.cwd(), props.config));
|
|
46
|
+
const tamaguiConfig = tamaguiConfigExport["default"] || tamaguiConfigExport;
|
|
47
|
+
const components = {};
|
|
48
|
+
for (const module of props.components) {
|
|
49
|
+
const exported = require(module);
|
|
50
|
+
Object.assign(components, exported);
|
|
51
|
+
}
|
|
52
|
+
process.env.IS_STATIC = void 0;
|
|
53
|
+
Mod.prototype.require = og;
|
|
54
|
+
return {
|
|
55
|
+
components,
|
|
56
|
+
tamaguiConfig
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
__name(loadTamagui, "loadTamagui");
|
|
30
60
|
function createExtractor() {
|
|
31
|
-
|
|
61
|
+
console.log("create");
|
|
62
|
+
const shouldAddDebugProp = process.env.TARGET !== "native" && process.env.IDENTIFY_TAGS !== "false" && (process.env.NODE_ENV === "development" || process.env.DEBUG || process.env.IDENTIFY_TAGS);
|
|
32
63
|
require("esbuild-register/dist/node").register({
|
|
33
64
|
target: "es2019",
|
|
34
65
|
format: "cjs"
|
|
35
66
|
});
|
|
36
|
-
let loadedTamaguiConfig;
|
|
37
|
-
let hasLogged = false;
|
|
38
67
|
return {
|
|
39
|
-
getTamagui() {
|
|
40
|
-
return loadedTamaguiConfig;
|
|
41
|
-
},
|
|
42
68
|
parse: (fileOrPath, {
|
|
43
69
|
config = "tamagui.config.ts",
|
|
44
70
|
importsWhitelist = ["constants.js"],
|
|
@@ -47,36 +73,29 @@ function createExtractor() {
|
|
|
47
73
|
sourcePath = "",
|
|
48
74
|
onExtractTag,
|
|
49
75
|
getFlattenedNode,
|
|
50
|
-
|
|
51
|
-
disableExtractInlineMedia,
|
|
52
|
-
disableDebugAttr,
|
|
76
|
+
onDidFlatten,
|
|
53
77
|
...props
|
|
54
78
|
}) => {
|
|
55
79
|
if (sourcePath === "") {
|
|
56
80
|
throw new Error(`Must provide a source file name`);
|
|
57
81
|
}
|
|
58
|
-
if (!Array.isArray(props.components)) {
|
|
59
|
-
throw new Error(`Must provide components array with list of Tamagui component modules`);
|
|
60
|
-
}
|
|
61
82
|
const { components, tamaguiConfig } = loadTamagui({
|
|
62
83
|
config,
|
|
63
84
|
components: props.components || ["tamagui"]
|
|
64
85
|
});
|
|
65
|
-
|
|
66
|
-
const defaultTheme = tamaguiConfig.themes[Object.keys(tamaguiConfig.themes)[0]];
|
|
86
|
+
let doesUseValidImport = false;
|
|
67
87
|
const body = fileOrPath.type === "Program" ? fileOrPath.get("body") : fileOrPath.program.body;
|
|
68
88
|
const isInternalImport = /* @__PURE__ */ __name((importStr) => isInsideTamagui(sourcePath) && importStr[0] === ".", "isInternalImport");
|
|
69
|
-
const validComponents = Object.keys(components).filter((key) =>
|
|
89
|
+
const validComponents = Object.keys(components).filter((key) => !!components[key]?.staticConfig).reduce((obj, name) => {
|
|
70
90
|
obj[name] = components[name];
|
|
71
91
|
return obj;
|
|
72
92
|
}, {});
|
|
73
|
-
let doesUseValidImport = false;
|
|
74
93
|
for (const bodyPath of body) {
|
|
75
94
|
if (bodyPath.type !== "ImportDeclaration")
|
|
76
95
|
continue;
|
|
77
96
|
const node = "node" in bodyPath ? bodyPath.node : bodyPath;
|
|
78
97
|
const from = node.source.value;
|
|
79
|
-
if (
|
|
98
|
+
if (from === "tamagui" || isInternalImport(from)) {
|
|
80
99
|
if (node.specifiers.some((specifier) => {
|
|
81
100
|
const name = specifier.local.name;
|
|
82
101
|
return validComponents[name] || validHooks[name];
|
|
@@ -99,11 +118,6 @@ function createExtractor() {
|
|
|
99
118
|
return fileOrPath.type === "File" ? traverse(fileOrPath, a) : fileOrPath.traverse(a);
|
|
100
119
|
}, "callTraverse");
|
|
101
120
|
let programPath;
|
|
102
|
-
const res = {
|
|
103
|
-
flattened: 0,
|
|
104
|
-
optimized: 0,
|
|
105
|
-
modified: 0
|
|
106
|
-
};
|
|
107
121
|
callTraverse({
|
|
108
122
|
Program: {
|
|
109
123
|
enter(path) {
|
|
@@ -124,7 +138,7 @@ function createExtractor() {
|
|
|
124
138
|
return;
|
|
125
139
|
}
|
|
126
140
|
const source = binding.path.parent.source;
|
|
127
|
-
if (
|
|
141
|
+
if (source.value !== "tamagui" && !isInternalImport(source.value)) {
|
|
128
142
|
return;
|
|
129
143
|
}
|
|
130
144
|
if (!validComponents[binding.identifier.name]) {
|
|
@@ -135,29 +149,11 @@ function createExtractor() {
|
|
|
135
149
|
if (!component || !component.staticConfig) {
|
|
136
150
|
return;
|
|
137
151
|
}
|
|
138
|
-
const originalNodeName = node.name.name;
|
|
139
|
-
if (shouldPrintDebug) {
|
|
140
|
-
console.log(`
|
|
141
|
-
<${originalNodeName} />`);
|
|
142
|
-
}
|
|
143
|
-
const filePath = sourcePath.replace(process.cwd(), ".");
|
|
144
|
-
const lineNumbers = node.loc ? node.loc.start.line + (node.loc.start.line !== node.loc.end.line ? `-${node.loc.end.line}` : "") : "";
|
|
145
|
-
if (shouldAddDebugProp && !disableDebugAttr) {
|
|
146
|
-
const preName = componentName ? `${componentName}:` : "";
|
|
147
|
-
res.modified++;
|
|
148
|
-
node.attributes.unshift(t.jsxAttribute(t.jsxIdentifier("data-is"), t.stringLiteral(` ${preName}${node.name.name} ${filePath.replace("./", "")}:${lineNumbers} `)));
|
|
149
|
-
}
|
|
150
|
-
if (disableExtraction) {
|
|
151
|
-
if (!hasLogged) {
|
|
152
|
-
console.log("\u{1F95A} Tamagui disableExtraction set: no CSS or optimizations will be run");
|
|
153
|
-
hasLogged = true;
|
|
154
|
-
}
|
|
155
|
-
return;
|
|
156
|
-
}
|
|
157
152
|
const { staticConfig } = component;
|
|
153
|
+
const originalNodeName = node.name.name;
|
|
158
154
|
const isTextView = staticConfig.isText || false;
|
|
159
155
|
const validStyles = staticConfig?.validStyles ?? {};
|
|
160
|
-
let tagName =
|
|
156
|
+
let tagName = isTextView ? "span" : "div";
|
|
161
157
|
traversePath.get("openingElement").get("attributes").forEach((path) => {
|
|
162
158
|
const attr = path.node;
|
|
163
159
|
if (t.isJSXSpreadAttribute(attr))
|
|
@@ -176,17 +172,21 @@ function createExtractor() {
|
|
|
176
172
|
]);
|
|
177
173
|
const excludeProps = new Set(props.excludeProps ?? []);
|
|
178
174
|
const isExcludedProp = /* @__PURE__ */ __name((name) => {
|
|
179
|
-
const
|
|
180
|
-
if (
|
|
175
|
+
const res = excludeProps.has(name);
|
|
176
|
+
if (res && shouldPrintDebug)
|
|
181
177
|
console.log(` excluding ${name}`);
|
|
182
|
-
return
|
|
178
|
+
return res;
|
|
183
179
|
}, "isExcludedProp");
|
|
184
180
|
const isDeoptedProp = /* @__PURE__ */ __name((name) => {
|
|
185
|
-
const
|
|
186
|
-
if (
|
|
181
|
+
const res = deoptProps.has(name);
|
|
182
|
+
if (res && shouldPrintDebug)
|
|
187
183
|
console.log(` deopting ${name}`);
|
|
188
|
-
return
|
|
184
|
+
return res;
|
|
189
185
|
}, "isDeoptedProp");
|
|
186
|
+
if (shouldPrintDebug) {
|
|
187
|
+
console.log(`
|
|
188
|
+
<${originalNodeName} />`);
|
|
189
|
+
}
|
|
190
190
|
const staticNamespace = getStaticBindingsForScope(traversePath.scope, importsWhitelist, sourcePath, bindingCache, shouldPrintDebug);
|
|
191
191
|
const attemptEval = !evaluateVars ? evaluateAstNode : createEvaluator({
|
|
192
192
|
tamaguiConfig,
|
|
@@ -259,11 +259,11 @@ function createExtractor() {
|
|
|
259
259
|
let isFlattened = false;
|
|
260
260
|
attrs = traversePath.get("openingElement").get("attributes").flatMap((path) => {
|
|
261
261
|
try {
|
|
262
|
-
const
|
|
263
|
-
if (!
|
|
262
|
+
const res = evaluateAttribute(path);
|
|
263
|
+
if (!res) {
|
|
264
264
|
path.remove();
|
|
265
265
|
}
|
|
266
|
-
return
|
|
266
|
+
return res;
|
|
267
267
|
} catch (err) {
|
|
268
268
|
console.log("Error extracting attribute", err.message, err.stack);
|
|
269
269
|
console.log("node", path.node);
|
|
@@ -274,7 +274,7 @@ function createExtractor() {
|
|
|
274
274
|
}
|
|
275
275
|
}).flat(4).filter(isPresent);
|
|
276
276
|
function isStaticAttributeName(name) {
|
|
277
|
-
return !!
|
|
277
|
+
return !!validStyles[name] || staticConfig.validPropsExtra?.[name] || !!pseudos[name];
|
|
278
278
|
}
|
|
279
279
|
__name(isStaticAttributeName, "isStaticAttributeName");
|
|
280
280
|
function isExtractable(obj) {
|
|
@@ -284,10 +284,8 @@ function createExtractor() {
|
|
|
284
284
|
return false;
|
|
285
285
|
}
|
|
286
286
|
const propName = prop.key["name"];
|
|
287
|
-
if (!isStaticAttributeName(propName)
|
|
288
|
-
|
|
289
|
-
console.log(" not a valid style prop!", propName);
|
|
290
|
-
}
|
|
287
|
+
if (!isStaticAttributeName(propName)) {
|
|
288
|
+
console.log(" not a valid style prop!", propName);
|
|
291
289
|
return false;
|
|
292
290
|
}
|
|
293
291
|
return true;
|
|
@@ -347,15 +345,13 @@ function createExtractor() {
|
|
|
347
345
|
const attr = { type: "attr", value: attribute };
|
|
348
346
|
if (t.isJSXSpreadAttribute(attribute)) {
|
|
349
347
|
const arg = attribute.argument;
|
|
350
|
-
const conditional = t.isConditionalExpression(arg) ? [arg.test, arg.
|
|
348
|
+
const conditional = t.isConditionalExpression(arg) ? [arg.test, arg.alternate, arg.consequent] : t.isLogicalExpression(arg) && arg.operator === "&&" ? [arg.left, arg.right, null] : null;
|
|
351
349
|
if (conditional) {
|
|
352
350
|
const [test, alt, cons] = conditional;
|
|
353
351
|
if (!test)
|
|
354
352
|
throw new Error(`no test`);
|
|
355
353
|
if ([alt, cons].some((side) => side && !isExtractable(side))) {
|
|
356
|
-
|
|
357
|
-
console.log("not extractable", alt, cons);
|
|
358
|
-
}
|
|
354
|
+
console.log("not extractable", alt, cons);
|
|
359
355
|
return attr;
|
|
360
356
|
}
|
|
361
357
|
return [
|
|
@@ -386,9 +382,6 @@ function createExtractor() {
|
|
|
386
382
|
return attr;
|
|
387
383
|
}
|
|
388
384
|
if (name[0] === "$" && t.isJSXExpressionContainer(attribute?.value)) {
|
|
389
|
-
if (disableExtractInlineMedia) {
|
|
390
|
-
return attr;
|
|
391
|
-
}
|
|
392
385
|
const shortname = name.slice(1);
|
|
393
386
|
if (mediaQueryConfig[shortname]) {
|
|
394
387
|
const expression = attribute.value.expression;
|
|
@@ -422,22 +415,11 @@ function createExtractor() {
|
|
|
422
415
|
inlinePropCount++;
|
|
423
416
|
return attr;
|
|
424
417
|
}
|
|
425
|
-
if (name === "tag") {
|
|
426
|
-
return {
|
|
427
|
-
type: "attr",
|
|
428
|
-
value: path.node
|
|
429
|
-
};
|
|
430
|
-
}
|
|
431
418
|
const styleValue = attemptEvalSafe(value);
|
|
432
419
|
if (!isStaticAttributeName(name)) {
|
|
433
420
|
let keys = [name];
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
if (out) {
|
|
437
|
-
keys = Object.keys(out);
|
|
438
|
-
}
|
|
439
|
-
}
|
|
440
|
-
if (keys.some((k) => !isStaticAttributeName(k) && k !== "tag")) {
|
|
421
|
+
console.warn("\u26A0\uFE0F NEED TO DO PROP MAPPING HERE");
|
|
422
|
+
if (keys.some((k) => !isStaticAttributeName(k))) {
|
|
441
423
|
if (shouldPrintDebug) {
|
|
442
424
|
console.log(" ! inlining, not static attribute name", name);
|
|
443
425
|
}
|
|
@@ -448,9 +430,7 @@ function createExtractor() {
|
|
|
448
430
|
if (styleValue !== FAILED_EVAL) {
|
|
449
431
|
return {
|
|
450
432
|
type: "style",
|
|
451
|
-
value: { [name]: styleValue }
|
|
452
|
-
name,
|
|
453
|
-
attr: path.node
|
|
433
|
+
value: { [name]: styleValue }
|
|
454
434
|
};
|
|
455
435
|
}
|
|
456
436
|
if (t.isBinaryExpression(value)) {
|
|
@@ -512,9 +492,6 @@ function createExtractor() {
|
|
|
512
492
|
function getStaticConditional(value2) {
|
|
513
493
|
if (t.isConditionalExpression(value2)) {
|
|
514
494
|
try {
|
|
515
|
-
if (shouldPrintDebug) {
|
|
516
|
-
console.log("attempt", value2.alternate, value2.consequent);
|
|
517
|
-
}
|
|
518
495
|
const aVal = attemptEval(value2.alternate);
|
|
519
496
|
const cVal = attemptEval(value2.consequent);
|
|
520
497
|
if (shouldPrintDebug) {
|
|
@@ -577,6 +554,8 @@ function createExtractor() {
|
|
|
577
554
|
if (parentFn) {
|
|
578
555
|
modifiedComponents.add(parentFn);
|
|
579
556
|
}
|
|
557
|
+
const filePath = sourcePath.replace(process.cwd(), ".");
|
|
558
|
+
const lineNumbers = node.loc ? node.loc.start.line + (node.loc.start.line !== node.loc.end.line ? `-${node.loc.end.line}` : "") : "";
|
|
580
559
|
let ternaries = [];
|
|
581
560
|
attrs = attrs.reduce((out, cur) => {
|
|
582
561
|
const next = attrs[attrs.indexOf(cur) + 1];
|
|
@@ -639,16 +618,14 @@ function createExtractor() {
|
|
|
639
618
|
attrs = attrs.reduce((acc, cur) => {
|
|
640
619
|
if (cur.type === "style") {
|
|
641
620
|
for (const key in cur.value) {
|
|
642
|
-
const
|
|
621
|
+
const shouldInsertNull = !!staticConfig.ensureOverriddenProp?.[key];
|
|
643
622
|
const isSetInAttrsAlready = attrs.some((x) => x.type === "attr" && x.value.type === "JSXAttribute" && x.value.name.name === key);
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
});
|
|
651
|
-
}
|
|
623
|
+
const shouldInsertNullOverride = shouldInsertNull && !isSetInAttrsAlready;
|
|
624
|
+
if (shouldInsertNullOverride) {
|
|
625
|
+
acc.push({
|
|
626
|
+
type: "attr",
|
|
627
|
+
value: t.jsxAttribute(t.jsxIdentifier(key), t.jsxExpressionContainer(t.nullLiteral()))
|
|
628
|
+
});
|
|
652
629
|
}
|
|
653
630
|
}
|
|
654
631
|
}
|
|
@@ -681,6 +658,9 @@ function createExtractor() {
|
|
|
681
658
|
attrs = attrs.reduce((acc, cur) => {
|
|
682
659
|
if (cur.type === "style") {
|
|
683
660
|
if (prev?.type === "style") {
|
|
661
|
+
if (shouldPrintDebug) {
|
|
662
|
+
console.log(" \u{1F500} merging style");
|
|
663
|
+
}
|
|
684
664
|
Object.assign(prev.value, cur.value);
|
|
685
665
|
return acc;
|
|
686
666
|
}
|
|
@@ -690,7 +670,7 @@ function createExtractor() {
|
|
|
690
670
|
return acc;
|
|
691
671
|
}, []);
|
|
692
672
|
if (shouldPrintDebug) {
|
|
693
|
-
console.log(" - attrs (combined
|
|
673
|
+
console.log(" - attrs (combined styles): ", attrs.map(attrStr).join(", "));
|
|
694
674
|
}
|
|
695
675
|
const getStyles = /* @__PURE__ */ __name((props2) => {
|
|
696
676
|
if (!props2)
|
|
@@ -701,7 +681,7 @@ function createExtractor() {
|
|
|
701
681
|
delete props2[key];
|
|
702
682
|
}
|
|
703
683
|
}
|
|
704
|
-
const out = postProcessStyles(props2, staticConfig
|
|
684
|
+
const out = postProcessStyles(props2, staticConfig);
|
|
705
685
|
const next = out?.style ?? props2;
|
|
706
686
|
if (shouldPrintDebug) {
|
|
707
687
|
console.log(" >> getStyles: ", objToStr(props2), "==>>", objToStr(next));
|
|
@@ -757,11 +737,7 @@ function createExtractor() {
|
|
|
757
737
|
case "style":
|
|
758
738
|
const next = {};
|
|
759
739
|
for (const key in attr.value) {
|
|
760
|
-
|
|
761
|
-
next["transform"] = completeStylesProcessed["transform"];
|
|
762
|
-
} else {
|
|
763
|
-
next[key] = completeStylesProcessed[key] ?? attr.value[key];
|
|
764
|
-
}
|
|
740
|
+
next[key] = completeStylesProcessed[key] ?? attr.value[key];
|
|
765
741
|
}
|
|
766
742
|
attr.value = next;
|
|
767
743
|
break;
|
|
@@ -777,13 +753,20 @@ function createExtractor() {
|
|
|
777
753
|
if (shouldPrintDebug) {
|
|
778
754
|
console.log(" - attrs (after): ", attrs.map(attrStr).join(", "));
|
|
779
755
|
}
|
|
756
|
+
if (shouldAddDebugProp) {
|
|
757
|
+
const preName = componentName ? `${componentName}:` : "";
|
|
758
|
+
attrs.unshift({
|
|
759
|
+
type: "attr",
|
|
760
|
+
value: t.jsxAttribute(t.jsxIdentifier("data-is"), t.stringLiteral(` ${preName}${node.name.name} ${filePath.replace("./", "")}:${lineNumbers} `))
|
|
761
|
+
});
|
|
762
|
+
}
|
|
780
763
|
if (shouldFlatten) {
|
|
781
764
|
if (shouldPrintDebug) {
|
|
782
765
|
console.log(" [\u2705] flattening", originalNodeName, flatNode);
|
|
783
766
|
}
|
|
784
767
|
isFlattened = true;
|
|
785
768
|
node.name.name = flatNode;
|
|
786
|
-
|
|
769
|
+
onDidFlatten?.();
|
|
787
770
|
if (closingElement) {
|
|
788
771
|
closingElement.name.name = flatNode;
|
|
789
772
|
}
|
|
@@ -792,7 +775,6 @@ function createExtractor() {
|
|
|
792
775
|
console.log(" [\u274A] inline props ", inlinePropCount, shouldDeopt ? " deopted" : "", hasSpread ? " spread" : "", "!flatten", staticConfig.neverFlatten);
|
|
793
776
|
console.log(" - attrs (end): ", attrs.map(attrStr).join(", "));
|
|
794
777
|
}
|
|
795
|
-
res.optimized++;
|
|
796
778
|
onExtractTag({
|
|
797
779
|
attrs,
|
|
798
780
|
node,
|
|
@@ -815,7 +797,6 @@ function createExtractor() {
|
|
|
815
797
|
removeUnusedHooks(comp, shouldPrintDebug);
|
|
816
798
|
}
|
|
817
799
|
}
|
|
818
|
-
return res;
|
|
819
800
|
}
|
|
820
801
|
};
|
|
821
802
|
}
|