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