@tamagui/static 1.0.0-alpha.38 → 1.0.0-alpha.41
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 +43 -0
- package/dist/cjs/constants.js.map +7 -0
- package/dist/cjs/extractor/accessSafe.js +39 -0
- package/dist/cjs/extractor/accessSafe.js.map +7 -0
- package/dist/cjs/extractor/babelParse.js +58 -0
- package/dist/cjs/extractor/babelParse.js.map +7 -0
- package/dist/cjs/extractor/buildClassName.js +68 -0
- package/dist/cjs/extractor/buildClassName.js.map +7 -0
- package/dist/cjs/extractor/createEvaluator.js +79 -0
- package/dist/cjs/extractor/createEvaluator.js.map +7 -0
- package/dist/cjs/extractor/createExtractor.js +907 -0
- package/dist/cjs/extractor/createExtractor.js.map +7 -0
- package/dist/cjs/extractor/ensureImportingConcat.js +52 -0
- package/dist/cjs/extractor/ensureImportingConcat.js.map +7 -0
- package/dist/cjs/extractor/evaluateAstNode.js +122 -0
- package/dist/cjs/extractor/evaluateAstNode.js.map +7 -0
- package/dist/cjs/extractor/extractHelpers.js +124 -0
- package/dist/cjs/extractor/extractHelpers.js.map +7 -0
- package/dist/cjs/extractor/extractMediaStyle.js +193 -0
- package/dist/cjs/extractor/extractMediaStyle.js.map +7 -0
- package/dist/cjs/extractor/extractToClassNames.js +284 -0
- package/dist/cjs/extractor/extractToClassNames.js.map +7 -0
- package/dist/cjs/extractor/findTopmostFunction.js +46 -0
- package/dist/cjs/extractor/findTopmostFunction.js.map +7 -0
- package/dist/cjs/extractor/generatedUid.js +56 -0
- package/dist/cjs/extractor/generatedUid.js.map +7 -0
- package/dist/cjs/extractor/getPropValueFromAttributes.js +77 -0
- package/dist/cjs/extractor/getPropValueFromAttributes.js.map +7 -0
- package/dist/cjs/extractor/getSourceModule.js +97 -0
- package/dist/cjs/extractor/getSourceModule.js.map +7 -0
- package/dist/cjs/extractor/getStaticBindingsForScope.js +156 -0
- package/dist/cjs/extractor/getStaticBindingsForScope.js.map +7 -0
- package/dist/cjs/extractor/hoistClassNames.js +72 -0
- package/dist/cjs/extractor/hoistClassNames.js.map +7 -0
- package/dist/cjs/extractor/literalToAst.js +62 -0
- package/dist/cjs/extractor/literalToAst.js.map +7 -0
- package/dist/cjs/extractor/loadTamagui.js +64 -0
- package/dist/cjs/extractor/loadTamagui.js.map +7 -0
- package/dist/cjs/extractor/logLines.js +40 -0
- package/dist/cjs/extractor/logLines.js.map +7 -0
- package/dist/cjs/extractor/normalizeTernaries.js +108 -0
- package/dist/cjs/extractor/normalizeTernaries.js.map +7 -0
- package/dist/cjs/extractor/removeUnusedHooks.js +107 -0
- package/dist/cjs/extractor/removeUnusedHooks.js.map +7 -0
- package/dist/cjs/index.js +38 -0
- package/dist/cjs/index.js.map +7 -0
- package/dist/cjs/patchReactNativeWeb.js +135 -0
- package/dist/cjs/patchReactNativeWeb.js.map +7 -0
- package/dist/cjs/types.js +21 -0
- package/dist/cjs/types.js.map +7 -0
- package/dist/{constants.js → esm/constants.js} +4 -0
- package/dist/{constants.js.map → esm/constants.js.map} +3 -3
- package/dist/{extractor → esm/extractor}/accessSafe.js +0 -0
- package/dist/{extractor → esm/extractor}/accessSafe.js.map +1 -1
- package/dist/{extractor → esm/extractor}/babelParse.js +0 -0
- package/dist/{extractor → esm/extractor}/babelParse.js.map +1 -1
- package/dist/{extractor → esm/extractor}/buildClassName.js +0 -0
- package/dist/{extractor → esm/extractor}/buildClassName.js.map +1 -1
- package/dist/{extractor → esm/extractor}/createEvaluator.js +1 -1
- package/dist/esm/extractor/createEvaluator.js.map +7 -0
- package/dist/{extractor → esm/extractor}/createExtractor.js +155 -118
- package/dist/esm/extractor/createExtractor.js.map +7 -0
- package/dist/{extractor → esm/extractor}/ensureImportingConcat.js +1 -1
- package/dist/esm/extractor/ensureImportingConcat.js.map +7 -0
- package/dist/{extractor → esm/extractor}/evaluateAstNode.js +0 -0
- package/dist/{extractor → esm/extractor}/evaluateAstNode.js.map +1 -1
- package/dist/{extractor → esm/extractor}/extractHelpers.js +8 -4
- package/dist/esm/extractor/extractHelpers.js.map +7 -0
- package/dist/{extractor → esm/extractor}/extractMediaStyle.js +13 -10
- package/dist/esm/extractor/extractMediaStyle.js.map +7 -0
- package/dist/{extractor → esm/extractor}/extractToClassNames.js +28 -32
- package/dist/esm/extractor/extractToClassNames.js.map +7 -0
- package/dist/{extractor → esm/extractor}/findTopmostFunction.js +0 -0
- package/dist/{extractor → esm/extractor}/findTopmostFunction.js.map +1 -1
- package/dist/{extractor → esm/extractor}/generatedUid.js +0 -0
- package/dist/{extractor → esm/extractor}/generatedUid.js.map +1 -1
- package/dist/{extractor → esm/extractor}/getPropValueFromAttributes.js +0 -0
- package/dist/{extractor → esm/extractor}/getPropValueFromAttributes.js.map +1 -1
- package/dist/{extractor → esm/extractor}/getSourceModule.js +0 -0
- package/dist/{extractor → esm/extractor}/getSourceModule.js.map +1 -1
- package/dist/{extractor → esm/extractor}/getStaticBindingsForScope.js +0 -7
- package/dist/esm/extractor/getStaticBindingsForScope.js.map +7 -0
- package/dist/{extractor → esm/extractor}/hoistClassNames.js +0 -0
- package/dist/{extractor → esm/extractor}/hoistClassNames.js.map +1 -1
- package/dist/{extractor → esm/extractor}/literalToAst.js +0 -0
- package/dist/{extractor → esm/extractor}/literalToAst.js.map +1 -1
- package/dist/esm/extractor/loadTamagui.js +41 -0
- package/dist/esm/extractor/loadTamagui.js.map +7 -0
- package/dist/esm/extractor/logLines.js +17 -0
- package/dist/esm/extractor/logLines.js.map +7 -0
- package/dist/{extractor → esm/extractor}/normalizeTernaries.js +3 -2
- package/dist/{extractor → esm/extractor}/normalizeTernaries.js.map +2 -2
- package/dist/{extractor → esm/extractor}/removeUnusedHooks.js +5 -3
- package/dist/{extractor → esm/extractor}/removeUnusedHooks.js.map +2 -2
- package/dist/{index.js → esm/index.js} +1 -1
- package/dist/{index.js.map → esm/index.js.map} +2 -2
- package/dist/{patchReactNativeWeb.js → esm/patchReactNativeWeb.js} +30 -3
- package/dist/esm/patchReactNativeWeb.js.map +7 -0
- package/dist/{types.js → esm/types.js} +0 -0
- package/dist/{types.js.map → esm/types.js.map} +0 -0
- package/dist/jsx/constants.js +13 -0
- package/dist/jsx/extractor/accessSafe.js +10 -0
- package/dist/jsx/extractor/babelParse.js +29 -0
- package/dist/jsx/extractor/buildClassName.js +39 -0
- package/dist/jsx/extractor/createEvaluator.js +50 -0
- package/dist/jsx/extractor/createExtractor.js +844 -0
- package/dist/jsx/extractor/ensureImportingConcat.js +23 -0
- package/dist/jsx/extractor/evaluateAstNode.js +93 -0
- package/dist/jsx/extractor/extractHelpers.js +95 -0
- package/dist/jsx/extractor/extractMediaStyle.js +151 -0
- package/dist/jsx/extractor/extractToClassNames.js +240 -0
- package/dist/jsx/extractor/findTopmostFunction.js +22 -0
- package/dist/jsx/extractor/generatedUid.js +27 -0
- package/dist/jsx/extractor/getPropValueFromAttributes.js +48 -0
- package/dist/jsx/extractor/getSourceModule.js +68 -0
- package/dist/jsx/extractor/getStaticBindingsForScope.js +127 -0
- package/dist/jsx/extractor/hoistClassNames.js +43 -0
- package/dist/jsx/extractor/literalToAst.js +33 -0
- package/dist/jsx/extractor/loadTamagui.js +40 -0
- package/dist/jsx/extractor/logLines.js +16 -0
- package/dist/jsx/extractor/normalizeTernaries.js +52 -0
- package/dist/jsx/extractor/removeUnusedHooks.js +79 -0
- package/dist/jsx/index.js +13 -0
- package/dist/jsx/patchReactNativeWeb.js +106 -0
- package/dist/jsx/types.js +0 -0
- package/package.json +7 -7
- package/types/constants.d.ts +2 -0
- package/types/constants.d.ts.map +1 -0
- package/types/extractor/accessSafe.d.ts.map +1 -0
- package/types/extractor/babelParse.d.ts.map +1 -0
- package/types/extractor/buildClassName.d.ts.map +1 -0
- package/types/extractor/createEvaluator.d.ts.map +1 -0
- package/types/extractor/createExtractor.d.ts +0 -1
- package/types/extractor/createExtractor.d.ts.map +1 -0
- package/types/extractor/ensureImportingConcat.d.ts.map +1 -0
- package/types/extractor/evaluateAstNode.d.ts.map +1 -0
- package/types/extractor/extractHelpers.d.ts.map +1 -0
- package/types/extractor/extractMediaStyle.d.ts.map +1 -0
- package/types/extractor/extractToClassNames.d.ts +0 -1
- package/types/extractor/extractToClassNames.d.ts.map +1 -0
- package/types/extractor/findTopmostFunction.d.ts.map +1 -0
- package/types/extractor/generatedUid.d.ts.map +1 -0
- package/types/extractor/getPropValueFromAttributes.d.ts.map +1 -0
- package/types/extractor/getSourceModule.d.ts.map +1 -0
- package/types/extractor/getStaticBindingsForScope.d.ts.map +1 -0
- package/types/extractor/hoistClassNames.d.ts.map +1 -0
- package/types/extractor/literalToAst.d.ts.map +1 -0
- package/types/extractor/loadTamagui.d.ts.map +1 -0
- package/types/extractor/logLines.d.ts.map +1 -0
- package/types/extractor/normalizeTernaries.d.ts.map +1 -0
- package/types/extractor/removeUnusedHooks.d.ts.map +1 -0
- package/types/index.d.ts.map +1 -0
- package/types/patchReactNativeWeb.d.ts.map +1 -0
- package/types/types.d.ts.map +1 -0
- package/dist/.buildinfo +0 -1
- package/dist/extractor/createEvaluator.js.map +0 -7
- package/dist/extractor/createExtractor.js.map +0 -7
- package/dist/extractor/ensureImportingConcat.js.map +0 -7
- package/dist/extractor/extractHelpers.js.map +0 -7
- package/dist/extractor/extractMediaStyle.js.map +0 -7
- package/dist/extractor/extractToClassNames.js.map +0 -7
- package/dist/extractor/getStaticBindingsForScope.js.map +0 -7
- package/dist/forwardPropsList.js +0 -140
- package/dist/forwardPropsList.js.map +0 -7
- package/dist/index.cjs +0 -2044
- package/dist/index.cjs.map +0 -7
- package/dist/patchReactNativeWeb.js.map +0 -7
|
@@ -1,21 +1,21 @@
|
|
|
1
1
|
var __defProp = Object.defineProperty;
|
|
2
2
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
-
import { join } from "path";
|
|
4
3
|
import traverse from "@babel/traverse";
|
|
5
4
|
import * as t from "@babel/types";
|
|
6
|
-
import
|
|
7
|
-
import {
|
|
5
|
+
import { mediaQueryConfig, postProcessStyles, pseudos } from "@tamagui/core-node";
|
|
6
|
+
import { stylePropsTransform } from "@tamagui/helpers";
|
|
8
7
|
import { difference, pick } from "lodash";
|
|
8
|
+
import { FAILED_EVAL } from "../constants";
|
|
9
9
|
import { createEvaluator, createSafeEvaluator } from "./createEvaluator";
|
|
10
10
|
import { evaluateAstNode } from "./evaluateAstNode";
|
|
11
11
|
import { attrStr, findComponentName, isInsideTamagui, isPresent, objToStr } from "./extractHelpers";
|
|
12
12
|
import { findTopmostFunction } from "./findTopmostFunction";
|
|
13
13
|
import { getStaticBindingsForScope } from "./getStaticBindingsForScope";
|
|
14
14
|
import { literalToAst } from "./literalToAst";
|
|
15
|
+
import { loadTamagui } from "./loadTamagui";
|
|
16
|
+
import { logLines } from "./logLines";
|
|
15
17
|
import { normalizeTernaries } from "./normalizeTernaries";
|
|
16
18
|
import { removeUnusedHooks } from "./removeUnusedHooks";
|
|
17
|
-
const { mediaQueryConfig, postProcessStyles } = CoreNode;
|
|
18
|
-
const FAILED_EVAL = Symbol("failed_style_eval");
|
|
19
19
|
const UNTOUCHED_PROPS = {
|
|
20
20
|
key: true,
|
|
21
21
|
style: true,
|
|
@@ -27,44 +27,18 @@ const validHooks = {
|
|
|
27
27
|
useTheme: true
|
|
28
28
|
};
|
|
29
29
|
const createTernary = /* @__PURE__ */ __name((x) => x, "createTernary");
|
|
30
|
-
let loadedTamagui = null;
|
|
31
|
-
function loadTamagui(props) {
|
|
32
|
-
if (loadedTamagui) {
|
|
33
|
-
return loadedTamagui;
|
|
34
|
-
}
|
|
35
|
-
process.env.IS_STATIC = "is_static";
|
|
36
|
-
const proxyWorm = require("@dish/proxy-worm");
|
|
37
|
-
const Mod = require("module");
|
|
38
|
-
const og = Mod.prototype.require;
|
|
39
|
-
Mod.prototype.require = function(path) {
|
|
40
|
-
if (path.startsWith("react-native")) {
|
|
41
|
-
return proxyWorm;
|
|
42
|
-
}
|
|
43
|
-
return og.apply(this, arguments);
|
|
44
|
-
};
|
|
45
|
-
const tamaguiConfigExport = require(join(process.cwd(), props.config));
|
|
46
|
-
const tamaguiConfig = tamaguiConfigExport["default"] || tamaguiConfigExport;
|
|
47
|
-
const components = {};
|
|
48
|
-
for (const module of props.components) {
|
|
49
|
-
const exported = require(module);
|
|
50
|
-
Object.assign(components, exported);
|
|
51
|
-
}
|
|
52
|
-
process.env.IS_STATIC = void 0;
|
|
53
|
-
Mod.prototype.require = og;
|
|
54
|
-
return {
|
|
55
|
-
components,
|
|
56
|
-
tamaguiConfig
|
|
57
|
-
};
|
|
58
|
-
}
|
|
59
|
-
__name(loadTamagui, "loadTamagui");
|
|
60
30
|
function createExtractor() {
|
|
61
|
-
|
|
62
|
-
const shouldAddDebugProp = process.env.TARGET !== "native" && process.env.IDENTIFY_TAGS !== "false" && (process.env.NODE_ENV === "development" || process.env.DEBUG || process.env.IDENTIFY_TAGS);
|
|
31
|
+
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);
|
|
63
32
|
require("esbuild-register/dist/node").register({
|
|
64
33
|
target: "es2019",
|
|
65
34
|
format: "cjs"
|
|
66
35
|
});
|
|
36
|
+
let loadedTamaguiConfig;
|
|
37
|
+
let hasLogged = false;
|
|
67
38
|
return {
|
|
39
|
+
getTamagui() {
|
|
40
|
+
return loadedTamaguiConfig;
|
|
41
|
+
},
|
|
68
42
|
parse: (fileOrPath, {
|
|
69
43
|
config = "tamagui.config.ts",
|
|
70
44
|
importsWhitelist = ["constants.js"],
|
|
@@ -73,29 +47,42 @@ function createExtractor() {
|
|
|
73
47
|
sourcePath = "",
|
|
74
48
|
onExtractTag,
|
|
75
49
|
getFlattenedNode,
|
|
76
|
-
|
|
50
|
+
disableExtraction,
|
|
51
|
+
disableExtractInlineMedia,
|
|
52
|
+
disableExtractVariables,
|
|
53
|
+
disableDebugAttr,
|
|
77
54
|
...props
|
|
78
55
|
}) => {
|
|
79
56
|
if (sourcePath === "") {
|
|
80
57
|
throw new Error(`Must provide a source file name`);
|
|
81
58
|
}
|
|
59
|
+
if (!Array.isArray(props.components)) {
|
|
60
|
+
throw new Error(`Must provide components array with list of Tamagui component modules`);
|
|
61
|
+
}
|
|
82
62
|
const { components, tamaguiConfig } = loadTamagui({
|
|
83
63
|
config,
|
|
84
64
|
components: props.components || ["tamagui"]
|
|
85
65
|
});
|
|
86
|
-
|
|
66
|
+
loadedTamaguiConfig = tamaguiConfig;
|
|
67
|
+
const defaultTheme = tamaguiConfig.themes[Object.keys(tamaguiConfig.themes)[0]];
|
|
87
68
|
const body = fileOrPath.type === "Program" ? fileOrPath.get("body") : fileOrPath.program.body;
|
|
88
|
-
const isInternalImport = /* @__PURE__ */ __name((importStr) =>
|
|
89
|
-
|
|
69
|
+
const isInternalImport = /* @__PURE__ */ __name((importStr) => {
|
|
70
|
+
return isInsideTamagui(sourcePath) && importStr[0] === ".";
|
|
71
|
+
}, "isInternalImport");
|
|
72
|
+
const validComponents = Object.keys(components).filter((key) => {
|
|
73
|
+
var _a;
|
|
74
|
+
return key[0].toUpperCase() === key[0] && !!((_a = components[key]) == null ? void 0 : _a.staticConfig);
|
|
75
|
+
}).reduce((obj, name) => {
|
|
90
76
|
obj[name] = components[name];
|
|
91
77
|
return obj;
|
|
92
78
|
}, {});
|
|
79
|
+
let doesUseValidImport = false;
|
|
93
80
|
for (const bodyPath of body) {
|
|
94
81
|
if (bodyPath.type !== "ImportDeclaration")
|
|
95
82
|
continue;
|
|
96
83
|
const node = "node" in bodyPath ? bodyPath.node : bodyPath;
|
|
97
84
|
const from = node.source.value;
|
|
98
|
-
if (from
|
|
85
|
+
if (props.components.includes(from) || isInternalImport(from)) {
|
|
99
86
|
if (node.specifiers.some((specifier) => {
|
|
100
87
|
const name = specifier.local.name;
|
|
101
88
|
return validComponents[name] || validHooks[name];
|
|
@@ -112,12 +99,17 @@ function createExtractor() {
|
|
|
112
99
|
return null;
|
|
113
100
|
}
|
|
114
101
|
let couldntParse = false;
|
|
115
|
-
const modifiedComponents = new Set();
|
|
102
|
+
const modifiedComponents = /* @__PURE__ */ new Set();
|
|
116
103
|
const bindingCache = {};
|
|
117
104
|
const callTraverse = /* @__PURE__ */ __name((a) => {
|
|
118
105
|
return fileOrPath.type === "File" ? traverse(fileOrPath, a) : fileOrPath.traverse(a);
|
|
119
106
|
}, "callTraverse");
|
|
120
107
|
let programPath;
|
|
108
|
+
const res = {
|
|
109
|
+
flattened: 0,
|
|
110
|
+
optimized: 0,
|
|
111
|
+
modified: 0
|
|
112
|
+
};
|
|
121
113
|
callTraverse({
|
|
122
114
|
Program: {
|
|
123
115
|
enter(path) {
|
|
@@ -125,11 +117,12 @@ function createExtractor() {
|
|
|
125
117
|
}
|
|
126
118
|
},
|
|
127
119
|
JSXElement(traversePath) {
|
|
120
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
128
121
|
const node = traversePath.node.openingElement;
|
|
129
122
|
const ogAttributes = node.attributes;
|
|
130
123
|
const componentName = findComponentName(traversePath.scope);
|
|
131
124
|
const closingElement = traversePath.node.closingElement;
|
|
132
|
-
if (t.isJSXMemberExpression(closingElement
|
|
125
|
+
if (t.isJSXMemberExpression(closingElement == null ? void 0 : closingElement.name) || !t.isJSXIdentifier(node.name)) {
|
|
133
126
|
return;
|
|
134
127
|
}
|
|
135
128
|
const binding = traversePath.scope.getBinding(node.name.name);
|
|
@@ -138,7 +131,7 @@ function createExtractor() {
|
|
|
138
131
|
return;
|
|
139
132
|
}
|
|
140
133
|
const source = binding.path.parent.source;
|
|
141
|
-
if (source.value
|
|
134
|
+
if (!props.components.includes(source.value) && !isInternalImport(source.value)) {
|
|
142
135
|
return;
|
|
143
136
|
}
|
|
144
137
|
if (!validComponents[binding.identifier.name]) {
|
|
@@ -149,11 +142,29 @@ function createExtractor() {
|
|
|
149
142
|
if (!component || !component.staticConfig) {
|
|
150
143
|
return;
|
|
151
144
|
}
|
|
152
|
-
const { staticConfig } = component;
|
|
153
145
|
const originalNodeName = node.name.name;
|
|
146
|
+
if (shouldPrintDebug) {
|
|
147
|
+
console.log(`
|
|
148
|
+
<${originalNodeName} />`);
|
|
149
|
+
}
|
|
150
|
+
const filePath = sourcePath.replace(process.cwd(), ".");
|
|
151
|
+
const lineNumbers = node.loc ? node.loc.start.line + (node.loc.start.line !== node.loc.end.line ? `-${node.loc.end.line}` : "") : "";
|
|
152
|
+
if (shouldAddDebugProp && !disableDebugAttr) {
|
|
153
|
+
const preName = componentName ? `${componentName}:` : "";
|
|
154
|
+
res.modified++;
|
|
155
|
+
node.attributes.unshift(t.jsxAttribute(t.jsxIdentifier("data-is"), t.stringLiteral(` ${preName}${node.name.name} ${filePath.replace("./", "")}:${lineNumbers} `)));
|
|
156
|
+
}
|
|
157
|
+
if (disableExtraction) {
|
|
158
|
+
if (!hasLogged) {
|
|
159
|
+
console.log("\u{1F95A} Tamagui disableExtraction set: no CSS or optimizations will be run");
|
|
160
|
+
hasLogged = true;
|
|
161
|
+
}
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
const { staticConfig } = component;
|
|
154
165
|
const isTextView = staticConfig.isText || false;
|
|
155
|
-
const validStyles = staticConfig
|
|
156
|
-
let tagName = isTextView ? "span" : "div";
|
|
166
|
+
const validStyles = (_a = staticConfig == null ? void 0 : staticConfig.validStyles) != null ? _a : {};
|
|
167
|
+
let tagName = (_c = (_b = staticConfig.defaultProps) == null ? void 0 : _b.tag) != null ? _c : isTextView ? "span" : "div";
|
|
157
168
|
traversePath.get("openingElement").get("attributes").forEach((path) => {
|
|
158
169
|
const attr = path.node;
|
|
159
170
|
if (t.isJSXSpreadAttribute(attr))
|
|
@@ -166,27 +177,23 @@ function createExtractor() {
|
|
|
166
177
|
tagName = val.value;
|
|
167
178
|
});
|
|
168
179
|
const flatNode = getFlattenedNode({ isTextView, tag: tagName });
|
|
169
|
-
const deoptProps = new Set([
|
|
170
|
-
...props.deoptProps
|
|
171
|
-
...staticConfig.deoptProps
|
|
180
|
+
const deoptProps = /* @__PURE__ */ new Set([
|
|
181
|
+
...(_d = props.deoptProps) != null ? _d : [],
|
|
182
|
+
...(_e = staticConfig.deoptProps) != null ? _e : []
|
|
172
183
|
]);
|
|
173
|
-
const excludeProps = new Set(props.excludeProps
|
|
184
|
+
const excludeProps = new Set((_f = props.excludeProps) != null ? _f : []);
|
|
174
185
|
const isExcludedProp = /* @__PURE__ */ __name((name) => {
|
|
175
|
-
const
|
|
176
|
-
if (
|
|
186
|
+
const res2 = excludeProps.has(name);
|
|
187
|
+
if (res2 && shouldPrintDebug)
|
|
177
188
|
console.log(` excluding ${name}`);
|
|
178
|
-
return
|
|
189
|
+
return res2;
|
|
179
190
|
}, "isExcludedProp");
|
|
180
191
|
const isDeoptedProp = /* @__PURE__ */ __name((name) => {
|
|
181
|
-
const
|
|
182
|
-
if (
|
|
192
|
+
const res2 = deoptProps.has(name);
|
|
193
|
+
if (res2 && shouldPrintDebug)
|
|
183
194
|
console.log(` deopting ${name}`);
|
|
184
|
-
return
|
|
195
|
+
return res2;
|
|
185
196
|
}, "isDeoptedProp");
|
|
186
|
-
if (shouldPrintDebug) {
|
|
187
|
-
console.log(`
|
|
188
|
-
<${originalNodeName} />`);
|
|
189
|
-
}
|
|
190
197
|
const staticNamespace = getStaticBindingsForScope(traversePath.scope, importsWhitelist, sourcePath, bindingCache, shouldPrintDebug);
|
|
191
198
|
const attemptEval = !evaluateVars ? evaluateAstNode : createEvaluator({
|
|
192
199
|
tamaguiConfig,
|
|
@@ -259,11 +266,11 @@ function createExtractor() {
|
|
|
259
266
|
let isFlattened = false;
|
|
260
267
|
attrs = traversePath.get("openingElement").get("attributes").flatMap((path) => {
|
|
261
268
|
try {
|
|
262
|
-
const
|
|
263
|
-
if (!
|
|
269
|
+
const res2 = evaluateAttribute(path);
|
|
270
|
+
if (!res2) {
|
|
264
271
|
path.remove();
|
|
265
272
|
}
|
|
266
|
-
return
|
|
273
|
+
return res2;
|
|
267
274
|
} catch (err) {
|
|
268
275
|
console.log("Error extracting attribute", err.message, err.stack);
|
|
269
276
|
console.log("node", path.node);
|
|
@@ -273,8 +280,12 @@ function createExtractor() {
|
|
|
273
280
|
};
|
|
274
281
|
}
|
|
275
282
|
}).flat(4).filter(isPresent);
|
|
283
|
+
if (shouldPrintDebug) {
|
|
284
|
+
console.log(" - attrs (before):\n", logLines(attrs.map(attrStr).join(", ")));
|
|
285
|
+
}
|
|
276
286
|
function isStaticAttributeName(name) {
|
|
277
|
-
|
|
287
|
+
var _a2, _b2;
|
|
288
|
+
return !!(!!validStyles[name] || ((_a2 = staticConfig.validPropsExtra) == null ? void 0 : _a2[name]) || !!pseudos[name] || ((_b2 = staticConfig.variants) == null ? void 0 : _b2[name]) || tamaguiConfig.shorthands[name] || (name[0] === "$" ? !!mediaQueryConfig[name.slice(1)] : false));
|
|
278
289
|
}
|
|
279
290
|
__name(isStaticAttributeName, "isStaticAttributeName");
|
|
280
291
|
function isExtractable(obj) {
|
|
@@ -284,8 +295,10 @@ function createExtractor() {
|
|
|
284
295
|
return false;
|
|
285
296
|
}
|
|
286
297
|
const propName = prop.key["name"];
|
|
287
|
-
if (!isStaticAttributeName(propName)) {
|
|
288
|
-
|
|
298
|
+
if (!isStaticAttributeName(propName) && propName !== "tag") {
|
|
299
|
+
if (shouldPrintDebug) {
|
|
300
|
+
console.log(" not a valid style prop!", propName);
|
|
301
|
+
}
|
|
289
302
|
return false;
|
|
290
303
|
}
|
|
291
304
|
return true;
|
|
@@ -345,13 +358,15 @@ function createExtractor() {
|
|
|
345
358
|
const attr = { type: "attr", value: attribute };
|
|
346
359
|
if (t.isJSXSpreadAttribute(attribute)) {
|
|
347
360
|
const arg = attribute.argument;
|
|
348
|
-
const conditional = t.isConditionalExpression(arg) ? [arg.test, arg.
|
|
361
|
+
const conditional = t.isConditionalExpression(arg) ? [arg.test, arg.consequent, arg.alternate] : t.isLogicalExpression(arg) && arg.operator === "&&" ? [arg.left, arg.right, null] : null;
|
|
349
362
|
if (conditional) {
|
|
350
363
|
const [test, alt, cons] = conditional;
|
|
351
364
|
if (!test)
|
|
352
365
|
throw new Error(`no test`);
|
|
353
366
|
if ([alt, cons].some((side) => side && !isExtractable(side))) {
|
|
354
|
-
|
|
367
|
+
if (shouldPrintDebug) {
|
|
368
|
+
console.log("not extractable", alt, cons);
|
|
369
|
+
}
|
|
355
370
|
return attr;
|
|
356
371
|
}
|
|
357
372
|
return [
|
|
@@ -381,7 +396,10 @@ function createExtractor() {
|
|
|
381
396
|
if (UNTOUCHED_PROPS[name]) {
|
|
382
397
|
return attr;
|
|
383
398
|
}
|
|
384
|
-
if (name[0] === "$" && t.isJSXExpressionContainer(attribute
|
|
399
|
+
if (name[0] === "$" && t.isJSXExpressionContainer(attribute == null ? void 0 : attribute.value)) {
|
|
400
|
+
if (disableExtractInlineMedia) {
|
|
401
|
+
return attr;
|
|
402
|
+
}
|
|
385
403
|
const shortname = name.slice(1);
|
|
386
404
|
if (mediaQueryConfig[shortname]) {
|
|
387
405
|
const expression = attribute.value.expression;
|
|
@@ -399,7 +417,7 @@ function createExtractor() {
|
|
|
399
417
|
}
|
|
400
418
|
}
|
|
401
419
|
const [value, valuePath] = (() => {
|
|
402
|
-
if (t.isJSXExpressionContainer(attribute
|
|
420
|
+
if (t.isJSXExpressionContainer(attribute == null ? void 0 : attribute.value)) {
|
|
403
421
|
return [attribute.value.expression, path.get("value")];
|
|
404
422
|
} else {
|
|
405
423
|
return [attribute.value, path.get("value")];
|
|
@@ -415,11 +433,33 @@ function createExtractor() {
|
|
|
415
433
|
inlinePropCount++;
|
|
416
434
|
return attr;
|
|
417
435
|
}
|
|
436
|
+
if (name === "tag") {
|
|
437
|
+
return {
|
|
438
|
+
type: "attr",
|
|
439
|
+
value: path.node
|
|
440
|
+
};
|
|
441
|
+
}
|
|
442
|
+
if (disableExtractVariables) {
|
|
443
|
+
if (value) {
|
|
444
|
+
if (value.type === "StringLiteral" && value.value[0] === "$") {
|
|
445
|
+
if (shouldPrintDebug) {
|
|
446
|
+
console.log(" native, disable extract var", value.value);
|
|
447
|
+
}
|
|
448
|
+
inlinePropCount++;
|
|
449
|
+
return attr;
|
|
450
|
+
}
|
|
451
|
+
}
|
|
452
|
+
}
|
|
418
453
|
const styleValue = attemptEvalSafe(value);
|
|
419
454
|
if (!isStaticAttributeName(name)) {
|
|
420
455
|
let keys = [name];
|
|
421
|
-
|
|
422
|
-
|
|
456
|
+
if (staticConfig.propMapper) {
|
|
457
|
+
const out = staticConfig.propMapper(name, styleValue, defaultTheme, staticConfig.defaultProps);
|
|
458
|
+
if (out) {
|
|
459
|
+
keys = Object.keys(out);
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
if (keys.some((k) => !isStaticAttributeName(k) && k !== "tag")) {
|
|
423
463
|
if (shouldPrintDebug) {
|
|
424
464
|
console.log(" ! inlining, not static attribute name", name);
|
|
425
465
|
}
|
|
@@ -430,7 +470,9 @@ function createExtractor() {
|
|
|
430
470
|
if (styleValue !== FAILED_EVAL) {
|
|
431
471
|
return {
|
|
432
472
|
type: "style",
|
|
433
|
-
value: { [name]: styleValue }
|
|
473
|
+
value: { [name]: styleValue },
|
|
474
|
+
name,
|
|
475
|
+
attr: path.node
|
|
434
476
|
};
|
|
435
477
|
}
|
|
436
478
|
if (t.isBinaryExpression(value)) {
|
|
@@ -492,6 +534,9 @@ function createExtractor() {
|
|
|
492
534
|
function getStaticConditional(value2) {
|
|
493
535
|
if (t.isConditionalExpression(value2)) {
|
|
494
536
|
try {
|
|
537
|
+
if (shouldPrintDebug) {
|
|
538
|
+
console.log("attempt", value2.alternate, value2.consequent);
|
|
539
|
+
}
|
|
495
540
|
const aVal = attemptEval(value2.alternate);
|
|
496
541
|
const cVal = attemptEval(value2.consequent);
|
|
497
542
|
if (shouldPrintDebug) {
|
|
@@ -539,9 +584,6 @@ function createExtractor() {
|
|
|
539
584
|
__name(getStaticLogical, "getStaticLogical");
|
|
540
585
|
}
|
|
541
586
|
__name(evaluateAttribute, "evaluateAttribute");
|
|
542
|
-
if (shouldPrintDebug) {
|
|
543
|
-
console.log(" - attrs (before): ", attrs.map(attrStr).join(", "));
|
|
544
|
-
}
|
|
545
587
|
node.attributes = attrs.filter(isAttr).map((x) => x.value);
|
|
546
588
|
if (couldntParse) {
|
|
547
589
|
if (shouldPrintDebug) {
|
|
@@ -554,8 +596,6 @@ function createExtractor() {
|
|
|
554
596
|
if (parentFn) {
|
|
555
597
|
modifiedComponents.add(parentFn);
|
|
556
598
|
}
|
|
557
|
-
const filePath = sourcePath.replace(process.cwd(), ".");
|
|
558
|
-
const lineNumbers = node.loc ? node.loc.start.line + (node.loc.start.line !== node.loc.end.line ? `-${node.loc.end.line}` : "") : "";
|
|
559
599
|
let ternaries = [];
|
|
560
600
|
attrs = attrs.reduce((out, cur) => {
|
|
561
601
|
const next = attrs[attrs.indexOf(cur) + 1];
|
|
@@ -616,16 +656,19 @@ function createExtractor() {
|
|
|
616
656
|
const shouldFlatten = !shouldDeopt && inlinePropCount === 0 && !hasSpread && staticConfig.neverFlatten !== true && (staticConfig.neverFlatten === "jsx" ? hasOnlyStringChildren : true);
|
|
617
657
|
if (!shouldFlatten) {
|
|
618
658
|
attrs = attrs.reduce((acc, cur) => {
|
|
659
|
+
var _a2, _b2;
|
|
619
660
|
if (cur.type === "style") {
|
|
620
661
|
for (const key in cur.value) {
|
|
621
|
-
const
|
|
662
|
+
const shouldEnsureOverridden = !!((_a2 = staticConfig.ensureOverriddenProp) == null ? void 0 : _a2[key]);
|
|
622
663
|
const isSetInAttrsAlready = attrs.some((x) => x.type === "attr" && x.value.type === "JSXAttribute" && x.value.name.name === key);
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
664
|
+
if (!isSetInAttrsAlready) {
|
|
665
|
+
const isVariant = !!((_b2 = staticConfig.variants) == null ? void 0 : _b2[cur.name || ""]);
|
|
666
|
+
if (isVariant || shouldEnsureOverridden) {
|
|
667
|
+
acc.push({
|
|
668
|
+
type: "attr",
|
|
669
|
+
value: cur.attr || t.jsxAttribute(t.jsxIdentifier(key), t.jsxExpressionContainer(t.nullLiteral()))
|
|
670
|
+
});
|
|
671
|
+
}
|
|
629
672
|
}
|
|
630
673
|
}
|
|
631
674
|
}
|
|
@@ -634,15 +677,15 @@ function createExtractor() {
|
|
|
634
677
|
}, []);
|
|
635
678
|
}
|
|
636
679
|
if (shouldPrintDebug) {
|
|
637
|
-
console.log(" - attrs (flattened):
|
|
680
|
+
console.log(" - attrs (flattened): \n", logLines(attrs.map(attrStr).join(", ")));
|
|
638
681
|
}
|
|
639
682
|
attrs = attrs.reduce((acc, cur) => {
|
|
640
683
|
if (cur.type !== "attr" || !t.isJSXAttribute(cur.value) || typeof cur.value.name.name !== "string") {
|
|
641
684
|
if (cur.type === "style") {
|
|
642
|
-
|
|
685
|
+
let key = Object.keys(cur.value)[0];
|
|
643
686
|
if (!validStyles[key] && !pseudos[key]) {
|
|
644
687
|
if (shouldPrintDebug) {
|
|
645
|
-
console.log("
|
|
688
|
+
console.log(" - ignoring (expanded already):", key);
|
|
646
689
|
}
|
|
647
690
|
return acc;
|
|
648
691
|
}
|
|
@@ -652,15 +695,12 @@ function createExtractor() {
|
|
|
652
695
|
return acc;
|
|
653
696
|
}, []);
|
|
654
697
|
if (shouldPrintDebug) {
|
|
655
|
-
console.log(" - attrs (evaluated styles):
|
|
698
|
+
console.log(" - attrs (evaluated styles): \n", logLines(attrs.map(attrStr).join(", ")));
|
|
656
699
|
}
|
|
657
700
|
let prev = null;
|
|
658
701
|
attrs = attrs.reduce((acc, cur) => {
|
|
659
702
|
if (cur.type === "style") {
|
|
660
|
-
if (prev
|
|
661
|
-
if (shouldPrintDebug) {
|
|
662
|
-
console.log(" \u{1F500} merging style");
|
|
663
|
-
}
|
|
703
|
+
if ((prev == null ? void 0 : prev.type) === "style") {
|
|
664
704
|
Object.assign(prev.value, cur.value);
|
|
665
705
|
return acc;
|
|
666
706
|
}
|
|
@@ -670,9 +710,10 @@ function createExtractor() {
|
|
|
670
710
|
return acc;
|
|
671
711
|
}, []);
|
|
672
712
|
if (shouldPrintDebug) {
|
|
673
|
-
console.log(" - attrs (combined
|
|
713
|
+
console.log(" - attrs (combined \u{1F500}): \n", logLines(attrs.map(attrStr).join(", ")));
|
|
674
714
|
}
|
|
675
715
|
const getStyles = /* @__PURE__ */ __name((props2) => {
|
|
716
|
+
var _a2;
|
|
676
717
|
if (!props2)
|
|
677
718
|
return;
|
|
678
719
|
if (!!excludeProps.size) {
|
|
@@ -681,12 +722,13 @@ function createExtractor() {
|
|
|
681
722
|
delete props2[key];
|
|
682
723
|
}
|
|
683
724
|
}
|
|
684
|
-
const out = postProcessStyles(props2, staticConfig);
|
|
685
|
-
const next = out
|
|
725
|
+
const out = postProcessStyles(props2, staticConfig, defaultTheme);
|
|
726
|
+
const next = (_a2 = out == null ? void 0 : out.style) != null ? _a2 : props2;
|
|
686
727
|
if (shouldPrintDebug) {
|
|
687
|
-
console.log("
|
|
688
|
-
console.log("
|
|
689
|
-
console.log("
|
|
728
|
+
console.log(" getStyles props >>\n", logLines(objToStr(props2)));
|
|
729
|
+
console.log(" getStyles next >>\n", logLines(objToStr(next)));
|
|
730
|
+
console.log(" getStyles style >>\n", logLines(objToStr(out.style)));
|
|
731
|
+
console.log(" getStyles viewp >>\n", logLines(objToStr(out.viewProps)));
|
|
690
732
|
}
|
|
691
733
|
if (staticConfig.validStyles) {
|
|
692
734
|
for (const key in next) {
|
|
@@ -697,9 +739,6 @@ function createExtractor() {
|
|
|
697
739
|
}
|
|
698
740
|
return next;
|
|
699
741
|
}, "getStyles");
|
|
700
|
-
if (shouldPrintDebug) {
|
|
701
|
-
console.log(" staticConfig.defaultProps", staticConfig.defaultProps);
|
|
702
|
-
}
|
|
703
742
|
const completeStylesProcessed = getStyles({
|
|
704
743
|
...staticConfig.defaultProps,
|
|
705
744
|
...completeStaticProps
|
|
@@ -719,8 +758,8 @@ function createExtractor() {
|
|
|
719
758
|
}
|
|
720
759
|
}
|
|
721
760
|
if (shouldPrintDebug) {
|
|
722
|
-
console.log("
|
|
723
|
-
console.log("
|
|
761
|
+
console.log(" completeStaticProps\n", logLines(objToStr(completeStaticProps)));
|
|
762
|
+
console.log(" completeStylesProcessed\n", logLines(objToStr(completeStylesProcessed)));
|
|
724
763
|
}
|
|
725
764
|
for (const attr of attrs) {
|
|
726
765
|
try {
|
|
@@ -737,7 +776,11 @@ function createExtractor() {
|
|
|
737
776
|
case "style":
|
|
738
777
|
const next = {};
|
|
739
778
|
for (const key in attr.value) {
|
|
740
|
-
|
|
779
|
+
if (key in stylePropsTransform) {
|
|
780
|
+
next["transform"] = completeStylesProcessed["transform"];
|
|
781
|
+
} else {
|
|
782
|
+
next[key] = (_g = completeStylesProcessed[key]) != null ? _g : attr.value[key];
|
|
783
|
+
}
|
|
741
784
|
}
|
|
742
785
|
attr.value = next;
|
|
743
786
|
break;
|
|
@@ -751,14 +794,7 @@ function createExtractor() {
|
|
|
751
794
|
}
|
|
752
795
|
}
|
|
753
796
|
if (shouldPrintDebug) {
|
|
754
|
-
console.log(" - attrs (after)
|
|
755
|
-
}
|
|
756
|
-
if (shouldAddDebugProp) {
|
|
757
|
-
const preName = componentName ? `${componentName}:` : "";
|
|
758
|
-
attrs.unshift({
|
|
759
|
-
type: "attr",
|
|
760
|
-
value: t.jsxAttribute(t.jsxIdentifier("data-is"), t.stringLiteral(` ${preName}${node.name.name} ${filePath.replace("./", "")}:${lineNumbers} `))
|
|
761
|
-
});
|
|
797
|
+
console.log(" - attrs (after):\n", logLines(attrs.map(attrStr).join(", ")));
|
|
762
798
|
}
|
|
763
799
|
if (shouldFlatten) {
|
|
764
800
|
if (shouldPrintDebug) {
|
|
@@ -766,15 +802,16 @@ function createExtractor() {
|
|
|
766
802
|
}
|
|
767
803
|
isFlattened = true;
|
|
768
804
|
node.name.name = flatNode;
|
|
769
|
-
|
|
805
|
+
res.flattened++;
|
|
770
806
|
if (closingElement) {
|
|
771
807
|
closingElement.name.name = flatNode;
|
|
772
808
|
}
|
|
773
809
|
}
|
|
774
810
|
if (shouldPrintDebug) {
|
|
775
811
|
console.log(" [\u274A] inline props ", inlinePropCount, shouldDeopt ? " deopted" : "", hasSpread ? " spread" : "", "!flatten", staticConfig.neverFlatten);
|
|
776
|
-
console.log(" - attrs (end)
|
|
812
|
+
console.log(" - attrs (end):\n", logLines(attrs.map(attrStr).join(", ")));
|
|
777
813
|
}
|
|
814
|
+
res.optimized++;
|
|
778
815
|
onExtractTag({
|
|
779
816
|
attrs,
|
|
780
817
|
node,
|
|
@@ -797,12 +834,12 @@ function createExtractor() {
|
|
|
797
834
|
removeUnusedHooks(comp, shouldPrintDebug);
|
|
798
835
|
}
|
|
799
836
|
}
|
|
837
|
+
return res;
|
|
800
838
|
}
|
|
801
839
|
};
|
|
802
840
|
}
|
|
803
841
|
__name(createExtractor, "createExtractor");
|
|
804
842
|
export {
|
|
805
|
-
FAILED_EVAL,
|
|
806
843
|
createExtractor
|
|
807
844
|
};
|
|
808
845
|
//# sourceMappingURL=createExtractor.js.map
|