@tamagui/static 1.14.1 → 1.14.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/constants.js +52 -1
- package/dist/cjs/constants.js.map +2 -2
- package/dist/cjs/extractor/accessSafe.js +52 -1
- package/dist/cjs/extractor/accessSafe.js.map +2 -2
- package/dist/cjs/extractor/babelParse.js +66 -1
- package/dist/cjs/extractor/babelParse.js.map +2 -2
- package/dist/cjs/extractor/buildClassName.js +99 -1
- package/dist/cjs/extractor/buildClassName.js.map +2 -2
- package/dist/cjs/extractor/bundle.js +126 -1
- package/dist/cjs/extractor/bundle.js.map +2 -2
- package/dist/cjs/extractor/createEvaluator.js +86 -1
- package/dist/cjs/extractor/createEvaluator.js.map +2 -2
- package/dist/cjs/extractor/createExtractor.js +1630 -15
- package/dist/cjs/extractor/createExtractor.js.map +2 -2
- package/dist/cjs/extractor/ensureImportingConcat.js +64 -1
- package/dist/cjs/extractor/ensureImportingConcat.js.map +2 -2
- package/dist/cjs/extractor/evaluateAstNode.js +130 -1
- package/dist/cjs/extractor/evaluateAstNode.js.map +2 -2
- package/dist/cjs/extractor/extractHelpers.js +207 -1
- package/dist/cjs/extractor/extractHelpers.js.map +2 -2
- package/dist/cjs/extractor/extractMediaStyle.js +193 -1
- package/dist/cjs/extractor/extractMediaStyle.js.map +2 -2
- package/dist/cjs/extractor/extractToClassNames.js +413 -13
- package/dist/cjs/extractor/extractToClassNames.js.map +2 -2
- package/dist/cjs/extractor/findTopmostFunction.js +43 -1
- package/dist/cjs/extractor/findTopmostFunction.js.map +2 -2
- package/dist/cjs/extractor/generatedUid.js +59 -1
- package/dist/cjs/extractor/generatedUid.js.map +2 -2
- package/dist/cjs/extractor/getPrefixLogs.js +31 -1
- package/dist/cjs/extractor/getPrefixLogs.js.map +2 -2
- package/dist/cjs/extractor/getPropValueFromAttributes.js +89 -1
- package/dist/cjs/extractor/getPropValueFromAttributes.js.map +2 -2
- package/dist/cjs/extractor/getSourceModule.js +103 -1
- package/dist/cjs/extractor/getSourceModule.js.map +2 -2
- package/dist/cjs/extractor/getStaticBindingsForScope.js +225 -1
- package/dist/cjs/extractor/getStaticBindingsForScope.js.map +2 -2
- package/dist/cjs/extractor/hoistClassNames.js +74 -1
- package/dist/cjs/extractor/hoistClassNames.js.map +2 -2
- package/dist/cjs/extractor/literalToAst.js +115 -1
- package/dist/cjs/extractor/literalToAst.js.map +2 -2
- package/dist/cjs/extractor/loadFile.js +20 -2
- package/dist/cjs/extractor/loadFile.js.map +2 -2
- package/dist/cjs/extractor/loadTamagui.js +432 -15
- package/dist/cjs/extractor/loadTamagui.js.map +2 -2
- package/dist/cjs/extractor/logLines.js +43 -3
- package/dist/cjs/extractor/logLines.js.map +2 -2
- package/dist/cjs/extractor/normalizeTernaries.js +85 -1
- package/dist/cjs/extractor/normalizeTernaries.js.map +2 -2
- package/dist/cjs/extractor/removeUnusedHooks.js +109 -1
- package/dist/cjs/extractor/removeUnusedHooks.js.map +2 -2
- package/dist/cjs/extractor/timer.js +52 -1
- package/dist/cjs/extractor/timer.js.map +2 -2
- package/dist/cjs/extractor/validHTMLAttributes.js +126 -1
- package/dist/cjs/extractor/validHTMLAttributes.js.map +2 -2
- package/dist/cjs/getPragmaOptions.js +67 -2
- package/dist/cjs/getPragmaOptions.js.map +2 -2
- package/dist/cjs/helpers/memoize.js +45 -1
- package/dist/cjs/helpers/memoize.js.map +2 -2
- package/dist/cjs/index.js +42 -1
- package/dist/cjs/index.js.map +2 -2
- package/dist/cjs/require.js +81 -5
- package/dist/cjs/require.js.map +2 -2
- package/dist/cjs/types.js +16 -1
- package/dist/cjs/types.js.map +2 -2
- package/dist/cjs/webpackPlugin.js +34 -1
- package/dist/cjs/webpackPlugin.js.map +2 -2
- package/dist/esm/constants.js +14 -1
- package/dist/esm/constants.js.map +2 -2
- package/dist/esm/constants.mjs +14 -1
- package/dist/esm/constants.mjs.map +2 -2
- package/dist/esm/extractor/accessSafe.js +18 -1
- package/dist/esm/extractor/accessSafe.js.map +2 -2
- package/dist/esm/extractor/accessSafe.mjs +18 -1
- package/dist/esm/extractor/accessSafe.mjs.map +2 -2
- package/dist/esm/extractor/babelParse.js +31 -1
- package/dist/esm/extractor/babelParse.js.map +2 -2
- package/dist/esm/extractor/babelParse.mjs +31 -1
- package/dist/esm/extractor/babelParse.mjs.map +2 -2
- package/dist/esm/extractor/buildClassName.js +64 -1
- package/dist/esm/extractor/buildClassName.js.map +2 -2
- package/dist/esm/extractor/buildClassName.mjs +64 -1
- package/dist/esm/extractor/buildClassName.mjs.map +2 -2
- package/dist/esm/extractor/bundle.js +91 -1
- package/dist/esm/extractor/bundle.js.map +2 -2
- package/dist/esm/extractor/bundle.mjs +91 -1
- package/dist/esm/extractor/bundle.mjs.map +2 -2
- package/dist/esm/extractor/createEvaluator.js +51 -1
- package/dist/esm/extractor/createEvaluator.js.map +2 -2
- package/dist/esm/extractor/createEvaluator.mjs +51 -1
- package/dist/esm/extractor/createEvaluator.mjs.map +2 -2
- package/dist/esm/extractor/createExtractor.js +1613 -15
- package/dist/esm/extractor/createExtractor.js.map +2 -2
- package/dist/esm/extractor/createExtractor.mjs +1613 -15
- package/dist/esm/extractor/createExtractor.mjs.map +2 -2
- package/dist/esm/extractor/ensureImportingConcat.js +30 -1
- package/dist/esm/extractor/ensureImportingConcat.js.map +2 -2
- package/dist/esm/extractor/ensureImportingConcat.mjs +30 -1
- package/dist/esm/extractor/ensureImportingConcat.mjs.map +2 -2
- package/dist/esm/extractor/evaluateAstNode.js +96 -1
- package/dist/esm/extractor/evaluateAstNode.js.map +2 -2
- package/dist/esm/extractor/evaluateAstNode.mjs +96 -1
- package/dist/esm/extractor/evaluateAstNode.mjs.map +2 -2
- package/dist/esm/extractor/extractHelpers.js +161 -1
- package/dist/esm/extractor/extractHelpers.js.map +2 -2
- package/dist/esm/extractor/extractHelpers.mjs +161 -1
- package/dist/esm/extractor/extractHelpers.mjs.map +2 -2
- package/dist/esm/extractor/extractMediaStyle.js +158 -1
- package/dist/esm/extractor/extractMediaStyle.js.map +2 -2
- package/dist/esm/extractor/extractMediaStyle.mjs +158 -1
- package/dist/esm/extractor/extractMediaStyle.mjs.map +2 -2
- package/dist/esm/extractor/extractToClassNames.js +379 -13
- package/dist/esm/extractor/extractToClassNames.js.map +2 -2
- package/dist/esm/extractor/extractToClassNames.mjs +379 -13
- package/dist/esm/extractor/extractToClassNames.mjs.map +2 -2
- package/dist/esm/extractor/findTopmostFunction.js +19 -1
- package/dist/esm/extractor/findTopmostFunction.js.map +2 -2
- package/dist/esm/extractor/findTopmostFunction.mjs +19 -1
- package/dist/esm/extractor/findTopmostFunction.mjs.map +2 -2
- package/dist/esm/extractor/generatedUid.js +25 -1
- package/dist/esm/extractor/generatedUid.js.map +2 -2
- package/dist/esm/extractor/generatedUid.mjs +25 -1
- package/dist/esm/extractor/generatedUid.mjs.map +2 -2
- package/dist/esm/extractor/getPrefixLogs.js +7 -1
- package/dist/esm/extractor/getPrefixLogs.js.map +2 -2
- package/dist/esm/extractor/getPrefixLogs.mjs +7 -1
- package/dist/esm/extractor/getPrefixLogs.mjs.map +2 -2
- package/dist/esm/extractor/getPropValueFromAttributes.js +55 -1
- package/dist/esm/extractor/getPropValueFromAttributes.js.map +2 -2
- package/dist/esm/extractor/getPropValueFromAttributes.mjs +55 -1
- package/dist/esm/extractor/getPropValueFromAttributes.mjs.map +2 -2
- package/dist/esm/extractor/getSourceModule.js +69 -1
- package/dist/esm/extractor/getSourceModule.js.map +2 -2
- package/dist/esm/extractor/getSourceModule.mjs +69 -1
- package/dist/esm/extractor/getSourceModule.mjs.map +2 -2
- package/dist/esm/extractor/getStaticBindingsForScope.js +190 -1
- package/dist/esm/extractor/getStaticBindingsForScope.js.map +2 -2
- package/dist/esm/extractor/getStaticBindingsForScope.mjs +190 -1
- package/dist/esm/extractor/getStaticBindingsForScope.mjs.map +2 -2
- package/dist/esm/extractor/hoistClassNames.js +40 -1
- package/dist/esm/extractor/hoistClassNames.js.map +2 -2
- package/dist/esm/extractor/hoistClassNames.mjs +40 -1
- package/dist/esm/extractor/hoistClassNames.mjs.map +2 -2
- package/dist/esm/extractor/literalToAst.js +80 -1
- package/dist/esm/extractor/literalToAst.js.map +2 -2
- package/dist/esm/extractor/literalToAst.mjs +80 -1
- package/dist/esm/extractor/literalToAst.mjs.map +2 -2
- package/dist/esm/extractor/loadFile.js +19 -2
- package/dist/esm/extractor/loadFile.js.map +2 -2
- package/dist/esm/extractor/loadFile.mjs +19 -2
- package/dist/esm/extractor/loadFile.mjs.map +2 -2
- package/dist/esm/extractor/loadTamagui.js +396 -15
- package/dist/esm/extractor/loadTamagui.js.map +2 -2
- package/dist/esm/extractor/loadTamagui.mjs +396 -15
- package/dist/esm/extractor/loadTamagui.mjs.map +2 -2
- package/dist/esm/extractor/logLines.js +19 -3
- package/dist/esm/extractor/logLines.js.map +2 -2
- package/dist/esm/extractor/logLines.mjs +19 -3
- package/dist/esm/extractor/logLines.mjs.map +2 -2
- package/dist/esm/extractor/normalizeTernaries.js +51 -1
- package/dist/esm/extractor/normalizeTernaries.js.map +2 -2
- package/dist/esm/extractor/normalizeTernaries.mjs +51 -1
- package/dist/esm/extractor/normalizeTernaries.mjs.map +2 -2
- package/dist/esm/extractor/removeUnusedHooks.js +75 -1
- package/dist/esm/extractor/removeUnusedHooks.js.map +2 -2
- package/dist/esm/extractor/removeUnusedHooks.mjs +75 -1
- package/dist/esm/extractor/removeUnusedHooks.mjs.map +2 -2
- package/dist/esm/extractor/timer.js +28 -1
- package/dist/esm/extractor/timer.js.map +2 -2
- package/dist/esm/extractor/timer.mjs +28 -1
- package/dist/esm/extractor/timer.mjs.map +2 -2
- package/dist/esm/extractor/validHTMLAttributes.js +101 -1
- package/dist/esm/extractor/validHTMLAttributes.js.map +2 -2
- package/dist/esm/extractor/validHTMLAttributes.mjs +101 -1
- package/dist/esm/extractor/validHTMLAttributes.mjs.map +2 -2
- package/dist/esm/getPragmaOptions.js +43 -2
- package/dist/esm/getPragmaOptions.js.map +2 -2
- package/dist/esm/getPragmaOptions.mjs +43 -2
- package/dist/esm/getPragmaOptions.mjs.map +2 -2
- package/dist/esm/helpers/memoize.js +21 -1
- package/dist/esm/helpers/memoize.js.map +2 -2
- package/dist/esm/helpers/memoize.mjs +21 -1
- package/dist/esm/helpers/memoize.mjs.map +2 -2
- package/dist/esm/index.js +15 -1
- package/dist/esm/index.js.map +2 -2
- package/dist/esm/index.mjs +15 -1
- package/dist/esm/index.mjs.map +2 -2
- package/dist/esm/require.js +55 -5
- package/dist/esm/require.js.map +2 -2
- package/dist/esm/require.mjs +55 -5
- package/dist/esm/require.mjs.map +2 -2
- package/dist/esm/webpackPlugin.js +10 -1
- package/dist/esm/webpackPlugin.js.map +2 -2
- package/dist/esm/webpackPlugin.mjs +10 -1
- package/dist/esm/webpackPlugin.mjs.map +2 -2
- package/package.json +14 -14
|
@@ -1,16 +1,1614 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
1
|
+
import { basename, relative } from "path";
|
|
2
|
+
import traverse from "@babel/traverse";
|
|
3
|
+
import * as t from "@babel/types";
|
|
4
|
+
import {
|
|
5
|
+
expandStyles,
|
|
6
|
+
getSplitStyles,
|
|
7
|
+
mediaQueryConfig,
|
|
8
|
+
proxyThemeVariables,
|
|
9
|
+
pseudoDescriptors
|
|
10
|
+
} from "@tamagui/core-node";
|
|
11
|
+
import { createDOMProps } from "react-native-web-internals";
|
|
12
|
+
import { FAILED_EVAL } from "../constants.js";
|
|
13
|
+
import { createEvaluator, createSafeEvaluator } from "./createEvaluator.js";
|
|
14
|
+
import { evaluateAstNode } from "./evaluateAstNode.js";
|
|
15
|
+
import {
|
|
16
|
+
attrStr,
|
|
17
|
+
findComponentName,
|
|
18
|
+
getValidComponent,
|
|
19
|
+
getValidImport,
|
|
20
|
+
isPresent,
|
|
21
|
+
isValidImport,
|
|
22
|
+
objToStr
|
|
23
|
+
} from "./extractHelpers.js";
|
|
24
|
+
import { findTopmostFunction } from "./findTopmostFunction.js";
|
|
25
|
+
import {
|
|
26
|
+
cleanupBeforeExit,
|
|
27
|
+
getStaticBindingsForScope
|
|
28
|
+
} from "./getStaticBindingsForScope.js";
|
|
29
|
+
import { literalToAst } from "./literalToAst.js";
|
|
30
|
+
import { loadTamagui, loadTamaguiSync } from "./loadTamagui.js";
|
|
31
|
+
import { logLines } from "./logLines.js";
|
|
32
|
+
import { normalizeTernaries } from "./normalizeTernaries.js";
|
|
33
|
+
import { removeUnusedHooks } from "./removeUnusedHooks.js";
|
|
34
|
+
import { timer } from "./timer.js";
|
|
35
|
+
import { validHTMLAttributes } from "./validHTMLAttributes.js";
|
|
36
|
+
const UNTOUCHED_PROPS = {
|
|
37
|
+
key: true,
|
|
38
|
+
style: true,
|
|
39
|
+
className: true
|
|
40
|
+
};
|
|
41
|
+
const INLINE_EXTRACTABLE = {
|
|
42
|
+
ref: "ref",
|
|
43
|
+
key: "key",
|
|
44
|
+
...process.env.TAMAGUI_TARGET === "web" && {
|
|
45
|
+
onPress: "onClick",
|
|
46
|
+
onHoverIn: "onMouseEnter",
|
|
47
|
+
onHoverOut: "onMouseLeave",
|
|
48
|
+
onPressIn: "onMouseDown",
|
|
49
|
+
onPressOut: "onMouseUp"
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
const validHooks = {
|
|
53
|
+
useMedia: true,
|
|
54
|
+
useTheme: true
|
|
55
|
+
};
|
|
56
|
+
const isAttr = (x) => x.type === "attr";
|
|
57
|
+
const createTernary = (x) => x;
|
|
58
|
+
let hasLoggedBaseInfo = false;
|
|
59
|
+
function createExtractor({ logger = console } = { logger: console }) {
|
|
60
|
+
if (!process.env.TAMAGUI_TARGET) {
|
|
61
|
+
console.log('\u26A0\uFE0F Please set process.env.TAMAGUI_TARGET to either "web" or "native"');
|
|
62
|
+
process.exit(1);
|
|
63
|
+
}
|
|
64
|
+
const shouldAddDebugProp = (
|
|
65
|
+
// really basic disable this for next.js because it messes with ssr
|
|
66
|
+
!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)
|
|
67
|
+
);
|
|
68
|
+
let projectInfo = null;
|
|
69
|
+
function loadSync(props) {
|
|
70
|
+
return projectInfo ||= loadTamaguiSync({
|
|
71
|
+
config: props.config || "tamagui.config.ts",
|
|
72
|
+
components: props.components || ["tamagui"]
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
async function load(props) {
|
|
76
|
+
return projectInfo ||= await loadTamagui({
|
|
77
|
+
config: props.config || "tamagui.config.ts",
|
|
78
|
+
components: props.components || ["tamagui"]
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
return {
|
|
82
|
+
options: {
|
|
83
|
+
logger
|
|
84
|
+
},
|
|
85
|
+
cleanupBeforeExit,
|
|
86
|
+
loadTamagui: load,
|
|
87
|
+
loadTamaguiSync: loadSync,
|
|
88
|
+
getTamagui() {
|
|
89
|
+
return projectInfo == null ? void 0 : projectInfo.tamaguiConfig;
|
|
90
|
+
},
|
|
91
|
+
parseSync: (f, props) => {
|
|
92
|
+
const projectInfo2 = loadSync(props);
|
|
93
|
+
return parseWithConfig(projectInfo2, f, props);
|
|
94
|
+
},
|
|
95
|
+
parse: async (f, props) => {
|
|
96
|
+
const projectInfo2 = await load(props);
|
|
97
|
+
return parseWithConfig(projectInfo2, f, props);
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
function parseWithConfig({ components, tamaguiConfig }, fileOrPath, options) {
|
|
101
|
+
var _a;
|
|
102
|
+
const {
|
|
103
|
+
config = "tamagui.config.ts",
|
|
104
|
+
importsWhitelist = ["constants.js"],
|
|
105
|
+
evaluateVars = true,
|
|
106
|
+
sourcePath = "",
|
|
107
|
+
onExtractTag,
|
|
108
|
+
onStyleRule,
|
|
109
|
+
getFlattenedNode,
|
|
110
|
+
disable,
|
|
111
|
+
disableExtraction,
|
|
112
|
+
disableExtractInlineMedia,
|
|
113
|
+
disableExtractVariables,
|
|
114
|
+
disableDebugAttr,
|
|
115
|
+
disableExtractFoundComponents,
|
|
116
|
+
includeExtensions = [".ts", ".tsx", ".jsx"],
|
|
117
|
+
extractStyledDefinitions = false,
|
|
118
|
+
prefixLogs,
|
|
119
|
+
excludeProps,
|
|
120
|
+
target,
|
|
121
|
+
...restProps
|
|
122
|
+
} = options;
|
|
123
|
+
let shouldPrintDebug = options.shouldPrintDebug || false;
|
|
124
|
+
if (disable === true || Array.isArray(disable) && disable.includes(sourcePath)) {
|
|
125
|
+
return null;
|
|
126
|
+
}
|
|
127
|
+
if (!components) {
|
|
128
|
+
throw new Error(`Must provide components`);
|
|
129
|
+
}
|
|
130
|
+
if (sourcePath && includeExtensions && !includeExtensions.some((ext) => sourcePath.endsWith(ext))) {
|
|
131
|
+
if (shouldPrintDebug) {
|
|
132
|
+
logger.info(
|
|
133
|
+
`Ignoring file due to includeExtensions: ${sourcePath}, includeExtensions: ${includeExtensions.join(
|
|
134
|
+
", "
|
|
135
|
+
)}`
|
|
136
|
+
);
|
|
137
|
+
}
|
|
138
|
+
return null;
|
|
139
|
+
}
|
|
140
|
+
function isValidStyleKey(name, staticConfig) {
|
|
141
|
+
var _a2, _b;
|
|
142
|
+
if (!projectInfo) {
|
|
143
|
+
throw new Error(`Tamagui extractor not loaded yet`);
|
|
144
|
+
}
|
|
145
|
+
if (target === "native" && name[0] === "$" && mediaQueryConfig[name.slice(1)]) {
|
|
146
|
+
return false;
|
|
147
|
+
}
|
|
148
|
+
return !!(!!((_a2 = staticConfig.validStyles) == null ? void 0 : _a2[name]) || !!pseudoDescriptors[name] || // dont disable variants or else you lose many things flattening
|
|
149
|
+
((_b = staticConfig.variants) == null ? void 0 : _b[name]) || (projectInfo == null ? void 0 : projectInfo.tamaguiConfig.shorthands[name]) || (name[0] === "$" ? !!mediaQueryConfig[name.slice(1)] : false));
|
|
150
|
+
}
|
|
151
|
+
const isTargetingHTML = target === "html";
|
|
152
|
+
const ogDebug = shouldPrintDebug;
|
|
153
|
+
const tm = timer();
|
|
154
|
+
const propsWithFileInfo = {
|
|
155
|
+
...options,
|
|
156
|
+
sourcePath,
|
|
157
|
+
allLoadedComponents: [...components]
|
|
158
|
+
};
|
|
159
|
+
if (!hasLoggedBaseInfo) {
|
|
160
|
+
hasLoggedBaseInfo = true;
|
|
161
|
+
if (shouldPrintDebug) {
|
|
162
|
+
logger.info(
|
|
163
|
+
[
|
|
164
|
+
"loaded components:",
|
|
165
|
+
propsWithFileInfo.allLoadedComponents.map((comp) => Object.keys(comp.nameToInfo).join(", ")).join(", ")
|
|
166
|
+
].join(" ")
|
|
167
|
+
);
|
|
168
|
+
}
|
|
169
|
+
if ((_a = process.env.DEBUG) == null ? void 0 : _a.startsWith("tamagui")) {
|
|
170
|
+
const next = [...propsWithFileInfo.allLoadedComponents].map((info) => {
|
|
171
|
+
const nameToInfo = { ...info.nameToInfo };
|
|
172
|
+
for (const key in nameToInfo) {
|
|
173
|
+
delete nameToInfo[key].staticConfig.validStyles;
|
|
174
|
+
}
|
|
175
|
+
return { ...info, nameToInfo };
|
|
176
|
+
});
|
|
177
|
+
logger.info(["loaded:", JSON.stringify(next, null, 2)].join("\n"));
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
tm.mark("load-tamagui", !!shouldPrintDebug);
|
|
181
|
+
const firstThemeName = Object.keys(tamaguiConfig.themes)[0];
|
|
182
|
+
const firstTheme = tamaguiConfig.themes[firstThemeName];
|
|
183
|
+
if (!firstTheme || typeof firstTheme !== "object") {
|
|
184
|
+
console.error(`Missing theme, an error occurred when importing your config`);
|
|
185
|
+
console.log(`Got config:`, tamaguiConfig);
|
|
186
|
+
console.log(`Looking for theme:`, firstThemeName);
|
|
187
|
+
process.exit(0);
|
|
188
|
+
}
|
|
189
|
+
const proxiedTheme = proxyThemeVariables(firstTheme);
|
|
190
|
+
const themeAccessListeners = /* @__PURE__ */ new Set();
|
|
191
|
+
const defaultTheme = new Proxy(proxiedTheme, {
|
|
192
|
+
get(target2, key) {
|
|
193
|
+
if (Reflect.has(target2, key)) {
|
|
194
|
+
themeAccessListeners.forEach((cb) => cb(String(key)));
|
|
195
|
+
}
|
|
196
|
+
return Reflect.get(target2, key);
|
|
197
|
+
}
|
|
198
|
+
});
|
|
199
|
+
const body = fileOrPath.type === "Program" ? fileOrPath.get("body") : fileOrPath.program.body;
|
|
200
|
+
if (Object.keys(components).length === 0) {
|
|
201
|
+
console.warn(
|
|
202
|
+
`Warning: Tamagui didn't find any valid components (DEBUG=tamagui for more)`
|
|
203
|
+
);
|
|
204
|
+
if (process.env.DEBUG === "tamagui") {
|
|
205
|
+
console.log(`components`, Object.keys(components), components);
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
if (shouldPrintDebug === "verbose") {
|
|
209
|
+
logger.info(
|
|
210
|
+
`allLoadedComponent modules ${propsWithFileInfo.allLoadedComponents.map((k) => k.moduleName).join(", ")}`
|
|
211
|
+
);
|
|
212
|
+
}
|
|
213
|
+
let doesUseValidImport = false;
|
|
214
|
+
let hasImportedTheme = false;
|
|
215
|
+
const importDeclarations = [];
|
|
216
|
+
for (const bodyPath of body) {
|
|
217
|
+
if (bodyPath.type !== "ImportDeclaration")
|
|
218
|
+
continue;
|
|
219
|
+
const node = "node" in bodyPath ? bodyPath.node : bodyPath;
|
|
220
|
+
const moduleName = node.source.value;
|
|
221
|
+
const valid = isValidImport(propsWithFileInfo, moduleName);
|
|
222
|
+
if (valid) {
|
|
223
|
+
importDeclarations.push(node);
|
|
224
|
+
}
|
|
225
|
+
if (extractStyledDefinitions) {
|
|
226
|
+
if (valid) {
|
|
227
|
+
if (node.specifiers.some((specifier) => specifier.local.name === "styled")) {
|
|
228
|
+
doesUseValidImport = true;
|
|
229
|
+
break;
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
if (valid) {
|
|
234
|
+
const names = node.specifiers.map((specifier) => specifier.local.name);
|
|
235
|
+
const isValidComponent = names.some(
|
|
236
|
+
(name) => Boolean(isValidImport(propsWithFileInfo, moduleName, name) || validHooks[name])
|
|
237
|
+
);
|
|
238
|
+
if (shouldPrintDebug === "verbose") {
|
|
239
|
+
logger.info(
|
|
240
|
+
`import ${names.join(
|
|
241
|
+
", "
|
|
242
|
+
)} from ${moduleName} isValidComponent ${isValidComponent}`
|
|
243
|
+
);
|
|
244
|
+
}
|
|
245
|
+
if (isValidComponent) {
|
|
246
|
+
doesUseValidImport = true;
|
|
247
|
+
break;
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
if (shouldPrintDebug) {
|
|
252
|
+
logger.info(
|
|
253
|
+
`file: ${sourcePath} ${JSON.stringify({ doesUseValidImport, hasImportedTheme })}`
|
|
254
|
+
);
|
|
255
|
+
}
|
|
256
|
+
if (!doesUseValidImport) {
|
|
257
|
+
return null;
|
|
258
|
+
}
|
|
259
|
+
function getValidImportedComponent(componentName) {
|
|
260
|
+
const importDeclaration = importDeclarations.find(
|
|
261
|
+
(dec) => dec.specifiers.some((spec) => spec.local.name === componentName)
|
|
262
|
+
);
|
|
263
|
+
if (!importDeclaration) {
|
|
264
|
+
return null;
|
|
265
|
+
}
|
|
266
|
+
return getValidImport(
|
|
267
|
+
propsWithFileInfo,
|
|
268
|
+
importDeclaration.source.value,
|
|
269
|
+
componentName
|
|
270
|
+
);
|
|
271
|
+
}
|
|
272
|
+
tm.mark("import-check", !!shouldPrintDebug);
|
|
273
|
+
let couldntParse = false;
|
|
274
|
+
const modifiedComponents = /* @__PURE__ */ new Set();
|
|
275
|
+
const bindingCache = {};
|
|
276
|
+
const callTraverse = (a) => {
|
|
277
|
+
return fileOrPath.type === "File" ? traverse(fileOrPath, a) : fileOrPath.traverse(a);
|
|
278
|
+
};
|
|
279
|
+
const shouldDisableExtraction = disableExtraction === true || Array.isArray(disableExtraction) && disableExtraction.includes(sourcePath);
|
|
280
|
+
let programPath = null;
|
|
281
|
+
const res = {
|
|
282
|
+
styled: 0,
|
|
283
|
+
flattened: 0,
|
|
284
|
+
optimized: 0,
|
|
285
|
+
modified: 0,
|
|
286
|
+
found: 0
|
|
287
|
+
};
|
|
288
|
+
callTraverse({
|
|
289
|
+
// @ts-ignore
|
|
290
|
+
Program: {
|
|
291
|
+
enter(path) {
|
|
292
|
+
programPath = path;
|
|
293
|
+
}
|
|
294
|
+
},
|
|
295
|
+
// styled() calls
|
|
296
|
+
CallExpression(path) {
|
|
297
|
+
var _a2;
|
|
298
|
+
if (disable || shouldDisableExtraction || extractStyledDefinitions === false) {
|
|
299
|
+
return;
|
|
300
|
+
}
|
|
301
|
+
if (!t.isIdentifier(path.node.callee) || path.node.callee.name !== "styled") {
|
|
302
|
+
return;
|
|
303
|
+
}
|
|
304
|
+
const variableName = t.isVariableDeclarator(path.parent) && t.isIdentifier(path.parent.id) ? path.parent.id.name : "unknown";
|
|
305
|
+
const parentNode = path.node.arguments[0];
|
|
306
|
+
if (!t.isIdentifier(parentNode)) {
|
|
307
|
+
return;
|
|
308
|
+
}
|
|
309
|
+
const parentName = parentNode.name;
|
|
310
|
+
const definition = path.node.arguments[1];
|
|
311
|
+
if (!parentName || !definition || !t.isObjectExpression(definition)) {
|
|
312
|
+
return;
|
|
313
|
+
}
|
|
314
|
+
const Component = getValidImportedComponent(parentName);
|
|
315
|
+
if (!Component) {
|
|
316
|
+
return;
|
|
317
|
+
}
|
|
318
|
+
const componentSkipProps = /* @__PURE__ */ new Set([
|
|
319
|
+
...Component.staticConfig.inlineWhenUnflattened || [],
|
|
320
|
+
...Component.staticConfig.inlineProps || [],
|
|
321
|
+
...Component.staticConfig.deoptProps || [],
|
|
322
|
+
// for now skip variants, will return to them
|
|
323
|
+
"variants",
|
|
324
|
+
"defaultVariants",
|
|
325
|
+
// skip fontFamily its basically a "variant", important for theme use to be value always
|
|
326
|
+
"fontFamily",
|
|
327
|
+
"name",
|
|
328
|
+
"focusStyle",
|
|
329
|
+
"hoverStyle",
|
|
330
|
+
"pressStyle"
|
|
331
|
+
]);
|
|
332
|
+
const skipped = [];
|
|
333
|
+
const styles = {};
|
|
334
|
+
const staticNamespace = getStaticBindingsForScope(
|
|
335
|
+
path.scope,
|
|
336
|
+
importsWhitelist,
|
|
337
|
+
sourcePath,
|
|
338
|
+
bindingCache,
|
|
339
|
+
shouldPrintDebug
|
|
340
|
+
);
|
|
341
|
+
const attemptEval = !evaluateVars ? evaluateAstNode : createEvaluator({
|
|
342
|
+
props: propsWithFileInfo,
|
|
343
|
+
staticNamespace,
|
|
344
|
+
sourcePath,
|
|
345
|
+
shouldPrintDebug
|
|
346
|
+
});
|
|
347
|
+
const attemptEvalSafe = createSafeEvaluator(attemptEval);
|
|
348
|
+
for (const property of definition.properties) {
|
|
349
|
+
if (!t.isObjectProperty(property) || !t.isIdentifier(property.key) || !isValidStyleKey(property.key.name, Component.staticConfig) || // skip variants
|
|
350
|
+
((_a2 = Component.staticConfig.variants) == null ? void 0 : _a2[property.key.name]) || componentSkipProps.has(property.key.name)) {
|
|
351
|
+
skipped.push(property);
|
|
352
|
+
continue;
|
|
353
|
+
}
|
|
354
|
+
const out2 = attemptEvalSafe(property.value);
|
|
355
|
+
if (out2 === FAILED_EVAL) {
|
|
356
|
+
skipped.push(property);
|
|
357
|
+
} else {
|
|
358
|
+
styles[property.key.name] = out2;
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
const out = getSplitStyles(
|
|
362
|
+
styles,
|
|
363
|
+
Component.staticConfig,
|
|
364
|
+
defaultTheme,
|
|
365
|
+
{
|
|
366
|
+
focus: false,
|
|
367
|
+
hover: false,
|
|
368
|
+
unmounted: true,
|
|
369
|
+
press: false,
|
|
370
|
+
pressIn: false,
|
|
371
|
+
resolveVariablesAs: "variable",
|
|
372
|
+
noClassNames: false
|
|
373
|
+
},
|
|
374
|
+
void 0,
|
|
375
|
+
void 0,
|
|
376
|
+
void 0,
|
|
377
|
+
shouldPrintDebug
|
|
378
|
+
);
|
|
379
|
+
const classNames = {
|
|
380
|
+
...out.classNames
|
|
381
|
+
};
|
|
382
|
+
if (shouldPrintDebug) {
|
|
383
|
+
logger.info([`Extracted styled(${variableName})
|
|
384
|
+
`, JSON.stringify(styles, null, 2), "\n rulesToInsert:", out.rulesToInsert.flatMap((rule) => rule.rules).join("\n")].join(" "));
|
|
385
|
+
}
|
|
386
|
+
definition.properties = skipped;
|
|
387
|
+
for (const cn in classNames) {
|
|
388
|
+
if (componentSkipProps.has(cn)) {
|
|
389
|
+
continue;
|
|
390
|
+
}
|
|
391
|
+
const val = classNames[cn];
|
|
392
|
+
definition.properties.push(
|
|
393
|
+
t.objectProperty(t.stringLiteral(cn), t.stringLiteral(val))
|
|
394
|
+
);
|
|
395
|
+
}
|
|
396
|
+
if (out.rulesToInsert) {
|
|
397
|
+
for (const { identifier, rules } of out.rulesToInsert) {
|
|
398
|
+
onStyleRule == null ? void 0 : onStyleRule(identifier, rules);
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
res.styled++;
|
|
402
|
+
if (shouldPrintDebug) {
|
|
403
|
+
logger.info(`Extracted styled(${variableName})`);
|
|
404
|
+
}
|
|
405
|
+
},
|
|
406
|
+
JSXElement(traversePath) {
|
|
407
|
+
var _a2;
|
|
408
|
+
tm.mark("jsx-element", !!shouldPrintDebug);
|
|
409
|
+
const node = traversePath.node.openingElement;
|
|
410
|
+
const ogAttributes = node.attributes.map((attr) => ({ ...attr }));
|
|
411
|
+
const componentName = findComponentName(traversePath.scope);
|
|
412
|
+
const closingElement = traversePath.node.closingElement;
|
|
413
|
+
if (t.isJSXMemberExpression(closingElement == null ? void 0 : closingElement.name) || !t.isJSXIdentifier(node.name)) {
|
|
414
|
+
return;
|
|
415
|
+
}
|
|
416
|
+
const binding = traversePath.scope.getBinding(node.name.name);
|
|
417
|
+
let modulePath = "";
|
|
418
|
+
if (binding) {
|
|
419
|
+
if (!t.isImportDeclaration(binding.path.parent)) {
|
|
420
|
+
if (shouldPrintDebug) {
|
|
421
|
+
logger.info(` - Binding not import declaration, skip`);
|
|
422
|
+
}
|
|
423
|
+
return;
|
|
424
|
+
}
|
|
425
|
+
modulePath = binding.path.parent.source.value;
|
|
426
|
+
if (!isValidImport(propsWithFileInfo, modulePath, binding.identifier.name)) {
|
|
427
|
+
if (shouldPrintDebug) {
|
|
428
|
+
logger.info(
|
|
429
|
+
` - Binding not internal import or from components ${binding.identifier.name} in ${modulePath}`
|
|
430
|
+
);
|
|
431
|
+
}
|
|
432
|
+
return;
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
const component = getValidComponent(propsWithFileInfo, modulePath, node.name.name);
|
|
436
|
+
if (!component || !component.staticConfig) {
|
|
437
|
+
if (shouldPrintDebug) {
|
|
438
|
+
logger.info(` - No Tamagui conf on this: ${node.name.name}`);
|
|
439
|
+
}
|
|
440
|
+
return;
|
|
441
|
+
}
|
|
442
|
+
const originalNodeName = node.name.name;
|
|
443
|
+
res.found++;
|
|
444
|
+
const filePath = `./${relative(process.cwd(), sourcePath)}`;
|
|
445
|
+
const lineNumbers = node.loc ? node.loc.start.line + (node.loc.start.line !== node.loc.end.line ? `-${node.loc.end.line}` : "") : "";
|
|
446
|
+
const codePosition = `${filePath}:${lineNumbers}`;
|
|
447
|
+
const debugPropValue = node.attributes.filter(
|
|
448
|
+
(n) => t.isJSXAttribute(n) && t.isJSXIdentifier(n.name) && n.name.name === "debug"
|
|
449
|
+
).map((n) => {
|
|
450
|
+
if (n.value === null)
|
|
451
|
+
return true;
|
|
452
|
+
if (t.isStringLiteral(n.value))
|
|
453
|
+
return n.value.value;
|
|
454
|
+
return false;
|
|
455
|
+
})[0];
|
|
456
|
+
if (debugPropValue) {
|
|
457
|
+
shouldPrintDebug = debugPropValue;
|
|
458
|
+
}
|
|
459
|
+
if (shouldPrintDebug) {
|
|
460
|
+
logger.info("\n");
|
|
461
|
+
logger.info(
|
|
462
|
+
`\x1B[33m%s\x1B[0m ${componentName} | ${codePosition} -------------------`
|
|
463
|
+
);
|
|
464
|
+
logger.info(["\x1B[1m", "\x1B[32m", `<${originalNodeName} />`, disableDebugAttr ? "" : "\u{1F41B}"].join(" "));
|
|
465
|
+
}
|
|
466
|
+
if (shouldAddDebugProp && !disableDebugAttr) {
|
|
467
|
+
res.modified++;
|
|
468
|
+
node.attributes.unshift(
|
|
469
|
+
t.jsxAttribute(t.jsxIdentifier("data-is"), t.stringLiteral(node.name.name))
|
|
470
|
+
);
|
|
471
|
+
if (componentName) {
|
|
472
|
+
node.attributes.unshift(
|
|
473
|
+
t.jsxAttribute(t.jsxIdentifier("data-in"), t.stringLiteral(componentName))
|
|
474
|
+
);
|
|
475
|
+
}
|
|
476
|
+
node.attributes.unshift(
|
|
477
|
+
t.jsxAttribute(
|
|
478
|
+
t.jsxIdentifier("data-at"),
|
|
479
|
+
t.stringLiteral(`${basename(filePath)}:${lineNumbers}`)
|
|
480
|
+
)
|
|
481
|
+
);
|
|
482
|
+
}
|
|
483
|
+
if (shouldDisableExtraction) {
|
|
484
|
+
return;
|
|
485
|
+
}
|
|
486
|
+
try {
|
|
487
|
+
let evaluateAttribute2 = function(path) {
|
|
488
|
+
const attribute = path.node;
|
|
489
|
+
const attr = { type: "attr", value: attribute };
|
|
490
|
+
if (t.isJSXSpreadAttribute(attribute)) {
|
|
491
|
+
const arg = attribute.argument;
|
|
492
|
+
const conditional = t.isConditionalExpression(arg) ? (
|
|
493
|
+
// <YStack {...isSmall ? { color: 'red } : { color: 'blue }}
|
|
494
|
+
[arg.test, arg.consequent, arg.alternate]
|
|
495
|
+
) : t.isLogicalExpression(arg) && arg.operator === "&&" ? (
|
|
496
|
+
// <YStack {...isSmall && { color: 'red }}
|
|
497
|
+
[arg.left, arg.right, null]
|
|
498
|
+
) : null;
|
|
499
|
+
if (conditional) {
|
|
500
|
+
const [test, alt, cons] = conditional;
|
|
501
|
+
if (!test)
|
|
502
|
+
throw new Error(`no test`);
|
|
503
|
+
if ([alt, cons].some((side) => side && !isStaticObject2(side))) {
|
|
504
|
+
if (shouldPrintDebug) {
|
|
505
|
+
logger.info(`not extractable ${alt} ${cons}`);
|
|
506
|
+
}
|
|
507
|
+
return attr;
|
|
508
|
+
}
|
|
509
|
+
return [
|
|
510
|
+
...createTernariesFromObjectProperties2(test, alt) || [],
|
|
511
|
+
...cons && createTernariesFromObjectProperties2(
|
|
512
|
+
t.unaryExpression("!", test),
|
|
513
|
+
cons
|
|
514
|
+
) || []
|
|
515
|
+
].map((ternary) => ({
|
|
516
|
+
type: "ternary",
|
|
517
|
+
value: ternary
|
|
518
|
+
}));
|
|
519
|
+
}
|
|
520
|
+
}
|
|
521
|
+
if (t.isJSXSpreadAttribute(attribute) || !attribute.name || typeof attribute.name.name !== "string") {
|
|
522
|
+
if (shouldPrintDebug) {
|
|
523
|
+
logger.info(" ! inlining, spread attr");
|
|
524
|
+
}
|
|
525
|
+
inlined.set(`${Math.random()}`, "spread");
|
|
526
|
+
return attr;
|
|
527
|
+
}
|
|
528
|
+
const name = attribute.name.name;
|
|
529
|
+
if (excludeProps == null ? void 0 : excludeProps.has(name)) {
|
|
530
|
+
if (shouldPrintDebug) {
|
|
531
|
+
logger.info([" excluding prop", name].join(" "));
|
|
532
|
+
}
|
|
533
|
+
return null;
|
|
534
|
+
}
|
|
535
|
+
if (inlineProps.has(name)) {
|
|
536
|
+
inlined.set(name, name);
|
|
537
|
+
if (shouldPrintDebug) {
|
|
538
|
+
logger.info([" ! inlining, inline prop", name].join(" "));
|
|
539
|
+
}
|
|
540
|
+
return attr;
|
|
541
|
+
}
|
|
542
|
+
if (deoptProps.has(name)) {
|
|
543
|
+
shouldDeopt = true;
|
|
544
|
+
inlined.set(name, name);
|
|
545
|
+
if (shouldPrintDebug) {
|
|
546
|
+
logger.info([" ! inlining, deopted prop", name].join(" "));
|
|
547
|
+
}
|
|
548
|
+
return attr;
|
|
549
|
+
}
|
|
550
|
+
if (UNTOUCHED_PROPS[name]) {
|
|
551
|
+
return attr;
|
|
552
|
+
}
|
|
553
|
+
if (INLINE_EXTRACTABLE[name]) {
|
|
554
|
+
inlined.set(name, INLINE_EXTRACTABLE[name]);
|
|
555
|
+
return attr;
|
|
556
|
+
}
|
|
557
|
+
if (name.startsWith("data-")) {
|
|
558
|
+
return attr;
|
|
559
|
+
}
|
|
560
|
+
if (name[0] === "$" && t.isJSXExpressionContainer(attribute == null ? void 0 : attribute.value)) {
|
|
561
|
+
const shortname = name.slice(1);
|
|
562
|
+
if (mediaQueryConfig[shortname]) {
|
|
563
|
+
if (target === "native") {
|
|
564
|
+
shouldDeopt = true;
|
|
565
|
+
}
|
|
566
|
+
if (disableExtractInlineMedia) {
|
|
567
|
+
return attr;
|
|
568
|
+
}
|
|
569
|
+
const expression = attribute.value.expression;
|
|
570
|
+
if (!t.isJSXEmptyExpression(expression)) {
|
|
571
|
+
const ternaries2 = createTernariesFromObjectProperties2(
|
|
572
|
+
t.stringLiteral(shortname),
|
|
573
|
+
expression,
|
|
574
|
+
{
|
|
575
|
+
inlineMediaQuery: shortname
|
|
576
|
+
}
|
|
577
|
+
);
|
|
578
|
+
if (ternaries2) {
|
|
579
|
+
return ternaries2.map((value2) => ({
|
|
580
|
+
type: "ternary",
|
|
581
|
+
value: value2
|
|
582
|
+
}));
|
|
583
|
+
}
|
|
584
|
+
}
|
|
585
|
+
}
|
|
586
|
+
}
|
|
587
|
+
const [value, valuePath] = (() => {
|
|
588
|
+
if (t.isJSXExpressionContainer(attribute == null ? void 0 : attribute.value)) {
|
|
589
|
+
return [attribute.value.expression, path.get("value")];
|
|
590
|
+
} else {
|
|
591
|
+
return [attribute.value, path.get("value")];
|
|
592
|
+
}
|
|
593
|
+
})();
|
|
594
|
+
const remove = () => {
|
|
595
|
+
Array.isArray(valuePath) ? valuePath.map((p) => p.remove()) : valuePath.remove();
|
|
596
|
+
};
|
|
597
|
+
if (name === "ref") {
|
|
598
|
+
if (shouldPrintDebug) {
|
|
599
|
+
logger.info([" ! inlining, ref", name].join(" "));
|
|
600
|
+
}
|
|
601
|
+
inlined.set("ref", "ref");
|
|
602
|
+
return attr;
|
|
603
|
+
}
|
|
604
|
+
if (name === "tag") {
|
|
605
|
+
return {
|
|
606
|
+
type: "attr",
|
|
607
|
+
value: path.node
|
|
608
|
+
};
|
|
609
|
+
}
|
|
610
|
+
if (disableExtractVariables === true) {
|
|
611
|
+
if (value) {
|
|
612
|
+
if (value.type === "StringLiteral" && value.value[0] === "$") {
|
|
613
|
+
if (shouldPrintDebug) {
|
|
614
|
+
logger.info(
|
|
615
|
+
[
|
|
616
|
+
` ! inlining, native disable extract: ${name} =`,
|
|
617
|
+
value.value
|
|
618
|
+
].join(" ")
|
|
619
|
+
);
|
|
620
|
+
}
|
|
621
|
+
inlined.set(name, true);
|
|
622
|
+
return attr;
|
|
623
|
+
}
|
|
624
|
+
}
|
|
625
|
+
}
|
|
626
|
+
if (name === "theme") {
|
|
627
|
+
inlined.set("theme", attr.value);
|
|
628
|
+
return attr;
|
|
629
|
+
}
|
|
630
|
+
const styleValue = attemptEvalSafe(value);
|
|
631
|
+
if (!variants[name] && !isValidStyleKey(name, staticConfig)) {
|
|
632
|
+
let keys = [name];
|
|
633
|
+
let out = null;
|
|
634
|
+
out = staticConfig.propMapper(
|
|
635
|
+
name,
|
|
636
|
+
styleValue,
|
|
637
|
+
defaultTheme,
|
|
638
|
+
staticConfig.defaultProps,
|
|
639
|
+
{ resolveVariablesAs: "auto" },
|
|
640
|
+
void 0,
|
|
641
|
+
void 0,
|
|
642
|
+
shouldPrintDebug
|
|
643
|
+
);
|
|
644
|
+
if (out) {
|
|
645
|
+
if (!Array.isArray(out)) {
|
|
646
|
+
logger.warn(`Error expected array but got`, out);
|
|
647
|
+
couldntParse = true;
|
|
648
|
+
shouldDeopt = true;
|
|
649
|
+
} else {
|
|
650
|
+
out = Object.fromEntries(out);
|
|
651
|
+
keys = Object.keys(out);
|
|
652
|
+
}
|
|
653
|
+
}
|
|
654
|
+
if (out) {
|
|
655
|
+
if (isTargetingHTML) {
|
|
656
|
+
out = createDOMProps(isTextView ? "span" : "div", out);
|
|
657
|
+
delete out.className;
|
|
658
|
+
}
|
|
659
|
+
keys = Object.keys(out);
|
|
660
|
+
}
|
|
661
|
+
let didInline = false;
|
|
662
|
+
const attributes = keys.map((key) => {
|
|
663
|
+
const val = out[key];
|
|
664
|
+
const isStyle = isValidStyleKey(key, staticConfig);
|
|
665
|
+
if (isStyle) {
|
|
666
|
+
return {
|
|
667
|
+
type: "style",
|
|
668
|
+
value: { [key]: styleValue },
|
|
669
|
+
name: key,
|
|
670
|
+
attr: path.node
|
|
671
|
+
};
|
|
672
|
+
}
|
|
673
|
+
if (validHTMLAttributes[key] || key.startsWith("aria-") || key.startsWith("data-") || // this is debug stuff added by vite / new jsx transform
|
|
674
|
+
key === "__source" || key === "__self") {
|
|
675
|
+
return attr;
|
|
676
|
+
}
|
|
677
|
+
if (shouldPrintDebug) {
|
|
678
|
+
logger.info(" ! inlining, non-static " + key);
|
|
679
|
+
}
|
|
680
|
+
didInline = true;
|
|
681
|
+
inlined.set(key, val);
|
|
682
|
+
return val;
|
|
683
|
+
});
|
|
684
|
+
if (didInline) {
|
|
685
|
+
if (shouldPrintDebug) {
|
|
686
|
+
logger.info(` bailing flattening due to attributes ${attributes}`);
|
|
687
|
+
}
|
|
688
|
+
return attr;
|
|
689
|
+
}
|
|
690
|
+
return attributes;
|
|
691
|
+
}
|
|
692
|
+
if (styleValue !== FAILED_EVAL) {
|
|
693
|
+
if (inlineWhenUnflattened.has(name)) {
|
|
694
|
+
inlineWhenUnflattenedOGVals[name] = { styleValue, attr };
|
|
695
|
+
}
|
|
696
|
+
if (isValidStyleKey(name, staticConfig)) {
|
|
697
|
+
if (shouldPrintDebug) {
|
|
698
|
+
logger.info(` style: ${name} = ${styleValue}`);
|
|
699
|
+
}
|
|
700
|
+
if (!(name in staticConfig.defaultProps)) {
|
|
701
|
+
if (!hasSetOptimized) {
|
|
702
|
+
res.optimized++;
|
|
703
|
+
hasSetOptimized = true;
|
|
704
|
+
}
|
|
705
|
+
}
|
|
706
|
+
return {
|
|
707
|
+
type: "style",
|
|
708
|
+
value: { [name]: styleValue },
|
|
709
|
+
name,
|
|
710
|
+
attr: path.node
|
|
711
|
+
};
|
|
712
|
+
} else {
|
|
713
|
+
if (variants[name]) {
|
|
714
|
+
variantValues.set(name, styleValue);
|
|
715
|
+
}
|
|
716
|
+
inlined.set(name, true);
|
|
717
|
+
return attr;
|
|
718
|
+
}
|
|
719
|
+
}
|
|
720
|
+
if (t.isBinaryExpression(value)) {
|
|
721
|
+
if (shouldPrintDebug) {
|
|
722
|
+
logger.info(` binary expression ${name} = ${value}`);
|
|
723
|
+
}
|
|
724
|
+
const { operator, left, right } = value;
|
|
725
|
+
const lVal = attemptEvalSafe(left);
|
|
726
|
+
const rVal = attemptEvalSafe(right);
|
|
727
|
+
if (shouldPrintDebug) {
|
|
728
|
+
logger.info(
|
|
729
|
+
` evalBinaryExpression lVal ${String(lVal)}, rVal ${String(rVal)}`
|
|
730
|
+
);
|
|
731
|
+
}
|
|
732
|
+
if (lVal !== FAILED_EVAL && t.isConditionalExpression(right)) {
|
|
733
|
+
const ternary = addBinaryConditional(operator, left, right);
|
|
734
|
+
if (ternary)
|
|
735
|
+
return ternary;
|
|
736
|
+
}
|
|
737
|
+
if (rVal !== FAILED_EVAL && t.isConditionalExpression(left)) {
|
|
738
|
+
const ternary = addBinaryConditional(operator, right, left);
|
|
739
|
+
if (ternary)
|
|
740
|
+
return ternary;
|
|
741
|
+
}
|
|
742
|
+
if (shouldPrintDebug) {
|
|
743
|
+
logger.info(` evalBinaryExpression cant extract`);
|
|
744
|
+
}
|
|
745
|
+
inlined.set(name, true);
|
|
746
|
+
return attr;
|
|
747
|
+
}
|
|
748
|
+
const staticConditional = getStaticConditional(value);
|
|
749
|
+
if (staticConditional) {
|
|
750
|
+
if (shouldPrintDebug === "verbose") {
|
|
751
|
+
logger.info(` static conditional ${name} ${value}`);
|
|
752
|
+
}
|
|
753
|
+
return { type: "ternary", value: staticConditional };
|
|
754
|
+
}
|
|
755
|
+
const staticLogical = getStaticLogical(value);
|
|
756
|
+
if (staticLogical) {
|
|
757
|
+
if (shouldPrintDebug === "verbose") {
|
|
758
|
+
logger.info(` static ternary ${name} = ${value}`);
|
|
759
|
+
}
|
|
760
|
+
return { type: "ternary", value: staticLogical };
|
|
761
|
+
}
|
|
762
|
+
inlined.set(name, true);
|
|
763
|
+
if (shouldPrintDebug) {
|
|
764
|
+
logger.info(` ! inline no match ${name} ${value}`);
|
|
765
|
+
}
|
|
766
|
+
return attr;
|
|
767
|
+
function addBinaryConditional(operator, staticExpr, cond) {
|
|
768
|
+
if (getStaticConditional(cond)) {
|
|
769
|
+
const alt = attemptEval(
|
|
770
|
+
t.binaryExpression(operator, staticExpr, cond.alternate)
|
|
771
|
+
);
|
|
772
|
+
const cons = attemptEval(
|
|
773
|
+
t.binaryExpression(operator, staticExpr, cond.consequent)
|
|
774
|
+
);
|
|
775
|
+
if (shouldPrintDebug) {
|
|
776
|
+
logger.info([" binaryConditional", cond.test, cons, alt].join(" "));
|
|
777
|
+
}
|
|
778
|
+
return {
|
|
779
|
+
type: "ternary",
|
|
780
|
+
value: {
|
|
781
|
+
test: cond.test,
|
|
782
|
+
remove,
|
|
783
|
+
alternate: { [name]: alt },
|
|
784
|
+
consequent: { [name]: cons }
|
|
785
|
+
}
|
|
786
|
+
};
|
|
787
|
+
}
|
|
788
|
+
return null;
|
|
789
|
+
}
|
|
790
|
+
function getStaticConditional(value2) {
|
|
791
|
+
if (t.isConditionalExpression(value2)) {
|
|
792
|
+
try {
|
|
793
|
+
const aVal = attemptEval(value2.alternate);
|
|
794
|
+
const cVal = attemptEval(value2.consequent);
|
|
795
|
+
if (shouldPrintDebug) {
|
|
796
|
+
const type = value2.test.type;
|
|
797
|
+
logger.info([" static ternary", type, cVal, aVal].join(" "));
|
|
798
|
+
}
|
|
799
|
+
return {
|
|
800
|
+
test: value2.test,
|
|
801
|
+
remove,
|
|
802
|
+
consequent: { [name]: cVal },
|
|
803
|
+
alternate: { [name]: aVal }
|
|
804
|
+
};
|
|
805
|
+
} catch (err) {
|
|
806
|
+
if (shouldPrintDebug) {
|
|
807
|
+
logger.info([" cant eval ternary", err.message].join(" "));
|
|
808
|
+
}
|
|
809
|
+
}
|
|
810
|
+
}
|
|
811
|
+
return null;
|
|
812
|
+
}
|
|
813
|
+
function getStaticLogical(value2) {
|
|
814
|
+
if (t.isLogicalExpression(value2)) {
|
|
815
|
+
if (value2.operator === "&&") {
|
|
816
|
+
try {
|
|
817
|
+
const val = attemptEval(value2.right);
|
|
818
|
+
if (shouldPrintDebug) {
|
|
819
|
+
logger.info([" staticLogical", value2.left, name, val].join(" "));
|
|
820
|
+
}
|
|
821
|
+
return {
|
|
822
|
+
test: value2.left,
|
|
823
|
+
remove,
|
|
824
|
+
consequent: { [name]: val },
|
|
825
|
+
alternate: null
|
|
826
|
+
};
|
|
827
|
+
} catch (err) {
|
|
828
|
+
if (shouldPrintDebug) {
|
|
829
|
+
logger.info([" cant static eval logical", err].join(" "));
|
|
830
|
+
}
|
|
831
|
+
}
|
|
832
|
+
}
|
|
833
|
+
}
|
|
834
|
+
return null;
|
|
835
|
+
}
|
|
836
|
+
}, isStaticObject2 = function(obj) {
|
|
837
|
+
return t.isObjectExpression(obj) && obj.properties.every((prop) => {
|
|
838
|
+
if (!t.isObjectProperty(prop)) {
|
|
839
|
+
logger.info(["not object prop", prop].join(" "));
|
|
840
|
+
return false;
|
|
841
|
+
}
|
|
842
|
+
const propName = prop.key["name"];
|
|
843
|
+
if (!isValidStyleKey(propName, staticConfig) && propName !== "tag") {
|
|
844
|
+
if (shouldPrintDebug) {
|
|
845
|
+
logger.info([" not a valid style prop!", propName].join(" "));
|
|
846
|
+
}
|
|
847
|
+
return false;
|
|
848
|
+
}
|
|
849
|
+
return true;
|
|
850
|
+
});
|
|
851
|
+
}, createTernariesFromObjectProperties2 = function(test, side, ternaryPartial = {}) {
|
|
852
|
+
if (!side) {
|
|
853
|
+
return null;
|
|
854
|
+
}
|
|
855
|
+
if (!isStaticObject2(side)) {
|
|
856
|
+
throw new Error("not extractable");
|
|
857
|
+
}
|
|
858
|
+
return side.properties.flatMap((property) => {
|
|
859
|
+
if (!t.isObjectProperty(property)) {
|
|
860
|
+
throw new Error("expected object property");
|
|
861
|
+
}
|
|
862
|
+
if (t.isIdentifier(property.key)) {
|
|
863
|
+
const key = property.key.name;
|
|
864
|
+
const mediaQueryKey = key.slice(1);
|
|
865
|
+
const isMediaQuery = key[0] === "$" && mediaQueryConfig[mediaQueryKey];
|
|
866
|
+
if (isMediaQuery) {
|
|
867
|
+
if (t.isExpression(property.value)) {
|
|
868
|
+
const ternaries2 = createTernariesFromObjectProperties2(
|
|
869
|
+
t.stringLiteral(mediaQueryKey),
|
|
870
|
+
property.value,
|
|
871
|
+
{
|
|
872
|
+
inlineMediaQuery: mediaQueryKey
|
|
873
|
+
}
|
|
874
|
+
);
|
|
875
|
+
if (ternaries2) {
|
|
876
|
+
return ternaries2.map((value) => ({
|
|
877
|
+
...ternaryPartial,
|
|
878
|
+
...value,
|
|
879
|
+
// ensure media query test stays on left side (see getMediaQueryTernary)
|
|
880
|
+
test: t.logicalExpression("&&", value.test, test)
|
|
881
|
+
}));
|
|
882
|
+
} else {
|
|
883
|
+
logger.info(["\u26A0\uFE0F no ternaries?", property].join(" "));
|
|
884
|
+
}
|
|
885
|
+
} else {
|
|
886
|
+
logger.info(["\u26A0\uFE0F not expression", property].join(" "));
|
|
887
|
+
}
|
|
888
|
+
}
|
|
889
|
+
}
|
|
890
|
+
if (t.isConditionalExpression(property.value)) {
|
|
891
|
+
const [truthy, falsy] = [
|
|
892
|
+
t.objectExpression([
|
|
893
|
+
t.objectProperty(property.key, property.value.consequent)
|
|
894
|
+
]),
|
|
895
|
+
t.objectExpression([
|
|
896
|
+
t.objectProperty(property.key, property.value.alternate)
|
|
897
|
+
])
|
|
898
|
+
].map((x) => attemptEval(x));
|
|
899
|
+
return [
|
|
900
|
+
createTernary({
|
|
901
|
+
remove() {
|
|
902
|
+
},
|
|
903
|
+
...ternaryPartial,
|
|
904
|
+
test: t.logicalExpression("&&", test, property.value.test),
|
|
905
|
+
consequent: truthy,
|
|
906
|
+
alternate: null
|
|
907
|
+
}),
|
|
908
|
+
createTernary({
|
|
909
|
+
...ternaryPartial,
|
|
910
|
+
test: t.logicalExpression(
|
|
911
|
+
"&&",
|
|
912
|
+
test,
|
|
913
|
+
t.unaryExpression("!", property.value.test)
|
|
914
|
+
),
|
|
915
|
+
consequent: falsy,
|
|
916
|
+
alternate: null,
|
|
917
|
+
remove() {
|
|
918
|
+
}
|
|
919
|
+
})
|
|
920
|
+
];
|
|
921
|
+
}
|
|
922
|
+
const obj = t.objectExpression([
|
|
923
|
+
t.objectProperty(property.key, property.value)
|
|
924
|
+
]);
|
|
925
|
+
const consequent = attemptEval(obj);
|
|
926
|
+
return createTernary({
|
|
927
|
+
remove() {
|
|
928
|
+
},
|
|
929
|
+
...ternaryPartial,
|
|
930
|
+
test,
|
|
931
|
+
consequent,
|
|
932
|
+
alternate: null
|
|
933
|
+
});
|
|
934
|
+
});
|
|
935
|
+
}, splitVariants2 = function(style) {
|
|
936
|
+
var _a3;
|
|
937
|
+
const variants2 = {};
|
|
938
|
+
const styles = {};
|
|
939
|
+
for (const key in style) {
|
|
940
|
+
if ((_a3 = staticConfig.variants) == null ? void 0 : _a3[key]) {
|
|
941
|
+
variants2[key] = style[key];
|
|
942
|
+
} else {
|
|
943
|
+
styles[key] = style[key];
|
|
944
|
+
}
|
|
945
|
+
}
|
|
946
|
+
return {
|
|
947
|
+
variants: variants2,
|
|
948
|
+
styles
|
|
949
|
+
};
|
|
950
|
+
}, expandStylesWithoutVariants2 = function(style) {
|
|
951
|
+
const { variants: variants2, styles } = splitVariants2(style);
|
|
952
|
+
return {
|
|
953
|
+
...expandStyles(styles),
|
|
954
|
+
...variants2
|
|
955
|
+
};
|
|
956
|
+
}, mergeStyles2 = function(prev2, next) {
|
|
957
|
+
for (const key in next) {
|
|
958
|
+
if (pseudoDescriptors[key]) {
|
|
959
|
+
prev2[key] = prev2[key] || {};
|
|
960
|
+
Object.assign(prev2[key], next[key]);
|
|
961
|
+
} else {
|
|
962
|
+
prev2[key] = next[key];
|
|
963
|
+
}
|
|
964
|
+
}
|
|
965
|
+
};
|
|
966
|
+
var evaluateAttribute = evaluateAttribute2, isStaticObject = isStaticObject2, createTernariesFromObjectProperties = createTernariesFromObjectProperties2, splitVariants = splitVariants2, expandStylesWithoutVariants = expandStylesWithoutVariants2, mergeStyles = mergeStyles2;
|
|
967
|
+
const { staticConfig } = component;
|
|
968
|
+
const variants = staticConfig.variants || {};
|
|
969
|
+
const isTextView = staticConfig.isText || false;
|
|
970
|
+
const validStyles = (staticConfig == null ? void 0 : staticConfig.validStyles) ?? {};
|
|
971
|
+
let tagName = staticConfig.defaultProps.tag ?? (isTextView ? "span" : "div");
|
|
972
|
+
traversePath.get("openingElement").get("attributes").forEach((path) => {
|
|
973
|
+
const attr = path.node;
|
|
974
|
+
if (t.isJSXSpreadAttribute(attr))
|
|
975
|
+
return;
|
|
976
|
+
if (attr.name.name !== "tag")
|
|
977
|
+
return;
|
|
978
|
+
const val = attr.value;
|
|
979
|
+
if (!t.isStringLiteral(val))
|
|
980
|
+
return;
|
|
981
|
+
tagName = val.value;
|
|
982
|
+
});
|
|
983
|
+
const flatNode = getFlattenedNode == null ? void 0 : getFlattenedNode({ isTextView, tag: tagName });
|
|
984
|
+
const inlineProps = /* @__PURE__ */ new Set([
|
|
985
|
+
// adding some always inline props
|
|
986
|
+
"dataSet",
|
|
987
|
+
...restProps.inlineProps || [],
|
|
988
|
+
...staticConfig.inlineProps || []
|
|
989
|
+
]);
|
|
990
|
+
const deoptProps = /* @__PURE__ */ new Set([
|
|
991
|
+
// always de-opt animation
|
|
992
|
+
"animation",
|
|
993
|
+
...restProps.deoptProps || [],
|
|
994
|
+
...staticConfig.deoptProps || []
|
|
995
|
+
]);
|
|
996
|
+
const inlineWhenUnflattened = /* @__PURE__ */ new Set([
|
|
997
|
+
...staticConfig.inlineWhenUnflattened || []
|
|
998
|
+
]);
|
|
999
|
+
const staticNamespace = getStaticBindingsForScope(
|
|
1000
|
+
traversePath.scope,
|
|
1001
|
+
importsWhitelist,
|
|
1002
|
+
sourcePath,
|
|
1003
|
+
bindingCache,
|
|
1004
|
+
shouldPrintDebug
|
|
1005
|
+
);
|
|
1006
|
+
const attemptEval = !evaluateVars ? evaluateAstNode : createEvaluator({
|
|
1007
|
+
props: propsWithFileInfo,
|
|
1008
|
+
staticNamespace,
|
|
1009
|
+
sourcePath,
|
|
1010
|
+
traversePath,
|
|
1011
|
+
shouldPrintDebug
|
|
1012
|
+
});
|
|
1013
|
+
const attemptEvalSafe = createSafeEvaluator(attemptEval);
|
|
1014
|
+
if (shouldPrintDebug) {
|
|
1015
|
+
logger.info(` staticNamespace ${Object.keys(staticNamespace).join(", ")}`);
|
|
1016
|
+
}
|
|
1017
|
+
if (couldntParse) {
|
|
1018
|
+
return;
|
|
1019
|
+
}
|
|
1020
|
+
tm.mark("jsx-element-flattened", !!shouldPrintDebug);
|
|
1021
|
+
let attrs = [];
|
|
1022
|
+
let shouldDeopt = false;
|
|
1023
|
+
const inlined = /* @__PURE__ */ new Map();
|
|
1024
|
+
const variantValues = /* @__PURE__ */ new Map();
|
|
1025
|
+
let hasSetOptimized = false;
|
|
1026
|
+
const inlineWhenUnflattenedOGVals = {};
|
|
1027
|
+
attrs = traversePath.get("openingElement").get("attributes").flatMap((path) => {
|
|
1028
|
+
var _a3;
|
|
1029
|
+
try {
|
|
1030
|
+
const res2 = evaluateAttribute2(path);
|
|
1031
|
+
tm.mark("jsx-element-evaluate-attr", !!shouldPrintDebug);
|
|
1032
|
+
if (!res2) {
|
|
1033
|
+
path.remove();
|
|
1034
|
+
}
|
|
1035
|
+
return res2;
|
|
1036
|
+
} catch (err) {
|
|
1037
|
+
if (shouldPrintDebug) {
|
|
1038
|
+
logger.info(
|
|
1039
|
+
[
|
|
1040
|
+
"Recoverable error extracting attribute",
|
|
1041
|
+
err.message,
|
|
1042
|
+
shouldPrintDebug === "verbose" ? err.stack : ""
|
|
1043
|
+
].join(" ")
|
|
1044
|
+
);
|
|
1045
|
+
if (shouldPrintDebug === "verbose") {
|
|
1046
|
+
logger.info(`node ${(_a3 = path.node) == null ? void 0 : _a3.type}`);
|
|
1047
|
+
}
|
|
1048
|
+
}
|
|
1049
|
+
inlined.set(`${Math.random()}`, "spread");
|
|
1050
|
+
return {
|
|
1051
|
+
type: "attr",
|
|
1052
|
+
value: path.node
|
|
1053
|
+
};
|
|
1054
|
+
}
|
|
1055
|
+
}).flat(4).filter(isPresent);
|
|
1056
|
+
if (shouldPrintDebug) {
|
|
1057
|
+
logger.info(
|
|
1058
|
+
[" - attrs (before):\n", logLines(attrs.map(attrStr).join(", "))].join(" ")
|
|
1059
|
+
);
|
|
1060
|
+
}
|
|
1061
|
+
if (couldntParse || shouldDeopt) {
|
|
1062
|
+
if (shouldPrintDebug) {
|
|
1063
|
+
logger.info(
|
|
1064
|
+
[` avoid optimizing:`, { couldntParse, shouldDeopt }].join(" ")
|
|
1065
|
+
);
|
|
1066
|
+
}
|
|
1067
|
+
node.attributes = ogAttributes;
|
|
1068
|
+
return;
|
|
1069
|
+
}
|
|
1070
|
+
const parentFn = findTopmostFunction(traversePath);
|
|
1071
|
+
if (parentFn) {
|
|
1072
|
+
modifiedComponents.add(parentFn);
|
|
1073
|
+
}
|
|
1074
|
+
let ternaries = [];
|
|
1075
|
+
attrs = attrs.reduce((out, cur) => {
|
|
1076
|
+
const next = attrs[attrs.indexOf(cur) + 1];
|
|
1077
|
+
if (cur.type === "ternary") {
|
|
1078
|
+
ternaries.push(cur.value);
|
|
1079
|
+
}
|
|
1080
|
+
if ((!next || next.type !== "ternary") && ternaries.length) {
|
|
1081
|
+
const normalized = normalizeTernaries(ternaries).map(
|
|
1082
|
+
({ alternate, consequent, ...rest }) => {
|
|
1083
|
+
return {
|
|
1084
|
+
type: "ternary",
|
|
1085
|
+
value: {
|
|
1086
|
+
...rest,
|
|
1087
|
+
alternate: alternate || null,
|
|
1088
|
+
consequent: consequent || null
|
|
1089
|
+
}
|
|
1090
|
+
};
|
|
1091
|
+
}
|
|
1092
|
+
);
|
|
1093
|
+
try {
|
|
1094
|
+
return [...out, ...normalized];
|
|
1095
|
+
} finally {
|
|
1096
|
+
if (shouldPrintDebug) {
|
|
1097
|
+
logger.info(
|
|
1098
|
+
` normalizeTernaries (${ternaries.length} => ${normalized.length})`
|
|
1099
|
+
);
|
|
1100
|
+
}
|
|
1101
|
+
ternaries = [];
|
|
1102
|
+
}
|
|
1103
|
+
}
|
|
1104
|
+
if (cur.type === "ternary") {
|
|
1105
|
+
return out;
|
|
1106
|
+
}
|
|
1107
|
+
out.push(cur);
|
|
1108
|
+
return out;
|
|
1109
|
+
}, []).flat();
|
|
1110
|
+
const hasSpread = attrs.some(
|
|
1111
|
+
(x) => x.type === "attr" && t.isJSXSpreadAttribute(x.value)
|
|
1112
|
+
);
|
|
1113
|
+
const hasOnlyStringChildren = !hasSpread && (node.selfClosing || traversePath.node.children && traversePath.node.children.every((x) => x.type === "JSXText"));
|
|
1114
|
+
const themeVal = inlined.get("theme");
|
|
1115
|
+
if (target !== "native") {
|
|
1116
|
+
inlined.delete("theme");
|
|
1117
|
+
}
|
|
1118
|
+
for (const [key] of [...inlined]) {
|
|
1119
|
+
const isStaticObjectVariant = ((_a2 = staticConfig.variants) == null ? void 0 : _a2[key]) && variantValues.has(key);
|
|
1120
|
+
if (INLINE_EXTRACTABLE[key] || isStaticObjectVariant) {
|
|
1121
|
+
inlined.delete(key);
|
|
1122
|
+
}
|
|
1123
|
+
}
|
|
1124
|
+
const canFlattenProps = inlined.size === 0;
|
|
1125
|
+
let shouldFlatten = Boolean(
|
|
1126
|
+
flatNode && !shouldDeopt && canFlattenProps && !hasSpread && staticConfig.neverFlatten !== true && (staticConfig.neverFlatten === "jsx" ? hasOnlyStringChildren : true)
|
|
1127
|
+
);
|
|
1128
|
+
const shouldWrapTheme = shouldFlatten && themeVal;
|
|
1129
|
+
const usedThemeKeys = /* @__PURE__ */ new Set();
|
|
1130
|
+
if (disableExtractVariables) {
|
|
1131
|
+
themeAccessListeners.add((key) => {
|
|
1132
|
+
shouldFlatten = false;
|
|
1133
|
+
usedThemeKeys.add(key);
|
|
1134
|
+
if (shouldPrintDebug === "verbose") {
|
|
1135
|
+
logger.info([" ! accessing theme key, avoid flatten", key].join(" "));
|
|
1136
|
+
}
|
|
1137
|
+
});
|
|
1138
|
+
}
|
|
1139
|
+
if (shouldPrintDebug) {
|
|
1140
|
+
try {
|
|
1141
|
+
logger.info([" flatten?", shouldFlatten, objToStr({ hasSpread, shouldDeopt, canFlattenProps, shouldWrapTheme, hasOnlyStringChildren }), "inlined", inlined.size, [...inlined]].join(" "));
|
|
1142
|
+
} catch {
|
|
1143
|
+
}
|
|
1144
|
+
}
|
|
1145
|
+
if (shouldFlatten && shouldWrapTheme) {
|
|
1146
|
+
if (!programPath) {
|
|
1147
|
+
console.warn(
|
|
1148
|
+
`No program path found, avoiding importing flattening / importing theme in ${sourcePath}`
|
|
1149
|
+
);
|
|
1150
|
+
} else {
|
|
1151
|
+
if (shouldPrintDebug) {
|
|
1152
|
+
logger.info([" - wrapping theme", themeVal].join(" "));
|
|
1153
|
+
}
|
|
1154
|
+
attrs = attrs.filter(
|
|
1155
|
+
(x) => x.type === "attr" && t.isJSXAttribute(x.value) && x.value.name.name === "theme" ? false : true
|
|
1156
|
+
);
|
|
1157
|
+
if (!hasImportedTheme) {
|
|
1158
|
+
hasImportedTheme = true;
|
|
1159
|
+
programPath.node.body.push(
|
|
1160
|
+
t.importDeclaration(
|
|
1161
|
+
[
|
|
1162
|
+
t.importSpecifier(
|
|
1163
|
+
t.identifier("_TamaguiTheme"),
|
|
1164
|
+
t.identifier("Theme")
|
|
1165
|
+
)
|
|
1166
|
+
],
|
|
1167
|
+
t.stringLiteral("@tamagui/core")
|
|
1168
|
+
)
|
|
1169
|
+
);
|
|
1170
|
+
}
|
|
1171
|
+
traversePath.replaceWith(
|
|
1172
|
+
t.jsxElement(
|
|
1173
|
+
t.jsxOpeningElement(t.jsxIdentifier("_TamaguiTheme"), [
|
|
1174
|
+
t.jsxAttribute(t.jsxIdentifier("name"), themeVal.value)
|
|
1175
|
+
]),
|
|
1176
|
+
t.jsxClosingElement(t.jsxIdentifier("_TamaguiTheme")),
|
|
1177
|
+
[traversePath.node]
|
|
1178
|
+
)
|
|
1179
|
+
);
|
|
1180
|
+
}
|
|
1181
|
+
}
|
|
1182
|
+
if (shouldFlatten) {
|
|
1183
|
+
const defaultStyleAttrs = Object.keys(staticConfig.defaultProps).flatMap(
|
|
1184
|
+
(key) => {
|
|
1185
|
+
if (!isValidStyleKey(key, staticConfig)) {
|
|
1186
|
+
return [];
|
|
1187
|
+
}
|
|
1188
|
+
const value = staticConfig.defaultProps[key];
|
|
1189
|
+
const name = tamaguiConfig.shorthands[key] || key;
|
|
1190
|
+
if (value === void 0) {
|
|
1191
|
+
logger.warn(
|
|
1192
|
+
`\u26A0\uFE0F Error evaluating default style for component, prop ${key} ${value}`
|
|
1193
|
+
);
|
|
1194
|
+
shouldDeopt = true;
|
|
1195
|
+
return;
|
|
1196
|
+
}
|
|
1197
|
+
const attr = {
|
|
1198
|
+
type: "style",
|
|
1199
|
+
name,
|
|
1200
|
+
value: { [name]: value }
|
|
1201
|
+
};
|
|
1202
|
+
return attr;
|
|
1203
|
+
}
|
|
1204
|
+
);
|
|
1205
|
+
if (defaultStyleAttrs.length) {
|
|
1206
|
+
attrs = [...defaultStyleAttrs, ...attrs];
|
|
1207
|
+
}
|
|
1208
|
+
}
|
|
1209
|
+
if (shouldDeopt || !shouldFlatten) {
|
|
1210
|
+
if (shouldPrintDebug) {
|
|
1211
|
+
logger.info(`Deopting ${shouldDeopt} ${shouldFlatten}`);
|
|
1212
|
+
}
|
|
1213
|
+
node.attributes = ogAttributes;
|
|
1214
|
+
return;
|
|
1215
|
+
}
|
|
1216
|
+
if (shouldPrintDebug) {
|
|
1217
|
+
logger.info(
|
|
1218
|
+
[" - attrs (flattened): \n", logLines(attrs.map(attrStr).join(", "))].join(
|
|
1219
|
+
" "
|
|
1220
|
+
)
|
|
1221
|
+
);
|
|
1222
|
+
}
|
|
1223
|
+
const state = {
|
|
1224
|
+
noClassNames: false,
|
|
1225
|
+
focus: false,
|
|
1226
|
+
hover: false,
|
|
1227
|
+
unmounted: false,
|
|
1228
|
+
// TODO match logic in createComponent
|
|
1229
|
+
press: false,
|
|
1230
|
+
pressIn: false
|
|
1231
|
+
};
|
|
1232
|
+
let foundStaticProps = {};
|
|
1233
|
+
for (const key in attrs) {
|
|
1234
|
+
const cur = attrs[key];
|
|
1235
|
+
if (cur.type === "style") {
|
|
1236
|
+
foundStaticProps = {
|
|
1237
|
+
...foundStaticProps,
|
|
1238
|
+
...expandStylesWithoutVariants2(cur.value)
|
|
1239
|
+
};
|
|
1240
|
+
continue;
|
|
1241
|
+
}
|
|
1242
|
+
if (cur.type === "attr") {
|
|
1243
|
+
if (t.isJSXSpreadAttribute(cur.value)) {
|
|
1244
|
+
continue;
|
|
1245
|
+
}
|
|
1246
|
+
if (!t.isJSXIdentifier(cur.value.name)) {
|
|
1247
|
+
continue;
|
|
1248
|
+
}
|
|
1249
|
+
const key2 = cur.value.name.name;
|
|
1250
|
+
const value = attemptEvalSafe(cur.value.value || t.booleanLiteral(true));
|
|
1251
|
+
if (value !== FAILED_EVAL) {
|
|
1252
|
+
foundStaticProps = {
|
|
1253
|
+
...foundStaticProps,
|
|
1254
|
+
[key2]: value
|
|
1255
|
+
};
|
|
1256
|
+
}
|
|
1257
|
+
}
|
|
1258
|
+
}
|
|
1259
|
+
const completeProps = {};
|
|
1260
|
+
for (const key in staticConfig.defaultProps) {
|
|
1261
|
+
if (!(key in foundStaticProps)) {
|
|
1262
|
+
completeProps[key] = staticConfig.defaultProps[key];
|
|
1263
|
+
}
|
|
1264
|
+
}
|
|
1265
|
+
for (const key in foundStaticProps) {
|
|
1266
|
+
completeProps[key] = foundStaticProps[key];
|
|
1267
|
+
}
|
|
1268
|
+
attrs = attrs.reduce((acc, cur) => {
|
|
1269
|
+
if (!cur)
|
|
1270
|
+
return acc;
|
|
1271
|
+
if (cur.type === "attr" && !t.isJSXSpreadAttribute(cur.value)) {
|
|
1272
|
+
if (shouldFlatten) {
|
|
1273
|
+
const name = cur.value.name.name;
|
|
1274
|
+
if (typeof name === "string") {
|
|
1275
|
+
if (name === "tag") {
|
|
1276
|
+
return acc;
|
|
1277
|
+
}
|
|
1278
|
+
if (variants[name] && variantValues.has(name)) {
|
|
1279
|
+
let out = Object.fromEntries(
|
|
1280
|
+
staticConfig.propMapper(
|
|
1281
|
+
name,
|
|
1282
|
+
variantValues.get(name),
|
|
1283
|
+
defaultTheme,
|
|
1284
|
+
completeProps,
|
|
1285
|
+
{ ...state, resolveVariablesAs: "auto" },
|
|
1286
|
+
void 0,
|
|
1287
|
+
void 0,
|
|
1288
|
+
shouldPrintDebug
|
|
1289
|
+
) || []
|
|
1290
|
+
);
|
|
1291
|
+
if (out && isTargetingHTML) {
|
|
1292
|
+
const cn = out.className;
|
|
1293
|
+
out = createDOMProps(isTextView ? "span" : "div", out);
|
|
1294
|
+
out.className = cn;
|
|
1295
|
+
}
|
|
1296
|
+
if (shouldPrintDebug) {
|
|
1297
|
+
logger.info([" - expanded variant", name, out].join(" "));
|
|
1298
|
+
}
|
|
1299
|
+
for (const key2 in out) {
|
|
1300
|
+
const value2 = out[key2];
|
|
1301
|
+
if (isValidStyleKey(key2, staticConfig)) {
|
|
1302
|
+
acc.push({
|
|
1303
|
+
type: "style",
|
|
1304
|
+
value: { [key2]: value2 },
|
|
1305
|
+
name: key2,
|
|
1306
|
+
attr: cur.value
|
|
1307
|
+
});
|
|
1308
|
+
} else {
|
|
1309
|
+
acc.push({
|
|
1310
|
+
type: "attr",
|
|
1311
|
+
value: t.jsxAttribute(
|
|
1312
|
+
t.jsxIdentifier(key2),
|
|
1313
|
+
t.jsxExpressionContainer(
|
|
1314
|
+
typeof value2 === "string" ? t.stringLiteral(value2) : literalToAst(value2)
|
|
1315
|
+
)
|
|
1316
|
+
)
|
|
1317
|
+
});
|
|
1318
|
+
}
|
|
1319
|
+
}
|
|
1320
|
+
}
|
|
1321
|
+
}
|
|
1322
|
+
}
|
|
1323
|
+
}
|
|
1324
|
+
if (cur.type !== "style") {
|
|
1325
|
+
acc.push(cur);
|
|
1326
|
+
return acc;
|
|
1327
|
+
}
|
|
1328
|
+
let key = Object.keys(cur.value)[0];
|
|
1329
|
+
const value = cur.value[key];
|
|
1330
|
+
const fullKey = tamaguiConfig.shorthands[key];
|
|
1331
|
+
if (fullKey) {
|
|
1332
|
+
cur.value = { [fullKey]: value };
|
|
1333
|
+
key = fullKey;
|
|
1334
|
+
}
|
|
1335
|
+
if (disableExtractVariables) {
|
|
1336
|
+
if (value[0] === "$" && (usedThemeKeys.has(key) || usedThemeKeys.has(fullKey))) {
|
|
1337
|
+
if (shouldPrintDebug) {
|
|
1338
|
+
logger.info([` keeping variable inline: ${key} =`, value].join(" "));
|
|
1339
|
+
}
|
|
1340
|
+
acc.push({
|
|
1341
|
+
type: "attr",
|
|
1342
|
+
value: t.jsxAttribute(
|
|
1343
|
+
t.jsxIdentifier(key),
|
|
1344
|
+
t.jsxExpressionContainer(t.stringLiteral(value))
|
|
1345
|
+
)
|
|
1346
|
+
});
|
|
1347
|
+
return acc;
|
|
1348
|
+
}
|
|
1349
|
+
}
|
|
1350
|
+
acc.push(cur);
|
|
1351
|
+
return acc;
|
|
1352
|
+
}, []);
|
|
1353
|
+
tm.mark("jsx-element-expanded", !!shouldPrintDebug);
|
|
1354
|
+
if (shouldPrintDebug) {
|
|
1355
|
+
logger.info(
|
|
1356
|
+
[" - attrs (expanded): \n", logLines(attrs.map(attrStr).join(", "))].join(
|
|
1357
|
+
" "
|
|
1358
|
+
)
|
|
1359
|
+
);
|
|
1360
|
+
}
|
|
1361
|
+
let prev = null;
|
|
1362
|
+
attrs = attrs.reduce((acc, cur) => {
|
|
1363
|
+
if (cur.type === "style") {
|
|
1364
|
+
const key = Object.keys(cur.value)[0];
|
|
1365
|
+
const value = cur.value[key];
|
|
1366
|
+
const shouldKeepOriginalAttr = (
|
|
1367
|
+
// !isStyleAndAttr[key] &&
|
|
1368
|
+
!shouldFlatten && // de-opt if non-style
|
|
1369
|
+
!validStyles[key] && !pseudoDescriptors[key] && !(key.startsWith("data-") || key.startsWith("aria-"))
|
|
1370
|
+
);
|
|
1371
|
+
if (shouldKeepOriginalAttr) {
|
|
1372
|
+
if (shouldPrintDebug) {
|
|
1373
|
+
logger.info([" - keeping as non-style", key].join(" "));
|
|
1374
|
+
}
|
|
1375
|
+
prev = cur;
|
|
1376
|
+
acc.push({
|
|
1377
|
+
type: "attr",
|
|
1378
|
+
value: t.jsxAttribute(
|
|
1379
|
+
t.jsxIdentifier(key),
|
|
1380
|
+
t.jsxExpressionContainer(
|
|
1381
|
+
typeof value === "string" ? t.stringLiteral(value) : literalToAst(value)
|
|
1382
|
+
)
|
|
1383
|
+
)
|
|
1384
|
+
});
|
|
1385
|
+
acc.push(cur);
|
|
1386
|
+
return acc;
|
|
1387
|
+
}
|
|
1388
|
+
if ((prev == null ? void 0 : prev.type) === "style") {
|
|
1389
|
+
mergeStyles2(prev.value, cur.value);
|
|
1390
|
+
return acc;
|
|
1391
|
+
}
|
|
1392
|
+
}
|
|
1393
|
+
prev = cur;
|
|
1394
|
+
acc.push(cur);
|
|
1395
|
+
return acc;
|
|
1396
|
+
}, []);
|
|
1397
|
+
if (shouldPrintDebug) {
|
|
1398
|
+
logger.info(
|
|
1399
|
+
[
|
|
1400
|
+
" - attrs (combined \u{1F500}): \n",
|
|
1401
|
+
logLines(attrs.map(attrStr).join(", "))
|
|
1402
|
+
].join(" ")
|
|
1403
|
+
);
|
|
1404
|
+
logger.info(
|
|
1405
|
+
[
|
|
1406
|
+
" - defaultProps: \n",
|
|
1407
|
+
logLines(objToStr(staticConfig.defaultProps))
|
|
1408
|
+
].join(" ")
|
|
1409
|
+
);
|
|
1410
|
+
logger.info([" - foundStaticProps: \n", logLines(objToStr(foundStaticProps))].join(" "));
|
|
1411
|
+
logger.info(
|
|
1412
|
+
[" - completeProps: \n", logLines(objToStr(completeProps))].join(" ")
|
|
1413
|
+
);
|
|
1414
|
+
}
|
|
1415
|
+
const getStyles = (props, debugName = "") => {
|
|
1416
|
+
if (!props || !Object.keys(props).length) {
|
|
1417
|
+
if (shouldPrintDebug)
|
|
1418
|
+
logger.info([" getStyles() no props"].join(" "));
|
|
1419
|
+
return {};
|
|
1420
|
+
}
|
|
1421
|
+
if (excludeProps && !!excludeProps.size) {
|
|
1422
|
+
for (const key in props) {
|
|
1423
|
+
if (excludeProps.has(key)) {
|
|
1424
|
+
if (shouldPrintDebug)
|
|
1425
|
+
logger.info([" delete excluded", key].join(" "));
|
|
1426
|
+
delete props[key];
|
|
1427
|
+
}
|
|
1428
|
+
}
|
|
1429
|
+
}
|
|
1430
|
+
try {
|
|
1431
|
+
const out = getSplitStyles(
|
|
1432
|
+
props,
|
|
1433
|
+
staticConfig,
|
|
1434
|
+
defaultTheme,
|
|
1435
|
+
{
|
|
1436
|
+
...state,
|
|
1437
|
+
fallbackProps: completeProps
|
|
1438
|
+
},
|
|
1439
|
+
void 0,
|
|
1440
|
+
void 0,
|
|
1441
|
+
void 0,
|
|
1442
|
+
debugPropValue
|
|
1443
|
+
);
|
|
1444
|
+
const outStyle = {
|
|
1445
|
+
...out.style,
|
|
1446
|
+
...out.pseudos
|
|
1447
|
+
};
|
|
1448
|
+
if (shouldPrintDebug === "verbose") {
|
|
1449
|
+
logger.info(` getStyles ${debugName} (props in): ${Object.keys(props)}`);
|
|
1450
|
+
logger.info(` getStyles ${debugName} (outStyle): ${Object.keys(outStyle)}`);
|
|
1451
|
+
}
|
|
1452
|
+
return outStyle;
|
|
1453
|
+
} catch (err) {
|
|
1454
|
+
logger.info(["error", err.message, err.stack].join(" "));
|
|
1455
|
+
return {};
|
|
1456
|
+
}
|
|
1457
|
+
};
|
|
1458
|
+
const completeStyles = getStyles(completeProps, "completeStyles");
|
|
1459
|
+
if (!completeStyles) {
|
|
1460
|
+
throw new Error(`Impossible, no styles`);
|
|
1461
|
+
}
|
|
1462
|
+
let getStyleError = null;
|
|
1463
|
+
for (const attr of attrs) {
|
|
1464
|
+
try {
|
|
1465
|
+
switch (attr.type) {
|
|
1466
|
+
case "ternary": {
|
|
1467
|
+
const a = getStyles(attr.value.alternate, "ternary.alternate");
|
|
1468
|
+
const c = getStyles(attr.value.consequent, "ternary.consequent");
|
|
1469
|
+
if (a)
|
|
1470
|
+
attr.value.alternate = a;
|
|
1471
|
+
if (c)
|
|
1472
|
+
attr.value.consequent = c;
|
|
1473
|
+
if (shouldPrintDebug)
|
|
1474
|
+
logger.info([" => tern ", attrStr(attr)].join(" "));
|
|
1475
|
+
continue;
|
|
1476
|
+
}
|
|
1477
|
+
case "style": {
|
|
1478
|
+
const styles = getStyles(attr.value, "style");
|
|
1479
|
+
if (styles) {
|
|
1480
|
+
attr.value = styles;
|
|
1481
|
+
}
|
|
1482
|
+
if (shouldPrintDebug)
|
|
1483
|
+
logger.info([" * styles (in)", logLines(objToStr(attr.value))].join(" "));
|
|
1484
|
+
if (shouldPrintDebug)
|
|
1485
|
+
logger.info([" * styles (out)", logLines(objToStr(styles))].join(" "));
|
|
1486
|
+
continue;
|
|
1487
|
+
}
|
|
1488
|
+
}
|
|
1489
|
+
} catch (err) {
|
|
1490
|
+
getStyleError = err;
|
|
1491
|
+
}
|
|
1492
|
+
}
|
|
1493
|
+
if (shouldPrintDebug) {
|
|
1494
|
+
logger.info([" - attrs (ternaries/combined):\n", logLines(attrs.map(attrStr).join(", "))].join(" "));
|
|
1495
|
+
}
|
|
1496
|
+
tm.mark("jsx-element-styles", !!shouldPrintDebug);
|
|
1497
|
+
if (getStyleError) {
|
|
1498
|
+
logger.info([" \u26A0\uFE0F postprocessing error, deopt", getStyleError].join(" "));
|
|
1499
|
+
node.attributes = ogAttributes;
|
|
1500
|
+
return null;
|
|
1501
|
+
}
|
|
1502
|
+
const existingStyleKeys = /* @__PURE__ */ new Set();
|
|
1503
|
+
for (let i = attrs.length - 1; i >= 0; i--) {
|
|
1504
|
+
const attr = attrs[i];
|
|
1505
|
+
if (shouldFlatten) {
|
|
1506
|
+
if (attr.type === "attr") {
|
|
1507
|
+
if (t.isJSXAttribute(attr.value)) {
|
|
1508
|
+
if (t.isJSXIdentifier(attr.value.name)) {
|
|
1509
|
+
const name = attr.value.name.name;
|
|
1510
|
+
if (INLINE_EXTRACTABLE[name]) {
|
|
1511
|
+
attr.value.name.name = INLINE_EXTRACTABLE[name];
|
|
1512
|
+
}
|
|
1513
|
+
}
|
|
1514
|
+
}
|
|
1515
|
+
}
|
|
1516
|
+
}
|
|
1517
|
+
if (attr.type === "style") {
|
|
1518
|
+
for (const key in attr.value) {
|
|
1519
|
+
if (existingStyleKeys.has(key)) {
|
|
1520
|
+
if (shouldPrintDebug) {
|
|
1521
|
+
logger.info([` >> delete existing ${key}`].join(" "));
|
|
1522
|
+
}
|
|
1523
|
+
delete attr.value[key];
|
|
1524
|
+
} else {
|
|
1525
|
+
existingStyleKeys.add(key);
|
|
1526
|
+
}
|
|
1527
|
+
}
|
|
1528
|
+
}
|
|
1529
|
+
}
|
|
1530
|
+
if (!shouldFlatten) {
|
|
1531
|
+
if (inlineWhenUnflattened.size) {
|
|
1532
|
+
for (const [index, attr] of attrs.entries()) {
|
|
1533
|
+
if (attr.type === "style") {
|
|
1534
|
+
for (const key in attr.value) {
|
|
1535
|
+
if (!inlineWhenUnflattened.has(key))
|
|
1536
|
+
continue;
|
|
1537
|
+
const val = inlineWhenUnflattenedOGVals[key];
|
|
1538
|
+
if (val) {
|
|
1539
|
+
delete attr.value[key];
|
|
1540
|
+
attrs.splice(index - 1, 0, val.attr);
|
|
1541
|
+
} else {
|
|
1542
|
+
delete attr.value[key];
|
|
1543
|
+
}
|
|
1544
|
+
}
|
|
1545
|
+
}
|
|
1546
|
+
}
|
|
1547
|
+
}
|
|
1548
|
+
}
|
|
1549
|
+
if (shouldFlatten) {
|
|
1550
|
+
if (shouldPrintDebug) {
|
|
1551
|
+
logger.info([" [\u2705] flattening", originalNodeName, flatNode].join(" "));
|
|
1552
|
+
}
|
|
1553
|
+
node.name.name = flatNode;
|
|
1554
|
+
res.flattened++;
|
|
1555
|
+
if (closingElement) {
|
|
1556
|
+
closingElement.name.name = flatNode;
|
|
1557
|
+
}
|
|
1558
|
+
}
|
|
1559
|
+
const isNativeNotFlat = !shouldFlatten && target === "native";
|
|
1560
|
+
if (isNativeNotFlat) {
|
|
1561
|
+
if (shouldPrintDebug) {
|
|
1562
|
+
logger.info(`Disabled flattening except for simple cases on native for now`);
|
|
1563
|
+
}
|
|
1564
|
+
node.attributes = ogAttributes;
|
|
1565
|
+
return null;
|
|
1566
|
+
}
|
|
1567
|
+
if (shouldPrintDebug) {
|
|
1568
|
+
logger.info([` - inlined props (${inlined.size}):`, shouldDeopt ? " deopted" : "", hasSpread ? " has spread" : "", staticConfig.neverFlatten ? "neverFlatten" : ""].join(" "));
|
|
1569
|
+
logger.info(` - shouldFlatten/isFlattened: ${shouldFlatten}`);
|
|
1570
|
+
logger.info(` - attrs (end):
|
|
1571
|
+
${logLines(attrs.map(attrStr).join(", "))}`);
|
|
1572
|
+
}
|
|
1573
|
+
onExtractTag({
|
|
1574
|
+
parserProps: propsWithFileInfo,
|
|
1575
|
+
attrs,
|
|
1576
|
+
node,
|
|
1577
|
+
lineNumbers,
|
|
1578
|
+
filePath,
|
|
1579
|
+
attemptEval,
|
|
1580
|
+
jsxPath: traversePath,
|
|
1581
|
+
originalNodeName,
|
|
1582
|
+
isFlattened: shouldFlatten,
|
|
1583
|
+
programPath,
|
|
1584
|
+
completeProps,
|
|
1585
|
+
staticConfig
|
|
1586
|
+
});
|
|
1587
|
+
} catch (err) {
|
|
1588
|
+
node.attributes = ogAttributes;
|
|
1589
|
+
console.error(`err: ${err}`);
|
|
1590
|
+
} finally {
|
|
1591
|
+
if (debugPropValue) {
|
|
1592
|
+
shouldPrintDebug = ogDebug;
|
|
1593
|
+
}
|
|
1594
|
+
}
|
|
1595
|
+
}
|
|
1596
|
+
});
|
|
1597
|
+
tm.mark("jsx-done", !!shouldPrintDebug);
|
|
1598
|
+
if (modifiedComponents.size) {
|
|
1599
|
+
const all = Array.from(modifiedComponents);
|
|
1600
|
+
if (shouldPrintDebug) {
|
|
1601
|
+
logger.info(` [\u{1FA9D}] hook check ${all.length}`);
|
|
1602
|
+
}
|
|
1603
|
+
for (const comp of all) {
|
|
1604
|
+
removeUnusedHooks(comp, shouldPrintDebug);
|
|
1605
|
+
}
|
|
1606
|
+
}
|
|
1607
|
+
tm.done(shouldPrintDebug === "verbose");
|
|
1608
|
+
return res;
|
|
1609
|
+
}
|
|
1610
|
+
}
|
|
1611
|
+
export {
|
|
1612
|
+
createExtractor
|
|
1613
|
+
};
|
|
16
1614
|
//# sourceMappingURL=createExtractor.mjs.map
|