@tamagui/static 1.0.11 → 1.0.13
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/extractor/createExtractor.js +0 -46
- package/dist/extractor/createExtractor.js.map +2 -2
- package/dist/extractor/ensureImportingConcat.js +3 -1
- package/dist/extractor/ensureImportingConcat.js.map +2 -2
- package/dist/extractor/extractToClassNames.js +19 -2
- package/dist/extractor/extractToClassNames.js.map +2 -2
- package/dist/extractor/getStaticBindingsForScope.js +3 -5
- package/dist/extractor/getStaticBindingsForScope.js.map +2 -2
- package/package.json +13 -13
- package/src/extractor/createExtractor.ts +0 -59
- package/src/extractor/ensureImportingConcat.ts +36 -0
- package/src/extractor/extractToClassNames.ts +23 -2
- package/src/extractor/getStaticBindingsForScope.ts +3 -5
- package/dist/cjs/constants.js +0 -49
- package/dist/cjs/constants.js.map +0 -7
- package/dist/cjs/extractor/accessSafe.js +0 -35
- package/dist/cjs/extractor/accessSafe.js.map +0 -7
- package/dist/cjs/extractor/babelParse.js +0 -56
- package/dist/cjs/extractor/babelParse.js.map +0 -7
- package/dist/cjs/extractor/buildClassName.js +0 -64
- package/dist/cjs/extractor/buildClassName.js.map +0 -7
- package/dist/cjs/extractor/bundle.js +0 -137
- package/dist/cjs/extractor/bundle.js.map +0 -7
- package/dist/cjs/extractor/createEvaluator.js +0 -81
- package/dist/cjs/extractor/createEvaluator.js.map +0 -7
- package/dist/cjs/extractor/createExtractor.js +0 -1330
- package/dist/cjs/extractor/createExtractor.js.map +0 -7
- package/dist/cjs/extractor/defaultTamaguiConfig.js +0 -167
- package/dist/cjs/extractor/defaultTamaguiConfig.js.map +0 -7
- package/dist/cjs/extractor/ensureImportingConcat.js +0 -48
- package/dist/cjs/extractor/ensureImportingConcat.js.map +0 -7
- package/dist/cjs/extractor/evaluateAstNode.js +0 -118
- package/dist/cjs/extractor/evaluateAstNode.js.map +0 -7
- package/dist/cjs/extractor/extractHelpers.js +0 -131
- package/dist/cjs/extractor/extractHelpers.js.map +0 -7
- package/dist/cjs/extractor/extractMediaStyle.js +0 -174
- package/dist/cjs/extractor/extractMediaStyle.js.map +0 -7
- package/dist/cjs/extractor/extractToClassNames.js +0 -305
- package/dist/cjs/extractor/extractToClassNames.js.map +0 -7
- package/dist/cjs/extractor/findTopmostFunction.js +0 -44
- package/dist/cjs/extractor/findTopmostFunction.js.map +0 -7
- package/dist/cjs/extractor/generatedUid.js +0 -52
- package/dist/cjs/extractor/generatedUid.js.map +0 -7
- package/dist/cjs/extractor/getPrefixLogs.js +0 -32
- package/dist/cjs/extractor/getPrefixLogs.js.map +0 -7
- package/dist/cjs/extractor/getPropValueFromAttributes.js +0 -73
- package/dist/cjs/extractor/getPropValueFromAttributes.js.map +0 -7
- package/dist/cjs/extractor/getSourceModule.js +0 -93
- package/dist/cjs/extractor/getSourceModule.js.map +0 -7
- package/dist/cjs/extractor/getStaticBindingsForScope.js +0 -184
- package/dist/cjs/extractor/getStaticBindingsForScope.js.map +0 -7
- package/dist/cjs/extractor/hoistClassNames.js +0 -67
- package/dist/cjs/extractor/hoistClassNames.js.map +0 -7
- package/dist/cjs/extractor/literalToAst.js +0 -103
- package/dist/cjs/extractor/literalToAst.js.map +0 -7
- package/dist/cjs/extractor/loadFile.js +0 -21
- package/dist/cjs/extractor/loadFile.js.map +0 -7
- package/dist/cjs/extractor/loadTamagui.js +0 -105
- package/dist/cjs/extractor/loadTamagui.js.map +0 -7
- package/dist/cjs/extractor/logLines.js +0 -44
- package/dist/cjs/extractor/logLines.js.map +0 -7
- package/dist/cjs/extractor/normalizeTernaries.js +0 -76
- package/dist/cjs/extractor/normalizeTernaries.js.map +0 -7
- package/dist/cjs/extractor/removeUnusedHooks.js +0 -103
- package/dist/cjs/extractor/removeUnusedHooks.js.map +0 -7
- package/dist/cjs/extractor/timer.js +0 -46
- package/dist/cjs/extractor/timer.js.map +0 -7
- package/dist/cjs/extractor/validHTMLAttributes.js +0 -127
- package/dist/cjs/extractor/validHTMLAttributes.js.map +0 -7
- package/dist/cjs/getPragmaOptions.js +0 -67
- package/dist/cjs/getPragmaOptions.js.map +0 -7
- package/dist/cjs/helpers/memoize.js +0 -45
- package/dist/cjs/helpers/memoize.js.map +0 -7
- package/dist/cjs/index.js +0 -43
- package/dist/cjs/index.js.map +0 -7
- package/dist/cjs/require.js +0 -104
- package/dist/cjs/require.js.map +0 -7
- package/dist/cjs/types.js +0 -17
- package/dist/cjs/types.js.map +0 -7
- package/dist/cjs/webpackPlugin.js +0 -34
- package/dist/cjs/webpackPlugin.js.map +0 -7
- package/dist/esm/constants.js +0 -17
- package/dist/esm/constants.js.map +0 -7
- package/dist/esm/extractor/accessSafe.js +0 -8
- package/dist/esm/extractor/accessSafe.js.map +0 -7
- package/dist/esm/extractor/babelParse.js +0 -28
- package/dist/esm/extractor/babelParse.js.map +0 -7
- package/dist/esm/extractor/buildClassName.js +0 -37
- package/dist/esm/extractor/buildClassName.js.map +0 -7
- package/dist/esm/extractor/bundle.js +0 -112
- package/dist/esm/extractor/bundle.js.map +0 -7
- package/dist/esm/extractor/createEvaluator.js +0 -53
- package/dist/esm/extractor/createEvaluator.js.map +0 -7
- package/dist/esm/extractor/createExtractor.js +0 -1311
- package/dist/esm/extractor/createExtractor.js.map +0 -7
- package/dist/esm/extractor/defaultTamaguiConfig.js +0 -143
- package/dist/esm/extractor/defaultTamaguiConfig.js.map +0 -7
- package/dist/esm/extractor/ensureImportingConcat.js +0 -21
- package/dist/esm/extractor/ensureImportingConcat.js.map +0 -7
- package/dist/esm/extractor/evaluateAstNode.js +0 -91
- package/dist/esm/extractor/evaluateAstNode.js.map +0 -7
- package/dist/esm/extractor/extractHelpers.js +0 -97
- package/dist/esm/extractor/extractHelpers.js.map +0 -7
- package/dist/esm/extractor/extractMediaStyle.js +0 -146
- package/dist/esm/extractor/extractMediaStyle.js.map +0 -7
- package/dist/esm/extractor/extractToClassNames.js +0 -278
- package/dist/esm/extractor/extractToClassNames.js.map +0 -7
- package/dist/esm/extractor/findTopmostFunction.js +0 -20
- package/dist/esm/extractor/findTopmostFunction.js.map +0 -7
- package/dist/esm/extractor/generatedUid.js +0 -25
- package/dist/esm/extractor/generatedUid.js.map +0 -7
- package/dist/esm/extractor/getPrefixLogs.js +0 -8
- package/dist/esm/extractor/getPrefixLogs.js.map +0 -7
- package/dist/esm/extractor/getPropValueFromAttributes.js +0 -46
- package/dist/esm/extractor/getPropValueFromAttributes.js.map +0 -7
- package/dist/esm/extractor/getSourceModule.js +0 -66
- package/dist/esm/extractor/getSourceModule.js.map +0 -7
- package/dist/esm/extractor/getStaticBindingsForScope.js +0 -157
- package/dist/esm/extractor/getStaticBindingsForScope.js.map +0 -7
- package/dist/esm/extractor/hoistClassNames.js +0 -40
- package/dist/esm/extractor/hoistClassNames.js.map +0 -7
- package/dist/esm/extractor/literalToAst.js +0 -75
- package/dist/esm/extractor/literalToAst.js.map +0 -7
- package/dist/esm/extractor/loadFile.js +0 -20
- package/dist/esm/extractor/loadFile.js.map +0 -7
- package/dist/esm/extractor/loadTamagui.js +0 -81
- package/dist/esm/extractor/loadTamagui.js.map +0 -7
- package/dist/esm/extractor/logLines.js +0 -20
- package/dist/esm/extractor/logLines.js.map +0 -7
- package/dist/esm/extractor/normalizeTernaries.js +0 -49
- package/dist/esm/extractor/normalizeTernaries.js.map +0 -7
- package/dist/esm/extractor/removeUnusedHooks.js +0 -76
- package/dist/esm/extractor/removeUnusedHooks.js.map +0 -7
- package/dist/esm/extractor/timer.js +0 -22
- package/dist/esm/extractor/timer.js.map +0 -7
- package/dist/esm/extractor/validHTMLAttributes.js +0 -102
- package/dist/esm/extractor/validHTMLAttributes.js.map +0 -7
- package/dist/esm/getPragmaOptions.js +0 -44
- package/dist/esm/getPragmaOptions.js.map +0 -7
- package/dist/esm/helpers/memoize.js +0 -22
- package/dist/esm/helpers/memoize.js.map +0 -7
- package/dist/esm/index.js +0 -16
- package/dist/esm/index.js.map +0 -7
- package/dist/esm/require.js +0 -78
- package/dist/esm/require.js.map +0 -7
- package/dist/esm/types.js +0 -1
- package/dist/esm/types.js.map +0 -7
- package/dist/esm/webpackPlugin.js +0 -11
- package/dist/esm/webpackPlugin.js.map +0 -7
- package/dist/jsx/constants.js +0 -17
- package/dist/jsx/constants.js.map +0 -7
- package/dist/jsx/extractor/accessSafe.js +0 -8
- package/dist/jsx/extractor/accessSafe.js.map +0 -7
- package/dist/jsx/extractor/babelParse.js +0 -28
- package/dist/jsx/extractor/babelParse.js.map +0 -7
- package/dist/jsx/extractor/buildClassName.js +0 -37
- package/dist/jsx/extractor/buildClassName.js.map +0 -7
- package/dist/jsx/extractor/bundle.js +0 -86
- package/dist/jsx/extractor/bundle.js.map +0 -7
- package/dist/jsx/extractor/createEvaluator.js +0 -53
- package/dist/jsx/extractor/createEvaluator.js.map +0 -7
- package/dist/jsx/extractor/createExtractor.js +0 -1311
- package/dist/jsx/extractor/createExtractor.js.map +0 -7
- package/dist/jsx/extractor/defaultTamaguiConfig.js +0 -143
- package/dist/jsx/extractor/defaultTamaguiConfig.js.map +0 -7
- package/dist/jsx/extractor/ensureImportingConcat.js +0 -21
- package/dist/jsx/extractor/ensureImportingConcat.js.map +0 -7
- package/dist/jsx/extractor/evaluateAstNode.js +0 -91
- package/dist/jsx/extractor/evaluateAstNode.js.map +0 -7
- package/dist/jsx/extractor/extractHelpers.js +0 -97
- package/dist/jsx/extractor/extractHelpers.js.map +0 -7
- package/dist/jsx/extractor/extractMediaStyle.js +0 -146
- package/dist/jsx/extractor/extractMediaStyle.js.map +0 -7
- package/dist/jsx/extractor/extractToClassNames.js +0 -280
- package/dist/jsx/extractor/extractToClassNames.js.map +0 -7
- package/dist/jsx/extractor/findTopmostFunction.js +0 -20
- package/dist/jsx/extractor/findTopmostFunction.js.map +0 -7
- package/dist/jsx/extractor/generatedUid.js +0 -25
- package/dist/jsx/extractor/generatedUid.js.map +0 -7
- package/dist/jsx/extractor/getPrefixLogs.js +0 -9
- package/dist/jsx/extractor/getPrefixLogs.js.map +0 -7
- package/dist/jsx/extractor/getPropValueFromAttributes.js +0 -46
- package/dist/jsx/extractor/getPropValueFromAttributes.js.map +0 -7
- package/dist/jsx/extractor/getSourceModule.js +0 -66
- package/dist/jsx/extractor/getSourceModule.js.map +0 -7
- package/dist/jsx/extractor/getStaticBindingsForScope.js +0 -157
- package/dist/jsx/extractor/getStaticBindingsForScope.js.map +0 -7
- package/dist/jsx/extractor/hoistClassNames.js +0 -40
- package/dist/jsx/extractor/hoistClassNames.js.map +0 -7
- package/dist/jsx/extractor/literalToAst.js +0 -75
- package/dist/jsx/extractor/literalToAst.js.map +0 -7
- package/dist/jsx/extractor/loadFile.js +0 -20
- package/dist/jsx/extractor/loadFile.js.map +0 -7
- package/dist/jsx/extractor/loadTamagui.js +0 -81
- package/dist/jsx/extractor/loadTamagui.js.map +0 -7
- package/dist/jsx/extractor/logLines.js +0 -20
- package/dist/jsx/extractor/logLines.js.map +0 -7
- package/dist/jsx/extractor/normalizeTernaries.js +0 -50
- package/dist/jsx/extractor/normalizeTernaries.js.map +0 -7
- package/dist/jsx/extractor/removeUnusedHooks.js +0 -77
- package/dist/jsx/extractor/removeUnusedHooks.js.map +0 -7
- package/dist/jsx/extractor/timer.js +0 -22
- package/dist/jsx/extractor/timer.js.map +0 -7
- package/dist/jsx/extractor/validHTMLAttributes.js +0 -102
- package/dist/jsx/extractor/validHTMLAttributes.js.map +0 -7
- package/dist/jsx/getPragmaOptions.js +0 -44
- package/dist/jsx/getPragmaOptions.js.map +0 -7
- package/dist/jsx/helpers/memoize.js +0 -22
- package/dist/jsx/helpers/memoize.js.map +0 -7
- package/dist/jsx/index.js +0 -16
- package/dist/jsx/index.js.map +0 -7
- package/dist/jsx/require.js +0 -78
- package/dist/jsx/require.js.map +0 -7
- package/dist/jsx/types.js +0 -1
- package/dist/jsx/types.js.map +0 -7
- package/dist/jsx/webpackPlugin.js +0 -11
- package/dist/jsx/webpackPlugin.js.map +0 -7
|
@@ -1,1311 +0,0 @@
|
|
|
1
|
-
import { relative } from "path";
|
|
2
|
-
import traverse from "@babel/traverse";
|
|
3
|
-
import * as t from "@babel/types";
|
|
4
|
-
import {
|
|
5
|
-
createDOMProps,
|
|
6
|
-
expandStyles,
|
|
7
|
-
getSplitStyles,
|
|
8
|
-
getStylesAtomic,
|
|
9
|
-
mediaQueryConfig,
|
|
10
|
-
proxyThemeVariables,
|
|
11
|
-
pseudoDescriptors
|
|
12
|
-
} from "@tamagui/core-node";
|
|
13
|
-
import { FAILED_EVAL } from "../constants";
|
|
14
|
-
import { createEvaluator, createSafeEvaluator } from "./createEvaluator";
|
|
15
|
-
import { evaluateAstNode } from "./evaluateAstNode";
|
|
16
|
-
import { attrStr, findComponentName, isInsideTamagui, isPresent, objToStr } from "./extractHelpers";
|
|
17
|
-
import { findTopmostFunction } from "./findTopmostFunction";
|
|
18
|
-
import { getStaticBindingsForScope } from "./getStaticBindingsForScope";
|
|
19
|
-
import { literalToAst } from "./literalToAst";
|
|
20
|
-
import { loadTamagui } from "./loadTamagui";
|
|
21
|
-
import { logLines } from "./logLines";
|
|
22
|
-
import { normalizeTernaries } from "./normalizeTernaries";
|
|
23
|
-
import { removeUnusedHooks } from "./removeUnusedHooks";
|
|
24
|
-
import { timer } from "./timer";
|
|
25
|
-
import { validHTMLAttributes } from "./validHTMLAttributes";
|
|
26
|
-
const UNTOUCHED_PROPS = {
|
|
27
|
-
key: true,
|
|
28
|
-
style: true,
|
|
29
|
-
className: true
|
|
30
|
-
};
|
|
31
|
-
const INLINE_EXTRACTABLE = {
|
|
32
|
-
ref: "ref",
|
|
33
|
-
key: "key",
|
|
34
|
-
...process.env.TAMAGUI_TARGET === "web" && {
|
|
35
|
-
onPress: "onClick",
|
|
36
|
-
onHoverIn: "onMouseEnter",
|
|
37
|
-
onHoverOut: "onMouseLeave",
|
|
38
|
-
onPressIn: "onMouseDown",
|
|
39
|
-
onPressOut: "onMouseUp"
|
|
40
|
-
}
|
|
41
|
-
};
|
|
42
|
-
const isAttr = (x) => x.type === "attr";
|
|
43
|
-
const validHooks = {
|
|
44
|
-
useMedia: true,
|
|
45
|
-
useTheme: true
|
|
46
|
-
};
|
|
47
|
-
const createTernary = (x) => x;
|
|
48
|
-
function createExtractor() {
|
|
49
|
-
if (!process.env.TAMAGUI_TARGET) {
|
|
50
|
-
console.log('\u26A0\uFE0F Please set process.env.TAMAGUI_TARGET to either "web" or "native"');
|
|
51
|
-
process.exit(1);
|
|
52
|
-
}
|
|
53
|
-
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);
|
|
54
|
-
let loadedTamaguiConfig;
|
|
55
|
-
let hasLogged = false;
|
|
56
|
-
function isValidStyleKey(name, staticConfig) {
|
|
57
|
-
var _a, _b;
|
|
58
|
-
return !!(!!((_a = staticConfig.validStyles) == null ? void 0 : _a[name]) || !!pseudoDescriptors[name] || ((_b = staticConfig.variants) == null ? void 0 : _b[name]) || loadedTamaguiConfig.shorthands[name] || (name[0] === "$" ? !!mediaQueryConfig[name.slice(1)] : false));
|
|
59
|
-
}
|
|
60
|
-
return {
|
|
61
|
-
getTamagui() {
|
|
62
|
-
return loadedTamaguiConfig;
|
|
63
|
-
},
|
|
64
|
-
parse: (fileOrPath, {
|
|
65
|
-
config = "tamagui.config.ts",
|
|
66
|
-
importsWhitelist = ["constants.js"],
|
|
67
|
-
evaluateVars = true,
|
|
68
|
-
shouldPrintDebug = false,
|
|
69
|
-
sourcePath = "",
|
|
70
|
-
onExtractTag,
|
|
71
|
-
onStyleRule,
|
|
72
|
-
getFlattenedNode,
|
|
73
|
-
disable,
|
|
74
|
-
disableExtraction,
|
|
75
|
-
disableExtractInlineMedia,
|
|
76
|
-
disableExtractVariables,
|
|
77
|
-
disableDebugAttr,
|
|
78
|
-
extractStyledDefinitions = false,
|
|
79
|
-
prefixLogs,
|
|
80
|
-
excludeProps,
|
|
81
|
-
target,
|
|
82
|
-
...props
|
|
83
|
-
}) => {
|
|
84
|
-
if (disable) {
|
|
85
|
-
return null;
|
|
86
|
-
}
|
|
87
|
-
if (sourcePath === "") {
|
|
88
|
-
throw new Error(`Must provide a source file name`);
|
|
89
|
-
}
|
|
90
|
-
if (!Array.isArray(props.components)) {
|
|
91
|
-
throw new Error(`Must provide components array with list of Tamagui component modules`);
|
|
92
|
-
}
|
|
93
|
-
const isTargetingHTML = target === "html";
|
|
94
|
-
const ogDebug = shouldPrintDebug;
|
|
95
|
-
const tm = timer();
|
|
96
|
-
const { components, tamaguiConfig } = loadTamagui({
|
|
97
|
-
config,
|
|
98
|
-
components: props.components || ["tamagui"]
|
|
99
|
-
});
|
|
100
|
-
if (shouldPrintDebug === "verbose") {
|
|
101
|
-
console.log("tamagui.config.ts:", { components, config });
|
|
102
|
-
}
|
|
103
|
-
tm.mark("load-tamagui", shouldPrintDebug === "verbose");
|
|
104
|
-
loadedTamaguiConfig = tamaguiConfig;
|
|
105
|
-
const proxiedTheme = proxyThemeVariables(tamaguiConfig.themes[Object.keys(tamaguiConfig.themes)[0]]);
|
|
106
|
-
const themeAccessListeners = /* @__PURE__ */ new Set();
|
|
107
|
-
const defaultTheme = new Proxy(proxiedTheme, {
|
|
108
|
-
get(target2, key) {
|
|
109
|
-
if (key[0] === "$") {
|
|
110
|
-
themeAccessListeners.forEach((cb) => cb(String(key)));
|
|
111
|
-
}
|
|
112
|
-
return Reflect.get(target2, key);
|
|
113
|
-
}
|
|
114
|
-
});
|
|
115
|
-
const body = fileOrPath.type === "Program" ? fileOrPath.get("body") : fileOrPath.program.body;
|
|
116
|
-
const isInternalImport = (importStr) => {
|
|
117
|
-
return isInsideTamagui(sourcePath) && importStr[0] === ".";
|
|
118
|
-
};
|
|
119
|
-
const validComponents = Object.keys(components).filter((key) => {
|
|
120
|
-
var _a;
|
|
121
|
-
return key[0].toUpperCase() === key[0] && !!((_a = components[key]) == null ? void 0 : _a.staticConfig);
|
|
122
|
-
}).reduce((obj, name) => {
|
|
123
|
-
obj[name] = components[name];
|
|
124
|
-
return obj;
|
|
125
|
-
}, {});
|
|
126
|
-
if (shouldPrintDebug === "verbose") {
|
|
127
|
-
console.log("validComponents", Object.keys(validComponents));
|
|
128
|
-
}
|
|
129
|
-
let doesUseValidImport = false;
|
|
130
|
-
let hasImportedTheme = false;
|
|
131
|
-
for (const bodyPath of body) {
|
|
132
|
-
if (bodyPath.type !== "ImportDeclaration")
|
|
133
|
-
continue;
|
|
134
|
-
const node = "node" in bodyPath ? bodyPath.node : bodyPath;
|
|
135
|
-
const from = node.source.value;
|
|
136
|
-
if (extractStyledDefinitions) {
|
|
137
|
-
if (from === "@tamagui/core" || from === "tamagui") {
|
|
138
|
-
if (node.specifiers.some((specifier) => {
|
|
139
|
-
return specifier.local.name === "styled";
|
|
140
|
-
})) {
|
|
141
|
-
doesUseValidImport = true;
|
|
142
|
-
break;
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
const isValidImport = props.components.includes(from) || isInternalImport(from);
|
|
147
|
-
if (isValidImport) {
|
|
148
|
-
const isValidComponent = node.specifiers.some((specifier) => {
|
|
149
|
-
const name = specifier.local.name;
|
|
150
|
-
return !!(validComponents[name] || validHooks[name]);
|
|
151
|
-
});
|
|
152
|
-
if (shouldPrintDebug === "verbose") {
|
|
153
|
-
console.log("import from", from, { isValidComponent });
|
|
154
|
-
}
|
|
155
|
-
if (isValidComponent) {
|
|
156
|
-
doesUseValidImport = true;
|
|
157
|
-
break;
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
if (shouldPrintDebug) {
|
|
162
|
-
console.log(sourcePath, { doesUseValidImport });
|
|
163
|
-
}
|
|
164
|
-
if (!doesUseValidImport) {
|
|
165
|
-
return null;
|
|
166
|
-
}
|
|
167
|
-
tm.mark("import-check", shouldPrintDebug === "verbose");
|
|
168
|
-
let couldntParse = false;
|
|
169
|
-
const modifiedComponents = /* @__PURE__ */ new Set();
|
|
170
|
-
const bindingCache = {};
|
|
171
|
-
const callTraverse = (a) => {
|
|
172
|
-
return fileOrPath.type === "File" ? traverse(fileOrPath, a) : fileOrPath.traverse(a);
|
|
173
|
-
};
|
|
174
|
-
let programPath;
|
|
175
|
-
const res = {
|
|
176
|
-
styled: 0,
|
|
177
|
-
flattened: 0,
|
|
178
|
-
optimized: 0,
|
|
179
|
-
modified: 0,
|
|
180
|
-
found: 0
|
|
181
|
-
};
|
|
182
|
-
callTraverse({
|
|
183
|
-
Program: {
|
|
184
|
-
enter(path) {
|
|
185
|
-
programPath = path;
|
|
186
|
-
}
|
|
187
|
-
},
|
|
188
|
-
CallExpression(path) {
|
|
189
|
-
var _a;
|
|
190
|
-
if (disable || disableExtraction || extractStyledDefinitions === false) {
|
|
191
|
-
return;
|
|
192
|
-
}
|
|
193
|
-
if (!t.isIdentifier(path.node.callee) || path.node.callee.name !== "styled") {
|
|
194
|
-
return;
|
|
195
|
-
}
|
|
196
|
-
const name = t.isVariableDeclarator(path.parent) && t.isIdentifier(path.parent.id) ? path.parent.id.name : "unknown";
|
|
197
|
-
const definition = path.node.arguments[1];
|
|
198
|
-
if (!name || !definition || !t.isObjectExpression(definition)) {
|
|
199
|
-
return;
|
|
200
|
-
}
|
|
201
|
-
const Component = validComponents[name];
|
|
202
|
-
if (!Component) {
|
|
203
|
-
if (shouldPrintDebug) {
|
|
204
|
-
console.log(`Didn't recognize styled(${name}), ${name} isn't in design system provided to tamagui.config.ts`);
|
|
205
|
-
}
|
|
206
|
-
return;
|
|
207
|
-
}
|
|
208
|
-
const componentSkipProps = /* @__PURE__ */ new Set([
|
|
209
|
-
...Component.staticConfig.inlineWhenUnflattened || [],
|
|
210
|
-
...Component.staticConfig.inlineProps || [],
|
|
211
|
-
...Component.staticConfig.deoptProps || [],
|
|
212
|
-
"variants",
|
|
213
|
-
"defaultVariants",
|
|
214
|
-
"fontFamily",
|
|
215
|
-
"name"
|
|
216
|
-
]);
|
|
217
|
-
const skipped = [];
|
|
218
|
-
const styles = {};
|
|
219
|
-
const staticNamespace = getStaticBindingsForScope(path.scope, importsWhitelist, sourcePath, bindingCache, shouldPrintDebug);
|
|
220
|
-
const attemptEval = !evaluateVars ? evaluateAstNode : createEvaluator({
|
|
221
|
-
tamaguiConfig,
|
|
222
|
-
staticNamespace,
|
|
223
|
-
sourcePath,
|
|
224
|
-
shouldPrintDebug
|
|
225
|
-
});
|
|
226
|
-
const attemptEvalSafe = createSafeEvaluator(attemptEval);
|
|
227
|
-
for (const property of definition.properties) {
|
|
228
|
-
if (!t.isObjectProperty(property) || !t.isIdentifier(property.key) || !isValidStyleKey(property.key.name, Component.staticConfig) || ((_a = Component.staticConfig.variants) == null ? void 0 : _a[property.key.name]) || componentSkipProps.has(property.key.name)) {
|
|
229
|
-
skipped.push(property);
|
|
230
|
-
continue;
|
|
231
|
-
}
|
|
232
|
-
const out2 = attemptEvalSafe(property.value);
|
|
233
|
-
if (out2 === FAILED_EVAL) {
|
|
234
|
-
skipped.push(property);
|
|
235
|
-
} else {
|
|
236
|
-
styles[property.key.name] = out2;
|
|
237
|
-
}
|
|
238
|
-
}
|
|
239
|
-
const out = getSplitStyles(styles, Component.staticConfig, defaultTheme, {
|
|
240
|
-
focus: false,
|
|
241
|
-
hover: false,
|
|
242
|
-
mounted: false,
|
|
243
|
-
press: false,
|
|
244
|
-
pressIn: false,
|
|
245
|
-
resolveVariablesAs: "variable"
|
|
246
|
-
});
|
|
247
|
-
const classNames = {
|
|
248
|
-
...out.classNames
|
|
249
|
-
};
|
|
250
|
-
const atomics = getStylesAtomic(out.style);
|
|
251
|
-
if (shouldPrintDebug) {
|
|
252
|
-
console.log("Exctacting styled()", styles, out, "to", atomics);
|
|
253
|
-
}
|
|
254
|
-
for (const atomic of atomics) {
|
|
255
|
-
out.rulesToInsert = out.rulesToInsert || [];
|
|
256
|
-
out.rulesToInsert.push(atomic);
|
|
257
|
-
classNames[atomic.property] = atomic.identifier;
|
|
258
|
-
}
|
|
259
|
-
definition.properties = skipped;
|
|
260
|
-
for (const cn in classNames) {
|
|
261
|
-
if (componentSkipProps.has(cn)) {
|
|
262
|
-
continue;
|
|
263
|
-
}
|
|
264
|
-
const val = classNames[cn];
|
|
265
|
-
definition.properties.push(t.objectProperty(t.stringLiteral(cn), t.stringLiteral(val)));
|
|
266
|
-
}
|
|
267
|
-
if (out.rulesToInsert) {
|
|
268
|
-
for (const { identifier, rules } of out.rulesToInsert) {
|
|
269
|
-
onStyleRule == null ? void 0 : onStyleRule(identifier, rules);
|
|
270
|
-
}
|
|
271
|
-
}
|
|
272
|
-
res.styled++;
|
|
273
|
-
if (shouldPrintDebug) {
|
|
274
|
-
console.log(`Extracted styled(${name}) props:`, styles);
|
|
275
|
-
}
|
|
276
|
-
},
|
|
277
|
-
JSXElement(traversePath) {
|
|
278
|
-
var _a, _b, _c, _d, _e;
|
|
279
|
-
tm.mark("jsx-element", shouldPrintDebug === "verbose");
|
|
280
|
-
const node = traversePath.node.openingElement;
|
|
281
|
-
const ogAttributes = node.attributes;
|
|
282
|
-
const componentName = findComponentName(traversePath.scope);
|
|
283
|
-
const closingElement = traversePath.node.closingElement;
|
|
284
|
-
if (t.isJSXMemberExpression(closingElement == null ? void 0 : closingElement.name) || !t.isJSXIdentifier(node.name)) {
|
|
285
|
-
return;
|
|
286
|
-
}
|
|
287
|
-
const binding = traversePath.scope.getBinding(node.name.name);
|
|
288
|
-
if (binding) {
|
|
289
|
-
if (!t.isImportDeclaration(binding.path.parent)) {
|
|
290
|
-
return;
|
|
291
|
-
}
|
|
292
|
-
const source = binding.path.parent.source;
|
|
293
|
-
if (!props.components.includes(source.value) && !isInternalImport(source.value)) {
|
|
294
|
-
return;
|
|
295
|
-
}
|
|
296
|
-
if (!validComponents[binding.identifier.name]) {
|
|
297
|
-
return;
|
|
298
|
-
}
|
|
299
|
-
}
|
|
300
|
-
const component = validComponents[node.name.name];
|
|
301
|
-
if (!component || !component.staticConfig) {
|
|
302
|
-
return;
|
|
303
|
-
}
|
|
304
|
-
const originalNodeName = node.name.name;
|
|
305
|
-
res.found++;
|
|
306
|
-
const filePath = `./${relative(process.cwd(), sourcePath)}`;
|
|
307
|
-
const lineNumbers = node.loc ? node.loc.start.line + (node.loc.start.line !== node.loc.end.line ? `-${node.loc.end.line}` : "") : "";
|
|
308
|
-
const tagId = [componentName, `${node.name.name}`, `${filePath}:${lineNumbers}`].filter(Boolean);
|
|
309
|
-
const debugPropValue = node.attributes.filter((n) => t.isJSXAttribute(n) && t.isJSXIdentifier(n.name) && n.name.name === "debug").map((n) => {
|
|
310
|
-
if (n.value === null)
|
|
311
|
-
return true;
|
|
312
|
-
if (t.isStringLiteral(n.value))
|
|
313
|
-
return n.value.value;
|
|
314
|
-
return false;
|
|
315
|
-
})[0];
|
|
316
|
-
if (debugPropValue) {
|
|
317
|
-
shouldPrintDebug = debugPropValue;
|
|
318
|
-
}
|
|
319
|
-
try {
|
|
320
|
-
let evaluateAttribute2 = function(path) {
|
|
321
|
-
const attribute = path.node;
|
|
322
|
-
const attr = { type: "attr", value: attribute };
|
|
323
|
-
if (t.isJSXSpreadAttribute(attribute)) {
|
|
324
|
-
const arg = attribute.argument;
|
|
325
|
-
const conditional = t.isConditionalExpression(arg) ? [arg.test, arg.consequent, arg.alternate] : t.isLogicalExpression(arg) && arg.operator === "&&" ? [arg.left, arg.right, null] : null;
|
|
326
|
-
if (conditional) {
|
|
327
|
-
const [test, alt, cons] = conditional;
|
|
328
|
-
if (!test)
|
|
329
|
-
throw new Error(`no test`);
|
|
330
|
-
if ([alt, cons].some((side) => side && !isExtractable2(side))) {
|
|
331
|
-
if (shouldPrintDebug) {
|
|
332
|
-
console.log("not extractable", alt, cons);
|
|
333
|
-
}
|
|
334
|
-
return attr;
|
|
335
|
-
}
|
|
336
|
-
return [
|
|
337
|
-
...createTernariesFromObjectProperties2(test, alt) || [],
|
|
338
|
-
...cons && createTernariesFromObjectProperties2(t.unaryExpression("!", test), cons) || []
|
|
339
|
-
].map((ternary) => ({
|
|
340
|
-
type: "ternary",
|
|
341
|
-
value: ternary
|
|
342
|
-
}));
|
|
343
|
-
}
|
|
344
|
-
}
|
|
345
|
-
if (t.isJSXSpreadAttribute(attribute) || !attribute.name || typeof attribute.name.name !== "string") {
|
|
346
|
-
if (shouldPrintDebug) {
|
|
347
|
-
console.log(" ! inlining, spread attr");
|
|
348
|
-
}
|
|
349
|
-
inlined.set(`${Math.random()}`, "spread");
|
|
350
|
-
return attr;
|
|
351
|
-
}
|
|
352
|
-
const name = attribute.name.name;
|
|
353
|
-
if (excludeProps == null ? void 0 : excludeProps.has(name)) {
|
|
354
|
-
if (shouldPrintDebug) {
|
|
355
|
-
console.log(" excluding prop", name);
|
|
356
|
-
}
|
|
357
|
-
return null;
|
|
358
|
-
}
|
|
359
|
-
if (inlineProps.has(name)) {
|
|
360
|
-
inlined.set(name, name);
|
|
361
|
-
if (shouldPrintDebug) {
|
|
362
|
-
console.log(" ! inlining, inline prop", name);
|
|
363
|
-
}
|
|
364
|
-
return attr;
|
|
365
|
-
}
|
|
366
|
-
if (deoptProps.has(name)) {
|
|
367
|
-
shouldDeopt = true;
|
|
368
|
-
inlined.set(name, name);
|
|
369
|
-
if (shouldPrintDebug) {
|
|
370
|
-
console.log(" ! inlining, deopted prop", name);
|
|
371
|
-
}
|
|
372
|
-
return attr;
|
|
373
|
-
}
|
|
374
|
-
if (UNTOUCHED_PROPS[name]) {
|
|
375
|
-
return attr;
|
|
376
|
-
}
|
|
377
|
-
if (INLINE_EXTRACTABLE[name]) {
|
|
378
|
-
inlined.set(name, INLINE_EXTRACTABLE[name]);
|
|
379
|
-
return attr;
|
|
380
|
-
}
|
|
381
|
-
if (name.startsWith("data-")) {
|
|
382
|
-
return attr;
|
|
383
|
-
}
|
|
384
|
-
if (name[0] === "$" && t.isJSXExpressionContainer(attribute == null ? void 0 : attribute.value)) {
|
|
385
|
-
if (disableExtractInlineMedia) {
|
|
386
|
-
return attr;
|
|
387
|
-
}
|
|
388
|
-
const shortname = name.slice(1);
|
|
389
|
-
if (mediaQueryConfig[shortname]) {
|
|
390
|
-
const expression = attribute.value.expression;
|
|
391
|
-
if (!t.isJSXEmptyExpression(expression)) {
|
|
392
|
-
const ternaries2 = createTernariesFromObjectProperties2(t.stringLiteral(shortname), expression, {
|
|
393
|
-
inlineMediaQuery: shortname
|
|
394
|
-
});
|
|
395
|
-
if (ternaries2) {
|
|
396
|
-
return ternaries2.map((value2) => ({
|
|
397
|
-
type: "ternary",
|
|
398
|
-
value: value2
|
|
399
|
-
}));
|
|
400
|
-
}
|
|
401
|
-
}
|
|
402
|
-
}
|
|
403
|
-
}
|
|
404
|
-
const [value, valuePath] = (() => {
|
|
405
|
-
if (t.isJSXExpressionContainer(attribute == null ? void 0 : attribute.value)) {
|
|
406
|
-
return [attribute.value.expression, path.get("value")];
|
|
407
|
-
} else {
|
|
408
|
-
return [attribute.value, path.get("value")];
|
|
409
|
-
}
|
|
410
|
-
})();
|
|
411
|
-
const remove = () => {
|
|
412
|
-
Array.isArray(valuePath) ? valuePath.map((p) => p.remove()) : valuePath.remove();
|
|
413
|
-
};
|
|
414
|
-
if (name === "ref") {
|
|
415
|
-
if (shouldPrintDebug) {
|
|
416
|
-
console.log(" ! inlining, ref", name);
|
|
417
|
-
}
|
|
418
|
-
inlined.set("ref", "ref");
|
|
419
|
-
return attr;
|
|
420
|
-
}
|
|
421
|
-
if (name === "tag") {
|
|
422
|
-
return {
|
|
423
|
-
type: "attr",
|
|
424
|
-
value: path.node
|
|
425
|
-
};
|
|
426
|
-
}
|
|
427
|
-
if (disableExtractVariables) {
|
|
428
|
-
if (value) {
|
|
429
|
-
if (value.type === "StringLiteral" && value.value[0] === "$") {
|
|
430
|
-
if (shouldPrintDebug) {
|
|
431
|
-
console.log(` ! inlining, native disable extract: ${name} =`, value.value);
|
|
432
|
-
}
|
|
433
|
-
inlined.set(name, true);
|
|
434
|
-
return attr;
|
|
435
|
-
}
|
|
436
|
-
}
|
|
437
|
-
}
|
|
438
|
-
if (name === "theme") {
|
|
439
|
-
inlined.set("theme", attr.value);
|
|
440
|
-
return attr;
|
|
441
|
-
}
|
|
442
|
-
const styleValue = attemptEvalSafe(value);
|
|
443
|
-
if (!variants[name] && !isValidStyleKey(name, staticConfig)) {
|
|
444
|
-
let keys = [name];
|
|
445
|
-
let out = null;
|
|
446
|
-
out = staticConfig.propMapper(name, styleValue, defaultTheme, staticConfig.defaultProps, { resolveVariablesAs: "auto" }, void 0, void 0, shouldPrintDebug);
|
|
447
|
-
if (out) {
|
|
448
|
-
if (!Array.isArray(out)) {
|
|
449
|
-
console.warn(`Error expected array but got`, out);
|
|
450
|
-
couldntParse = true;
|
|
451
|
-
shouldDeopt = true;
|
|
452
|
-
} else {
|
|
453
|
-
out = Object.fromEntries(out);
|
|
454
|
-
keys = Object.keys(out);
|
|
455
|
-
}
|
|
456
|
-
}
|
|
457
|
-
if (out) {
|
|
458
|
-
if (isTargetingHTML) {
|
|
459
|
-
out = createDOMProps(isTextView ? "span" : "div", out);
|
|
460
|
-
delete out.className;
|
|
461
|
-
}
|
|
462
|
-
keys = Object.keys(out);
|
|
463
|
-
}
|
|
464
|
-
let didInline = false;
|
|
465
|
-
const attributes = keys.map((key) => {
|
|
466
|
-
const val = out[key];
|
|
467
|
-
if (isValidStyleKey(key, staticConfig)) {
|
|
468
|
-
return {
|
|
469
|
-
type: "style",
|
|
470
|
-
value: { [key]: styleValue },
|
|
471
|
-
name: key,
|
|
472
|
-
attr: path.node
|
|
473
|
-
};
|
|
474
|
-
}
|
|
475
|
-
if (validHTMLAttributes[key] || key.startsWith("aria-") || key.startsWith("data-")) {
|
|
476
|
-
return attr;
|
|
477
|
-
}
|
|
478
|
-
if (shouldPrintDebug) {
|
|
479
|
-
console.log(" ! inlining, non-static", key);
|
|
480
|
-
}
|
|
481
|
-
didInline = true;
|
|
482
|
-
inlined.set(key, val);
|
|
483
|
-
return val;
|
|
484
|
-
});
|
|
485
|
-
if (didInline) {
|
|
486
|
-
if (shouldPrintDebug) {
|
|
487
|
-
console.log(" bailing flattening due to attributes", attributes);
|
|
488
|
-
}
|
|
489
|
-
return attr;
|
|
490
|
-
}
|
|
491
|
-
return attributes;
|
|
492
|
-
}
|
|
493
|
-
if (styleValue !== FAILED_EVAL) {
|
|
494
|
-
if (inlineWhenUnflattened.has(name)) {
|
|
495
|
-
inlineWhenUnflattenedOGVals[name] = { styleValue, attr };
|
|
496
|
-
}
|
|
497
|
-
if (isValidStyleKey(name, staticConfig)) {
|
|
498
|
-
if (shouldPrintDebug) {
|
|
499
|
-
console.log(` style: ${name} =`, styleValue);
|
|
500
|
-
}
|
|
501
|
-
if (!(name in staticConfig.defaultProps)) {
|
|
502
|
-
if (!hasSetOptimized) {
|
|
503
|
-
res.optimized++;
|
|
504
|
-
hasSetOptimized = true;
|
|
505
|
-
}
|
|
506
|
-
}
|
|
507
|
-
return {
|
|
508
|
-
type: "style",
|
|
509
|
-
value: { [name]: styleValue },
|
|
510
|
-
name,
|
|
511
|
-
attr: path.node
|
|
512
|
-
};
|
|
513
|
-
} else {
|
|
514
|
-
if (variants[name]) {
|
|
515
|
-
variantValues.set(name, styleValue);
|
|
516
|
-
}
|
|
517
|
-
inlined.set(name, true);
|
|
518
|
-
return attr;
|
|
519
|
-
}
|
|
520
|
-
}
|
|
521
|
-
if (t.isBinaryExpression(value)) {
|
|
522
|
-
if (shouldPrintDebug) {
|
|
523
|
-
console.log(` binary expression ${name} = `, value);
|
|
524
|
-
}
|
|
525
|
-
const { operator, left, right } = value;
|
|
526
|
-
const lVal = attemptEvalSafe(left);
|
|
527
|
-
const rVal = attemptEvalSafe(right);
|
|
528
|
-
if (shouldPrintDebug) {
|
|
529
|
-
console.log(` evalBinaryExpression lVal ${String(lVal)}, rVal ${String(rVal)}`);
|
|
530
|
-
}
|
|
531
|
-
if (lVal !== FAILED_EVAL && t.isConditionalExpression(right)) {
|
|
532
|
-
const ternary = addBinaryConditional(operator, left, right);
|
|
533
|
-
if (ternary)
|
|
534
|
-
return ternary;
|
|
535
|
-
}
|
|
536
|
-
if (rVal !== FAILED_EVAL && t.isConditionalExpression(left)) {
|
|
537
|
-
const ternary = addBinaryConditional(operator, right, left);
|
|
538
|
-
if (ternary)
|
|
539
|
-
return ternary;
|
|
540
|
-
}
|
|
541
|
-
if (shouldPrintDebug) {
|
|
542
|
-
console.log(` evalBinaryExpression cant extract`);
|
|
543
|
-
}
|
|
544
|
-
inlined.set(name, true);
|
|
545
|
-
return attr;
|
|
546
|
-
}
|
|
547
|
-
const staticConditional = getStaticConditional(value);
|
|
548
|
-
if (staticConditional) {
|
|
549
|
-
if (shouldPrintDebug === "verbose") {
|
|
550
|
-
console.log(` static conditional ${name}`, value);
|
|
551
|
-
}
|
|
552
|
-
return { type: "ternary", value: staticConditional };
|
|
553
|
-
}
|
|
554
|
-
const staticLogical = getStaticLogical(value);
|
|
555
|
-
if (staticLogical) {
|
|
556
|
-
if (shouldPrintDebug === "verbose") {
|
|
557
|
-
console.log(` static ternary ${name} = `, value);
|
|
558
|
-
}
|
|
559
|
-
return { type: "ternary", value: staticLogical };
|
|
560
|
-
}
|
|
561
|
-
inlined.set(name, true);
|
|
562
|
-
if (shouldPrintDebug) {
|
|
563
|
-
console.log(` ! inline no match ${name}`, value);
|
|
564
|
-
}
|
|
565
|
-
return attr;
|
|
566
|
-
function addBinaryConditional(operator, staticExpr, cond) {
|
|
567
|
-
if (getStaticConditional(cond)) {
|
|
568
|
-
const alt = attemptEval(t.binaryExpression(operator, staticExpr, cond.alternate));
|
|
569
|
-
const cons = attemptEval(t.binaryExpression(operator, staticExpr, cond.consequent));
|
|
570
|
-
if (shouldPrintDebug) {
|
|
571
|
-
console.log(" binaryConditional", cond.test, cons, alt);
|
|
572
|
-
}
|
|
573
|
-
return {
|
|
574
|
-
type: "ternary",
|
|
575
|
-
value: {
|
|
576
|
-
test: cond.test,
|
|
577
|
-
remove,
|
|
578
|
-
alternate: { [name]: alt },
|
|
579
|
-
consequent: { [name]: cons }
|
|
580
|
-
}
|
|
581
|
-
};
|
|
582
|
-
}
|
|
583
|
-
return null;
|
|
584
|
-
}
|
|
585
|
-
function getStaticConditional(value2) {
|
|
586
|
-
if (t.isConditionalExpression(value2)) {
|
|
587
|
-
try {
|
|
588
|
-
const aVal = attemptEval(value2.alternate);
|
|
589
|
-
const cVal = attemptEval(value2.consequent);
|
|
590
|
-
if (shouldPrintDebug) {
|
|
591
|
-
const type = value2.test.type;
|
|
592
|
-
console.log(" static ternary", type, cVal, aVal);
|
|
593
|
-
}
|
|
594
|
-
return {
|
|
595
|
-
test: value2.test,
|
|
596
|
-
remove,
|
|
597
|
-
consequent: { [name]: cVal },
|
|
598
|
-
alternate: { [name]: aVal }
|
|
599
|
-
};
|
|
600
|
-
} catch (err) {
|
|
601
|
-
if (shouldPrintDebug) {
|
|
602
|
-
console.log(" cant eval ternary", err.message);
|
|
603
|
-
}
|
|
604
|
-
}
|
|
605
|
-
}
|
|
606
|
-
return null;
|
|
607
|
-
}
|
|
608
|
-
function getStaticLogical(value2) {
|
|
609
|
-
if (t.isLogicalExpression(value2)) {
|
|
610
|
-
if (value2.operator === "&&") {
|
|
611
|
-
try {
|
|
612
|
-
const val = attemptEval(value2.right);
|
|
613
|
-
if (shouldPrintDebug) {
|
|
614
|
-
console.log(" staticLogical", value2.left, name, val);
|
|
615
|
-
}
|
|
616
|
-
return {
|
|
617
|
-
test: value2.left,
|
|
618
|
-
remove,
|
|
619
|
-
consequent: { [name]: val },
|
|
620
|
-
alternate: null
|
|
621
|
-
};
|
|
622
|
-
} catch (err) {
|
|
623
|
-
if (shouldPrintDebug) {
|
|
624
|
-
console.log(" cant static eval logical", err);
|
|
625
|
-
}
|
|
626
|
-
}
|
|
627
|
-
}
|
|
628
|
-
}
|
|
629
|
-
return null;
|
|
630
|
-
}
|
|
631
|
-
}, isExtractable2 = function(obj) {
|
|
632
|
-
return t.isObjectExpression(obj) && obj.properties.every((prop) => {
|
|
633
|
-
if (!t.isObjectProperty(prop)) {
|
|
634
|
-
console.log("not object prop", prop);
|
|
635
|
-
return false;
|
|
636
|
-
}
|
|
637
|
-
const propName = prop.key["name"];
|
|
638
|
-
if (!isValidStyleKey(propName, staticConfig) && propName !== "tag") {
|
|
639
|
-
if (shouldPrintDebug) {
|
|
640
|
-
console.log(" not a valid style prop!", propName);
|
|
641
|
-
}
|
|
642
|
-
return false;
|
|
643
|
-
}
|
|
644
|
-
return true;
|
|
645
|
-
});
|
|
646
|
-
}, createTernariesFromObjectProperties2 = function(test, side, ternaryPartial = {}) {
|
|
647
|
-
if (!side) {
|
|
648
|
-
return null;
|
|
649
|
-
}
|
|
650
|
-
if (!isExtractable2(side)) {
|
|
651
|
-
throw new Error("not extractable");
|
|
652
|
-
}
|
|
653
|
-
return side.properties.flatMap((property) => {
|
|
654
|
-
if (!t.isObjectProperty(property)) {
|
|
655
|
-
throw new Error("expected object property");
|
|
656
|
-
}
|
|
657
|
-
if (t.isIdentifier(property.key)) {
|
|
658
|
-
const key = property.key.name;
|
|
659
|
-
const mediaQueryKey = key.slice(1);
|
|
660
|
-
const isMediaQuery = key[0] === "$" && mediaQueryConfig[mediaQueryKey];
|
|
661
|
-
if (isMediaQuery) {
|
|
662
|
-
if (t.isExpression(property.value)) {
|
|
663
|
-
const ternaries2 = createTernariesFromObjectProperties2(t.stringLiteral(mediaQueryKey), property.value, {
|
|
664
|
-
inlineMediaQuery: mediaQueryKey
|
|
665
|
-
});
|
|
666
|
-
if (ternaries2) {
|
|
667
|
-
return ternaries2.map((value) => ({
|
|
668
|
-
...ternaryPartial,
|
|
669
|
-
...value,
|
|
670
|
-
test: t.logicalExpression("&&", value.test, test)
|
|
671
|
-
}));
|
|
672
|
-
} else {
|
|
673
|
-
console.log("\u26A0\uFE0F no ternaries?", property);
|
|
674
|
-
}
|
|
675
|
-
} else {
|
|
676
|
-
console.log("\u26A0\uFE0F not expression", property);
|
|
677
|
-
}
|
|
678
|
-
}
|
|
679
|
-
}
|
|
680
|
-
if (t.isConditionalExpression(property.value)) {
|
|
681
|
-
const [truthy, falsy] = [
|
|
682
|
-
t.objectExpression([t.objectProperty(property.key, property.value.consequent)]),
|
|
683
|
-
t.objectExpression([t.objectProperty(property.key, property.value.alternate)])
|
|
684
|
-
].map((x) => attemptEval(x));
|
|
685
|
-
return [
|
|
686
|
-
createTernary({
|
|
687
|
-
remove() {
|
|
688
|
-
},
|
|
689
|
-
...ternaryPartial,
|
|
690
|
-
test: t.logicalExpression("&&", test, property.value.test),
|
|
691
|
-
consequent: truthy,
|
|
692
|
-
alternate: null
|
|
693
|
-
}),
|
|
694
|
-
createTernary({
|
|
695
|
-
...ternaryPartial,
|
|
696
|
-
test: t.logicalExpression("&&", test, t.unaryExpression("!", property.value.test)),
|
|
697
|
-
consequent: falsy,
|
|
698
|
-
alternate: null,
|
|
699
|
-
remove() {
|
|
700
|
-
}
|
|
701
|
-
})
|
|
702
|
-
];
|
|
703
|
-
}
|
|
704
|
-
const obj = t.objectExpression([t.objectProperty(property.key, property.value)]);
|
|
705
|
-
const consequent = attemptEval(obj);
|
|
706
|
-
return createTernary({
|
|
707
|
-
remove() {
|
|
708
|
-
},
|
|
709
|
-
...ternaryPartial,
|
|
710
|
-
test,
|
|
711
|
-
consequent,
|
|
712
|
-
alternate: null
|
|
713
|
-
});
|
|
714
|
-
});
|
|
715
|
-
}, mergeStyles2 = function(prev2, nextIn) {
|
|
716
|
-
const next = expandStyles(nextIn);
|
|
717
|
-
for (const key in next) {
|
|
718
|
-
if (pseudoDescriptors[key]) {
|
|
719
|
-
prev2[key] = prev2[key] || {};
|
|
720
|
-
if (shouldPrintDebug) {
|
|
721
|
-
if (!next[key] || !prev2[key]) {
|
|
722
|
-
console.log("warn: missing", key, prev2, next);
|
|
723
|
-
}
|
|
724
|
-
}
|
|
725
|
-
Object.assign(prev2[key], next[key]);
|
|
726
|
-
} else {
|
|
727
|
-
prev2[key] = next[key];
|
|
728
|
-
}
|
|
729
|
-
}
|
|
730
|
-
};
|
|
731
|
-
var evaluateAttribute = evaluateAttribute2, isExtractable = isExtractable2, createTernariesFromObjectProperties = createTernariesFromObjectProperties2, mergeStyles = mergeStyles2;
|
|
732
|
-
node.attributes.find((n) => t.isJSXAttribute(n) && t.isJSXIdentifier(n.name) && n.name.name === "debug" && n.value === null);
|
|
733
|
-
if (shouldPrintDebug) {
|
|
734
|
-
console.log("\n");
|
|
735
|
-
console.log("\x1B[33m%s\x1B[0m", `${tagId[0]} | ${tagId[2]} -------------------`);
|
|
736
|
-
console.log("\x1B[1m", "\x1B[32m", `<${originalNodeName} />`);
|
|
737
|
-
}
|
|
738
|
-
if (shouldAddDebugProp && !disableDebugAttr) {
|
|
739
|
-
res.modified++;
|
|
740
|
-
node.attributes.unshift(t.jsxAttribute(t.jsxIdentifier("data-is"), t.stringLiteral(tagId.join(" "))));
|
|
741
|
-
}
|
|
742
|
-
const shouldLog = !hasLogged;
|
|
743
|
-
if (shouldLog) {
|
|
744
|
-
console.log(` 1\uFE0F\u20E3 Inline optimized 2\uFE0F\u20E3 Inline flattened 3\uFE0F\u20E3 styled() extracted`);
|
|
745
|
-
const prefix = " |";
|
|
746
|
-
console.log(prefixLogs || prefix, " total \xB7 1\uFE0F\u20E3 \xB7 2\uFE0F\u20E3 \xB7 3\uFE0F\u20E3");
|
|
747
|
-
hasLogged = true;
|
|
748
|
-
}
|
|
749
|
-
if (disableExtraction) {
|
|
750
|
-
return;
|
|
751
|
-
}
|
|
752
|
-
const { staticConfig } = component;
|
|
753
|
-
const variants = staticConfig.variants || {};
|
|
754
|
-
const isTextView = staticConfig.isText || false;
|
|
755
|
-
const validStyles = (_a = staticConfig == null ? void 0 : staticConfig.validStyles) != null ? _a : {};
|
|
756
|
-
let tagName = (_b = staticConfig.defaultProps.tag) != null ? _b : isTextView ? "span" : "div";
|
|
757
|
-
traversePath.get("openingElement").get("attributes").forEach((path) => {
|
|
758
|
-
const attr = path.node;
|
|
759
|
-
if (t.isJSXSpreadAttribute(attr))
|
|
760
|
-
return;
|
|
761
|
-
if (attr.name.name !== "tag")
|
|
762
|
-
return;
|
|
763
|
-
const val = attr.value;
|
|
764
|
-
if (!t.isStringLiteral(val))
|
|
765
|
-
return;
|
|
766
|
-
tagName = val.value;
|
|
767
|
-
});
|
|
768
|
-
const flatNode = getFlattenedNode({ isTextView, tag: tagName });
|
|
769
|
-
const inlineProps = /* @__PURE__ */ new Set([
|
|
770
|
-
...props.inlineProps || [],
|
|
771
|
-
...staticConfig.inlineProps || []
|
|
772
|
-
]);
|
|
773
|
-
const deoptProps = /* @__PURE__ */ new Set([
|
|
774
|
-
"animation",
|
|
775
|
-
...props.deoptProps || [],
|
|
776
|
-
...staticConfig.deoptProps || []
|
|
777
|
-
]);
|
|
778
|
-
const inlineWhenUnflattened = /* @__PURE__ */ new Set([...staticConfig.inlineWhenUnflattened || []]);
|
|
779
|
-
const staticNamespace = getStaticBindingsForScope(traversePath.scope, importsWhitelist, sourcePath, bindingCache, shouldPrintDebug);
|
|
780
|
-
const attemptEval = !evaluateVars ? evaluateAstNode : createEvaluator({
|
|
781
|
-
tamaguiConfig,
|
|
782
|
-
staticNamespace,
|
|
783
|
-
sourcePath,
|
|
784
|
-
traversePath,
|
|
785
|
-
shouldPrintDebug
|
|
786
|
-
});
|
|
787
|
-
const attemptEvalSafe = createSafeEvaluator(attemptEval);
|
|
788
|
-
if (shouldPrintDebug) {
|
|
789
|
-
console.log(" staticNamespace", Object.keys(staticNamespace).join(", "));
|
|
790
|
-
}
|
|
791
|
-
const flattenedAttrs = [];
|
|
792
|
-
traversePath.get("openingElement").get("attributes").forEach((path) => {
|
|
793
|
-
const attr = path.node;
|
|
794
|
-
if (!t.isJSXSpreadAttribute(attr)) {
|
|
795
|
-
flattenedAttrs.push(attr);
|
|
796
|
-
return;
|
|
797
|
-
}
|
|
798
|
-
let arg;
|
|
799
|
-
try {
|
|
800
|
-
arg = attemptEval(attr.argument);
|
|
801
|
-
} catch (e) {
|
|
802
|
-
if (shouldPrintDebug) {
|
|
803
|
-
console.log(" couldnt parse spread", e.message);
|
|
804
|
-
}
|
|
805
|
-
flattenedAttrs.push(attr);
|
|
806
|
-
return;
|
|
807
|
-
}
|
|
808
|
-
if (arg !== void 0) {
|
|
809
|
-
try {
|
|
810
|
-
if (typeof arg !== "object" || arg == null) {
|
|
811
|
-
if (shouldPrintDebug) {
|
|
812
|
-
console.log(" non object or null arg", arg);
|
|
813
|
-
}
|
|
814
|
-
flattenedAttrs.push(attr);
|
|
815
|
-
} else {
|
|
816
|
-
for (const k in arg) {
|
|
817
|
-
const value = arg[k];
|
|
818
|
-
if (!value && typeof value === "object") {
|
|
819
|
-
console.log("shouldnt we handle this?", k, value, arg);
|
|
820
|
-
continue;
|
|
821
|
-
}
|
|
822
|
-
flattenedAttrs.push(t.jsxAttribute(t.jsxIdentifier(k), t.jsxExpressionContainer(literalToAst(value))));
|
|
823
|
-
}
|
|
824
|
-
}
|
|
825
|
-
} catch (err) {
|
|
826
|
-
console.warn("cant parse spread, caught err", err);
|
|
827
|
-
couldntParse = true;
|
|
828
|
-
}
|
|
829
|
-
}
|
|
830
|
-
});
|
|
831
|
-
if (couldntParse) {
|
|
832
|
-
return;
|
|
833
|
-
}
|
|
834
|
-
tm.mark("jsx-element-flattened", shouldPrintDebug === "verbose");
|
|
835
|
-
node.attributes = flattenedAttrs;
|
|
836
|
-
let attrs = [];
|
|
837
|
-
let shouldDeopt = false;
|
|
838
|
-
const inlined = /* @__PURE__ */ new Map();
|
|
839
|
-
const variantValues = /* @__PURE__ */ new Map();
|
|
840
|
-
let hasSetOptimized = false;
|
|
841
|
-
const inlineWhenUnflattenedOGVals = {};
|
|
842
|
-
attrs = traversePath.get("openingElement").get("attributes").flatMap((path) => {
|
|
843
|
-
try {
|
|
844
|
-
const res2 = evaluateAttribute2(path);
|
|
845
|
-
tm.mark("jsx-element-evaluate-attr", shouldPrintDebug === "verbose");
|
|
846
|
-
if (!res2) {
|
|
847
|
-
path.remove();
|
|
848
|
-
}
|
|
849
|
-
return res2;
|
|
850
|
-
} catch (err) {
|
|
851
|
-
if (shouldPrintDebug) {
|
|
852
|
-
console.log("Error extracting attribute", err.message, err.stack);
|
|
853
|
-
console.log("node", path.node);
|
|
854
|
-
}
|
|
855
|
-
inlined.set(`${Math.random()}`, "spread");
|
|
856
|
-
return {
|
|
857
|
-
type: "attr",
|
|
858
|
-
value: path.node
|
|
859
|
-
};
|
|
860
|
-
}
|
|
861
|
-
}).flat(4).filter(isPresent);
|
|
862
|
-
if (shouldPrintDebug) {
|
|
863
|
-
console.log(" - attrs (before):\n", logLines(attrs.map(attrStr).join(", ")));
|
|
864
|
-
}
|
|
865
|
-
node.attributes = attrs.filter(isAttr).map((x) => x.value);
|
|
866
|
-
if (couldntParse || shouldDeopt) {
|
|
867
|
-
if (shouldPrintDebug) {
|
|
868
|
-
console.log(` avoid optimizing:`, { couldntParse, shouldDeopt });
|
|
869
|
-
}
|
|
870
|
-
node.attributes = ogAttributes;
|
|
871
|
-
return;
|
|
872
|
-
}
|
|
873
|
-
const parentFn = findTopmostFunction(traversePath);
|
|
874
|
-
if (parentFn) {
|
|
875
|
-
modifiedComponents.add(parentFn);
|
|
876
|
-
}
|
|
877
|
-
let ternaries = [];
|
|
878
|
-
attrs = attrs.reduce((out, cur) => {
|
|
879
|
-
const next = attrs[attrs.indexOf(cur) + 1];
|
|
880
|
-
if (cur.type === "ternary") {
|
|
881
|
-
ternaries.push(cur.value);
|
|
882
|
-
}
|
|
883
|
-
if ((!next || next.type !== "ternary") && ternaries.length) {
|
|
884
|
-
const normalized = normalizeTernaries(ternaries).map(({ alternate, consequent, ...rest }) => {
|
|
885
|
-
return {
|
|
886
|
-
type: "ternary",
|
|
887
|
-
value: {
|
|
888
|
-
...rest,
|
|
889
|
-
alternate: alternate || null,
|
|
890
|
-
consequent: consequent || null
|
|
891
|
-
}
|
|
892
|
-
};
|
|
893
|
-
});
|
|
894
|
-
try {
|
|
895
|
-
return [...out, ...normalized];
|
|
896
|
-
} finally {
|
|
897
|
-
if (shouldPrintDebug) {
|
|
898
|
-
console.log(` normalizeTernaries (${ternaries.length} => ${normalized.length})`);
|
|
899
|
-
}
|
|
900
|
-
ternaries = [];
|
|
901
|
-
}
|
|
902
|
-
}
|
|
903
|
-
if (cur.type === "ternary") {
|
|
904
|
-
return out;
|
|
905
|
-
}
|
|
906
|
-
out.push(cur);
|
|
907
|
-
return out;
|
|
908
|
-
}, []).flat();
|
|
909
|
-
const hasSpread = node.attributes.some((x) => t.isJSXSpreadAttribute(x));
|
|
910
|
-
const hasOnlyStringChildren = !hasSpread && (node.selfClosing || traversePath.node.children && traversePath.node.children.every((x) => x.type === "JSXText"));
|
|
911
|
-
const themeVal = inlined.get("theme");
|
|
912
|
-
inlined.delete("theme");
|
|
913
|
-
for (const [key] of [...inlined]) {
|
|
914
|
-
if (INLINE_EXTRACTABLE[key] || ((_c = staticConfig.variants) == null ? void 0 : _c[key])) {
|
|
915
|
-
inlined.delete(key);
|
|
916
|
-
}
|
|
917
|
-
}
|
|
918
|
-
const canFlattenProps = inlined.size === 0;
|
|
919
|
-
let shouldFlatten = !shouldDeopt && canFlattenProps && !hasSpread && staticConfig.neverFlatten !== true && (staticConfig.neverFlatten === "jsx" ? hasOnlyStringChildren : true);
|
|
920
|
-
const shouldWrapTheme = shouldFlatten && themeVal;
|
|
921
|
-
if (disableExtractVariables) {
|
|
922
|
-
themeAccessListeners.add((key) => {
|
|
923
|
-
shouldFlatten = false;
|
|
924
|
-
if (shouldPrintDebug) {
|
|
925
|
-
console.log(" ! accessing theme key, avoid flatten", key);
|
|
926
|
-
}
|
|
927
|
-
});
|
|
928
|
-
}
|
|
929
|
-
if (shouldPrintDebug) {
|
|
930
|
-
console.log(" - flatten?", objToStr({ hasSpread, shouldDeopt, shouldFlatten, canFlattenProps, shouldWrapTheme, hasOnlyStringChildren }), "inlined", [...inlined]);
|
|
931
|
-
}
|
|
932
|
-
if (shouldFlatten && shouldWrapTheme) {
|
|
933
|
-
if (shouldPrintDebug) {
|
|
934
|
-
console.log(" - wrapping theme", themeVal);
|
|
935
|
-
}
|
|
936
|
-
attrs = attrs.filter((x) => x.type === "attr" && t.isJSXAttribute(x.value) && x.value.name.name === "theme" ? false : true);
|
|
937
|
-
if (!hasImportedTheme) {
|
|
938
|
-
hasImportedTheme = true;
|
|
939
|
-
programPath.node.body.push(t.importDeclaration([t.importSpecifier(t.identifier("_TamaguiTheme"), t.identifier("Theme"))], t.stringLiteral("@tamagui/core")));
|
|
940
|
-
}
|
|
941
|
-
traversePath.replaceWith(t.jsxElement(t.jsxOpeningElement(t.jsxIdentifier("_TamaguiTheme"), [
|
|
942
|
-
t.jsxAttribute(t.jsxIdentifier("name"), themeVal.value)
|
|
943
|
-
]), t.jsxClosingElement(t.jsxIdentifier("_TamaguiTheme")), [traversePath.node]));
|
|
944
|
-
}
|
|
945
|
-
if (shouldFlatten) {
|
|
946
|
-
const defaultStyleAttrs = Object.keys(staticConfig.defaultProps).flatMap((key) => {
|
|
947
|
-
if (!isValidStyleKey(key, staticConfig)) {
|
|
948
|
-
return [];
|
|
949
|
-
}
|
|
950
|
-
const value = staticConfig.defaultProps[key];
|
|
951
|
-
const name = tamaguiConfig.shorthands[key] || key;
|
|
952
|
-
if (value === void 0) {
|
|
953
|
-
console.warn(`\u26A0\uFE0F Error evaluating default style for component, prop ${key} ${value}`);
|
|
954
|
-
shouldDeopt = true;
|
|
955
|
-
return;
|
|
956
|
-
}
|
|
957
|
-
const attr = {
|
|
958
|
-
type: "style",
|
|
959
|
-
name,
|
|
960
|
-
value: { [name]: value }
|
|
961
|
-
};
|
|
962
|
-
return attr;
|
|
963
|
-
});
|
|
964
|
-
if (defaultStyleAttrs.length) {
|
|
965
|
-
attrs = [...defaultStyleAttrs, ...attrs];
|
|
966
|
-
}
|
|
967
|
-
}
|
|
968
|
-
if (shouldDeopt) {
|
|
969
|
-
node.attributes = ogAttributes;
|
|
970
|
-
return;
|
|
971
|
-
}
|
|
972
|
-
const ensureOverridden = {};
|
|
973
|
-
if (!shouldFlatten) {
|
|
974
|
-
for (const cur of attrs) {
|
|
975
|
-
if (cur.type === "style") {
|
|
976
|
-
for (const key in cur.value) {
|
|
977
|
-
const shouldEnsureOverridden = !!((_d = staticConfig.ensureOverriddenProp) == null ? void 0 : _d[key]);
|
|
978
|
-
const isSetInAttrsAlready = attrs.some((x) => x.type === "attr" && x.value.type === "JSXAttribute" && x.value.name.name === key);
|
|
979
|
-
if (!isSetInAttrsAlready) {
|
|
980
|
-
const isVariant = !!((_e = staticConfig.variants) == null ? void 0 : _e[cur.name || ""]);
|
|
981
|
-
if (isVariant || shouldEnsureOverridden) {
|
|
982
|
-
ensureOverridden[key] = true;
|
|
983
|
-
}
|
|
984
|
-
}
|
|
985
|
-
}
|
|
986
|
-
}
|
|
987
|
-
}
|
|
988
|
-
}
|
|
989
|
-
if (shouldPrintDebug) {
|
|
990
|
-
console.log(" - attrs (flattened): \n", logLines(attrs.map(attrStr).join(", ")));
|
|
991
|
-
console.log(" - ensureOverriden:", Object.keys(ensureOverridden).join(", "));
|
|
992
|
-
}
|
|
993
|
-
const state = {
|
|
994
|
-
noClassNames: false,
|
|
995
|
-
focus: false,
|
|
996
|
-
hover: false,
|
|
997
|
-
mounted: true,
|
|
998
|
-
press: false,
|
|
999
|
-
pressIn: false
|
|
1000
|
-
};
|
|
1001
|
-
let foundStaticProps = {};
|
|
1002
|
-
for (const key in attrs) {
|
|
1003
|
-
const cur = attrs[key];
|
|
1004
|
-
if (cur.type === "style") {
|
|
1005
|
-
foundStaticProps = {
|
|
1006
|
-
...foundStaticProps,
|
|
1007
|
-
...expandStyles(cur.value)
|
|
1008
|
-
};
|
|
1009
|
-
continue;
|
|
1010
|
-
}
|
|
1011
|
-
if (cur.type === "attr") {
|
|
1012
|
-
if (t.isJSXSpreadAttribute(cur.value)) {
|
|
1013
|
-
continue;
|
|
1014
|
-
}
|
|
1015
|
-
if (!t.isJSXIdentifier(cur.value.name)) {
|
|
1016
|
-
continue;
|
|
1017
|
-
}
|
|
1018
|
-
const key2 = cur.value.name.name;
|
|
1019
|
-
const value = attemptEvalSafe(cur.value.value || t.booleanLiteral(true));
|
|
1020
|
-
if (value !== FAILED_EVAL) {
|
|
1021
|
-
foundStaticProps = {
|
|
1022
|
-
...foundStaticProps,
|
|
1023
|
-
[key2]: value
|
|
1024
|
-
};
|
|
1025
|
-
}
|
|
1026
|
-
}
|
|
1027
|
-
}
|
|
1028
|
-
const completeProps = {};
|
|
1029
|
-
for (const key in staticConfig.defaultProps) {
|
|
1030
|
-
if (!(key in foundStaticProps)) {
|
|
1031
|
-
completeProps[key] = staticConfig.defaultProps[key];
|
|
1032
|
-
}
|
|
1033
|
-
}
|
|
1034
|
-
for (const key in foundStaticProps) {
|
|
1035
|
-
completeProps[key] = foundStaticProps[key];
|
|
1036
|
-
}
|
|
1037
|
-
attrs = attrs.reduce((acc, cur) => {
|
|
1038
|
-
if (!cur)
|
|
1039
|
-
return acc;
|
|
1040
|
-
if (cur.type === "attr" && !t.isJSXSpreadAttribute(cur.value)) {
|
|
1041
|
-
if (shouldFlatten) {
|
|
1042
|
-
const name = cur.value.name.name;
|
|
1043
|
-
if (typeof name === "string") {
|
|
1044
|
-
if (name === "tag") {
|
|
1045
|
-
return acc;
|
|
1046
|
-
}
|
|
1047
|
-
if (variants[name] && variantValues.has(name)) {
|
|
1048
|
-
let out = Object.fromEntries(staticConfig.propMapper(name, variantValues.get(name), defaultTheme, completeProps, { ...state, resolveVariablesAs: "auto" }, void 0, void 0, shouldPrintDebug) || []);
|
|
1049
|
-
if (out && isTargetingHTML) {
|
|
1050
|
-
const cn = out.className;
|
|
1051
|
-
out = createDOMProps(isTextView ? "span" : "div", out);
|
|
1052
|
-
out.className = cn;
|
|
1053
|
-
}
|
|
1054
|
-
if (shouldPrintDebug) {
|
|
1055
|
-
console.log(" - expanded variant", name, out);
|
|
1056
|
-
}
|
|
1057
|
-
for (const key2 in out) {
|
|
1058
|
-
const value2 = out[key2];
|
|
1059
|
-
if (isValidStyleKey(key2, staticConfig)) {
|
|
1060
|
-
acc.push({
|
|
1061
|
-
type: "style",
|
|
1062
|
-
value: { [key2]: value2 },
|
|
1063
|
-
name: key2,
|
|
1064
|
-
attr: cur.value
|
|
1065
|
-
});
|
|
1066
|
-
} else {
|
|
1067
|
-
acc.push({
|
|
1068
|
-
type: "attr",
|
|
1069
|
-
value: t.jsxAttribute(t.jsxIdentifier(key2), t.jsxExpressionContainer(typeof value2 === "string" ? t.stringLiteral(value2) : literalToAst(value2)))
|
|
1070
|
-
});
|
|
1071
|
-
}
|
|
1072
|
-
}
|
|
1073
|
-
}
|
|
1074
|
-
}
|
|
1075
|
-
}
|
|
1076
|
-
}
|
|
1077
|
-
if (cur.type !== "style") {
|
|
1078
|
-
acc.push(cur);
|
|
1079
|
-
return acc;
|
|
1080
|
-
}
|
|
1081
|
-
let key = Object.keys(cur.value)[0];
|
|
1082
|
-
const value = cur.value[key];
|
|
1083
|
-
const fullKey = tamaguiConfig.shorthands[key];
|
|
1084
|
-
if (fullKey) {
|
|
1085
|
-
cur.value = { [fullKey]: value };
|
|
1086
|
-
key = fullKey;
|
|
1087
|
-
}
|
|
1088
|
-
if (disableExtractVariables) {
|
|
1089
|
-
if (value[0] === "$") {
|
|
1090
|
-
if (shouldPrintDebug) {
|
|
1091
|
-
console.log(` keeping variable inline: ${key} =`, value);
|
|
1092
|
-
}
|
|
1093
|
-
acc.push({
|
|
1094
|
-
type: "attr",
|
|
1095
|
-
value: t.jsxAttribute(t.jsxIdentifier(key), t.jsxExpressionContainer(t.stringLiteral(value)))
|
|
1096
|
-
});
|
|
1097
|
-
return acc;
|
|
1098
|
-
}
|
|
1099
|
-
}
|
|
1100
|
-
acc.push(cur);
|
|
1101
|
-
return acc;
|
|
1102
|
-
}, []);
|
|
1103
|
-
tm.mark("jsx-element-expanded", shouldPrintDebug === "verbose");
|
|
1104
|
-
if (shouldPrintDebug) {
|
|
1105
|
-
console.log(" - attrs (expanded): \n", logLines(attrs.map(attrStr).join(", ")));
|
|
1106
|
-
}
|
|
1107
|
-
let prev = null;
|
|
1108
|
-
attrs = attrs.reduce((acc, cur) => {
|
|
1109
|
-
if (cur.type === "style") {
|
|
1110
|
-
const key = Object.keys(cur.value)[0];
|
|
1111
|
-
const value = cur.value[key];
|
|
1112
|
-
const shouldKeepOriginalAttr = !shouldFlatten && !validStyles[key] && !pseudoDescriptors[key] && !key.startsWith("data-");
|
|
1113
|
-
if (shouldKeepOriginalAttr) {
|
|
1114
|
-
if (shouldPrintDebug) {
|
|
1115
|
-
console.log(" - keeping as non-style", key);
|
|
1116
|
-
}
|
|
1117
|
-
prev = cur;
|
|
1118
|
-
acc.push({
|
|
1119
|
-
type: "attr",
|
|
1120
|
-
value: t.jsxAttribute(t.jsxIdentifier(key), t.jsxExpressionContainer(typeof value === "string" ? t.stringLiteral(value) : literalToAst(value)))
|
|
1121
|
-
});
|
|
1122
|
-
acc.push(cur);
|
|
1123
|
-
return acc;
|
|
1124
|
-
}
|
|
1125
|
-
if (ensureOverridden[key]) {
|
|
1126
|
-
acc.push({
|
|
1127
|
-
type: "attr",
|
|
1128
|
-
value: cur.attr || t.jsxAttribute(t.jsxIdentifier(key), t.jsxExpressionContainer(t.nullLiteral()))
|
|
1129
|
-
});
|
|
1130
|
-
}
|
|
1131
|
-
if ((prev == null ? void 0 : prev.type) === "style") {
|
|
1132
|
-
mergeStyles2(prev.value, cur.value);
|
|
1133
|
-
return acc;
|
|
1134
|
-
}
|
|
1135
|
-
}
|
|
1136
|
-
prev = cur;
|
|
1137
|
-
acc.push(cur);
|
|
1138
|
-
return acc;
|
|
1139
|
-
}, []);
|
|
1140
|
-
if (shouldPrintDebug) {
|
|
1141
|
-
console.log(" - attrs (combined \u{1F500}): \n", logLines(attrs.map(attrStr).join(", ")));
|
|
1142
|
-
console.log(" - defaultProps: \n", logLines(objToStr(staticConfig.defaultProps)));
|
|
1143
|
-
console.log(" - foundStaticProps: \n", logLines(objToStr(foundStaticProps)));
|
|
1144
|
-
console.log(" - completeProps: \n", logLines(objToStr(completeProps)));
|
|
1145
|
-
}
|
|
1146
|
-
const getStyles = (props2, debugName = "") => {
|
|
1147
|
-
if (!props2 || !Object.keys(props2).length) {
|
|
1148
|
-
if (shouldPrintDebug)
|
|
1149
|
-
console.log(" getStyles() no props");
|
|
1150
|
-
return {};
|
|
1151
|
-
}
|
|
1152
|
-
if (excludeProps && !!excludeProps.size) {
|
|
1153
|
-
for (const key in props2) {
|
|
1154
|
-
if (excludeProps.has(key)) {
|
|
1155
|
-
if (shouldPrintDebug)
|
|
1156
|
-
console.log(" delete excluded", key);
|
|
1157
|
-
delete props2[key];
|
|
1158
|
-
}
|
|
1159
|
-
}
|
|
1160
|
-
}
|
|
1161
|
-
try {
|
|
1162
|
-
const out = getSplitStyles(props2, staticConfig, defaultTheme, {
|
|
1163
|
-
...state,
|
|
1164
|
-
fallbackProps: completeProps
|
|
1165
|
-
}, void 0, props2["debug"]);
|
|
1166
|
-
const outStyle = {
|
|
1167
|
-
...out.style,
|
|
1168
|
-
...out.pseudos
|
|
1169
|
-
};
|
|
1170
|
-
return outStyle;
|
|
1171
|
-
} catch (err) {
|
|
1172
|
-
console.log("error", err.message, err.stack);
|
|
1173
|
-
return {};
|
|
1174
|
-
}
|
|
1175
|
-
};
|
|
1176
|
-
const completeStyles = getStyles(completeProps, "completeStyles");
|
|
1177
|
-
if (!completeStyles) {
|
|
1178
|
-
throw new Error(`Impossible, no styles`);
|
|
1179
|
-
}
|
|
1180
|
-
let getStyleError = null;
|
|
1181
|
-
for (const attr of attrs) {
|
|
1182
|
-
try {
|
|
1183
|
-
switch (attr.type) {
|
|
1184
|
-
case "ternary":
|
|
1185
|
-
const a = getStyles(attr.value.alternate, "ternary.alternate");
|
|
1186
|
-
const c = getStyles(attr.value.consequent, "ternary.consequent");
|
|
1187
|
-
if (a)
|
|
1188
|
-
attr.value.alternate = a;
|
|
1189
|
-
if (c)
|
|
1190
|
-
attr.value.consequent = c;
|
|
1191
|
-
if (shouldPrintDebug)
|
|
1192
|
-
console.log(" => tern ", attrStr(attr));
|
|
1193
|
-
continue;
|
|
1194
|
-
case "style":
|
|
1195
|
-
const styles = getStyles(attr.value, "style");
|
|
1196
|
-
if (styles) {
|
|
1197
|
-
attr.value = styles;
|
|
1198
|
-
}
|
|
1199
|
-
if (shouldPrintDebug)
|
|
1200
|
-
console.log(" * styles (in)", logLines(objToStr(attr.value)));
|
|
1201
|
-
if (shouldPrintDebug)
|
|
1202
|
-
console.log(" * styles (out)", logLines(objToStr(styles)));
|
|
1203
|
-
continue;
|
|
1204
|
-
}
|
|
1205
|
-
} catch (err) {
|
|
1206
|
-
getStyleError = err;
|
|
1207
|
-
}
|
|
1208
|
-
}
|
|
1209
|
-
if (shouldPrintDebug) {
|
|
1210
|
-
console.log(" - attrs (ternaries/combined):\n", logLines(attrs.map(attrStr).join(", ")));
|
|
1211
|
-
}
|
|
1212
|
-
tm.mark("jsx-element-styles", shouldPrintDebug === "verbose");
|
|
1213
|
-
if (getStyleError) {
|
|
1214
|
-
console.log(" \u26A0\uFE0F postprocessing error, deopt", getStyleError);
|
|
1215
|
-
node.attributes = ogAttributes;
|
|
1216
|
-
return node;
|
|
1217
|
-
}
|
|
1218
|
-
const existingStyleKeys = /* @__PURE__ */ new Set();
|
|
1219
|
-
for (let i = attrs.length - 1; i >= 0; i--) {
|
|
1220
|
-
const attr = attrs[i];
|
|
1221
|
-
if (shouldFlatten) {
|
|
1222
|
-
if (attr.type === "attr") {
|
|
1223
|
-
if (t.isJSXAttribute(attr.value)) {
|
|
1224
|
-
if (t.isJSXIdentifier(attr.value.name)) {
|
|
1225
|
-
const name = attr.value.name.name;
|
|
1226
|
-
if (INLINE_EXTRACTABLE[name]) {
|
|
1227
|
-
attr.value.name.name = INLINE_EXTRACTABLE[name];
|
|
1228
|
-
}
|
|
1229
|
-
}
|
|
1230
|
-
}
|
|
1231
|
-
}
|
|
1232
|
-
}
|
|
1233
|
-
if (attr.type === "style") {
|
|
1234
|
-
for (const key in attr.value) {
|
|
1235
|
-
if (existingStyleKeys.has(key)) {
|
|
1236
|
-
if (shouldPrintDebug) {
|
|
1237
|
-
console.log(" >> delete existing", key);
|
|
1238
|
-
}
|
|
1239
|
-
delete attr.value[key];
|
|
1240
|
-
} else {
|
|
1241
|
-
existingStyleKeys.add(key);
|
|
1242
|
-
}
|
|
1243
|
-
}
|
|
1244
|
-
}
|
|
1245
|
-
}
|
|
1246
|
-
if (!shouldFlatten) {
|
|
1247
|
-
if (Object.keys(inlineWhenUnflattenedOGVals).length) {
|
|
1248
|
-
for (const [index, attr] of attrs.entries()) {
|
|
1249
|
-
if (attr.type === "style") {
|
|
1250
|
-
for (const key in attr.value) {
|
|
1251
|
-
const val = inlineWhenUnflattenedOGVals[key];
|
|
1252
|
-
if (val) {
|
|
1253
|
-
delete attr.value[key];
|
|
1254
|
-
attrs.splice(index - 1, 0, val.attr);
|
|
1255
|
-
}
|
|
1256
|
-
}
|
|
1257
|
-
}
|
|
1258
|
-
}
|
|
1259
|
-
}
|
|
1260
|
-
}
|
|
1261
|
-
if (shouldFlatten) {
|
|
1262
|
-
if (shouldPrintDebug) {
|
|
1263
|
-
console.log(" [\u2705] flattening", originalNodeName, flatNode);
|
|
1264
|
-
}
|
|
1265
|
-
node.name.name = flatNode;
|
|
1266
|
-
res.flattened++;
|
|
1267
|
-
if (closingElement) {
|
|
1268
|
-
closingElement.name.name = flatNode;
|
|
1269
|
-
}
|
|
1270
|
-
}
|
|
1271
|
-
if (shouldPrintDebug) {
|
|
1272
|
-
console.log(` \u274A\u274A inline props (${inlined.size}):`, shouldDeopt ? " deopted" : "", hasSpread ? " has spread" : "", staticConfig.neverFlatten ? "neverFlatten" : "");
|
|
1273
|
-
console.log(" - attrs (end):\n", logLines(attrs.map(attrStr).join(", ")));
|
|
1274
|
-
}
|
|
1275
|
-
onExtractTag({
|
|
1276
|
-
attrs,
|
|
1277
|
-
node,
|
|
1278
|
-
lineNumbers,
|
|
1279
|
-
filePath,
|
|
1280
|
-
attemptEval,
|
|
1281
|
-
jsxPath: traversePath,
|
|
1282
|
-
originalNodeName,
|
|
1283
|
-
isFlattened: shouldFlatten,
|
|
1284
|
-
programPath
|
|
1285
|
-
});
|
|
1286
|
-
} finally {
|
|
1287
|
-
if (debugPropValue) {
|
|
1288
|
-
shouldPrintDebug = ogDebug;
|
|
1289
|
-
}
|
|
1290
|
-
}
|
|
1291
|
-
}
|
|
1292
|
-
});
|
|
1293
|
-
tm.mark("jsx-done", shouldPrintDebug === "verbose");
|
|
1294
|
-
if (modifiedComponents.size) {
|
|
1295
|
-
const all = Array.from(modifiedComponents);
|
|
1296
|
-
if (shouldPrintDebug) {
|
|
1297
|
-
console.log(" [\u{1FA9D}] hook check", all.length);
|
|
1298
|
-
}
|
|
1299
|
-
for (const comp of all) {
|
|
1300
|
-
removeUnusedHooks(comp, shouldPrintDebug);
|
|
1301
|
-
}
|
|
1302
|
-
}
|
|
1303
|
-
tm.done(shouldPrintDebug === "verbose");
|
|
1304
|
-
return res;
|
|
1305
|
-
}
|
|
1306
|
-
};
|
|
1307
|
-
}
|
|
1308
|
-
export {
|
|
1309
|
-
createExtractor
|
|
1310
|
-
};
|
|
1311
|
-
//# sourceMappingURL=createExtractor.js.map
|