@tamagui/static 2.0.0-rc.8 → 2.0.0
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/check-dep-versions.cjs +201 -96
- package/dist/checkDeps.cjs +250 -46
- package/dist/constants.cjs +32 -30
- package/dist/exports.cjs +20 -13
- package/dist/extractor/accessSafe.cjs +25 -23
- package/dist/extractor/babelParse.cjs +30 -28
- package/dist/extractor/buildClassName.cjs +59 -35
- package/dist/extractor/bundle.cjs +187 -101
- package/dist/extractor/bundleConfig.cjs +568 -168
- package/dist/extractor/concatClassName.cjs +73 -32
- package/dist/extractor/createEvaluator.cjs +54 -41
- package/dist/extractor/createExtractor.cjs +1405 -574
- package/dist/extractor/createLogger.cjs +30 -25
- package/dist/extractor/detectModuleFormat.cjs +55 -0
- package/dist/extractor/ensureImportingConcat.cjs +31 -25
- package/dist/extractor/errors.cjs +12 -10
- package/dist/extractor/esbuildAliasPlugin.cjs +28 -16
- package/dist/extractor/esbuildTsconfigPaths.cjs +60 -36
- package/dist/extractor/evaluateAstNode.cjs +104 -59
- package/dist/extractor/extractHelpers.cjs +130 -67
- package/dist/extractor/extractMediaStyle.cjs +110 -69
- package/dist/extractor/extractToClassNames.cjs +337 -229
- package/dist/extractor/extractToNative.cjs +248 -154
- package/dist/extractor/findTopmostFunction.cjs +22 -13
- package/dist/extractor/generatedUid.cjs +39 -28
- package/dist/extractor/getPrefixLogs.cjs +12 -10
- package/dist/extractor/getPropValueFromAttributes.cjs +52 -34
- package/dist/extractor/getSourceModule.cjs +73 -37
- package/dist/extractor/getStaticBindingsForScope.cjs +131 -68
- package/dist/extractor/getTamaguiConfigPathFromOptionsConfig.cjs +20 -14
- package/dist/extractor/hasTopLevelAwait.cjs +62 -0
- package/dist/extractor/hoistClassNames.cjs +46 -32
- package/dist/extractor/literalToAst.cjs +67 -42
- package/dist/extractor/loadFile.cjs +9 -3
- package/dist/extractor/loadTamagui.cjs +151 -105
- package/dist/extractor/logLines.cjs +27 -19
- package/dist/extractor/normalizeTernaries.cjs +66 -44
- package/dist/extractor/propsToFontFamilyCache.cjs +15 -11
- package/dist/extractor/regenerateConfig.cjs +109 -81
- package/dist/extractor/removeUnusedHooks.cjs +73 -41
- package/dist/extractor/timer.cjs +23 -14
- package/dist/extractor/validHTMLAttributes.cjs +61 -59
- package/dist/extractor/watchTamaguiConfig.cjs +35 -23
- package/dist/getPragmaOptions.cjs +34 -19
- package/dist/helpers/memoize.cjs +24 -16
- package/dist/helpers/requireTamaguiCore.cjs +22 -15
- package/dist/index.cjs +26 -24
- package/dist/registerRequire.cjs +168 -65
- package/dist/server.cjs +35 -28
- package/dist/types.cjs +7 -5
- package/dist/worker.cjs +62 -40
- package/package.json +27 -24
- package/src/checkDeps.ts +305 -68
- package/src/exports.ts +2 -0
- package/src/extractor/babelParse.ts +1 -0
- package/src/extractor/bundle.ts +172 -40
- package/src/extractor/bundleConfig.ts +459 -65
- package/src/extractor/concatClassName.ts +37 -20
- package/src/extractor/createExtractor.ts +300 -30
- package/src/extractor/detectModuleFormat.ts +42 -0
- package/src/extractor/esbuildTsconfigPaths.ts +6 -1
- package/src/extractor/extractToClassNames.ts +15 -9
- package/src/extractor/extractToNative.ts +66 -33
- package/src/extractor/hasTopLevelAwait.ts +28 -0
- package/src/extractor/loadTamagui.ts +5 -4
- package/src/registerRequire.ts +102 -9
- package/types/checkDeps.d.ts.map +1 -1
- package/types/exports.d.ts +2 -0
- package/types/exports.d.ts.map +1 -1
- package/types/extractor/babelParse.d.ts.map +1 -1
- package/types/extractor/bundle.d.ts +83 -1
- package/types/extractor/bundle.d.ts.map +1 -1
- package/types/extractor/bundleConfig.d.ts +15 -2
- package/types/extractor/bundleConfig.d.ts.map +1 -1
- package/types/extractor/createExtractor.d.ts.map +1 -1
- package/types/extractor/detectModuleFormat.d.ts +5 -0
- package/types/extractor/detectModuleFormat.d.ts.map +1 -0
- package/types/extractor/esbuildTsconfigPaths.d.ts +8 -0
- package/types/extractor/esbuildTsconfigPaths.d.ts.map +1 -1
- package/types/extractor/extractToClassNames.d.ts.map +1 -1
- package/types/extractor/extractToNative.d.ts.map +1 -1
- package/types/extractor/hasTopLevelAwait.d.ts +2 -0
- package/types/extractor/hasTopLevelAwait.d.ts.map +1 -0
- package/types/extractor/loadTamagui.d.ts +1 -1
- package/types/extractor/loadTamagui.d.ts.map +1 -1
- package/types/registerRequire.d.ts.map +1 -1
- package/dist/check-dep-versions.js +0 -389
- package/dist/check-dep-versions.js.map +0 -6
- package/dist/checkDeps.js +0 -60
- package/dist/checkDeps.js.map +0 -6
- package/dist/constants.js +0 -34
- package/dist/constants.js.map +0 -6
- package/dist/exports.js +0 -34
- package/dist/exports.js.map +0 -6
- package/dist/extractor/accessSafe.js +0 -47
- package/dist/extractor/accessSafe.js.map +0 -6
- package/dist/extractor/babelParse.js +0 -59
- package/dist/extractor/babelParse.js.map +0 -6
- package/dist/extractor/buildClassName.js +0 -72
- package/dist/extractor/buildClassName.js.map +0 -6
- package/dist/extractor/bundle.js +0 -135
- package/dist/extractor/bundle.js.map +0 -6
- package/dist/extractor/bundleConfig.js +0 -352
- package/dist/extractor/bundleConfig.js.map +0 -6
- package/dist/extractor/concatClassName.js +0 -69
- package/dist/extractor/concatClassName.js.map +0 -6
- package/dist/extractor/createEvaluator.js +0 -66
- package/dist/extractor/createEvaluator.js.map +0 -6
- package/dist/extractor/createExtractor.js +0 -1212
- package/dist/extractor/createExtractor.js.map +0 -6
- package/dist/extractor/createLogger.js +0 -32
- package/dist/extractor/createLogger.js.map +0 -6
- package/dist/extractor/ensureImportingConcat.js +0 -50
- package/dist/extractor/ensureImportingConcat.js.map +0 -6
- package/dist/extractor/errors.js +0 -22
- package/dist/extractor/errors.js.map +0 -6
- package/dist/extractor/esbuildAliasPlugin.js +0 -36
- package/dist/extractor/esbuildAliasPlugin.js.map +0 -6
- package/dist/extractor/esbuildTsconfigPaths.js +0 -79
- package/dist/extractor/esbuildTsconfigPaths.js.map +0 -6
- package/dist/extractor/evaluateAstNode.js +0 -99
- package/dist/extractor/evaluateAstNode.js.map +0 -6
- package/dist/extractor/extractHelpers.js +0 -108
- package/dist/extractor/extractHelpers.js.map +0 -6
- package/dist/extractor/extractMediaStyle.js +0 -123
- package/dist/extractor/extractMediaStyle.js.map +0 -6
- package/dist/extractor/extractToClassNames.js +0 -351
- package/dist/extractor/extractToClassNames.js.map +0 -6
- package/dist/extractor/extractToNative.js +0 -286
- package/dist/extractor/extractToNative.js.map +0 -6
- package/dist/extractor/findTopmostFunction.js +0 -32
- package/dist/extractor/findTopmostFunction.js.map +0 -6
- package/dist/extractor/generatedUid.js +0 -42
- package/dist/extractor/generatedUid.js.map +0 -6
- package/dist/extractor/getPrefixLogs.js +0 -24
- package/dist/extractor/getPrefixLogs.js.map +0 -6
- package/dist/extractor/getPropValueFromAttributes.js +0 -65
- package/dist/extractor/getPropValueFromAttributes.js.map +0 -6
- package/dist/extractor/getSourceModule.js +0 -62
- package/dist/extractor/getSourceModule.js.map +0 -6
- package/dist/extractor/getStaticBindingsForScope.js +0 -145
- package/dist/extractor/getStaticBindingsForScope.js.map +0 -6
- package/dist/extractor/getTamaguiConfigPathFromOptionsConfig.js +0 -32
- package/dist/extractor/getTamaguiConfigPathFromOptionsConfig.js.map +0 -6
- package/dist/extractor/hoistClassNames.js +0 -63
- package/dist/extractor/hoistClassNames.js.map +0 -6
- package/dist/extractor/literalToAst.js +0 -90
- package/dist/extractor/literalToAst.js.map +0 -6
- package/dist/extractor/loadFile.js +0 -14
- package/dist/extractor/loadFile.js.map +0 -6
- package/dist/extractor/loadTamagui.js +0 -306
- package/dist/extractor/loadTamagui.js.map +0 -6
- package/dist/extractor/logLines.js +0 -30
- package/dist/extractor/logLines.js.map +0 -6
- package/dist/extractor/normalizeTernaries.js +0 -61
- package/dist/extractor/normalizeTernaries.js.map +0 -6
- package/dist/extractor/propsToFontFamilyCache.js +0 -33
- package/dist/extractor/propsToFontFamilyCache.js.map +0 -6
- package/dist/extractor/regenerateConfig.js +0 -123
- package/dist/extractor/regenerateConfig.js.map +0 -6
- package/dist/extractor/removeUnusedHooks.js +0 -72
- package/dist/extractor/removeUnusedHooks.js.map +0 -6
- package/dist/extractor/timer.js +0 -38
- package/dist/extractor/timer.js.map +0 -6
- package/dist/extractor/validHTMLAttributes.js +0 -72
- package/dist/extractor/validHTMLAttributes.js.map +0 -6
- package/dist/extractor/watchTamaguiConfig.js +0 -57
- package/dist/extractor/watchTamaguiConfig.js.map +0 -6
- package/dist/getPragmaOptions.js +0 -50
- package/dist/getPragmaOptions.js.map +0 -6
- package/dist/helpers/memoize.js +0 -33
- package/dist/helpers/memoize.js.map +0 -6
- package/dist/helpers/requireTamaguiCore.js +0 -30
- package/dist/helpers/requireTamaguiCore.js.map +0 -6
- package/dist/index.js +0 -30
- package/dist/index.js.map +0 -6
- package/dist/registerRequire.js +0 -100
- package/dist/registerRequire.js.map +0 -6
- package/dist/server.js +0 -58
- package/dist/server.js.map +0 -6
- package/dist/setup.js +0 -1
- package/dist/setup.js.map +0 -6
- package/dist/types.js +0 -14
- package/dist/types.js.map +0 -6
- package/dist/worker.js +0 -72
- package/dist/worker.js.map +0 -6
|
@@ -2,66 +2,72 @@ var __create = Object.create;
|
|
|
2
2
|
var __defProp = Object.defineProperty;
|
|
3
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __getProtoOf = Object.getPrototypeOf
|
|
6
|
-
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
7
|
var __export = (target, all) => {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
8
|
+
for (var name in all) __defProp(target, name, {
|
|
9
|
+
get: all[name],
|
|
10
|
+
enumerable: true
|
|
11
|
+
});
|
|
12
|
+
};
|
|
13
|
+
var __copyProps = (to, from, except, desc) => {
|
|
14
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
15
|
+
for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
15
16
|
get: () => from[key],
|
|
16
17
|
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
17
18
|
});
|
|
18
|
-
|
|
19
|
-
|
|
19
|
+
}
|
|
20
|
+
return to;
|
|
21
|
+
};
|
|
20
22
|
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
23
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
24
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
25
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
26
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
27
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
28
|
+
value: mod,
|
|
29
|
+
enumerable: true
|
|
30
|
+
}) : target, mod));
|
|
31
|
+
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
32
|
+
value: true
|
|
33
|
+
}), mod);
|
|
32
34
|
var createExtractor_exports = {};
|
|
33
35
|
__export(createExtractor_exports, {
|
|
34
36
|
createExtractor: () => createExtractor
|
|
35
37
|
});
|
|
36
38
|
module.exports = __toCommonJS(createExtractor_exports);
|
|
37
|
-
var import_traverse = __toESM(require("@babel/traverse"))
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
39
|
+
var import_traverse = __toESM(require("@babel/traverse"));
|
|
40
|
+
var t = __toESM(require("@babel/types"));
|
|
41
|
+
var import_cli_color = require("@tamagui/cli-color");
|
|
42
|
+
var reactNativeWebInternals = __toESM(require("@tamagui/react-native-web-internals"));
|
|
43
|
+
var import_web = require("@tamagui/web");
|
|
44
|
+
var import_node_fs = require("node:fs");
|
|
45
|
+
var import_node_path = require("node:path");
|
|
46
|
+
var import_typescript = require("typescript");
|
|
47
|
+
var import_constants = require("../constants.cjs");
|
|
48
|
+
var import_requireTamaguiCore = require("../helpers/requireTamaguiCore.cjs");
|
|
49
|
+
var import_createEvaluator = require("./createEvaluator.cjs");
|
|
50
|
+
var import_evaluateAstNode = require("./evaluateAstNode.cjs");
|
|
51
|
+
var import_extractHelpers = require("./extractHelpers.cjs");
|
|
52
|
+
var import_findTopmostFunction = require("./findTopmostFunction.cjs");
|
|
53
|
+
var import_getStaticBindingsForScope = require("./getStaticBindingsForScope.cjs");
|
|
54
|
+
var import_literalToAst = require("./literalToAst.cjs");
|
|
55
|
+
var import_loadTamagui = require("./loadTamagui.cjs");
|
|
56
|
+
var import_logLines = require("./logLines.cjs");
|
|
57
|
+
var import_normalizeTernaries = require("./normalizeTernaries.cjs");
|
|
58
|
+
var import_propsToFontFamilyCache = require("./propsToFontFamilyCache.cjs");
|
|
59
|
+
var import_timer = require("./timer.cjs");
|
|
60
|
+
var import_validHTMLAttributes = require("./validHTMLAttributes.cjs");
|
|
61
|
+
var import_errors = require("./errors.cjs");
|
|
62
|
+
var import_esbuildTsconfigPaths = require("./esbuildTsconfigPaths.cjs");
|
|
58
63
|
const UNTOUCHED_PROPS = {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
64
|
+
key: true,
|
|
65
|
+
style: true,
|
|
66
|
+
className: true
|
|
67
|
+
};
|
|
68
|
+
const nativeOnlyPlatforms = /* @__PURE__ */new Set(["android", "ios", "tv", "androidtv", "tvos"]);
|
|
69
|
+
const createTernary = x => x;
|
|
70
|
+
let hasLoggedBaseInfo = false;
|
|
65
71
|
function isFullyDisabled(props) {
|
|
66
72
|
return props.disableExtraction && props.disableDebugAttr;
|
|
67
73
|
}
|
|
@@ -72,40 +78,124 @@ function createExtractor({
|
|
|
72
78
|
logger: console
|
|
73
79
|
}) {
|
|
74
80
|
const INLINE_EXTRACTABLE = {
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
81
|
+
ref: "ref",
|
|
82
|
+
key: "key",
|
|
83
|
+
...(platform === "web" && {
|
|
84
|
+
onPress: "onClick",
|
|
85
|
+
onHoverIn: "onMouseEnter",
|
|
86
|
+
onHoverOut: "onMouseLeave",
|
|
87
|
+
onPressIn: "onMouseDown",
|
|
88
|
+
onPressOut: "onMouseUp"
|
|
89
|
+
}),
|
|
90
|
+
...(platform === "native" && {
|
|
91
|
+
// native view props that should pass through without preventing flattening
|
|
92
|
+
testID: "testID",
|
|
93
|
+
nativeID: "nativeID",
|
|
94
|
+
accessibilityLabel: "accessibilityLabel",
|
|
95
|
+
accessibilityHint: "accessibilityHint",
|
|
96
|
+
accessibilityRole: "accessibilityRole",
|
|
97
|
+
accessibilityState: "accessibilityState",
|
|
98
|
+
accessibilityValue: "accessibilityValue",
|
|
99
|
+
accessibilityActions: "accessibilityActions",
|
|
100
|
+
accessibilityLabelledBy: "accessibilityLabelledBy",
|
|
101
|
+
accessibilityLiveRegion: "accessibilityLiveRegion",
|
|
102
|
+
accessibilityElementsHidden: "accessibilityElementsHidden",
|
|
103
|
+
accessibilityViewIsModal: "accessibilityViewIsModal",
|
|
104
|
+
importantForAccessibility: "importantForAccessibility",
|
|
105
|
+
collapsable: "collapsable",
|
|
106
|
+
needsOffscreenAlphaCompositing: "needsOffscreenAlphaCompositing",
|
|
107
|
+
removeClippedSubviews: "removeClippedSubviews",
|
|
108
|
+
renderToHardwareTextureAndroid: "renderToHardwareTextureAndroid",
|
|
109
|
+
shouldRasterizeIOS: "shouldRasterizeIOS",
|
|
110
|
+
hitSlop: "hitSlop",
|
|
111
|
+
pointerEvents: "pointerEvents"
|
|
112
|
+
})
|
|
113
|
+
};
|
|
114
|
+
const componentState = {
|
|
115
|
+
focus: false,
|
|
116
|
+
focusVisible: false,
|
|
117
|
+
focusWithin: false,
|
|
118
|
+
hover: false,
|
|
119
|
+
unmounted: true,
|
|
120
|
+
press: false,
|
|
121
|
+
pressIn: false,
|
|
122
|
+
disabled: false
|
|
123
|
+
};
|
|
124
|
+
const styleProps = {
|
|
125
|
+
resolveValues: platform === "native" ? "value" : "variable",
|
|
126
|
+
noClass: false,
|
|
127
|
+
isAnimated: false
|
|
128
|
+
};
|
|
129
|
+
const shouldAddDebugProp =
|
|
130
|
+
// really basic disable this for next.js because it messes with ssr
|
|
131
|
+
!process.env.npm_package_dependencies_next && platform !== "native" && process.env.IDENTIFY_TAGS !== "false" && (process.env.NODE_ENV === "development" || process.env.IDENTIFY_TAGS);
|
|
103
132
|
let projectInfo = null;
|
|
133
|
+
const dynamicComponentCache = /* @__PURE__ */new Map();
|
|
134
|
+
const dynamicLoadingInProgress = /* @__PURE__ */new Set();
|
|
135
|
+
let _compilerOptions = null;
|
|
136
|
+
function getCompilerOptions() {
|
|
137
|
+
if (!_compilerOptions) {
|
|
138
|
+
try {
|
|
139
|
+
_compilerOptions = (0, import_esbuildTsconfigPaths.loadCompilerOptionsFromTsconfig)();
|
|
140
|
+
} catch {
|
|
141
|
+
_compilerOptions = {};
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
return _compilerOptions;
|
|
145
|
+
}
|
|
146
|
+
function resolveImportPath(fromFile, importPath) {
|
|
147
|
+
if (importPath.startsWith(".")) {
|
|
148
|
+
const dir = (0, import_node_path.dirname)(fromFile);
|
|
149
|
+
const base = (0, import_node_path.resolve)(dir, importPath);
|
|
150
|
+
const extensions = [".tsx", ".ts", ".jsx", ".js"];
|
|
151
|
+
for (const ext of extensions) {
|
|
152
|
+
const full = base + ext;
|
|
153
|
+
if ((0, import_node_fs.existsSync)(full)) return full;
|
|
154
|
+
}
|
|
155
|
+
for (const ext of extensions) {
|
|
156
|
+
const full = (0, import_node_path.resolve)(base, `index${ext}`);
|
|
157
|
+
if ((0, import_node_fs.existsSync)(full)) return full;
|
|
158
|
+
}
|
|
159
|
+
return null;
|
|
160
|
+
}
|
|
161
|
+
const compilerOptions = getCompilerOptions();
|
|
162
|
+
if (compilerOptions.paths) {
|
|
163
|
+
try {
|
|
164
|
+
const {
|
|
165
|
+
resolvedModule
|
|
166
|
+
} = (0, import_typescript.nodeModuleNameResolver)(importPath, fromFile, compilerOptions, import_typescript.sys);
|
|
167
|
+
if (resolvedModule && !resolvedModule.resolvedFileName.endsWith(".d.ts") && !resolvedModule.isExternalLibraryImport) {
|
|
168
|
+
return resolvedModule.resolvedFileName;
|
|
169
|
+
}
|
|
170
|
+
} catch {}
|
|
171
|
+
}
|
|
172
|
+
return null;
|
|
173
|
+
}
|
|
174
|
+
const styledCheckCache = /* @__PURE__ */new Map();
|
|
175
|
+
function mightHaveStyledComponents(filePath) {
|
|
176
|
+
const cached = styledCheckCache.get(filePath);
|
|
177
|
+
if (cached !== void 0) return cached;
|
|
178
|
+
try {
|
|
179
|
+
const content = (0, import_node_fs.readFileSync)(filePath, "utf-8");
|
|
180
|
+
const result = content.includes("styled(");
|
|
181
|
+
styledCheckCache.set(filePath, result);
|
|
182
|
+
return result;
|
|
183
|
+
} catch {
|
|
184
|
+
styledCheckCache.set(filePath, false);
|
|
185
|
+
return false;
|
|
186
|
+
}
|
|
187
|
+
}
|
|
104
188
|
function loadSync(props) {
|
|
105
|
-
|
|
189
|
+
if (isFullyDisabled(props)) {
|
|
190
|
+
return null;
|
|
191
|
+
}
|
|
192
|
+
return projectInfo ||= (0, import_loadTamagui.loadTamaguiSync)(props);
|
|
106
193
|
}
|
|
107
194
|
async function load(props) {
|
|
108
|
-
|
|
195
|
+
if (isFullyDisabled(props)) {
|
|
196
|
+
return null;
|
|
197
|
+
}
|
|
198
|
+
return projectInfo ||= await (0, import_loadTamagui.loadTamagui)(props);
|
|
109
199
|
}
|
|
110
200
|
return {
|
|
111
201
|
options: {
|
|
@@ -135,7 +225,7 @@ function createExtractor({
|
|
|
135
225
|
const {
|
|
136
226
|
config = "tamagui.config.ts",
|
|
137
227
|
importsWhitelist = ["constants.js"],
|
|
138
|
-
evaluateVars =
|
|
228
|
+
evaluateVars = true,
|
|
139
229
|
sourcePath = "",
|
|
140
230
|
onExtractTag,
|
|
141
231
|
onStyledDefinitionRule,
|
|
@@ -144,15 +234,21 @@ function createExtractor({
|
|
|
144
234
|
disableExtraction,
|
|
145
235
|
disableExtractVariables,
|
|
146
236
|
disableDebugAttr,
|
|
147
|
-
enableDynamicEvaluation =
|
|
237
|
+
enableDynamicEvaluation = false,
|
|
148
238
|
includeExtensions = [".ts", ".tsx", ".jsx"],
|
|
149
|
-
extractStyledDefinitions =
|
|
239
|
+
extractStyledDefinitions = false,
|
|
150
240
|
prefixLogs,
|
|
151
241
|
excludeProps,
|
|
152
242
|
platform: platform2,
|
|
153
243
|
...restProps
|
|
154
244
|
} = options;
|
|
155
|
-
if (sourcePath.
|
|
245
|
+
if (sourcePath && dynamicComponentCache.has(sourcePath)) {
|
|
246
|
+
dynamicComponentCache.delete(sourcePath);
|
|
247
|
+
styledCheckCache.delete(sourcePath);
|
|
248
|
+
}
|
|
249
|
+
if (sourcePath.includes(".tamagui-dynamic-eval")) {
|
|
250
|
+
return null;
|
|
251
|
+
}
|
|
156
252
|
const {
|
|
157
253
|
normalizeStyle,
|
|
158
254
|
getSplitStyles,
|
|
@@ -162,31 +258,62 @@ function createExtractor({
|
|
|
162
258
|
getDefaultProps,
|
|
163
259
|
pseudoDescriptors
|
|
164
260
|
} = (0, import_requireTamaguiCore.requireTamaguiCore)(platform2);
|
|
165
|
-
let shouldPrintDebug = options.shouldPrintDebug ||
|
|
166
|
-
if (disable ===
|
|
167
|
-
|
|
168
|
-
|
|
261
|
+
let shouldPrintDebug = options.shouldPrintDebug || false;
|
|
262
|
+
if (disable === true || Array.isArray(disable) && disable.includes(sourcePath)) {
|
|
263
|
+
return null;
|
|
264
|
+
}
|
|
265
|
+
if (!isFullyDisabled(options)) {
|
|
266
|
+
if (!components) {
|
|
267
|
+
throw new Error(`Must provide components`);
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
if (sourcePath && includeExtensions && !includeExtensions.some(ext => sourcePath.endsWith(ext))) {
|
|
271
|
+
if (shouldPrintDebug) {
|
|
272
|
+
logger.info(`Ignoring file due to includeExtensions: ${sourcePath}, includeExtensions: ${includeExtensions.join(", ")}`);
|
|
273
|
+
}
|
|
274
|
+
return null;
|
|
275
|
+
}
|
|
169
276
|
function isValidStyleKey(name, staticConfig) {
|
|
170
|
-
if (!projectInfo)
|
|
171
|
-
|
|
277
|
+
if (!projectInfo) {
|
|
278
|
+
throw new Error(`Tamagui extractor not loaded yet`);
|
|
279
|
+
}
|
|
280
|
+
if (platform2 === "native" && name[0] === "$" && mediaQueryConfig[name.slice(1)]) {
|
|
281
|
+
return false;
|
|
282
|
+
}
|
|
172
283
|
if (name[0] === "$") {
|
|
173
284
|
const mediaName = name.slice(1);
|
|
174
|
-
if (mediaName.startsWith("theme-") || mediaName.startsWith("platform-") || mediaName.startsWith("group-")
|
|
285
|
+
if (mediaName.startsWith("theme-") || mediaName.startsWith("platform-") || mediaName.startsWith("group-")) {
|
|
286
|
+
return true;
|
|
287
|
+
}
|
|
288
|
+
if (mediaQueryConfig[mediaName]) {
|
|
289
|
+
return true;
|
|
290
|
+
}
|
|
175
291
|
}
|
|
176
292
|
return !!(staticConfig.validStyles?.[name] || pseudoDescriptors[name] ||
|
|
177
293
|
// don't disable variants or else you lose many things flattening
|
|
178
294
|
staticConfig.variants?.[name] || projectInfo?.tamaguiConfig?.shorthands[name]);
|
|
179
295
|
}
|
|
180
|
-
const isTargetingHTML = platform2 === "web"
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
296
|
+
const isTargetingHTML = platform2 === "web";
|
|
297
|
+
const ogDebug = shouldPrintDebug;
|
|
298
|
+
const tm = (0, import_timer.timer)();
|
|
299
|
+
const propsWithFileInfo = {
|
|
300
|
+
...options,
|
|
301
|
+
sourcePath,
|
|
302
|
+
allLoadedComponents: components ? [...components] : []
|
|
303
|
+
};
|
|
304
|
+
if (!hasLoggedBaseInfo) {
|
|
305
|
+
hasLoggedBaseInfo = true;
|
|
306
|
+
if (shouldPrintDebug) {
|
|
307
|
+
logger.info(["loaded components:", propsWithFileInfo.allLoadedComponents.map(comp => Object.keys(comp.nameToInfo).join(", ")).join(", ")].join(" "));
|
|
308
|
+
}
|
|
309
|
+
if (process.env.DEBUG?.startsWith("tamagui")) {
|
|
310
|
+
logger.info(["loaded:", propsWithFileInfo.allLoadedComponents.map(x => x.moduleName)].join("\n"));
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
tm.mark("load-tamagui", !!shouldPrintDebug);
|
|
314
|
+
if (!isFullyDisabled(options)) {
|
|
315
|
+
if (!tamaguiConfig?.themes) {
|
|
316
|
+
console.error(`\u26D4\uFE0F Error: Missing "themes" in your tamagui.config file:
|
|
190
317
|
|
|
191
318
|
You may not need the compiler! Remember you can run Tamagui with no configuration at all.
|
|
192
319
|
|
|
@@ -195,68 +322,125 @@ function createExtractor({
|
|
|
195
322
|
Or this may be due to duplicated dependency versions:
|
|
196
323
|
- try out https://github.com/bmish/check-dependency-version-consistency to see if there are mis-matches.
|
|
197
324
|
- or search your lockfile for mis-matches.
|
|
198
|
-
`)
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
325
|
+
`);
|
|
326
|
+
console.info(` Got config:`, tamaguiConfig);
|
|
327
|
+
process.exit(0);
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
const firstThemeName = Object.keys(tamaguiConfig?.themes || {})[0];
|
|
331
|
+
const firstTheme = tamaguiConfig?.themes[firstThemeName] || {};
|
|
332
|
+
if (!firstTheme || typeof firstTheme !== "object") {
|
|
202
333
|
const err = `Missing theme ${firstThemeName}, an error occurred when importing your config`;
|
|
203
|
-
|
|
334
|
+
console.info(err, `Got config:`, tamaguiConfig);
|
|
335
|
+
console.info(`Looking for theme:`, firstThemeName);
|
|
336
|
+
throw new Error(err);
|
|
204
337
|
}
|
|
205
|
-
const proxiedTheme = proxyThemeVariables(firstTheme)
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
338
|
+
const proxiedTheme = proxyThemeVariables(firstTheme);
|
|
339
|
+
const themeAccessListeners = /* @__PURE__ */new Set();
|
|
340
|
+
const defaultTheme = new Proxy(proxiedTheme, {
|
|
341
|
+
get(target, key) {
|
|
342
|
+
if (Reflect.has(target, key)) {
|
|
343
|
+
themeAccessListeners.forEach(cb => cb(String(key)));
|
|
344
|
+
}
|
|
345
|
+
return Reflect.get(target, key);
|
|
346
|
+
}
|
|
347
|
+
});
|
|
348
|
+
const body = fileOrPath.type === "Program" ? fileOrPath.get("body") : fileOrPath.program.body;
|
|
349
|
+
if (!isFullyDisabled(options)) {
|
|
350
|
+
if (Object.keys(components || []).length === 0) {
|
|
351
|
+
console.warn(`Warning: Tamagui didn't find any valid components (DEBUG=tamagui for more)`);
|
|
352
|
+
if (process.env.DEBUG === "tamagui") {
|
|
353
|
+
console.info(`components`, Object.keys(components || []), components);
|
|
210
354
|
}
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
if (shouldPrintDebug === "verbose") {
|
|
358
|
+
logger.info(`allLoadedComponent modules ${propsWithFileInfo.allLoadedComponents.map(k => k.moduleName).join(", ")}`);
|
|
359
|
+
logger.info(`valid import paths: ${JSON.stringify((0, import_extractHelpers.getValidComponentsPaths)(propsWithFileInfo))}`);
|
|
360
|
+
}
|
|
361
|
+
let doesUseValidImport = false;
|
|
362
|
+
let hasImportedTheme = false;
|
|
216
363
|
const importDeclarations = [];
|
|
217
364
|
for (const bodyPath of body) {
|
|
218
365
|
if (bodyPath.type !== "ImportDeclaration") continue;
|
|
219
|
-
const node = "node" in bodyPath ? bodyPath.node : bodyPath
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
if (valid
|
|
223
|
-
|
|
224
|
-
|
|
366
|
+
const node = "node" in bodyPath ? bodyPath.node : bodyPath;
|
|
367
|
+
const moduleName = node.source.value;
|
|
368
|
+
const valid = (0, import_extractHelpers.isValidImport)(propsWithFileInfo, moduleName);
|
|
369
|
+
if (valid) {
|
|
370
|
+
importDeclarations.push(node);
|
|
371
|
+
}
|
|
372
|
+
if (shouldPrintDebug === "verbose") {
|
|
373
|
+
logger.info(` - import via ${moduleName} ${valid}`);
|
|
374
|
+
}
|
|
375
|
+
if (extractStyledDefinitions && enableDynamicEvaluation) {
|
|
376
|
+
if (node.specifiers.some(specifier => specifier.local.name === "styled")) {
|
|
377
|
+
doesUseValidImport = true;
|
|
378
|
+
}
|
|
225
379
|
}
|
|
226
380
|
if (valid) {
|
|
227
|
-
const names = node.specifiers.map(specifier => specifier.local.name)
|
|
228
|
-
|
|
229
|
-
if (shouldPrintDebug === "verbose"
|
|
230
|
-
|
|
381
|
+
const names = node.specifiers.map(specifier => specifier.local.name);
|
|
382
|
+
const isValidComponent = names.some(name => Boolean((0, import_extractHelpers.isValidImport)(propsWithFileInfo, moduleName, name)));
|
|
383
|
+
if (shouldPrintDebug === "verbose") {
|
|
384
|
+
logger.info(` - import ${isValidComponent ? "\u2705" : "\u21E3"} - ${names.join(", ")} via package '${moduleName}' - (valid: ${JSON.stringify((0, import_extractHelpers.getValidComponentsPaths)(propsWithFileInfo))})`);
|
|
385
|
+
}
|
|
386
|
+
if (isValidComponent) {
|
|
387
|
+
doesUseValidImport = true;
|
|
388
|
+
if (!(extractStyledDefinitions && enableDynamicEvaluation)) break;
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
if (shouldPrintDebug) {
|
|
393
|
+
logger.info(`${JSON.stringify({
|
|
394
|
+
doesUseValidImport,
|
|
395
|
+
hasImportedTheme
|
|
396
|
+
}, null, 2)}
|
|
397
|
+
`);
|
|
398
|
+
}
|
|
399
|
+
if (!doesUseValidImport && extractStyledDefinitions && enableDynamicEvaluation && sourcePath) {
|
|
400
|
+
for (const bodyPath of body) {
|
|
401
|
+
if (bodyPath.type !== "ImportDeclaration") continue;
|
|
402
|
+
const node = "node" in bodyPath ? bodyPath.node : bodyPath;
|
|
403
|
+
const moduleName = node.source.value;
|
|
404
|
+
const resolved = resolveImportPath(sourcePath, moduleName);
|
|
405
|
+
if (!resolved) continue;
|
|
406
|
+
if (dynamicComponentCache.has(resolved)) {
|
|
407
|
+
doesUseValidImport = true;
|
|
408
|
+
break;
|
|
409
|
+
}
|
|
410
|
+
if (mightHaveStyledComponents(resolved)) {
|
|
411
|
+
doesUseValidImport = true;
|
|
231
412
|
break;
|
|
232
413
|
}
|
|
233
414
|
}
|
|
234
415
|
}
|
|
235
|
-
if (
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
}, null, 2)}
|
|
239
|
-
`), !doesUseValidImport) return null;
|
|
416
|
+
if (!doesUseValidImport) {
|
|
417
|
+
return null;
|
|
418
|
+
}
|
|
240
419
|
function getValidImportedComponent(componentName) {
|
|
241
420
|
const importDeclaration = importDeclarations.find(dec => dec.specifiers.some(spec => spec.local.name === componentName));
|
|
242
|
-
|
|
421
|
+
if (!importDeclaration) {
|
|
422
|
+
return null;
|
|
423
|
+
}
|
|
424
|
+
return (0, import_extractHelpers.getValidImport)(propsWithFileInfo, importDeclaration.source.value, componentName);
|
|
243
425
|
}
|
|
244
426
|
tm.mark("import-check", !!shouldPrintDebug);
|
|
245
|
-
let couldntParse =
|
|
246
|
-
const modifiedComponents = /* @__PURE__ */new Set()
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
427
|
+
let couldntParse = false;
|
|
428
|
+
const modifiedComponents = /* @__PURE__ */new Set();
|
|
429
|
+
const bindingCache = {};
|
|
430
|
+
const callTraverse = a => {
|
|
431
|
+
return fileOrPath.type === "File" ? (0, import_traverse.default)(fileOrPath, a) : fileOrPath.traverse(a);
|
|
432
|
+
};
|
|
433
|
+
const shouldDisableExtraction = disableExtraction === true || Array.isArray(disableExtraction) && disableExtraction.includes(sourcePath);
|
|
250
434
|
let programPath = null;
|
|
251
435
|
const res = {
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
436
|
+
styled: 0,
|
|
437
|
+
flattened: 0,
|
|
438
|
+
optimized: 0,
|
|
439
|
+
modified: 0,
|
|
440
|
+
found: 0
|
|
441
|
+
};
|
|
442
|
+
const version = `${Math.random()}`;
|
|
443
|
+
callTraverse({
|
|
260
444
|
// @ts-ignore
|
|
261
445
|
Program: {
|
|
262
446
|
enter(path) {
|
|
@@ -265,56 +449,89 @@ function createExtractor({
|
|
|
265
449
|
},
|
|
266
450
|
// styled() calls
|
|
267
451
|
CallExpression(path) {
|
|
268
|
-
if (disable || shouldDisableExtraction || extractStyledDefinitions ===
|
|
452
|
+
if (disable || shouldDisableExtraction || extractStyledDefinitions === false) {
|
|
453
|
+
return;
|
|
454
|
+
}
|
|
455
|
+
if (!t.isIdentifier(path.node.callee) || path.node.callee.name !== "styled") {
|
|
456
|
+
return;
|
|
457
|
+
}
|
|
269
458
|
const variableName = t.isVariableDeclarator(path.parent) && t.isIdentifier(path.parent.id) ? path.parent.id.name : "unknown";
|
|
270
|
-
|
|
459
|
+
if (shouldPrintDebug) {
|
|
460
|
+
logger.info(` [styled] Found styled(${variableName})`);
|
|
461
|
+
}
|
|
271
462
|
const parentNode = path.node.arguments[0];
|
|
272
|
-
if (!t.isIdentifier(parentNode))
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
463
|
+
if (!t.isIdentifier(parentNode)) {
|
|
464
|
+
return;
|
|
465
|
+
}
|
|
466
|
+
const parentName = parentNode.name;
|
|
467
|
+
const definition = path.node.arguments[1];
|
|
468
|
+
if (!parentName || !definition || !t.isObjectExpression(definition)) {
|
|
469
|
+
return;
|
|
470
|
+
}
|
|
276
471
|
let Component = getValidImportedComponent(parentName) || getValidImportedComponent(variableName);
|
|
277
472
|
if (!Component) {
|
|
278
|
-
if (enableDynamicEvaluation
|
|
473
|
+
if (!enableDynamicEvaluation) {
|
|
474
|
+
return;
|
|
475
|
+
}
|
|
279
476
|
try {
|
|
280
|
-
|
|
477
|
+
if (shouldPrintDebug) {
|
|
478
|
+
logger.info(`Unknown component: ${variableName} = styled(${parentName}) attempting dynamic load: ${sourcePath}`);
|
|
479
|
+
}
|
|
281
480
|
const out2 = (0, import_loadTamagui.loadTamaguiSync)({
|
|
282
|
-
forceExports:
|
|
481
|
+
forceExports: true,
|
|
283
482
|
components: [sourcePath],
|
|
284
483
|
cacheKey: version
|
|
285
484
|
});
|
|
286
485
|
if (!out2?.components) {
|
|
287
|
-
|
|
486
|
+
if (shouldPrintDebug) {
|
|
487
|
+
logger.info(`Couldn't load, got ${out2}`);
|
|
488
|
+
}
|
|
288
489
|
return;
|
|
289
490
|
}
|
|
290
|
-
|
|
491
|
+
propsWithFileInfo.allLoadedComponents = [...propsWithFileInfo.allLoadedComponents, ...out2.components];
|
|
492
|
+
Component = out2.components.flatMap(x => x.nameToInfo[variableName] ?? [])[0];
|
|
493
|
+
if (!out2.cached) {
|
|
291
494
|
const foundNames = out2.components?.map(x => Object.keys(x.nameToInfo).join(", ")).join(", ").trim();
|
|
292
|
-
|
|
495
|
+
if (foundNames) {
|
|
496
|
+
(0, import_cli_color.colorLog)(import_cli_color.Color.FgYellow, ` | Tamagui found dynamic components: ${foundNames}`);
|
|
497
|
+
}
|
|
498
|
+
}
|
|
499
|
+
} catch (err) {
|
|
500
|
+
if (shouldPrintDebug) {
|
|
501
|
+
logger.info(`skip optimize styled(${variableName}), unable to pre-process (DEBUG=tamagui for more)`);
|
|
293
502
|
}
|
|
294
|
-
} catch {
|
|
295
|
-
shouldPrintDebug && logger.info(`skip optimize styled(${variableName}), unable to pre-process (DEBUG=tamagui for more)`);
|
|
296
503
|
}
|
|
297
504
|
}
|
|
298
505
|
if (!Component) {
|
|
299
|
-
|
|
506
|
+
if (shouldPrintDebug) {
|
|
507
|
+
logger.info(` No component found`);
|
|
508
|
+
}
|
|
300
509
|
return;
|
|
301
510
|
}
|
|
302
511
|
const componentSkipProps = /* @__PURE__ */new Set([...(Component.staticConfig.inlineWhenUnflattened || []), ...(Component.staticConfig.inlineProps || []),
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
512
|
+
// for now skip variants, will return to them
|
|
513
|
+
"variants", "defaultVariants",
|
|
514
|
+
// skip fontFamily its basically a "variant", important for theme use to be value always
|
|
515
|
+
"fontFamily", "name", "focusStyle", "focusVisibleStyle", "focusWithinStyle", "disabledStyle", "hoverStyle", "pressStyle"]);
|
|
516
|
+
const skipped = /* @__PURE__ */new Set();
|
|
517
|
+
const styles = {};
|
|
518
|
+
const staticDefaultProps = {};
|
|
519
|
+
const staticNamespace = (0, import_getStaticBindingsForScope.getStaticBindingsForScope)(path.scope, importsWhitelist, sourcePath, bindingCache, shouldPrintDebug);
|
|
520
|
+
const attemptEval = !evaluateVars ? import_evaluateAstNode.evaluateAstNode : (0, import_createEvaluator.createEvaluator)({
|
|
521
|
+
props: propsWithFileInfo,
|
|
522
|
+
staticNamespace,
|
|
523
|
+
sourcePath,
|
|
524
|
+
shouldPrintDebug
|
|
525
|
+
});
|
|
526
|
+
const attemptEvalSafe = (0, import_createEvaluator.createSafeEvaluator)(attemptEval);
|
|
317
527
|
for (const property of definition.properties) {
|
|
528
|
+
if (t.isObjectProperty(property) && (t.isIdentifier(property.key) || t.isStringLiteral(property.key))) {
|
|
529
|
+
const key = t.isIdentifier(property.key) ? property.key.name : property.key.value;
|
|
530
|
+
const defaultPropValue = attemptEvalSafe(property.value);
|
|
531
|
+
if (defaultPropValue !== import_constants.FAILED_EVAL) {
|
|
532
|
+
staticDefaultProps[key] = defaultPropValue;
|
|
533
|
+
}
|
|
534
|
+
}
|
|
318
535
|
if (!t.isObjectProperty(property) || !t.isIdentifier(property.key) || !isValidStyleKey(property.key.name, Component.staticConfig) ||
|
|
319
536
|
// TODO make pseudos and variants work
|
|
320
537
|
// skip pseudos
|
|
@@ -325,90 +542,247 @@ function createExtractor({
|
|
|
325
542
|
continue;
|
|
326
543
|
}
|
|
327
544
|
const out2 = attemptEvalSafe(property.value);
|
|
328
|
-
out2 === import_constants.FAILED_EVAL
|
|
545
|
+
if (out2 === import_constants.FAILED_EVAL) {
|
|
546
|
+
skipped.add(property);
|
|
547
|
+
} else {
|
|
548
|
+
styles[property.key.name] = out2;
|
|
549
|
+
}
|
|
550
|
+
}
|
|
551
|
+
const out = getSplitStyles(styles, Component.staticConfig, defaultTheme, "", componentState, styleProps, void 0, void 0, void 0, void 0, false, shouldPrintDebug);
|
|
552
|
+
const classNames = {
|
|
553
|
+
...out.classNames
|
|
554
|
+
};
|
|
555
|
+
if (shouldPrintDebug) {
|
|
556
|
+
logger.info([`Extracted styled(${variableName})
|
|
557
|
+
`, JSON.stringify(styles, null, 2), "\n classNames:", JSON.stringify(classNames, null, 2), "\n rulesToInsert:", out.rulesToInsert].join(" "));
|
|
329
558
|
}
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
559
|
+
if (out.rulesToInsert) {
|
|
560
|
+
for (const key in out.rulesToInsert) {
|
|
561
|
+
const styleObject = out.rulesToInsert[key];
|
|
562
|
+
onStyledDefinitionRule?.(styleObject[import_web.StyleObjectIdentifier], styleObject[import_web.StyleObjectRules]);
|
|
563
|
+
}
|
|
564
|
+
}
|
|
565
|
+
res.styled++;
|
|
566
|
+
if (extractStyledDefinitions && enableDynamicEvaluation && Component) {
|
|
567
|
+
const dynamicStaticConfig = {
|
|
568
|
+
...Component.staticConfig,
|
|
569
|
+
defaultProps: {
|
|
570
|
+
...Component.staticConfig.defaultProps,
|
|
571
|
+
...staticDefaultProps
|
|
572
|
+
}
|
|
333
573
|
};
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
574
|
+
propsWithFileInfo.allLoadedComponents.push({
|
|
575
|
+
moduleName: "",
|
|
576
|
+
nameToInfo: {
|
|
577
|
+
[variableName]: {
|
|
578
|
+
staticConfig: dynamicStaticConfig
|
|
579
|
+
}
|
|
580
|
+
}
|
|
581
|
+
});
|
|
582
|
+
if (sourcePath) {
|
|
583
|
+
let existing = dynamicComponentCache.get(sourcePath);
|
|
584
|
+
if (!existing) {
|
|
585
|
+
existing = {
|
|
586
|
+
moduleName: sourcePath,
|
|
587
|
+
nameToInfo: {}
|
|
588
|
+
};
|
|
589
|
+
dynamicComponentCache.set(sourcePath, existing);
|
|
590
|
+
}
|
|
591
|
+
existing.nameToInfo[variableName] = {
|
|
592
|
+
staticConfig: dynamicStaticConfig
|
|
593
|
+
};
|
|
594
|
+
}
|
|
595
|
+
}
|
|
596
|
+
if (shouldPrintDebug) {
|
|
597
|
+
logger.info(`Extracted styled(${variableName})`);
|
|
340
598
|
}
|
|
341
|
-
res.styled++, shouldPrintDebug && logger.info(`Extracted styled(${variableName})`);
|
|
342
599
|
},
|
|
343
600
|
JSXElement(traversePath) {
|
|
344
601
|
tm.mark("jsx-element", !!shouldPrintDebug);
|
|
345
|
-
const node = traversePath.node.openingElement
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
602
|
+
const node = traversePath.node.openingElement;
|
|
603
|
+
const ogAttributes = node.attributes.map(attr => ({
|
|
604
|
+
...attr
|
|
605
|
+
}));
|
|
606
|
+
const componentName = (0, import_extractHelpers.findComponentName)(traversePath.scope);
|
|
607
|
+
const closingElement = traversePath.node.closingElement;
|
|
351
608
|
if (closingElement && t.isJSXMemberExpression(closingElement?.name) || !t.isJSXIdentifier(node.name)) {
|
|
352
|
-
|
|
609
|
+
if (shouldPrintDebug) {
|
|
610
|
+
logger.info(` skip non-identifier element`);
|
|
611
|
+
}
|
|
353
612
|
return;
|
|
354
613
|
}
|
|
355
614
|
const binding = traversePath.scope.getBinding(node.name.name);
|
|
356
615
|
let moduleName = "";
|
|
357
|
-
|
|
358
|
-
|
|
616
|
+
let dynamicComponent = null;
|
|
617
|
+
if (binding) {
|
|
618
|
+
if (t.isImportDeclaration(binding.path.parent)) {
|
|
619
|
+
moduleName = binding.path.parent.source.value;
|
|
620
|
+
if (!(0, import_extractHelpers.isValidImport)(propsWithFileInfo, moduleName, binding.identifier.name)) {
|
|
621
|
+
if (enableDynamicEvaluation && sourcePath) {
|
|
622
|
+
const resolved = resolveImportPath(sourcePath, moduleName);
|
|
623
|
+
if (resolved) {
|
|
624
|
+
const cached = dynamicComponentCache.get(resolved);
|
|
625
|
+
if (cached?.nameToInfo[binding.identifier.name]) {
|
|
626
|
+
dynamicComponent = cached.nameToInfo[binding.identifier.name];
|
|
627
|
+
} else if (!dynamicLoadingInProgress.has(resolved) && mightHaveStyledComponents(resolved)) {
|
|
628
|
+
dynamicLoadingInProgress.add(resolved);
|
|
629
|
+
try {
|
|
630
|
+
const out = (0, import_loadTamagui.loadTamaguiSync)({
|
|
631
|
+
forceExports: true,
|
|
632
|
+
components: [resolved]
|
|
633
|
+
});
|
|
634
|
+
if (out?.components) {
|
|
635
|
+
for (const comp of out.components) {
|
|
636
|
+
let existing = dynamicComponentCache.get(resolved);
|
|
637
|
+
if (!existing) {
|
|
638
|
+
existing = {
|
|
639
|
+
moduleName: resolved,
|
|
640
|
+
nameToInfo: {}
|
|
641
|
+
};
|
|
642
|
+
dynamicComponentCache.set(resolved, existing);
|
|
643
|
+
}
|
|
644
|
+
Object.assign(existing.nameToInfo, comp.nameToInfo);
|
|
645
|
+
propsWithFileInfo.allLoadedComponents.push({
|
|
646
|
+
moduleName: resolved,
|
|
647
|
+
nameToInfo: comp.nameToInfo
|
|
648
|
+
});
|
|
649
|
+
}
|
|
650
|
+
const cachedNow = dynamicComponentCache.get(resolved);
|
|
651
|
+
if (cachedNow?.nameToInfo[binding.identifier.name]) {
|
|
652
|
+
dynamicComponent = cachedNow.nameToInfo[binding.identifier.name];
|
|
653
|
+
}
|
|
654
|
+
}
|
|
655
|
+
} catch (err) {
|
|
656
|
+
if (shouldPrintDebug) {
|
|
657
|
+
logger.info(` - Failed to dynamically load ${resolved}: ${err}`);
|
|
658
|
+
}
|
|
659
|
+
} finally {
|
|
660
|
+
dynamicLoadingInProgress.delete(resolved);
|
|
661
|
+
}
|
|
662
|
+
}
|
|
663
|
+
}
|
|
664
|
+
}
|
|
665
|
+
if (!dynamicComponent) {
|
|
666
|
+
if (shouldPrintDebug) {
|
|
667
|
+
logger.info(` - Binding in component ${componentName} not valid import: "${binding.identifier.name}" isn't in ${moduleName}
|
|
359
668
|
`);
|
|
360
|
-
|
|
669
|
+
}
|
|
670
|
+
return;
|
|
671
|
+
}
|
|
672
|
+
}
|
|
673
|
+
}
|
|
361
674
|
}
|
|
362
|
-
const component = (0, import_extractHelpers.getValidComponent)(propsWithFileInfo, moduleName, node.name.name);
|
|
675
|
+
const component = dynamicComponent || (0, import_extractHelpers.getValidComponent)(propsWithFileInfo, moduleName, node.name.name);
|
|
363
676
|
if (!component || !component.staticConfig) {
|
|
364
|
-
shouldPrintDebug
|
|
677
|
+
if (shouldPrintDebug) {
|
|
678
|
+
logger.info(`
|
|
365
679
|
- No Tamagui conf for: ${node.name.name}
|
|
366
680
|
`);
|
|
681
|
+
}
|
|
367
682
|
return;
|
|
368
683
|
}
|
|
369
684
|
const originalNodeName = node.name.name;
|
|
370
685
|
res.found++;
|
|
371
|
-
const filePath = `./${(0, import_node_path.relative)(process.cwd(), sourcePath)}
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
686
|
+
const filePath = `./${(0, import_node_path.relative)(process.cwd(), sourcePath)}`;
|
|
687
|
+
const lineNumbers = node.loc ? node.loc.start.line + (node.loc.start.line !== node.loc.end.line ? `-${node.loc.end.line}` : "") : "";
|
|
688
|
+
const codePosition = `${filePath}:${lineNumbers}`;
|
|
689
|
+
const debugPropValue = node.attributes.filter(n => t.isJSXAttribute(n) && t.isJSXIdentifier(n.name) && n.name.name === "debug").map(n => {
|
|
690
|
+
if (n.value === null) return true;
|
|
691
|
+
if (t.isStringLiteral(n.value)) return n.value.value;
|
|
692
|
+
return false;
|
|
693
|
+
})[0];
|
|
694
|
+
if (debugPropValue) {
|
|
695
|
+
shouldPrintDebug = debugPropValue;
|
|
696
|
+
}
|
|
697
|
+
if (shouldPrintDebug) {
|
|
698
|
+
logger.info(`\x1B[33m\x1B[0m ${componentName} | ${codePosition} -------------------`);
|
|
699
|
+
logger.info(["\x1B[1m", "\x1B[32m", `<${originalNodeName} />`, disableDebugAttr ? "" : "\u{1F41B}"].join(" "));
|
|
700
|
+
}
|
|
701
|
+
if (platform2 !== "native") {
|
|
702
|
+
if (shouldAddDebugProp && !disableDebugAttr) {
|
|
703
|
+
res.modified++;
|
|
704
|
+
node.attributes.unshift(t.jsxAttribute(t.jsxIdentifier("data-is"), t.stringLiteral(node.name.name)));
|
|
705
|
+
if (componentName) {
|
|
706
|
+
node.attributes.unshift(t.jsxAttribute(t.jsxIdentifier("data-in"), t.stringLiteral(componentName)));
|
|
707
|
+
}
|
|
708
|
+
node.attributes.unshift(t.jsxAttribute(t.jsxIdentifier("data-at"), t.stringLiteral(`${(0, import_node_path.basename)(filePath)}:${lineNumbers}`)));
|
|
709
|
+
}
|
|
710
|
+
}
|
|
711
|
+
if (shouldDisableExtraction) {
|
|
712
|
+
if (shouldPrintDebug === "verbose") {
|
|
713
|
+
logger.info(` \u274C Extraction disabled: ${JSON.stringify(disableExtraction)}
|
|
377
714
|
`);
|
|
715
|
+
}
|
|
378
716
|
return;
|
|
379
717
|
}
|
|
380
718
|
try {
|
|
381
719
|
let evaluateAttribute = function (path) {
|
|
382
|
-
const attribute = path.node
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
720
|
+
const attribute = path.node;
|
|
721
|
+
const attr = {
|
|
722
|
+
type: "attr",
|
|
723
|
+
value: attribute
|
|
724
|
+
};
|
|
387
725
|
if (t.isJSXSpreadAttribute(attribute)) {
|
|
388
|
-
const arg = attribute.argument
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
726
|
+
const arg = attribute.argument;
|
|
727
|
+
const conditional = t.isConditionalExpression(arg) ?
|
|
728
|
+
// <YStack {...isSmall ? { color: 'red } : { color: 'blue }}
|
|
729
|
+
[arg.test, arg.consequent, arg.alternate] : t.isLogicalExpression(arg) && arg.operator === "&&" ?
|
|
730
|
+
// <YStack {...isSmall && { color: 'red }}
|
|
731
|
+
[arg.left, arg.right, null] : null;
|
|
394
732
|
if (conditional) {
|
|
395
733
|
const [test, alt, cons] = conditional;
|
|
396
|
-
if (!test) throw new Error(
|
|
397
|
-
|
|
734
|
+
if (!test) throw new Error(`no test`);
|
|
735
|
+
if ([alt, cons].some(side => side && !isStaticObject(side))) {
|
|
736
|
+
if (shouldPrintDebug) {
|
|
737
|
+
logger.info(`not extractable ${alt} ${cons}`);
|
|
738
|
+
}
|
|
739
|
+
return attr;
|
|
740
|
+
}
|
|
741
|
+
return [...(flattenNestedTernaries(test, alt) || []), ...(cons && flattenNestedTernaries(t.unaryExpression("!", test), cons) || [])].map(ternary => ({
|
|
398
742
|
type: "ternary",
|
|
399
743
|
value: ternary
|
|
400
744
|
}));
|
|
401
745
|
}
|
|
402
746
|
}
|
|
403
|
-
if (t.isJSXSpreadAttribute(attribute) || !attribute.name || typeof attribute.name.name
|
|
747
|
+
if (t.isJSXSpreadAttribute(attribute) || !attribute.name || typeof attribute.name.name !== "string") {
|
|
748
|
+
if (shouldPrintDebug) {
|
|
749
|
+
logger.info(" ! inlining, spread attr");
|
|
750
|
+
}
|
|
751
|
+
inlined.set(`${Math.random()}`, "spread");
|
|
752
|
+
return attr;
|
|
753
|
+
}
|
|
404
754
|
const name = attribute.name.name;
|
|
405
|
-
if (name === "style")
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
if (
|
|
410
|
-
|
|
411
|
-
|
|
755
|
+
if (name === "style") {
|
|
756
|
+
shouldDeopt = true;
|
|
757
|
+
return null;
|
|
758
|
+
}
|
|
759
|
+
if (excludeProps?.has(name)) {
|
|
760
|
+
if (shouldPrintDebug) {
|
|
761
|
+
logger.info([" excluding prop", name].join(" "));
|
|
762
|
+
}
|
|
763
|
+
return null;
|
|
764
|
+
}
|
|
765
|
+
if (inlineProps.has(name)) {
|
|
766
|
+
inlined.set(name, name);
|
|
767
|
+
if (shouldPrintDebug) {
|
|
768
|
+
logger.info([" ! inlining, inline prop", name].join(" "));
|
|
769
|
+
}
|
|
770
|
+
return attr;
|
|
771
|
+
}
|
|
772
|
+
if (UNTOUCHED_PROPS[name]) {
|
|
773
|
+
return attr;
|
|
774
|
+
}
|
|
775
|
+
if (INLINE_EXTRACTABLE[name]) {
|
|
776
|
+
inlined.set(name, INLINE_EXTRACTABLE[name]);
|
|
777
|
+
return attr;
|
|
778
|
+
}
|
|
779
|
+
if (name.startsWith("data-") || name.startsWith("aria-") || import_validHTMLAttributes.validHTMLAttributes[name]) {
|
|
780
|
+
return attr;
|
|
781
|
+
}
|
|
782
|
+
if ((name === "enterStyle" || name === "exitStyle") && t.isJSXExpressionContainer(attribute?.value)) {
|
|
783
|
+
shouldDeopt = true;
|
|
784
|
+
return attr;
|
|
785
|
+
}
|
|
412
786
|
if (name[0] === "$" && t.isJSXExpressionContainer(attribute?.value)) {
|
|
413
787
|
const shortname = name.slice(1);
|
|
414
788
|
if (mediaQueryConfig[shortname]) {
|
|
@@ -417,66 +791,168 @@ function createExtractor({
|
|
|
417
791
|
const ternaries2 = flattenNestedTernaries(t.stringLiteral(shortname), expression, {
|
|
418
792
|
inlineMediaQuery: shortname
|
|
419
793
|
});
|
|
420
|
-
if (ternaries2)
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
794
|
+
if (ternaries2) {
|
|
795
|
+
return ternaries2.map(value2 => ({
|
|
796
|
+
type: "ternary",
|
|
797
|
+
value: value2
|
|
798
|
+
}));
|
|
799
|
+
}
|
|
424
800
|
}
|
|
425
801
|
}
|
|
426
802
|
}
|
|
427
|
-
const [value, valuePath] =
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
}
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
803
|
+
const [value, valuePath] = (() => {
|
|
804
|
+
if (t.isJSXExpressionContainer(attribute?.value)) {
|
|
805
|
+
return [attribute.value.expression, path.get("value")];
|
|
806
|
+
}
|
|
807
|
+
return [attribute.value, path.get("value")];
|
|
808
|
+
})();
|
|
809
|
+
const remove = () => {
|
|
810
|
+
Array.isArray(valuePath) ? valuePath.map(p => p.remove()) : valuePath.remove();
|
|
435
811
|
};
|
|
436
|
-
if (
|
|
437
|
-
|
|
812
|
+
if (name === "ref") {
|
|
813
|
+
if (shouldPrintDebug) {
|
|
814
|
+
logger.info([" ! inlining, ref", name].join(" "));
|
|
815
|
+
}
|
|
816
|
+
inlined.set("ref", "ref");
|
|
817
|
+
return attr;
|
|
818
|
+
}
|
|
819
|
+
if (name === "render") {
|
|
820
|
+
if (!value || value.type !== "StringLiteral") {
|
|
821
|
+
if (shouldPrintDebug) {
|
|
822
|
+
logger.info(` ! deopt on render prop (not a string literal)`);
|
|
823
|
+
}
|
|
824
|
+
shouldDeopt = true;
|
|
825
|
+
}
|
|
826
|
+
return {
|
|
827
|
+
type: "attr",
|
|
828
|
+
value: path.node
|
|
829
|
+
};
|
|
830
|
+
}
|
|
831
|
+
if (disableExtractVariables === true) {
|
|
832
|
+
if (value) {
|
|
833
|
+
if (value.type === "StringLiteral" && value.value[0] === "$") {
|
|
834
|
+
if (shouldPrintDebug) {
|
|
835
|
+
logger.info([` ! inlining, native disable extract: ${name} =`, value.value].join(" "));
|
|
836
|
+
}
|
|
837
|
+
inlined.set(name, true);
|
|
838
|
+
return attr;
|
|
839
|
+
}
|
|
840
|
+
}
|
|
841
|
+
}
|
|
842
|
+
if (name === "theme") {
|
|
843
|
+
inlined.set("theme", attr.value);
|
|
844
|
+
return attr;
|
|
845
|
+
}
|
|
438
846
|
const styleValue = attemptEvalSafe(value);
|
|
439
847
|
if (!variants[name] && !isValidStyleKey(name, staticConfig)) {
|
|
440
848
|
let out = null;
|
|
441
|
-
propMapper(name, styleValue, propMapperStyleState,
|
|
442
|
-
out ||= {}
|
|
443
|
-
|
|
444
|
-
|
|
849
|
+
propMapper(name, styleValue, propMapperStyleState, false, (key, val) => {
|
|
850
|
+
out ||= {};
|
|
851
|
+
out[key] = val;
|
|
852
|
+
});
|
|
853
|
+
if (out) {
|
|
854
|
+
if (isTargetingHTML) {
|
|
855
|
+
out = reactNativeWebInternals.createDOMProps(isTextView ? "span" : "div", out);
|
|
856
|
+
delete out.className;
|
|
857
|
+
delete out.style;
|
|
858
|
+
}
|
|
859
|
+
}
|
|
860
|
+
let didInline = false;
|
|
445
861
|
const attributes = Object.keys(out).map(key => {
|
|
446
862
|
const val = out[key];
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
863
|
+
const isStyle = isValidStyleKey(key, staticConfig);
|
|
864
|
+
if (isStyle) {
|
|
865
|
+
return {
|
|
866
|
+
type: "style",
|
|
867
|
+
value: {
|
|
868
|
+
[key]: styleValue
|
|
869
|
+
},
|
|
870
|
+
name: key,
|
|
871
|
+
attr: path.node
|
|
872
|
+
};
|
|
873
|
+
}
|
|
874
|
+
if (import_validHTMLAttributes.validHTMLAttributes[key] || key.startsWith("aria-") || key.startsWith("data-") ||
|
|
455
875
|
// this is debug stuff added by vite / new jsx transform
|
|
456
|
-
key === "__source" || key === "__self"
|
|
876
|
+
key === "__source" || key === "__self") {
|
|
877
|
+
if (styleValue === import_constants.FAILED_EVAL && key !== name && t.isJSXAttribute(attr.value)) {
|
|
878
|
+
return {
|
|
879
|
+
type: "attr",
|
|
880
|
+
value: t.jsxAttribute(t.jsxIdentifier(key), attr.value.value)
|
|
881
|
+
};
|
|
882
|
+
}
|
|
883
|
+
return attr;
|
|
884
|
+
}
|
|
885
|
+
if (shouldPrintDebug) {
|
|
886
|
+
logger.info(" ! inlining, non-static " + key);
|
|
887
|
+
}
|
|
888
|
+
didInline = true;
|
|
889
|
+
inlined.set(key, val);
|
|
890
|
+
return val;
|
|
457
891
|
});
|
|
458
|
-
|
|
892
|
+
if (didInline) {
|
|
893
|
+
if (shouldPrintDebug) {
|
|
894
|
+
logger.info(` bailing flattening due to attributes ${attributes.map(x => x.toString())}`);
|
|
895
|
+
}
|
|
896
|
+
return attr;
|
|
897
|
+
}
|
|
898
|
+
return attributes;
|
|
459
899
|
}
|
|
460
900
|
if (styleValue !== import_constants.FAILED_EVAL) {
|
|
461
|
-
if (inlineWhenUnflattened.has(name)
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
901
|
+
if (inlineWhenUnflattened.has(name)) {
|
|
902
|
+
inlineWhenUnflattenedOGVals[name] = {
|
|
903
|
+
styleValue,
|
|
904
|
+
attr
|
|
905
|
+
};
|
|
906
|
+
}
|
|
907
|
+
if (isValidStyleKey(name, staticConfig)) {
|
|
465
908
|
if (name[0] === "$") {
|
|
466
|
-
if (name.startsWith("$theme-") || name.startsWith("$group-"))
|
|
909
|
+
if (name.startsWith("$theme-") || name.startsWith("$group-")) {
|
|
910
|
+
if (shouldPrintDebug) {
|
|
911
|
+
logger.info(` ! not flattening media-like style: ${name}`);
|
|
912
|
+
}
|
|
913
|
+
inlined.set(name, true);
|
|
914
|
+
return attr;
|
|
915
|
+
}
|
|
467
916
|
if (name.startsWith("$platform-")) {
|
|
468
917
|
const platformName = name.slice(10);
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
}
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
918
|
+
const isMatchingPlatform = platformName === platform2 || platformName === "native" && platform2 === "native" || platformName === "web" && platform2 === "web";
|
|
919
|
+
if (isMatchingPlatform && typeof styleValue === "object") {
|
|
920
|
+
if (shouldPrintDebug) {
|
|
921
|
+
logger.info(` flattening $platform-${platformName}: ${JSON.stringify(styleValue)}`);
|
|
922
|
+
}
|
|
923
|
+
return Object.entries(styleValue).map(([key, val]) => ({
|
|
924
|
+
type: "style",
|
|
925
|
+
value: {
|
|
926
|
+
[key]: val
|
|
927
|
+
},
|
|
928
|
+
name: key,
|
|
929
|
+
attr: path.node
|
|
930
|
+
}));
|
|
931
|
+
} else {
|
|
932
|
+
if (platform2 === "native" && nativeOnlyPlatforms.has(platformName)) {
|
|
933
|
+
if (shouldPrintDebug) {
|
|
934
|
+
logger.info(` ! keeping platform-specific style for runtime evaluation: ${name}`);
|
|
935
|
+
}
|
|
936
|
+
inlined.set(name, true);
|
|
937
|
+
return attr;
|
|
938
|
+
}
|
|
939
|
+
if (shouldPrintDebug) {
|
|
940
|
+
logger.info(` ! skipping non-matching platform style: ${name}`);
|
|
941
|
+
}
|
|
942
|
+
return [];
|
|
943
|
+
}
|
|
944
|
+
}
|
|
945
|
+
}
|
|
946
|
+
if (shouldPrintDebug) {
|
|
947
|
+
logger.info(` style: ${name} = ${JSON.stringify(styleValue)}`);
|
|
948
|
+
}
|
|
949
|
+
if (!(name in defaultProps)) {
|
|
950
|
+
if (!hasSetOptimized) {
|
|
951
|
+
res.optimized++;
|
|
952
|
+
hasSetOptimized = true;
|
|
477
953
|
}
|
|
478
954
|
}
|
|
479
|
-
return
|
|
955
|
+
return {
|
|
480
956
|
type: "style",
|
|
481
957
|
value: {
|
|
482
958
|
[name]: styleValue
|
|
@@ -485,18 +961,27 @@ function createExtractor({
|
|
|
485
961
|
attr: path.node
|
|
486
962
|
};
|
|
487
963
|
}
|
|
488
|
-
|
|
964
|
+
if (variants[name]) {
|
|
965
|
+
variantValues.set(name, styleValue);
|
|
966
|
+
}
|
|
967
|
+
inlined.set(name, true);
|
|
968
|
+
return attr;
|
|
489
969
|
}
|
|
490
970
|
if (t.isBinaryExpression(value)) {
|
|
491
|
-
|
|
971
|
+
if (shouldPrintDebug) {
|
|
972
|
+
logger.info(` binary expression ${name} = ${value}`);
|
|
973
|
+
}
|
|
492
974
|
const {
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
if (shouldPrintDebug
|
|
975
|
+
operator,
|
|
976
|
+
left,
|
|
977
|
+
right
|
|
978
|
+
} = value;
|
|
979
|
+
const lVal = attemptEvalSafe(left);
|
|
980
|
+
const rVal = attemptEvalSafe(right);
|
|
981
|
+
if (shouldPrintDebug) {
|
|
982
|
+
logger.info(` evalBinaryExpression lVal ${String(lVal)}, rVal ${String(rVal)}`);
|
|
983
|
+
}
|
|
984
|
+
if (lVal !== import_constants.FAILED_EVAL && t.isConditionalExpression(right)) {
|
|
500
985
|
const ternary = addBinaryConditional(operator, left, right);
|
|
501
986
|
if (ternary) return ternary;
|
|
502
987
|
}
|
|
@@ -504,24 +989,45 @@ function createExtractor({
|
|
|
504
989
|
const ternary = addBinaryConditional(operator, right, left);
|
|
505
990
|
if (ternary) return ternary;
|
|
506
991
|
}
|
|
507
|
-
|
|
992
|
+
if (shouldPrintDebug) {
|
|
993
|
+
logger.info(` evalBinaryExpression cant extract`);
|
|
994
|
+
}
|
|
995
|
+
inlined.set(name, true);
|
|
996
|
+
return attr;
|
|
508
997
|
}
|
|
509
998
|
const staticConditional = getStaticConditional(value);
|
|
510
|
-
if (staticConditional)
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
999
|
+
if (staticConditional) {
|
|
1000
|
+
if (shouldPrintDebug === "verbose") {
|
|
1001
|
+
logger.info(` static conditional ${name} ${value}`);
|
|
1002
|
+
}
|
|
1003
|
+
return {
|
|
1004
|
+
type: "ternary",
|
|
1005
|
+
value: staticConditional
|
|
1006
|
+
};
|
|
1007
|
+
}
|
|
514
1008
|
const staticLogical = getStaticLogical(value);
|
|
515
|
-
if (staticLogical)
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
1009
|
+
if (staticLogical) {
|
|
1010
|
+
if (shouldPrintDebug === "verbose") {
|
|
1011
|
+
logger.info(` static ternary ${name} = ${value}`);
|
|
1012
|
+
}
|
|
1013
|
+
return {
|
|
1014
|
+
type: "ternary",
|
|
1015
|
+
value: staticLogical
|
|
1016
|
+
};
|
|
1017
|
+
}
|
|
1018
|
+
inlined.set(name, true);
|
|
1019
|
+
if (shouldPrintDebug) {
|
|
1020
|
+
logger.info(` ! inline no match ${name} ${value}`);
|
|
1021
|
+
}
|
|
1022
|
+
return attr;
|
|
520
1023
|
function addBinaryConditional(operator, staticExpr, cond) {
|
|
521
1024
|
if (getStaticConditional(cond)) {
|
|
522
|
-
const alt = attemptEval(t.binaryExpression(operator, staticExpr, cond.alternate))
|
|
523
|
-
|
|
524
|
-
|
|
1025
|
+
const alt = attemptEval(t.binaryExpression(operator, staticExpr, cond.alternate));
|
|
1026
|
+
const cons = attemptEval(t.binaryExpression(operator, staticExpr, cond.consequent));
|
|
1027
|
+
if (shouldPrintDebug) {
|
|
1028
|
+
logger.info([" binaryConditional", cond.test, cons, alt].join(" "));
|
|
1029
|
+
}
|
|
1030
|
+
return {
|
|
525
1031
|
type: "ternary",
|
|
526
1032
|
value: {
|
|
527
1033
|
test: cond.test,
|
|
@@ -538,57 +1044,84 @@ function createExtractor({
|
|
|
538
1044
|
return null;
|
|
539
1045
|
}
|
|
540
1046
|
function getStaticConditional(value2) {
|
|
541
|
-
if (t.isConditionalExpression(value2))
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
return {
|
|
549
|
-
test: value2.test,
|
|
550
|
-
remove,
|
|
551
|
-
consequent: {
|
|
552
|
-
[name]: cVal
|
|
553
|
-
},
|
|
554
|
-
alternate: {
|
|
555
|
-
[name]: aVal
|
|
1047
|
+
if (t.isConditionalExpression(value2)) {
|
|
1048
|
+
try {
|
|
1049
|
+
const aVal = attemptEval(value2.alternate);
|
|
1050
|
+
const cVal = attemptEval(value2.consequent);
|
|
1051
|
+
if (shouldPrintDebug) {
|
|
1052
|
+
const type = value2.test.type;
|
|
1053
|
+
logger.info([" static ternary", type, cVal, aVal].join(" "));
|
|
556
1054
|
}
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
1055
|
+
return {
|
|
1056
|
+
test: value2.test,
|
|
1057
|
+
remove,
|
|
1058
|
+
consequent: {
|
|
1059
|
+
[name]: cVal
|
|
1060
|
+
},
|
|
1061
|
+
alternate: {
|
|
1062
|
+
[name]: aVal
|
|
1063
|
+
}
|
|
1064
|
+
};
|
|
1065
|
+
} catch (err) {
|
|
1066
|
+
if (shouldPrintDebug) {
|
|
1067
|
+
logger.info([" cant eval ternary", err.message].join(" "));
|
|
1068
|
+
}
|
|
1069
|
+
}
|
|
560
1070
|
}
|
|
561
1071
|
return null;
|
|
562
1072
|
}
|
|
563
1073
|
function getStaticLogical(value2) {
|
|
564
|
-
if (t.isLogicalExpression(value2)
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
1074
|
+
if (t.isLogicalExpression(value2)) {
|
|
1075
|
+
if (value2.operator === "&&") {
|
|
1076
|
+
try {
|
|
1077
|
+
const val = attemptEval(value2.right);
|
|
1078
|
+
if (shouldPrintDebug) {
|
|
1079
|
+
logger.info([" staticLogical", value2.left, name, val].join(" "));
|
|
1080
|
+
}
|
|
1081
|
+
return {
|
|
1082
|
+
test: value2.left,
|
|
1083
|
+
remove,
|
|
1084
|
+
consequent: {
|
|
1085
|
+
[name]: val
|
|
1086
|
+
},
|
|
1087
|
+
alternate: null
|
|
1088
|
+
};
|
|
1089
|
+
} catch (err) {
|
|
1090
|
+
if (shouldPrintDebug) {
|
|
1091
|
+
logger.info([" cant static eval logical", err].join(" "));
|
|
1092
|
+
}
|
|
1093
|
+
}
|
|
1094
|
+
}
|
|
576
1095
|
}
|
|
577
1096
|
return null;
|
|
578
1097
|
}
|
|
579
1098
|
},
|
|
580
1099
|
isStaticObject = function (obj) {
|
|
581
1100
|
return t.isObjectExpression(obj) && obj.properties.every(prop => {
|
|
582
|
-
if (!t.isObjectProperty(prop))
|
|
583
|
-
|
|
584
|
-
|
|
1101
|
+
if (!t.isObjectProperty(prop)) {
|
|
1102
|
+
return false;
|
|
1103
|
+
}
|
|
1104
|
+
const propName = prop.key["name"];
|
|
1105
|
+
if (!isValidStyleKey(propName, staticConfig) && propName !== "render") {
|
|
1106
|
+
if (shouldPrintDebug) {
|
|
1107
|
+
logger.info([" not a valid style prop!", propName].join(" "));
|
|
1108
|
+
}
|
|
1109
|
+
return false;
|
|
1110
|
+
}
|
|
1111
|
+
return true;
|
|
585
1112
|
});
|
|
586
1113
|
},
|
|
587
1114
|
flattenNestedTernaries = function (test, side, ternaryPartial = {}) {
|
|
588
|
-
if (!side)
|
|
589
|
-
|
|
1115
|
+
if (!side) {
|
|
1116
|
+
return null;
|
|
1117
|
+
}
|
|
1118
|
+
if (!isStaticObject(side)) {
|
|
1119
|
+
throw new Error("not extractable");
|
|
1120
|
+
}
|
|
590
1121
|
return side.properties.flatMap(property => {
|
|
591
|
-
if (!t.isObjectProperty(property))
|
|
1122
|
+
if (!t.isObjectProperty(property)) {
|
|
1123
|
+
throw new Error("expected object property");
|
|
1124
|
+
}
|
|
592
1125
|
if (t.isConditionalExpression(property.value)) {
|
|
593
1126
|
const [truthy, falsy] = [t.objectExpression([t.objectProperty(property.key, property.value.consequent)]), t.objectExpression([t.objectProperty(property.key, property.value.alternate)])].map(x => attemptEval(x));
|
|
594
1127
|
return [createTernary({
|
|
@@ -605,8 +1138,8 @@ function createExtractor({
|
|
|
605
1138
|
remove() {}
|
|
606
1139
|
})];
|
|
607
1140
|
}
|
|
608
|
-
const obj = t.objectExpression([t.objectProperty(property.key, property.value)])
|
|
609
|
-
|
|
1141
|
+
const obj = t.objectExpression([t.objectProperty(property.key, property.value)]);
|
|
1142
|
+
const consequent = attemptEval(obj);
|
|
610
1143
|
return createTernary({
|
|
611
1144
|
remove() {},
|
|
612
1145
|
...ternaryPartial,
|
|
@@ -617,271 +1150,458 @@ function createExtractor({
|
|
|
617
1150
|
});
|
|
618
1151
|
},
|
|
619
1152
|
mergeToEnd = function (obj, key, val) {
|
|
620
|
-
key in obj
|
|
1153
|
+
if (key in obj) {
|
|
1154
|
+
delete obj[key];
|
|
1155
|
+
}
|
|
1156
|
+
obj[key] = val;
|
|
621
1157
|
},
|
|
622
1158
|
normalizeStyleWithoutVariants = function (style) {
|
|
623
1159
|
let res2 = {};
|
|
624
|
-
for (const key in style)
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
}
|
|
628
|
-
|
|
1160
|
+
for (const key in style) {
|
|
1161
|
+
if (staticConfig.variants && key in staticConfig.variants) {
|
|
1162
|
+
mergeToEnd(res2, key, style[key]);
|
|
1163
|
+
} else {
|
|
1164
|
+
const expanded = normalizeStyle({
|
|
1165
|
+
[key]: style[key]
|
|
1166
|
+
}, true);
|
|
1167
|
+
for (const key2 in expanded) {
|
|
1168
|
+
mergeToEnd(res2, key2, expanded[key2]);
|
|
1169
|
+
}
|
|
1170
|
+
}
|
|
629
1171
|
}
|
|
630
1172
|
return res2;
|
|
631
1173
|
},
|
|
632
1174
|
mergeStyles = function (prev2, next) {
|
|
633
|
-
for (const key in next)
|
|
1175
|
+
for (const key in next) {
|
|
1176
|
+
if (pseudoDescriptors[key]) {
|
|
1177
|
+
prev2[key] = prev2[key] || {};
|
|
1178
|
+
Object.assign(prev2[key], next[key]);
|
|
1179
|
+
} else {
|
|
1180
|
+
mergeToEnd(prev2, key, next[key]);
|
|
1181
|
+
}
|
|
1182
|
+
}
|
|
634
1183
|
};
|
|
635
1184
|
const {
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
if (process.env.NODE_ENV === "production" && isTextView) return;
|
|
1185
|
+
staticConfig
|
|
1186
|
+
} = component;
|
|
1187
|
+
const defaultProps = {
|
|
1188
|
+
...getDefaultProps(staticConfig)
|
|
1189
|
+
};
|
|
1190
|
+
const variants = staticConfig.variants || {};
|
|
1191
|
+
const isTextView = staticConfig.isText || false;
|
|
1192
|
+
const validStyles = staticConfig?.validStyles ?? {};
|
|
645
1193
|
let tagName = defaultProps.render ?? (isTextView ? "span" : "div");
|
|
646
1194
|
traversePath.get("openingElement").get("attributes").forEach(path => {
|
|
647
1195
|
const attr = path.node;
|
|
648
|
-
if (t.isJSXSpreadAttribute(attr)
|
|
1196
|
+
if (t.isJSXSpreadAttribute(attr)) return;
|
|
1197
|
+
if (attr.name.name !== "render") return;
|
|
649
1198
|
const val = attr.value;
|
|
650
|
-
t.isStringLiteral(val)
|
|
651
|
-
|
|
1199
|
+
if (!t.isStringLiteral(val)) return;
|
|
1200
|
+
tagName = val.value;
|
|
1201
|
+
});
|
|
1202
|
+
if (shouldPrintDebug === "verbose") {
|
|
1203
|
+
console.info(` Start tag ${tagName}`);
|
|
1204
|
+
}
|
|
652
1205
|
const flatNodeName = getFlattenedNode?.({
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
if (shouldPrintDebug
|
|
1206
|
+
isTextView,
|
|
1207
|
+
tag: tagName
|
|
1208
|
+
});
|
|
1209
|
+
const inlineProps = /* @__PURE__ */new Set([
|
|
1210
|
+
// adding some always inline props
|
|
1211
|
+
...(restProps.inlineProps || []), ...(staticConfig.inlineProps || [])]);
|
|
1212
|
+
const deoptProps = /* @__PURE__ */new Set([
|
|
1213
|
+
// always de-opt animation these
|
|
1214
|
+
"animation", "animateOnly", "animatePresence", "disableOptimization", ...(!isTargetingHTML ? ["pressStyle", "focusStyle", "focusVisibleStyle", "focusWithinStyle", "disabledStyle"] : []),
|
|
1215
|
+
// when using a non-CSS driver, de-opt on enterStyle/exitStyle
|
|
1216
|
+
...(tamaguiConfig?.animations.isReactNative ? ["enterStyle", "exitStyle"] : [])]);
|
|
1217
|
+
const inlineWhenUnflattened = new Set(staticConfig.inlineWhenUnflattened || []);
|
|
1218
|
+
const staticNamespace = (0, import_getStaticBindingsForScope.getStaticBindingsForScope)(traversePath.scope, importsWhitelist, sourcePath, bindingCache, shouldPrintDebug);
|
|
1219
|
+
const attemptEval = !evaluateVars ? import_evaluateAstNode.evaluateAstNode : (0, import_createEvaluator.createEvaluator)({
|
|
1220
|
+
props: propsWithFileInfo,
|
|
1221
|
+
staticNamespace,
|
|
1222
|
+
sourcePath,
|
|
1223
|
+
traversePath,
|
|
1224
|
+
shouldPrintDebug
|
|
1225
|
+
});
|
|
1226
|
+
const attemptEvalSafe = (0, import_createEvaluator.createSafeEvaluator)(attemptEval);
|
|
1227
|
+
if (shouldPrintDebug) {
|
|
1228
|
+
logger.info(` staticNamespace ${Object.keys(staticNamespace).join(", ")}`);
|
|
1229
|
+
}
|
|
1230
|
+
if (couldntParse) {
|
|
1231
|
+
return;
|
|
1232
|
+
}
|
|
675
1233
|
tm.mark("jsx-element-flattened", !!shouldPrintDebug);
|
|
676
|
-
let attrs = []
|
|
677
|
-
|
|
678
|
-
const inlined = /* @__PURE__ */new Map()
|
|
679
|
-
|
|
680
|
-
let hasSetOptimized =
|
|
681
|
-
const inlineWhenUnflattenedOGVals = {}
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
if (
|
|
1234
|
+
let attrs = [];
|
|
1235
|
+
let shouldDeopt = false;
|
|
1236
|
+
const inlined = /* @__PURE__ */new Map();
|
|
1237
|
+
const variantValues = /* @__PURE__ */new Map();
|
|
1238
|
+
let hasSetOptimized = false;
|
|
1239
|
+
const inlineWhenUnflattenedOGVals = {};
|
|
1240
|
+
const propMapperStyleState = {
|
|
1241
|
+
staticConfig,
|
|
1242
|
+
usedKeys: {},
|
|
1243
|
+
classNames: {},
|
|
1244
|
+
style: {},
|
|
1245
|
+
theme: defaultTheme,
|
|
1246
|
+
viewProps: defaultProps,
|
|
1247
|
+
conf: tamaguiConfig,
|
|
1248
|
+
props: defaultProps,
|
|
1249
|
+
componentState,
|
|
1250
|
+
styleProps: {
|
|
1251
|
+
...styleProps,
|
|
1252
|
+
resolveValues: "auto"
|
|
1253
|
+
},
|
|
1254
|
+
debug: shouldPrintDebug
|
|
1255
|
+
};
|
|
1256
|
+
attrs = traversePath.get("openingElement").get("attributes").flatMap(path => {
|
|
1257
|
+
if (shouldDeopt) {
|
|
1258
|
+
return;
|
|
1259
|
+
}
|
|
1260
|
+
try {
|
|
700
1261
|
const res2 = evaluateAttribute(path);
|
|
701
|
-
|
|
1262
|
+
if (!res2) {
|
|
1263
|
+
path.remove();
|
|
1264
|
+
}
|
|
1265
|
+
return res2;
|
|
702
1266
|
} catch (err) {
|
|
703
|
-
|
|
1267
|
+
if (shouldPrintDebug) {
|
|
1268
|
+
logger.info(["Recoverable error extracting attribute", err.message, shouldPrintDebug === "verbose" ? err.stack : ""].join(" "));
|
|
1269
|
+
if (shouldPrintDebug === "verbose") {
|
|
1270
|
+
logger.info(`node ${path.node?.type}`);
|
|
1271
|
+
}
|
|
1272
|
+
}
|
|
1273
|
+
inlined.set(`${Math.random()}`, "spread");
|
|
1274
|
+
return {
|
|
704
1275
|
type: "attr",
|
|
705
1276
|
value: path.node
|
|
706
1277
|
};
|
|
707
1278
|
}
|
|
708
|
-
}).flat(4).filter(import_extractHelpers.isPresent)
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
1279
|
+
}).flat(4).filter(import_extractHelpers.isPresent);
|
|
1280
|
+
if (shouldPrintDebug) {
|
|
1281
|
+
logger.info([" - attrs (before):\n", (0, import_logLines.logLines)(attrs.map(import_extractHelpers.attrStr).join(", "))].join(" "));
|
|
1282
|
+
}
|
|
1283
|
+
if (couldntParse || shouldDeopt) {
|
|
1284
|
+
if (shouldPrintDebug) {
|
|
1285
|
+
logger.info([` avoid optimizing:`, {
|
|
1286
|
+
couldntParse,
|
|
1287
|
+
shouldDeopt
|
|
1288
|
+
}].join(" "));
|
|
1289
|
+
}
|
|
1290
|
+
node.attributes = ogAttributes;
|
|
714
1291
|
return;
|
|
715
1292
|
}
|
|
716
1293
|
const parentFn = (0, import_findTopmostFunction.findTopmostFunction)(traversePath);
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
1294
|
+
if (parentFn) {
|
|
1295
|
+
modifiedComponents.add(parentFn);
|
|
1296
|
+
}
|
|
1297
|
+
const hasSpread = attrs.some(x => x.type === "attr" && t.isJSXSpreadAttribute(x.value));
|
|
1298
|
+
const hasOnlyStringChildren = !hasSpread && (node.selfClosing || traversePath.node.children && traversePath.node.children.every(x => x.type === "JSXText"));
|
|
720
1299
|
let themeVal = inlined.get("theme");
|
|
721
|
-
platform2 !== "native"
|
|
1300
|
+
if (platform2 !== "native") {
|
|
1301
|
+
inlined.delete("theme");
|
|
1302
|
+
}
|
|
722
1303
|
for (const [key] of inlined) {
|
|
723
1304
|
const isStaticObjectVariant = staticConfig.variants?.[key] && variantValues.has(key);
|
|
724
|
-
(INLINE_EXTRACTABLE[key] || isStaticObjectVariant)
|
|
1305
|
+
if (INLINE_EXTRACTABLE[key] || isStaticObjectVariant) {
|
|
1306
|
+
inlined.delete(key);
|
|
1307
|
+
}
|
|
725
1308
|
}
|
|
726
1309
|
const canFlattenProps = inlined.size === 0;
|
|
727
|
-
let shouldFlatten =
|
|
1310
|
+
let shouldFlatten = Boolean(flatNodeName && !shouldDeopt && canFlattenProps && !hasSpread && !staticConfig.isStyledHOC && !staticConfig.isHOC && !staticConfig.isReactNative && staticConfig.neverFlatten !== true && (staticConfig.neverFlatten === "jsx" ? hasOnlyStringChildren : true));
|
|
728
1311
|
const usedThemeKeys = /* @__PURE__ */new Set();
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
1312
|
+
themeAccessListeners.add(key => {
|
|
1313
|
+
if (disableExtractVariables) {
|
|
1314
|
+
usedThemeKeys.add(key);
|
|
1315
|
+
shouldFlatten = false;
|
|
1316
|
+
if (shouldPrintDebug === "verbose") {
|
|
1317
|
+
logger.info([" ! accessing theme key, avoid flatten", key].join(" "));
|
|
1318
|
+
}
|
|
1319
|
+
}
|
|
1320
|
+
});
|
|
1321
|
+
if (!shouldFlatten) {
|
|
1322
|
+
if (shouldPrintDebug) {
|
|
1323
|
+
logger.info(`Deopting ${JSON.stringify({
|
|
1324
|
+
shouldFlatten,
|
|
1325
|
+
shouldDeopt,
|
|
1326
|
+
canFlattenProps,
|
|
1327
|
+
hasSpread,
|
|
1328
|
+
neverFlatten: staticConfig.neverFlatten
|
|
1329
|
+
})}`);
|
|
1330
|
+
}
|
|
1331
|
+
node.attributes = ogAttributes;
|
|
739
1332
|
return;
|
|
740
1333
|
}
|
|
741
|
-
let skipMap =
|
|
1334
|
+
let skipMap = false;
|
|
742
1335
|
const defaultStyleAttrs = Object.keys(defaultProps).flatMap(key => {
|
|
743
1336
|
if (skipMap) return [];
|
|
744
1337
|
const value = defaultProps[key];
|
|
745
|
-
if (key === "theme" && !themeVal)
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
1338
|
+
if (key === "theme" && !themeVal) {
|
|
1339
|
+
if (platform2 === "native") {
|
|
1340
|
+
shouldFlatten = false;
|
|
1341
|
+
skipMap = true;
|
|
1342
|
+
inlined.set("theme", {
|
|
1343
|
+
value: t.stringLiteral(value)
|
|
1344
|
+
});
|
|
1345
|
+
}
|
|
1346
|
+
themeVal = {
|
|
1347
|
+
value: t.stringLiteral(value)
|
|
1348
|
+
};
|
|
1349
|
+
return [];
|
|
1350
|
+
}
|
|
1351
|
+
if (!isValidStyleKey(key, staticConfig)) {
|
|
1352
|
+
return [];
|
|
1353
|
+
}
|
|
751
1354
|
const name = tamaguiConfig?.shorthands[key] || key;
|
|
752
1355
|
if (value === void 0) {
|
|
753
|
-
logger.warn(`\u26A0\uFE0F Error evaluating default style for component, prop ${key} ${value}`)
|
|
1356
|
+
logger.warn(`\u26A0\uFE0F Error evaluating default style for component, prop ${key} ${value}`);
|
|
1357
|
+
shouldDeopt = true;
|
|
754
1358
|
return;
|
|
755
1359
|
}
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
1360
|
+
if (name[0] === "$" && mediaQueryConfig[name.slice(1)]) {
|
|
1361
|
+
defaultProps[key] = void 0;
|
|
1362
|
+
return evaluateAttribute({
|
|
1363
|
+
node: t.jsxAttribute(t.jsxIdentifier(name), t.jsxExpressionContainer(t.objectExpression(Object.keys(value).filter(k => {
|
|
1364
|
+
return typeof value[k] !== "undefined";
|
|
1365
|
+
}).map(k => {
|
|
1366
|
+
return t.objectProperty(t.identifier(k), (0, import_literalToAst.literalToAst)(value[k]));
|
|
1367
|
+
}))))
|
|
1368
|
+
});
|
|
1369
|
+
}
|
|
1370
|
+
const attr = {
|
|
759
1371
|
type: "style",
|
|
760
1372
|
name,
|
|
761
1373
|
value: {
|
|
762
1374
|
[name]: value
|
|
763
1375
|
}
|
|
764
1376
|
};
|
|
1377
|
+
return attr;
|
|
765
1378
|
});
|
|
766
|
-
|
|
1379
|
+
if (!skipMap) {
|
|
1380
|
+
if (defaultStyleAttrs.length) {
|
|
1381
|
+
attrs = [...defaultStyleAttrs, ...attrs];
|
|
1382
|
+
}
|
|
1383
|
+
}
|
|
767
1384
|
let ternaries = [];
|
|
768
1385
|
attrs = attrs.reduce((out, cur) => {
|
|
769
1386
|
const next = attrs[attrs.indexOf(cur) + 1];
|
|
770
|
-
if (cur.type === "ternary"
|
|
1387
|
+
if (cur.type === "ternary") {
|
|
1388
|
+
ternaries.push(cur.value);
|
|
1389
|
+
}
|
|
1390
|
+
if ((!next || next.type !== "ternary") && ternaries.length) {
|
|
771
1391
|
const normalized = (0, import_normalizeTernaries.normalizeTernaries)(ternaries).map(({
|
|
772
1392
|
alternate,
|
|
773
1393
|
consequent,
|
|
774
1394
|
...rest
|
|
775
|
-
}) =>
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
1395
|
+
}) => {
|
|
1396
|
+
return {
|
|
1397
|
+
type: "ternary",
|
|
1398
|
+
value: {
|
|
1399
|
+
...rest,
|
|
1400
|
+
alternate: alternate || null,
|
|
1401
|
+
consequent: consequent || null
|
|
1402
|
+
}
|
|
1403
|
+
};
|
|
1404
|
+
});
|
|
783
1405
|
try {
|
|
784
1406
|
return [...out, ...normalized];
|
|
785
1407
|
} finally {
|
|
786
|
-
|
|
1408
|
+
if (shouldPrintDebug) {
|
|
1409
|
+
logger.info(` normalizeTernaries (${ternaries.length} => ${normalized.length})`);
|
|
1410
|
+
}
|
|
1411
|
+
ternaries = [];
|
|
1412
|
+
}
|
|
1413
|
+
}
|
|
1414
|
+
if (cur.type === "ternary") {
|
|
1415
|
+
return out;
|
|
1416
|
+
}
|
|
1417
|
+
out.push(cur);
|
|
1418
|
+
return out;
|
|
1419
|
+
}, []).flat();
|
|
1420
|
+
if (themeVal) {
|
|
1421
|
+
if (!programPath) {
|
|
1422
|
+
console.warn(`No program path found, avoiding importing flattening / importing theme in ${sourcePath}`);
|
|
1423
|
+
} else {
|
|
1424
|
+
if (shouldPrintDebug) {
|
|
1425
|
+
logger.info([" - wrapping theme", themeVal].join(" "));
|
|
1426
|
+
}
|
|
1427
|
+
attrs = attrs.filter(x => !(x.type === "attr" && t.isJSXAttribute(x.value) && x.value.name.name === "theme"));
|
|
1428
|
+
if (!hasImportedTheme) {
|
|
1429
|
+
hasImportedTheme = true;
|
|
1430
|
+
programPath.node.body.push(t.importDeclaration([t.importSpecifier(t.identifier("_TamaguiTheme"), t.identifier("Theme"))], t.stringLiteral("@tamagui/web")));
|
|
787
1431
|
}
|
|
1432
|
+
traversePath.replaceWith(t.jsxElement(t.jsxOpeningElement(t.jsxIdentifier("_TamaguiTheme"), [t.jsxAttribute(t.jsxIdentifier("name"), themeVal.value)]), t.jsxClosingElement(t.jsxIdentifier("_TamaguiTheme")), [traversePath.node]));
|
|
788
1433
|
}
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
1434
|
+
}
|
|
1435
|
+
if (shouldPrintDebug) {
|
|
1436
|
+
logger.info([" - attrs (flattened): \n", (0, import_logLines.logLines)(attrs.map(import_extractHelpers.attrStr).join(", "))].join(" "));
|
|
1437
|
+
}
|
|
792
1438
|
let foundStaticProps = {};
|
|
793
1439
|
for (const key in attrs) {
|
|
794
1440
|
const cur = attrs[key];
|
|
795
1441
|
if (cur.type === "style") {
|
|
796
1442
|
const expanded = normalizeStyleWithoutVariants(cur.value);
|
|
797
|
-
for (const key2 in expanded)
|
|
1443
|
+
for (const key2 in expanded) {
|
|
1444
|
+
mergeToEnd(foundStaticProps, key2, expanded[key2]);
|
|
1445
|
+
}
|
|
798
1446
|
continue;
|
|
799
1447
|
}
|
|
800
1448
|
if (cur.type === "attr") {
|
|
801
|
-
if (t.isJSXSpreadAttribute(cur.value)
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
1449
|
+
if (t.isJSXSpreadAttribute(cur.value)) {
|
|
1450
|
+
continue;
|
|
1451
|
+
}
|
|
1452
|
+
if (!t.isJSXIdentifier(cur.value.name)) {
|
|
1453
|
+
continue;
|
|
1454
|
+
}
|
|
1455
|
+
const key2 = cur.value.name.name;
|
|
1456
|
+
const value = attemptEvalSafe(cur.value.value || t.booleanLiteral(true));
|
|
1457
|
+
if (value !== import_constants.FAILED_EVAL) {
|
|
1458
|
+
mergeToEnd(foundStaticProps, key2, value);
|
|
1459
|
+
}
|
|
805
1460
|
}
|
|
806
1461
|
}
|
|
807
1462
|
const completeProps = {};
|
|
808
|
-
for (const key in defaultProps)
|
|
809
|
-
|
|
1463
|
+
for (const key in defaultProps) {
|
|
1464
|
+
if (!(key in foundStaticProps)) {
|
|
1465
|
+
completeProps[key] = defaultProps[key];
|
|
1466
|
+
}
|
|
1467
|
+
}
|
|
1468
|
+
for (const key in foundStaticProps) {
|
|
1469
|
+
completeProps[key] = foundStaticProps[key];
|
|
1470
|
+
}
|
|
810
1471
|
attrs = attrs.reduce((acc, cur) => {
|
|
811
1472
|
if (!cur) return acc;
|
|
812
|
-
if (cur.type === "attr" && !t.isJSXSpreadAttribute(cur.value)
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
if (name === "
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
...propMapperStyleState,
|
|
819
|
-
props: completeProps
|
|
820
|
-
};
|
|
821
|
-
let out = {};
|
|
822
|
-
if (propMapper(name, variantValues.get(name), styleState, !1, (key2, val) => {
|
|
823
|
-
out[key2] = val;
|
|
824
|
-
}), out && isTargetingHTML) {
|
|
825
|
-
const cn = out.className;
|
|
826
|
-
out = reactNativeWebInternals.createDOMProps(isTextView ? "span" : "div", out), out.className = cn;
|
|
1473
|
+
if (cur.type === "attr" && !t.isJSXSpreadAttribute(cur.value)) {
|
|
1474
|
+
if (shouldFlatten) {
|
|
1475
|
+
const name = cur.value.name.name;
|
|
1476
|
+
if (typeof name === "string") {
|
|
1477
|
+
if (name === "render") {
|
|
1478
|
+
return acc;
|
|
827
1479
|
}
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
name: key2,
|
|
837
|
-
attr: cur.value
|
|
838
|
-
}) : acc.push({
|
|
839
|
-
type: "attr",
|
|
840
|
-
value: t.jsxAttribute(t.jsxIdentifier(key2), t.jsxExpressionContainer(typeof value2 == "string" ? t.stringLiteral(value2) : (0, import_literalToAst.literalToAst)(value2)))
|
|
1480
|
+
if (variants[name] && variantValues.has(name)) {
|
|
1481
|
+
const styleState = {
|
|
1482
|
+
...propMapperStyleState,
|
|
1483
|
+
props: completeProps
|
|
1484
|
+
};
|
|
1485
|
+
let out = {};
|
|
1486
|
+
propMapper(name, variantValues.get(name), styleState, false, (key2, val) => {
|
|
1487
|
+
out[key2] = val;
|
|
841
1488
|
});
|
|
1489
|
+
if (out && isTargetingHTML) {
|
|
1490
|
+
const cn = out.className;
|
|
1491
|
+
out = reactNativeWebInternals.createDOMProps(isTextView ? "span" : "div", out);
|
|
1492
|
+
out.className = cn;
|
|
1493
|
+
delete out.style;
|
|
1494
|
+
}
|
|
1495
|
+
if (shouldPrintDebug) {
|
|
1496
|
+
logger.info([" - expanded variant", name, out].join(" "));
|
|
1497
|
+
}
|
|
1498
|
+
for (const key2 in out) {
|
|
1499
|
+
const value2 = out[key2];
|
|
1500
|
+
if (isValidStyleKey(key2, staticConfig)) {
|
|
1501
|
+
acc.push({
|
|
1502
|
+
type: "style",
|
|
1503
|
+
value: {
|
|
1504
|
+
[key2]: value2
|
|
1505
|
+
},
|
|
1506
|
+
name: key2,
|
|
1507
|
+
attr: cur.value
|
|
1508
|
+
});
|
|
1509
|
+
} else {
|
|
1510
|
+
acc.push({
|
|
1511
|
+
type: "attr",
|
|
1512
|
+
value: t.jsxAttribute(t.jsxIdentifier(key2), t.jsxExpressionContainer(typeof value2 === "string" ? t.stringLiteral(value2) : (0, import_literalToAst.literalToAst)(value2)))
|
|
1513
|
+
});
|
|
1514
|
+
}
|
|
1515
|
+
}
|
|
842
1516
|
}
|
|
843
1517
|
}
|
|
844
1518
|
}
|
|
845
1519
|
}
|
|
846
|
-
if (cur.type !== "style")
|
|
1520
|
+
if (cur.type !== "style") {
|
|
1521
|
+
acc.push(cur);
|
|
1522
|
+
return acc;
|
|
1523
|
+
}
|
|
847
1524
|
let key = Object.keys(cur.value)[0];
|
|
848
|
-
const value = cur.value[key]
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
}
|
|
856
|
-
|
|
857
|
-
|
|
1525
|
+
const value = cur.value[key];
|
|
1526
|
+
const fullKey = tamaguiConfig?.shorthands[key];
|
|
1527
|
+
if (fullKey) {
|
|
1528
|
+
cur.value = {
|
|
1529
|
+
[fullKey]: value
|
|
1530
|
+
};
|
|
1531
|
+
key = fullKey;
|
|
1532
|
+
}
|
|
1533
|
+
if (disableExtractVariables) {
|
|
1534
|
+
if (value[0] === "$" && (usedThemeKeys.has(key) || usedThemeKeys.has(fullKey))) {
|
|
1535
|
+
if (shouldPrintDebug) {
|
|
1536
|
+
logger.info([` keeping variable inline: ${key} =`, value].join(" "));
|
|
1537
|
+
}
|
|
1538
|
+
acc.push({
|
|
1539
|
+
type: "attr",
|
|
1540
|
+
value: t.jsxAttribute(t.jsxIdentifier(key), t.jsxExpressionContainer(t.stringLiteral(value)))
|
|
1541
|
+
});
|
|
1542
|
+
return acc;
|
|
1543
|
+
}
|
|
1544
|
+
}
|
|
1545
|
+
acc.push(cur);
|
|
1546
|
+
return acc;
|
|
1547
|
+
}, []);
|
|
1548
|
+
tm.mark("jsx-element-expanded", !!shouldPrintDebug);
|
|
1549
|
+
if (shouldPrintDebug) {
|
|
1550
|
+
logger.info([" - attrs (expanded): \n", (0, import_logLines.logLines)(attrs.map(import_extractHelpers.attrStr).join(", "))].join(" "));
|
|
1551
|
+
}
|
|
858
1552
|
let prev = null;
|
|
859
|
-
const getProps = (props, includeProps =
|
|
860
|
-
if (!props)
|
|
861
|
-
|
|
1553
|
+
const getProps = (props, includeProps = false, debugName = "") => {
|
|
1554
|
+
if (!props) {
|
|
1555
|
+
if (shouldPrintDebug) logger.info([" getProps() no props"].join(" "));
|
|
1556
|
+
return {};
|
|
1557
|
+
}
|
|
1558
|
+
if (excludeProps?.size) {
|
|
1559
|
+
for (const key in props) {
|
|
1560
|
+
if (excludeProps.has(key)) {
|
|
1561
|
+
if (shouldPrintDebug) logger.info([" delete excluded", key].join(" "));
|
|
1562
|
+
delete props[key];
|
|
1563
|
+
}
|
|
1564
|
+
}
|
|
1565
|
+
}
|
|
862
1566
|
const before = process.env.IS_STATIC;
|
|
863
1567
|
process.env.IS_STATIC = "is_static";
|
|
864
1568
|
try {
|
|
865
1569
|
const out = getSplitStyles(props, staticConfig, defaultTheme, "", componentState, {
|
|
866
1570
|
...styleProps,
|
|
867
|
-
noClass:
|
|
1571
|
+
noClass: true,
|
|
868
1572
|
fallbackProps: completeProps,
|
|
869
1573
|
...(platform2 === "native" && {
|
|
870
1574
|
resolveValues: "except-theme"
|
|
871
1575
|
})
|
|
872
|
-
}, void 0, void 0, void 0, void 0,
|
|
1576
|
+
}, void 0, void 0, void 0, void 0, false, debugPropValue || shouldPrintDebug);
|
|
873
1577
|
let outProps = {
|
|
874
1578
|
...(includeProps ? out.viewProps : {}),
|
|
875
1579
|
...out.style,
|
|
876
1580
|
...out.pseudos
|
|
877
1581
|
};
|
|
878
|
-
for (const key in outProps)
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
1582
|
+
for (const key in outProps) {
|
|
1583
|
+
if (deoptProps.has(key)) {
|
|
1584
|
+
shouldFlatten = false;
|
|
1585
|
+
}
|
|
1586
|
+
}
|
|
1587
|
+
if (shouldPrintDebug) {
|
|
1588
|
+
logger.info(`(${debugName})`);
|
|
1589
|
+
logger.info(`
|
|
1590
|
+
getProps (props in): ${(0, import_logLines.logLines)((0, import_extractHelpers.objToStr)(props))}`);
|
|
1591
|
+
logger.info(`
|
|
1592
|
+
getProps (outProps): ${(0, import_logLines.logLines)((0, import_extractHelpers.objToStr)(outProps))}`);
|
|
1593
|
+
}
|
|
1594
|
+
if (out.fontFamily) {
|
|
1595
|
+
(0, import_propsToFontFamilyCache.setPropsToFontFamily)(outProps, out.fontFamily);
|
|
1596
|
+
if (shouldPrintDebug) {
|
|
1597
|
+
logger.info(`
|
|
1598
|
+
\u{1F4AC} new font fam: ${out.fontFamily}`);
|
|
1599
|
+
}
|
|
1600
|
+
}
|
|
1601
|
+
return outProps;
|
|
883
1602
|
} catch (err) {
|
|
884
|
-
|
|
1603
|
+
logger.info(["error", err.message, err.stack].join(" "));
|
|
1604
|
+
return {};
|
|
885
1605
|
} finally {
|
|
886
1606
|
process.env.IS_STATIC = before;
|
|
887
1607
|
}
|
|
@@ -889,92 +1609,183 @@ function createExtractor({
|
|
|
889
1609
|
attrs.unshift({
|
|
890
1610
|
type: "style",
|
|
891
1611
|
value: defaultProps
|
|
892
|
-
})
|
|
1612
|
+
});
|
|
1613
|
+
attrs = attrs.reduce((acc, cur) => {
|
|
893
1614
|
if (cur.type === "style") {
|
|
894
1615
|
const keys = Object.keys(cur.value || {});
|
|
895
|
-
if (!keys.length)
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
1616
|
+
if (!keys.length) {
|
|
1617
|
+
return acc;
|
|
1618
|
+
}
|
|
1619
|
+
const key = keys[0];
|
|
1620
|
+
const value = cur.value[key];
|
|
1621
|
+
const isMediaLikeKey = key[0] === "$" && (key.startsWith("$theme-") || key.startsWith("$platform-") || key.startsWith("$group-") || mediaQueryConfig[key.slice(1)]);
|
|
1622
|
+
const shouldKeepOriginalAttr =
|
|
900
1623
|
// !isStyleAndAttr[key] &&
|
|
901
1624
|
!shouldFlatten &&
|
|
902
1625
|
// de-opt if non-style
|
|
903
|
-
!validStyles[key] && !pseudoDescriptors[key] && !isMediaLikeKey && !(key.startsWith("data-") || key.startsWith("aria-"))
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
1626
|
+
!validStyles[key] && !pseudoDescriptors[key] && !isMediaLikeKey && !(key.startsWith("data-") || key.startsWith("aria-"));
|
|
1627
|
+
if (shouldKeepOriginalAttr) {
|
|
1628
|
+
if (shouldPrintDebug) {
|
|
1629
|
+
logger.info([" - keeping as non-style", key].join(" "));
|
|
1630
|
+
}
|
|
1631
|
+
prev = cur;
|
|
1632
|
+
acc.push({
|
|
1633
|
+
type: "attr",
|
|
1634
|
+
value: t.jsxAttribute(t.jsxIdentifier(key), t.jsxExpressionContainer(typeof value === "string" ? t.stringLiteral(value) : (0, import_literalToAst.literalToAst)(value)))
|
|
1635
|
+
});
|
|
1636
|
+
acc.push(cur);
|
|
1637
|
+
return acc;
|
|
1638
|
+
}
|
|
1639
|
+
if (prev?.type === "style") {
|
|
1640
|
+
mergeStyles(prev.value, cur.value);
|
|
1641
|
+
return acc;
|
|
1642
|
+
}
|
|
908
1643
|
}
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
1644
|
+
if (cur.type === "style") {
|
|
1645
|
+
prev = cur;
|
|
1646
|
+
}
|
|
1647
|
+
acc.push(cur);
|
|
1648
|
+
return acc;
|
|
1649
|
+
}, []);
|
|
1650
|
+
if (shouldPrintDebug) {
|
|
1651
|
+
logger.info([" - attrs (combined \u{1F500}): \n", (0, import_logLines.logLines)(attrs.map(import_extractHelpers.attrStr).join(", "))].join(" "));
|
|
1652
|
+
}
|
|
912
1653
|
let getStyleError = null;
|
|
913
|
-
for (const attr of attrs)
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
{
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
if (value !== import_constants.FAILED_EVAL) {
|
|
934
|
-
const outProps = getProps({
|
|
935
|
-
[key]: value
|
|
936
|
-
}, !0, `attr.${key}`),
|
|
937
|
-
outKey = Object.keys(outProps)[0];
|
|
938
|
-
if (outKey) {
|
|
939
|
-
const outVal = outProps[outKey];
|
|
940
|
-
attr.value = t.jsxAttribute(t.jsxIdentifier(outKey), t.jsxExpressionContainer(typeof outVal == "string" ? t.stringLiteral(outVal) : (0, import_literalToAst.literalToAst)(outVal)));
|
|
1654
|
+
for (const attr of attrs) {
|
|
1655
|
+
try {
|
|
1656
|
+
if (shouldPrintDebug) {
|
|
1657
|
+
console.info(` Processing ${attr.type}:`);
|
|
1658
|
+
}
|
|
1659
|
+
switch (attr.type) {
|
|
1660
|
+
case "ternary":
|
|
1661
|
+
{
|
|
1662
|
+
const a = getProps(attr.value.alternate, false, "ternary.alternate");
|
|
1663
|
+
const c = getProps(attr.value.consequent, false, "ternary.consequent");
|
|
1664
|
+
if (a) attr.value.alternate = a;
|
|
1665
|
+
if (c) attr.value.consequent = c;
|
|
1666
|
+
if (shouldPrintDebug) logger.info([" => tern ", (0, import_extractHelpers.attrStr)(attr)].join(" "));
|
|
1667
|
+
continue;
|
|
1668
|
+
}
|
|
1669
|
+
case "style":
|
|
1670
|
+
{
|
|
1671
|
+
const styles = getProps(attr.value, false, "style");
|
|
1672
|
+
if (styles) {
|
|
1673
|
+
attr.value = styles;
|
|
941
1674
|
}
|
|
1675
|
+
if (shouldPrintDebug) logger.info([" * styles (in)", (0, import_logLines.logLines)((0, import_extractHelpers.objToStr)(attr.value))].join(" "));
|
|
1676
|
+
if (shouldPrintDebug) logger.info([" * styles (out)", (0, import_logLines.logLines)((0, import_extractHelpers.objToStr)(styles))].join(" "));
|
|
1677
|
+
continue;
|
|
942
1678
|
}
|
|
943
|
-
|
|
1679
|
+
case "attr":
|
|
1680
|
+
{
|
|
1681
|
+
if (shouldFlatten && t.isJSXAttribute(attr.value)) {
|
|
1682
|
+
const key = attr.value.name.name;
|
|
1683
|
+
if (key === "style" || key === "className" || key === "render") {
|
|
1684
|
+
continue;
|
|
1685
|
+
}
|
|
1686
|
+
const value = attemptEvalSafe(attr.value.value || t.booleanLiteral(true));
|
|
1687
|
+
if (value !== import_constants.FAILED_EVAL) {
|
|
1688
|
+
const outProps = getProps({
|
|
1689
|
+
[key]: value
|
|
1690
|
+
}, true, `attr.${key}`);
|
|
1691
|
+
const outKey = Object.keys(outProps)[0];
|
|
1692
|
+
if (outKey) {
|
|
1693
|
+
const outVal = outProps[outKey];
|
|
1694
|
+
attr.value = t.jsxAttribute(t.jsxIdentifier(outKey), t.jsxExpressionContainer(typeof outVal === "string" ? t.stringLiteral(outVal) : (0, import_literalToAst.literalToAst)(outVal)));
|
|
1695
|
+
}
|
|
1696
|
+
}
|
|
1697
|
+
}
|
|
1698
|
+
}
|
|
1699
|
+
}
|
|
1700
|
+
} catch (err) {
|
|
1701
|
+
getStyleError = err;
|
|
944
1702
|
}
|
|
945
|
-
} catch (err) {
|
|
946
|
-
getStyleError = err;
|
|
947
1703
|
}
|
|
948
|
-
if (shouldPrintDebug
|
|
949
|
-
|
|
1704
|
+
if (shouldPrintDebug) {
|
|
1705
|
+
logger.info([" - attrs (ternaries/combined):\n", (0, import_logLines.logLines)(attrs.map(import_extractHelpers.attrStr).join(", "))].join(" "));
|
|
1706
|
+
}
|
|
1707
|
+
tm.mark("jsx-element-styles", !!shouldPrintDebug);
|
|
1708
|
+
if (getStyleError) {
|
|
1709
|
+
logger.info([" \u26A0\uFE0F postprocessing error, deopt", getStyleError].join(" "));
|
|
1710
|
+
node.attributes = ogAttributes;
|
|
1711
|
+
return null;
|
|
1712
|
+
}
|
|
950
1713
|
const existingStyleKeys = /* @__PURE__ */new Set();
|
|
951
1714
|
for (let i = attrs.length - 1; i >= 0; i--) {
|
|
952
1715
|
const attr = attrs[i];
|
|
953
|
-
if (shouldFlatten
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
}
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
1716
|
+
if (shouldFlatten) {
|
|
1717
|
+
if (attr.type === "attr") {
|
|
1718
|
+
if (t.isJSXAttribute(attr.value)) {
|
|
1719
|
+
if (t.isJSXIdentifier(attr.value.name)) {
|
|
1720
|
+
const name = attr.value.name.name;
|
|
1721
|
+
if (INLINE_EXTRACTABLE[name]) {
|
|
1722
|
+
attr.value.name.name = INLINE_EXTRACTABLE[name];
|
|
1723
|
+
}
|
|
1724
|
+
}
|
|
1725
|
+
}
|
|
1726
|
+
}
|
|
1727
|
+
}
|
|
1728
|
+
if (attr.type === "style") {
|
|
1729
|
+
for (const key in attr.value) {
|
|
1730
|
+
if (existingStyleKeys.has(key)) {
|
|
1731
|
+
if (shouldPrintDebug) {
|
|
1732
|
+
logger.info([` >> delete existing ${key}`].join(" "));
|
|
1733
|
+
}
|
|
1734
|
+
delete attr.value[key];
|
|
1735
|
+
} else {
|
|
1736
|
+
existingStyleKeys.add(key);
|
|
1737
|
+
}
|
|
1738
|
+
}
|
|
1739
|
+
}
|
|
1740
|
+
}
|
|
1741
|
+
attrs = attrs.filter(Boolean);
|
|
1742
|
+
if (!shouldFlatten) {
|
|
1743
|
+
if (inlineWhenUnflattened.size) {
|
|
1744
|
+
for (const [index, attr] of attrs.entries()) {
|
|
1745
|
+
if (attr.type === "style") {
|
|
1746
|
+
for (const key in attr.value) {
|
|
1747
|
+
if (!inlineWhenUnflattened.has(key)) continue;
|
|
1748
|
+
const val = inlineWhenUnflattenedOGVals[key];
|
|
1749
|
+
if (val) {
|
|
1750
|
+
delete attr.value[key];
|
|
1751
|
+
attrs.splice(index - 1, 0, val.attr);
|
|
1752
|
+
} else {
|
|
1753
|
+
delete attr.value[key];
|
|
1754
|
+
}
|
|
1755
|
+
}
|
|
1756
|
+
}
|
|
1757
|
+
}
|
|
1758
|
+
}
|
|
1759
|
+
}
|
|
1760
|
+
attrs = attrs.filter(x => {
|
|
1761
|
+
if (x.type === "style" && Object.keys(x.value).length === 0) {
|
|
1762
|
+
return false;
|
|
1763
|
+
}
|
|
1764
|
+
return true;
|
|
1765
|
+
});
|
|
1766
|
+
const isNativeNotFlat = !shouldFlatten && platform2 === "native";
|
|
1767
|
+
if (isNativeNotFlat) {
|
|
1768
|
+
if (shouldPrintDebug) {
|
|
1769
|
+
logger.info(`Disabled flattening except for simple cases on native for now: ${JSON.stringify({
|
|
1770
|
+
flatNode: flatNodeName,
|
|
1771
|
+
shouldDeopt,
|
|
1772
|
+
canFlattenProps,
|
|
1773
|
+
hasSpread,
|
|
1774
|
+
"staticConfig.isStyledHOC": staticConfig.isStyledHOC,
|
|
1775
|
+
"!staticConfig.isHOC": !staticConfig.isHOC,
|
|
1776
|
+
"staticConfig.isReactNative": staticConfig.isReactNative,
|
|
1777
|
+
"staticConfig.neverFlatten": staticConfig.neverFlatten
|
|
1778
|
+
}, null, 2)}`);
|
|
1779
|
+
}
|
|
1780
|
+
node.attributes = ogAttributes;
|
|
1781
|
+
return null;
|
|
1782
|
+
}
|
|
1783
|
+
if (shouldPrintDebug) {
|
|
1784
|
+
logger.info([` - inlined props (${inlined.size}):`, shouldDeopt ? " deopted" : "", hasSpread ? " has spread" : "", staticConfig.neverFlatten ? "neverFlatten" : ""].join(" "));
|
|
1785
|
+
logger.info(` - attrs (end):
|
|
1786
|
+
${(0, import_logLines.logLines)(attrs.map(import_extractHelpers.attrStr).join(", "))}`);
|
|
1787
|
+
}
|
|
1788
|
+
onExtractTag({
|
|
978
1789
|
parserProps: propsWithFileInfo,
|
|
979
1790
|
attrs,
|
|
980
1791
|
node,
|
|
@@ -988,17 +1799,37 @@ function createExtractor({
|
|
|
988
1799
|
programPath,
|
|
989
1800
|
completeProps,
|
|
990
1801
|
staticConfig
|
|
991
|
-
})
|
|
992
|
-
|
|
1802
|
+
});
|
|
1803
|
+
if (shouldFlatten) {
|
|
1804
|
+
if (shouldPrintDebug) {
|
|
1805
|
+
logger.info([" [\u2705] flattened", originalNodeName, flatNodeName].join(" "));
|
|
1806
|
+
}
|
|
993
1807
|
const currentName = node.name?.name;
|
|
994
|
-
(!currentName || currentName === originalNodeName || currentName.startsWith("__ReactNative"))
|
|
1808
|
+
if (!currentName || currentName === originalNodeName || currentName.startsWith("__ReactNative")) {
|
|
1809
|
+
node.name.name = flatNodeName;
|
|
1810
|
+
if (closingElement) {
|
|
1811
|
+
closingElement.name.name = flatNodeName;
|
|
1812
|
+
}
|
|
1813
|
+
}
|
|
1814
|
+
res.flattened++;
|
|
995
1815
|
}
|
|
996
1816
|
} catch (err) {
|
|
997
|
-
node.attributes = ogAttributes
|
|
1817
|
+
node.attributes = ogAttributes;
|
|
1818
|
+
if (!(err instanceof import_errors.BailOptimizationError)) {
|
|
1819
|
+
console.error(`@tamagui/static error, reverting optimization. In ${filePath} ${lineNumbers} on ${originalNodeName}: ${err.message}. For stack trace set environment TAMAGUI_DEBUG=1`);
|
|
1820
|
+
if (process.env.TAMAGUI_DEBUG === "1") {
|
|
1821
|
+
console.error(err.stack);
|
|
1822
|
+
}
|
|
1823
|
+
}
|
|
998
1824
|
} finally {
|
|
999
|
-
|
|
1825
|
+
if (debugPropValue) {
|
|
1826
|
+
shouldPrintDebug = ogDebug;
|
|
1827
|
+
}
|
|
1000
1828
|
}
|
|
1001
1829
|
}
|
|
1002
|
-
})
|
|
1830
|
+
});
|
|
1831
|
+
tm.mark("jsx-done", !!shouldPrintDebug);
|
|
1832
|
+
tm.done(shouldPrintDebug === "verbose");
|
|
1833
|
+
return res;
|
|
1003
1834
|
}
|
|
1004
1835
|
}
|