@tamagui/static 1.0.0-alpha.35 → 1.0.0-alpha.39
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/esm/extractor/createExtractor.js +22 -15
- package/dist/esm/extractor/createExtractor.js.map +1 -1
- package/dist/esm/extractor/extractHelpers.js +5 -3
- package/dist/esm/extractor/extractHelpers.js.map +1 -1
- package/dist/esm/extractor/extractMediaStyle.js +3 -2
- package/dist/esm/extractor/extractMediaStyle.js.map +1 -1
- package/dist/esm/extractor/extractToClassNames.js +5 -3
- package/dist/esm/extractor/extractToClassNames.js.map +1 -1
- package/dist/esm/extractor/normalizeTernaries.js +3 -2
- package/dist/esm/extractor/normalizeTernaries.js.map +1 -1
- package/dist/esm/extractor/removeUnusedHooks.js +5 -3
- package/dist/esm/extractor/removeUnusedHooks.js.map +1 -1
- package/dist/jsx/extractor/createExtractor.js +22 -15
- package/dist/jsx/extractor/extractHelpers.js +5 -3
- package/dist/jsx/extractor/extractMediaStyle.js +3 -2
- package/dist/jsx/extractor/extractToClassNames.js +5 -3
- package/dist/jsx/extractor/normalizeTernaries.js +3 -2
- package/dist/jsx/extractor/removeUnusedHooks.js +5 -3
- package/package.json +7 -7
- package/dist/constants.js +0 -10
- package/dist/constants.js.map +0 -7
- package/dist/extractor/accessSafe.js +0 -11
- package/dist/extractor/accessSafe.js.map +0 -7
- package/dist/extractor/babelParse.js +0 -30
- package/dist/extractor/babelParse.js.map +0 -7
- package/dist/extractor/buildClassName.js +0 -40
- package/dist/extractor/buildClassName.js.map +0 -7
- package/dist/extractor/createEvaluator.js +0 -51
- package/dist/extractor/createEvaluator.js.map +0 -7
- package/dist/extractor/createExtractor.js +0 -827
- package/dist/extractor/createExtractor.js.map +0 -7
- package/dist/extractor/ensureImportingConcat.js +0 -24
- package/dist/extractor/ensureImportingConcat.js.map +0 -7
- package/dist/extractor/evaluateAstNode.js +0 -94
- package/dist/extractor/evaluateAstNode.js.map +0 -7
- package/dist/extractor/extractHelpers.js +0 -94
- package/dist/extractor/extractHelpers.js.map +0 -7
- package/dist/extractor/extractMediaStyle.js +0 -151
- package/dist/extractor/extractMediaStyle.js.map +0 -7
- package/dist/extractor/extractToClassNames.js +0 -235
- package/dist/extractor/extractToClassNames.js.map +0 -7
- package/dist/extractor/findTopmostFunction.js +0 -23
- package/dist/extractor/findTopmostFunction.js.map +0 -7
- package/dist/extractor/generatedUid.js +0 -28
- package/dist/extractor/generatedUid.js.map +0 -7
- package/dist/extractor/getPropValueFromAttributes.js +0 -49
- package/dist/extractor/getPropValueFromAttributes.js.map +0 -7
- package/dist/extractor/getSourceModule.js +0 -69
- package/dist/extractor/getSourceModule.js.map +0 -7
- package/dist/extractor/getStaticBindingsForScope.js +0 -128
- package/dist/extractor/getStaticBindingsForScope.js.map +0 -7
- package/dist/extractor/hoistClassNames.js +0 -44
- package/dist/extractor/hoistClassNames.js.map +0 -7
- package/dist/extractor/literalToAst.js +0 -34
- package/dist/extractor/literalToAst.js.map +0 -7
- package/dist/extractor/loadTamagui.js +0 -41
- package/dist/extractor/loadTamagui.js.map +0 -7
- package/dist/extractor/normalizeTernaries.js +0 -52
- package/dist/extractor/normalizeTernaries.js.map +0 -7
- package/dist/extractor/removeUnusedHooks.js +0 -78
- package/dist/extractor/removeUnusedHooks.js.map +0 -7
- package/dist/index.cjs +0 -2116
- package/dist/index.cjs.map +0 -7
- package/dist/index.js +0 -14
- package/dist/index.js.map +0 -7
- package/dist/patchReactNativeWeb.js +0 -107
- package/dist/patchReactNativeWeb.js.map +0 -7
- package/dist/types.js +0 -1
- package/dist/types.js.map +0 -7
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/extractor/removeUnusedHooks.ts"],
|
|
4
4
|
"sourcesContent": ["import { NodePath } from '@babel/traverse'\nimport * as t from '@babel/types'\n\nconst hooks = {\n useMedia: true,\n useTheme: true,\n}\n\nexport function removeUnusedHooks(compFn: NodePath<any>, shouldPrintDebug: boolean) {\n compFn.scope.crawl()\n // check the top level statements\n let bodyStatements = compFn?.get('body')\n if (!bodyStatements) {\n console.log('no body statemnts?', compFn)\n return\n }\n if (!Array.isArray(bodyStatements)) {\n if (bodyStatements.isFunctionExpression()) {\n bodyStatements = bodyStatements.scope.path.get('body')\n } else {\n bodyStatements = bodyStatements.get('body')\n }\n }\n if (!bodyStatements || !Array.isArray(bodyStatements)) {\n return\n }\n const statements = bodyStatements as NodePath<any>[]\n for (const statement of statements) {\n if (!statement.isVariableDeclaration()) {\n continue\n }\n const declarations = statement.get('declarations')\n if (!Array.isArray(declarations)) {\n continue\n }\n const isBindingReferenced = (name: string) => {\n return !!statement.scope.getBinding(name)?.referenced\n }\n for (const declarator of declarations) {\n const id = declarator.get('id')\n const init = declarator.node.init\n if (Array.isArray(id) || Array.isArray(init)) {\n continue\n }\n const shouldRemove = (() => {\n const isHook =\n t.isCallExpression(init) && t.isIdentifier(init.callee) && hooks[init.callee.name]\n if (!isHook) {\n return false\n }\n if (t.isIdentifier(id.node)) {\n // remove \"const media = useMedia()\"\n const name = id.node.name\n return !isBindingReferenced(name)\n } else if (t.isObjectPattern(id.node)) {\n // remove \"const { sm } = useMedia()\"\n const propPaths = id.get('properties') as NodePath<any>[]\n return propPaths.every((prop) => {\n if (!prop.isObjectProperty()) return false\n const value = prop.get('value')\n if (Array.isArray(value) || !value.isIdentifier()) return false\n const name = value.node.name\n return !isBindingReferenced(name)\n })\n }\n return false\n })()\n if (shouldRemove) {\n declarator.remove()\n if (shouldPrintDebug) {\n console.log(` [\uD83E\uDE9D] removed ${id.node['name'] ?? ''}`)\n }\n }\n }\n }\n}\n"],
|
|
5
|
-
"mappings": ";;AACA;AAEA,MAAM,QAAQ;AAAA,EACZ,UAAU;AAAA,EACV,UAAU;AAAA;AAGL,2BAA2B,QAAuB,kBAA2B;
|
|
5
|
+
"mappings": ";;AACA;AAEA,MAAM,QAAQ;AAAA,EACZ,UAAU;AAAA,EACV,UAAU;AAAA;AAGL,2BAA2B,QAAuB,kBAA2B;AARpF;AASE,SAAO,MAAM;AAEb,MAAI,iBAAiB,iCAAQ,IAAI;AACjC,MAAI,CAAC,gBAAgB;AACnB,YAAQ,IAAI,sBAAsB;AAClC;AAAA;AAEF,MAAI,CAAC,MAAM,QAAQ,iBAAiB;AAClC,QAAI,eAAe,wBAAwB;AACzC,uBAAiB,eAAe,MAAM,KAAK,IAAI;AAAA,WAC1C;AACL,uBAAiB,eAAe,IAAI;AAAA;AAAA;AAGxC,MAAI,CAAC,kBAAkB,CAAC,MAAM,QAAQ,iBAAiB;AACrD;AAAA;AAEF,QAAM,aAAa;AACnB,aAAW,aAAa,YAAY;AAClC,QAAI,CAAC,UAAU,yBAAyB;AACtC;AAAA;AAEF,UAAM,eAAe,UAAU,IAAI;AACnC,QAAI,CAAC,MAAM,QAAQ,eAAe;AAChC;AAAA;AAEF,UAAM,sBAAsB,wBAAC,SAAiB;AAnClD;AAoCM,aAAO,CAAC,CAAC,kBAAU,MAAM,WAAW,UAA3B,oBAAkC;AAAA,OADjB;AAG5B,eAAW,cAAc,cAAc;AACrC,YAAM,KAAK,WAAW,IAAI;AAC1B,YAAM,OAAO,WAAW,KAAK;AAC7B,UAAI,MAAM,QAAQ,OAAO,MAAM,QAAQ,OAAO;AAC5C;AAAA;AAEF,YAAM,eAAgB,OAAM;AAC1B,cAAM,SACJ,EAAE,iBAAiB,SAAS,EAAE,aAAa,KAAK,WAAW,MAAM,KAAK,OAAO;AAC/E,YAAI,CAAC,QAAQ;AACX,iBAAO;AAAA;AAET,YAAI,EAAE,aAAa,GAAG,OAAO;AAE3B,gBAAM,OAAO,GAAG,KAAK;AACrB,iBAAO,CAAC,oBAAoB;AAAA,mBACnB,EAAE,gBAAgB,GAAG,OAAO;AAErC,gBAAM,YAAY,GAAG,IAAI;AACzB,iBAAO,UAAU,MAAM,CAAC,SAAS;AAC/B,gBAAI,CAAC,KAAK;AAAoB,qBAAO;AACrC,kBAAM,QAAQ,KAAK,IAAI;AACvB,gBAAI,MAAM,QAAQ,UAAU,CAAC,MAAM;AAAgB,qBAAO;AAC1D,kBAAM,OAAO,MAAM,KAAK;AACxB,mBAAO,CAAC,oBAAoB;AAAA;AAAA;AAGhC,eAAO;AAAA;AAET,UAAI,cAAc;AAChB,mBAAW;AACX,YAAI,kBAAkB;AACpB,kBAAQ,IAAI,yBAAkB,SAAG,KAAK,YAAR,YAAmB;AAAA;AAAA;AAAA;AAAA;AAAA;AA9D3C;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -70,7 +70,10 @@ function createExtractor() {
|
|
|
70
70
|
const isInternalImport = /* @__PURE__ */ __name((importStr) => {
|
|
71
71
|
return isInsideTamagui(sourcePath) && importStr[0] === ".";
|
|
72
72
|
}, "isInternalImport");
|
|
73
|
-
const validComponents = Object.keys(components).filter((key) =>
|
|
73
|
+
const validComponents = Object.keys(components).filter((key) => {
|
|
74
|
+
var _a;
|
|
75
|
+
return key[0].toUpperCase() === key[0] && !!((_a = components[key]) == null ? void 0 : _a.staticConfig);
|
|
76
|
+
}).reduce((obj, name) => {
|
|
74
77
|
obj[name] = components[name];
|
|
75
78
|
return obj;
|
|
76
79
|
}, {});
|
|
@@ -115,11 +118,12 @@ function createExtractor() {
|
|
|
115
118
|
}
|
|
116
119
|
},
|
|
117
120
|
JSXElement(traversePath) {
|
|
121
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
118
122
|
const node = traversePath.node.openingElement;
|
|
119
123
|
const ogAttributes = node.attributes;
|
|
120
124
|
const componentName = findComponentName(traversePath.scope);
|
|
121
125
|
const closingElement = traversePath.node.closingElement;
|
|
122
|
-
if (t.isJSXMemberExpression(closingElement
|
|
126
|
+
if (t.isJSXMemberExpression(closingElement == null ? void 0 : closingElement.name) || !t.isJSXIdentifier(node.name)) {
|
|
123
127
|
return;
|
|
124
128
|
}
|
|
125
129
|
const binding = traversePath.scope.getBinding(node.name.name);
|
|
@@ -160,8 +164,8 @@ function createExtractor() {
|
|
|
160
164
|
}
|
|
161
165
|
const { staticConfig } = component;
|
|
162
166
|
const isTextView = staticConfig.isText || false;
|
|
163
|
-
const validStyles = staticConfig
|
|
164
|
-
let tagName = staticConfig.defaultProps
|
|
167
|
+
const validStyles = (_a = staticConfig == null ? void 0 : staticConfig.validStyles) != null ? _a : {};
|
|
168
|
+
let tagName = (_c = (_b = staticConfig.defaultProps) == null ? void 0 : _b.tag) != null ? _c : isTextView ? "span" : "div";
|
|
165
169
|
traversePath.get("openingElement").get("attributes").forEach((path) => {
|
|
166
170
|
const attr = path.node;
|
|
167
171
|
if (t.isJSXSpreadAttribute(attr))
|
|
@@ -175,10 +179,10 @@ function createExtractor() {
|
|
|
175
179
|
});
|
|
176
180
|
const flatNode = getFlattenedNode({ isTextView, tag: tagName });
|
|
177
181
|
const deoptProps = new Set([
|
|
178
|
-
...props.deoptProps
|
|
179
|
-
...staticConfig.deoptProps
|
|
182
|
+
...(_d = props.deoptProps) != null ? _d : [],
|
|
183
|
+
...(_e = staticConfig.deoptProps) != null ? _e : []
|
|
180
184
|
]);
|
|
181
|
-
const excludeProps = new Set(props.excludeProps
|
|
185
|
+
const excludeProps = new Set((_f = props.excludeProps) != null ? _f : []);
|
|
182
186
|
const isExcludedProp = /* @__PURE__ */ __name((name) => {
|
|
183
187
|
const res2 = excludeProps.has(name);
|
|
184
188
|
if (res2 && shouldPrintDebug)
|
|
@@ -278,7 +282,8 @@ function createExtractor() {
|
|
|
278
282
|
}
|
|
279
283
|
}).flat(4).filter(isPresent);
|
|
280
284
|
function isStaticAttributeName(name) {
|
|
281
|
-
|
|
285
|
+
var _a2, _b2;
|
|
286
|
+
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));
|
|
282
287
|
}
|
|
283
288
|
__name(isStaticAttributeName, "isStaticAttributeName");
|
|
284
289
|
function isExtractable(obj) {
|
|
@@ -389,7 +394,7 @@ function createExtractor() {
|
|
|
389
394
|
if (UNTOUCHED_PROPS[name]) {
|
|
390
395
|
return attr;
|
|
391
396
|
}
|
|
392
|
-
if (name[0] === "$" && t.isJSXExpressionContainer(attribute
|
|
397
|
+
if (name[0] === "$" && t.isJSXExpressionContainer(attribute == null ? void 0 : attribute.value)) {
|
|
393
398
|
if (disableExtractInlineMedia) {
|
|
394
399
|
return attr;
|
|
395
400
|
}
|
|
@@ -410,7 +415,7 @@ function createExtractor() {
|
|
|
410
415
|
}
|
|
411
416
|
}
|
|
412
417
|
const [value, valuePath] = (() => {
|
|
413
|
-
if (t.isJSXExpressionContainer(attribute
|
|
418
|
+
if (t.isJSXExpressionContainer(attribute == null ? void 0 : attribute.value)) {
|
|
414
419
|
return [attribute.value.expression, path.get("value")];
|
|
415
420
|
} else {
|
|
416
421
|
return [attribute.value, path.get("value")];
|
|
@@ -652,12 +657,13 @@ function createExtractor() {
|
|
|
652
657
|
const shouldFlatten = !shouldDeopt && inlinePropCount === 0 && !hasSpread && staticConfig.neverFlatten !== true && (staticConfig.neverFlatten === "jsx" ? hasOnlyStringChildren : true);
|
|
653
658
|
if (!shouldFlatten) {
|
|
654
659
|
attrs = attrs.reduce((acc, cur) => {
|
|
660
|
+
var _a2, _b2;
|
|
655
661
|
if (cur.type === "style") {
|
|
656
662
|
for (const key in cur.value) {
|
|
657
|
-
const shouldEnsureOverridden = !!staticConfig.ensureOverriddenProp
|
|
663
|
+
const shouldEnsureOverridden = !!((_a2 = staticConfig.ensureOverriddenProp) == null ? void 0 : _a2[key]);
|
|
658
664
|
const isSetInAttrsAlready = attrs.some((x) => x.type === "attr" && x.value.type === "JSXAttribute" && x.value.name.name === key);
|
|
659
665
|
if (!isSetInAttrsAlready) {
|
|
660
|
-
const isVariant = !!staticConfig.variants
|
|
666
|
+
const isVariant = !!((_b2 = staticConfig.variants) == null ? void 0 : _b2[cur.name || ""]);
|
|
661
667
|
if (isVariant || shouldEnsureOverridden) {
|
|
662
668
|
acc.push({
|
|
663
669
|
type: "attr",
|
|
@@ -695,7 +701,7 @@ function createExtractor() {
|
|
|
695
701
|
let prev = null;
|
|
696
702
|
attrs = attrs.reduce((acc, cur) => {
|
|
697
703
|
if (cur.type === "style") {
|
|
698
|
-
if (prev
|
|
704
|
+
if ((prev == null ? void 0 : prev.type) === "style") {
|
|
699
705
|
Object.assign(prev.value, cur.value);
|
|
700
706
|
return acc;
|
|
701
707
|
}
|
|
@@ -708,6 +714,7 @@ function createExtractor() {
|
|
|
708
714
|
console.log(" - attrs (combined \u{1F500}): \n", logLines(attrs.map(attrStr).join(", ")));
|
|
709
715
|
}
|
|
710
716
|
const getStyles = /* @__PURE__ */ __name((props2) => {
|
|
717
|
+
var _a2;
|
|
711
718
|
if (!props2)
|
|
712
719
|
return;
|
|
713
720
|
if (!!excludeProps.size) {
|
|
@@ -717,7 +724,7 @@ function createExtractor() {
|
|
|
717
724
|
}
|
|
718
725
|
}
|
|
719
726
|
const out = postProcessStyles(props2, staticConfig, defaultTheme);
|
|
720
|
-
const next = out
|
|
727
|
+
const next = (_a2 = out == null ? void 0 : out.style) != null ? _a2 : props2;
|
|
721
728
|
if (shouldPrintDebug) {
|
|
722
729
|
console.log(" getStyles props >>\n", logLines(objToStr(props2)));
|
|
723
730
|
console.log(" getStyles next >>\n", logLines(objToStr(next)));
|
|
@@ -773,7 +780,7 @@ function createExtractor() {
|
|
|
773
780
|
if (key in stylePropsTransform) {
|
|
774
781
|
next["transform"] = completeStylesProcessed["transform"];
|
|
775
782
|
} else {
|
|
776
|
-
next[key] = completeStylesProcessed[key]
|
|
783
|
+
next[key] = (_g = completeStylesProcessed[key]) != null ? _g : attr.value[key];
|
|
777
784
|
}
|
|
778
785
|
}
|
|
779
786
|
attr.value = next;
|
|
@@ -30,6 +30,7 @@ const ternaryStr = /* @__PURE__ */ __name((x) => {
|
|
|
30
30
|
].flat().join("");
|
|
31
31
|
}, "ternaryStr");
|
|
32
32
|
function findComponentName(scope) {
|
|
33
|
+
var _a;
|
|
33
34
|
let componentName = "";
|
|
34
35
|
let cur = scope.path;
|
|
35
36
|
while (cur.parentPath && !t.isProgram(cur.parentPath.parent)) {
|
|
@@ -46,17 +47,18 @@ function findComponentName(scope) {
|
|
|
46
47
|
}
|
|
47
48
|
}
|
|
48
49
|
if (t.isFunctionDeclaration(node)) {
|
|
49
|
-
return node.id
|
|
50
|
+
return (_a = node.id) == null ? void 0 : _a.name;
|
|
50
51
|
}
|
|
51
52
|
return componentName;
|
|
52
53
|
}
|
|
53
54
|
__name(findComponentName, "findComponentName");
|
|
54
55
|
function isValidThemeHook(jsxPath, n, sourcePath) {
|
|
56
|
+
var _a;
|
|
55
57
|
if (!t.isIdentifier(n.object) || !t.isIdentifier(n.property))
|
|
56
58
|
return false;
|
|
57
59
|
const bindings = jsxPath.scope.getAllBindings();
|
|
58
60
|
const binding = bindings[n.object.name];
|
|
59
|
-
if (!binding
|
|
61
|
+
if (!(binding == null ? void 0 : binding.path))
|
|
60
62
|
return false;
|
|
61
63
|
if (!binding.path.isVariableDeclarator())
|
|
62
64
|
return false;
|
|
@@ -67,7 +69,7 @@ function isValidThemeHook(jsxPath, n, sourcePath) {
|
|
|
67
69
|
return false;
|
|
68
70
|
if (init.callee.name !== "useTheme")
|
|
69
71
|
return false;
|
|
70
|
-
const importNode = binding.scope.getBinding("useTheme")
|
|
72
|
+
const importNode = (_a = binding.scope.getBinding("useTheme")) == null ? void 0 : _a.path.parent;
|
|
71
73
|
if (!t.isImportDeclaration(importNode))
|
|
72
74
|
return false;
|
|
73
75
|
if (importNode.source.value !== "tamagui") {
|
|
@@ -90,6 +90,7 @@ function getMediaQueryTernary(ternary, jsxPath, sourcePath) {
|
|
|
90
90
|
}
|
|
91
91
|
__name(getMediaQueryTernary, "getMediaQueryTernary");
|
|
92
92
|
function getMediaInfoFromExpression(test, jsxPath, sourcePath, inlineMediaQuery) {
|
|
93
|
+
var _a, _b, _c;
|
|
93
94
|
if (inlineMediaQuery) {
|
|
94
95
|
return {
|
|
95
96
|
key: inlineMediaQuery,
|
|
@@ -103,7 +104,7 @@ function getMediaInfoFromExpression(test, jsxPath, sourcePath, inlineMediaQuery)
|
|
|
103
104
|
const binding = bindings[name];
|
|
104
105
|
if (!binding)
|
|
105
106
|
return false;
|
|
106
|
-
const bindingNode = binding.path
|
|
107
|
+
const bindingNode = (_a = binding.path) == null ? void 0 : _a.node;
|
|
107
108
|
if (!t.isVariableDeclarator(bindingNode) || !bindingNode.init)
|
|
108
109
|
return false;
|
|
109
110
|
if (!isValidMediaCall(jsxPath, bindingNode.init, sourcePath))
|
|
@@ -112,7 +113,7 @@ function getMediaInfoFromExpression(test, jsxPath, sourcePath, inlineMediaQuery)
|
|
|
112
113
|
}
|
|
113
114
|
if (t.isIdentifier(test)) {
|
|
114
115
|
const key = test.name;
|
|
115
|
-
const node = jsxPath.scope.getBinding(test.name)
|
|
116
|
+
const node = (_c = (_b = jsxPath.scope.getBinding(test.name)) == null ? void 0 : _b.path) == null ? void 0 : _c.node;
|
|
116
117
|
if (!t.isVariableDeclarator(node))
|
|
117
118
|
return false;
|
|
118
119
|
if (!node.init || !isValidMediaCall(jsxPath, node.init, sourcePath))
|
|
@@ -33,11 +33,12 @@ function extractToClassNames({
|
|
|
33
33
|
threaded,
|
|
34
34
|
cssPath
|
|
35
35
|
}) {
|
|
36
|
+
var _a;
|
|
36
37
|
if (typeof source !== "string") {
|
|
37
38
|
throw new Error("`source` must be a string of javascript");
|
|
38
39
|
}
|
|
39
40
|
invariant(typeof sourcePath === "string" && path.isAbsolute(sourcePath), "`sourcePath` must be an absolute path to a .js file");
|
|
40
|
-
const shouldLogTiming = options.logTimings
|
|
41
|
+
const shouldLogTiming = (_a = options.logTimings) != null ? _a : true;
|
|
41
42
|
const start = Date.now();
|
|
42
43
|
const mem = shouldLogTiming ? process.memoryUsage() : null;
|
|
43
44
|
let ast;
|
|
@@ -74,13 +75,14 @@ function extractToClassNames({
|
|
|
74
75
|
}
|
|
75
76
|
}
|
|
76
77
|
const ensureNeededPrevStyle = /* @__PURE__ */ __name((style) => {
|
|
78
|
+
var _a2;
|
|
77
79
|
const keys = Object.keys(style);
|
|
78
80
|
if (!keys.some((key) => mergeStyleGroups[key])) {
|
|
79
81
|
return style;
|
|
80
82
|
}
|
|
81
83
|
for (const k in mergeStyleGroups) {
|
|
82
84
|
if (k in viewStyles) {
|
|
83
|
-
style[k] = style[k]
|
|
85
|
+
style[k] = (_a2 = style[k]) != null ? _a2 : viewStyles[k];
|
|
84
86
|
}
|
|
85
87
|
}
|
|
86
88
|
return style;
|
|
@@ -144,7 +146,7 @@ function extractToClassNames({
|
|
|
144
146
|
continue;
|
|
145
147
|
}
|
|
146
148
|
}
|
|
147
|
-
const ternary = mediaExtraction
|
|
149
|
+
const ternary = (mediaExtraction == null ? void 0 : mediaExtraction.ternaryWithoutMedia) || attr.value;
|
|
148
150
|
const consInfo = addStyles(ternary.consequent);
|
|
149
151
|
const altInfo = addStyles(ternary.alternate);
|
|
150
152
|
const cCN = consInfo.map((x) => x.identifier).join(" ");
|
|
@@ -4,6 +4,7 @@ import generate from "@babel/generator";
|
|
|
4
4
|
import * as t from "@babel/types";
|
|
5
5
|
import invariant from "invariant";
|
|
6
6
|
function normalizeTernaries(ternaries) {
|
|
7
|
+
var _a, _b;
|
|
7
8
|
invariant(Array.isArray(ternaries), "extractStaticTernaries expects param 1 to be an array of ternaries");
|
|
8
9
|
if (ternaries.length === 0) {
|
|
9
10
|
return [];
|
|
@@ -35,8 +36,8 @@ function normalizeTernaries(ternaries) {
|
|
|
35
36
|
remove
|
|
36
37
|
};
|
|
37
38
|
}
|
|
38
|
-
const altStyle = (shouldSwap ? consequent : alternate)
|
|
39
|
-
const consStyle = (shouldSwap ? alternate : consequent)
|
|
39
|
+
const altStyle = (_a = shouldSwap ? consequent : alternate) != null ? _a : {};
|
|
40
|
+
const consStyle = (_b = shouldSwap ? alternate : consequent) != null ? _b : {};
|
|
40
41
|
Object.assign(ternariesByKey[key].alternate, altStyle);
|
|
41
42
|
Object.assign(ternariesByKey[key].consequent, consStyle);
|
|
42
43
|
}
|
|
@@ -6,8 +6,9 @@ const hooks = {
|
|
|
6
6
|
useTheme: true
|
|
7
7
|
};
|
|
8
8
|
function removeUnusedHooks(compFn, shouldPrintDebug) {
|
|
9
|
+
var _a;
|
|
9
10
|
compFn.scope.crawl();
|
|
10
|
-
let bodyStatements = compFn
|
|
11
|
+
let bodyStatements = compFn == null ? void 0 : compFn.get("body");
|
|
11
12
|
if (!bodyStatements) {
|
|
12
13
|
console.log("no body statemnts?", compFn);
|
|
13
14
|
return;
|
|
@@ -32,7 +33,8 @@ function removeUnusedHooks(compFn, shouldPrintDebug) {
|
|
|
32
33
|
continue;
|
|
33
34
|
}
|
|
34
35
|
const isBindingReferenced = /* @__PURE__ */ __name((name) => {
|
|
35
|
-
|
|
36
|
+
var _a2;
|
|
37
|
+
return !!((_a2 = statement.scope.getBinding(name)) == null ? void 0 : _a2.referenced);
|
|
36
38
|
}, "isBindingReferenced");
|
|
37
39
|
for (const declarator of declarations) {
|
|
38
40
|
const id = declarator.get("id");
|
|
@@ -65,7 +67,7 @@ function removeUnusedHooks(compFn, shouldPrintDebug) {
|
|
|
65
67
|
if (shouldRemove) {
|
|
66
68
|
declarator.remove();
|
|
67
69
|
if (shouldPrintDebug) {
|
|
68
|
-
console.log(` [\u{1FA9D}] removed ${id.node["name"]
|
|
70
|
+
console.log(` [\u{1FA9D}] removed ${(_a = id.node["name"]) != null ? _a : ""}`);
|
|
69
71
|
}
|
|
70
72
|
}
|
|
71
73
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tamagui/static",
|
|
3
|
-
"version": "1.0.0-alpha.
|
|
3
|
+
"version": "1.0.0-alpha.39",
|
|
4
4
|
"source": "src/index.ts",
|
|
5
5
|
"typings": "types",
|
|
6
6
|
"main": "dist/cjs",
|
|
@@ -53,11 +53,11 @@
|
|
|
53
53
|
"@babel/traverse": "^7.15.4",
|
|
54
54
|
"@dish/babel-preset": "^0.0.6",
|
|
55
55
|
"@expo/match-media": "^0.1.0",
|
|
56
|
-
"@tamagui/build": "^1.0.0-alpha.
|
|
57
|
-
"@tamagui/core": "^1.0.0-alpha.
|
|
58
|
-
"@tamagui/core-node": "^1.0.0-alpha.
|
|
56
|
+
"@tamagui/build": "^1.0.0-alpha.39",
|
|
57
|
+
"@tamagui/core": "^1.0.0-alpha.39",
|
|
58
|
+
"@tamagui/core-node": "^1.0.0-alpha.39",
|
|
59
59
|
"@tamagui/fake-react-native": "^1.0.0-alpha.17",
|
|
60
|
-
"@tamagui/helpers": "^1.0.0-alpha.
|
|
60
|
+
"@tamagui/helpers": "^1.0.0-alpha.39",
|
|
61
61
|
"babel-literal-to-ast": "^2.1.0",
|
|
62
62
|
"esbuild": "^0.13.12",
|
|
63
63
|
"esbuild-register": "^3.1.2",
|
|
@@ -66,10 +66,10 @@
|
|
|
66
66
|
"invariant": "^2.2.4",
|
|
67
67
|
"loader-utils": "^2.0.0",
|
|
68
68
|
"lodash": "^4.17.21",
|
|
69
|
-
"tamagui": "^1.0.0-alpha.
|
|
69
|
+
"tamagui": "^1.0.0-alpha.39"
|
|
70
70
|
},
|
|
71
71
|
"peerDependencies": {
|
|
72
72
|
"react-native-web": "*"
|
|
73
73
|
},
|
|
74
|
-
"gitHead": "
|
|
74
|
+
"gitHead": "20b8c3487cae35a29bf878191fdc0381020b5304"
|
|
75
75
|
}
|
package/dist/constants.js
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import findCacheDir from "find-cache-dir";
|
|
2
|
-
const CSS_FILE_NAME = "__snack.css";
|
|
3
|
-
const MEDIA_SEP = "_";
|
|
4
|
-
const cacheDir = findCacheDir({ name: "tamagui", create: true });
|
|
5
|
-
export {
|
|
6
|
-
CSS_FILE_NAME,
|
|
7
|
-
MEDIA_SEP,
|
|
8
|
-
cacheDir
|
|
9
|
-
};
|
|
10
|
-
//# sourceMappingURL=constants.js.map
|
package/dist/constants.js.map
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../src/constants.ts"],
|
|
4
|
-
"sourcesContent": ["import findCacheDir from 'find-cache-dir'\n\nexport const CSS_FILE_NAME = '__snack.css'\n\n// ENSURE THIS ISNT THE SAME AS THE SEPARATOR USED FOR STYLE KEYS\n// SEE matching one in concatClassName\nexport const MEDIA_SEP = '_'\n\n// ensure cache dir\nexport const cacheDir = findCacheDir({ name: 'tamagui', create: true })\n"],
|
|
5
|
-
"mappings": "AAAA;AAEO,MAAM,gBAAgB;AAItB,MAAM,YAAY;AAGlB,MAAM,WAAW,aAAa,EAAE,MAAM,WAAW,QAAQ;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
-
import * as t from "@babel/types";
|
|
4
|
-
function accessSafe(obj, member) {
|
|
5
|
-
return t.logicalExpression("&&", t.logicalExpression("&&", t.binaryExpression("===", t.unaryExpression("typeof", obj), t.stringLiteral("object")), t.binaryExpression("!==", obj, t.nullLiteral())), t.memberExpression(obj, t.identifier(member), false));
|
|
6
|
-
}
|
|
7
|
-
__name(accessSafe, "accessSafe");
|
|
8
|
-
export {
|
|
9
|
-
accessSafe
|
|
10
|
-
};
|
|
11
|
-
//# sourceMappingURL=accessSafe.js.map
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../src/extractor/accessSafe.ts"],
|
|
4
|
-
"sourcesContent": ["import * as t from '@babel/types'\n\n// accessSafe wraps memberExpressions in object/null checks\n// TODO: inject this as a function? this gets pretty repetitive\nexport function accessSafe(obj: t.Expression, member: string): t.LogicalExpression {\n return t.logicalExpression(\n '&&',\n t.logicalExpression(\n '&&',\n // typeof obj === 'object\n t.binaryExpression('===', t.unaryExpression('typeof', obj), t.stringLiteral('object')),\n // obj !== null\n t.binaryExpression('!==', obj, t.nullLiteral())\n ),\n // obj.member\n t.memberExpression(obj, t.identifier(member), false)\n )\n}\n"],
|
|
5
|
-
"mappings": ";;AAAA;AAIO,oBAAoB,KAAmB,QAAqC;AACjF,SAAO,EAAE,kBACP,MACA,EAAE,kBACA,MAEA,EAAE,iBAAiB,OAAO,EAAE,gBAAgB,UAAU,MAAM,EAAE,cAAc,YAE5E,EAAE,iBAAiB,OAAO,KAAK,EAAE,iBAGnC,EAAE,iBAAiB,KAAK,EAAE,WAAW,SAAS;AAAA;AAXlC;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
-
import * as babelParser from "@babel/parser";
|
|
4
|
-
const parserOptions = Object.freeze({
|
|
5
|
-
plugins: [
|
|
6
|
-
"asyncGenerators",
|
|
7
|
-
"classProperties",
|
|
8
|
-
"dynamicImport",
|
|
9
|
-
"functionBind",
|
|
10
|
-
"jsx",
|
|
11
|
-
"numericSeparator",
|
|
12
|
-
"objectRestSpread",
|
|
13
|
-
"optionalCatchBinding",
|
|
14
|
-
"decorators-legacy",
|
|
15
|
-
"typescript",
|
|
16
|
-
"optionalChaining",
|
|
17
|
-
"nullishCoalescingOperator"
|
|
18
|
-
],
|
|
19
|
-
sourceType: "module"
|
|
20
|
-
});
|
|
21
|
-
const parser = babelParser.parse.bind(babelParser);
|
|
22
|
-
function babelParse(code) {
|
|
23
|
-
return parser(code.toString(), parserOptions);
|
|
24
|
-
}
|
|
25
|
-
__name(babelParse, "babelParse");
|
|
26
|
-
export {
|
|
27
|
-
babelParse,
|
|
28
|
-
parserOptions
|
|
29
|
-
};
|
|
30
|
-
//# sourceMappingURL=babelParse.js.map
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../src/extractor/babelParse.ts"],
|
|
4
|
-
"sourcesContent": ["import * as babelParser from '@babel/parser'\n\nexport const parserOptions: babelParser.ParserOptions = Object.freeze({\n plugins: [\n 'asyncGenerators',\n 'classProperties',\n 'dynamicImport',\n 'functionBind',\n 'jsx',\n 'numericSeparator',\n 'objectRestSpread',\n 'optionalCatchBinding',\n 'decorators-legacy',\n 'typescript',\n 'optionalChaining',\n 'nullishCoalescingOperator',\n // 'objectRestSpread',\n // 'dynamicImport'\n ],\n sourceType: 'module',\n})\n\nconst parser = babelParser.parse.bind(babelParser)\n\nexport function babelParse(code: string | Buffer): any {\n return parser(code.toString(), parserOptions)\n}\n"],
|
|
5
|
-
"mappings": ";;AAAA;AAEO,MAAM,gBAA2C,OAAO,OAAO;AAAA,EACpE,SAAS;AAAA,IACP;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA;AAAA,EAIF,YAAY;AAAA;AAGd,MAAM,SAAS,YAAY,MAAM,KAAK;AAE/B,oBAAoB,MAA4B;AACrD,SAAO,OAAO,KAAK,YAAY;AAAA;AADjB;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
-
import * as t from "@babel/types";
|
|
4
|
-
function buildClassName(classNameObjects) {
|
|
5
|
-
return classNameObjects.reduce((acc, val) => {
|
|
6
|
-
if (acc == null) {
|
|
7
|
-
if (t.isConditionalExpression(val) || t.isStringLiteral(val) || t.isNumericLiteral(val)) {
|
|
8
|
-
return val;
|
|
9
|
-
}
|
|
10
|
-
return t.logicalExpression("||", val, t.stringLiteral(""));
|
|
11
|
-
}
|
|
12
|
-
let inner;
|
|
13
|
-
if (t.isStringLiteral(val)) {
|
|
14
|
-
if (t.isStringLiteral(acc)) {
|
|
15
|
-
return t.stringLiteral(`${acc.value} ${val.value}`);
|
|
16
|
-
}
|
|
17
|
-
inner = t.stringLiteral(` ${val.value}`);
|
|
18
|
-
} else if (t.isLiteral(val)) {
|
|
19
|
-
inner = t.binaryExpression("+", t.stringLiteral(" "), val);
|
|
20
|
-
} else if (t.isConditionalExpression(val) || t.isBinaryExpression(val)) {
|
|
21
|
-
if (t.isStringLiteral(acc)) {
|
|
22
|
-
return t.binaryExpression("+", t.stringLiteral(`${acc.value} `), val);
|
|
23
|
-
}
|
|
24
|
-
inner = t.binaryExpression("+", t.stringLiteral(" "), val);
|
|
25
|
-
} else if (t.isIdentifier(val) || t.isMemberExpression(val)) {
|
|
26
|
-
inner = t.conditionalExpression(val, t.binaryExpression("+", t.stringLiteral(" "), val), t.stringLiteral(""));
|
|
27
|
-
} else {
|
|
28
|
-
if (t.isStringLiteral(acc)) {
|
|
29
|
-
return t.binaryExpression("+", t.stringLiteral(`${acc.value} `), t.logicalExpression("||", val, t.stringLiteral("")));
|
|
30
|
-
}
|
|
31
|
-
inner = t.binaryExpression("+", t.stringLiteral(" "), t.logicalExpression("||", val, t.stringLiteral("")));
|
|
32
|
-
}
|
|
33
|
-
return t.binaryExpression("+", acc, inner);
|
|
34
|
-
}, null);
|
|
35
|
-
}
|
|
36
|
-
__name(buildClassName, "buildClassName");
|
|
37
|
-
export {
|
|
38
|
-
buildClassName
|
|
39
|
-
};
|
|
40
|
-
//# sourceMappingURL=buildClassName.js.map
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../src/extractor/buildClassName.ts"],
|
|
4
|
-
"sourcesContent": ["import * as t from '@babel/types'\n\nimport { ClassNameObject } from '../types'\n\nexport function buildClassName(\n classNameObjects: ClassNameObject[]\n): t.Expression | t.StringLiteral | null {\n return classNameObjects.reduce<t.Expression | null>((acc, val) => {\n if (acc == null) {\n if (\n // pass conditional expressions through\n t.isConditionalExpression(val) ||\n // pass non-null literals through\n t.isStringLiteral(val) ||\n t.isNumericLiteral(val)\n ) {\n return val\n }\n return t.logicalExpression('||', val, t.stringLiteral(''))\n }\n\n let inner: t.Expression\n if (t.isStringLiteral(val)) {\n if (t.isStringLiteral(acc)) {\n // join adjacent string literals\n return t.stringLiteral(`${acc.value} ${val.value}`)\n }\n inner = t.stringLiteral(` ${val.value}`)\n } else if (t.isLiteral(val)) {\n inner = t.binaryExpression('+', t.stringLiteral(' '), val)\n } else if (t.isConditionalExpression(val) || t.isBinaryExpression(val)) {\n if (t.isStringLiteral(acc)) {\n return t.binaryExpression('+', t.stringLiteral(`${acc.value} `), val)\n }\n inner = t.binaryExpression('+', t.stringLiteral(' '), val)\n } else if (t.isIdentifier(val) || t.isMemberExpression(val)) {\n // identifiers and member expressions make for reasonable ternaries\n inner = t.conditionalExpression(\n val,\n t.binaryExpression('+', t.stringLiteral(' '), val),\n t.stringLiteral('')\n )\n } else {\n if (t.isStringLiteral(acc)) {\n return t.binaryExpression(\n '+',\n t.stringLiteral(`${acc.value} `),\n t.logicalExpression('||', val, t.stringLiteral(''))\n )\n }\n // use a logical expression for more complex prop values\n inner = t.binaryExpression(\n '+',\n t.stringLiteral(' '),\n t.logicalExpression('||', val, t.stringLiteral(''))\n )\n }\n\n return t.binaryExpression('+', acc, inner)\n }, null)\n}\n"],
|
|
5
|
-
"mappings": ";;AAAA;AAIO,wBACL,kBACuC;AACvC,SAAO,iBAAiB,OAA4B,CAAC,KAAK,QAAQ;AAChE,QAAI,OAAO,MAAM;AACf,UAEE,EAAE,wBAAwB,QAE1B,EAAE,gBAAgB,QAClB,EAAE,iBAAiB,MACnB;AACA,eAAO;AAAA;AAET,aAAO,EAAE,kBAAkB,MAAM,KAAK,EAAE,cAAc;AAAA;AAGxD,QAAI;AACJ,QAAI,EAAE,gBAAgB,MAAM;AAC1B,UAAI,EAAE,gBAAgB,MAAM;AAE1B,eAAO,EAAE,cAAc,GAAG,IAAI,SAAS,IAAI;AAAA;AAE7C,cAAQ,EAAE,cAAc,IAAI,IAAI;AAAA,eACvB,EAAE,UAAU,MAAM;AAC3B,cAAQ,EAAE,iBAAiB,KAAK,EAAE,cAAc,MAAM;AAAA,eAC7C,EAAE,wBAAwB,QAAQ,EAAE,mBAAmB,MAAM;AACtE,UAAI,EAAE,gBAAgB,MAAM;AAC1B,eAAO,EAAE,iBAAiB,KAAK,EAAE,cAAc,GAAG,IAAI,WAAW;AAAA;AAEnE,cAAQ,EAAE,iBAAiB,KAAK,EAAE,cAAc,MAAM;AAAA,eAC7C,EAAE,aAAa,QAAQ,EAAE,mBAAmB,MAAM;AAE3D,cAAQ,EAAE,sBACR,KACA,EAAE,iBAAiB,KAAK,EAAE,cAAc,MAAM,MAC9C,EAAE,cAAc;AAAA,WAEb;AACL,UAAI,EAAE,gBAAgB,MAAM;AAC1B,eAAO,EAAE,iBACP,KACA,EAAE,cAAc,GAAG,IAAI,WACvB,EAAE,kBAAkB,MAAM,KAAK,EAAE,cAAc;AAAA;AAInD,cAAQ,EAAE,iBACR,KACA,EAAE,cAAc,MAChB,EAAE,kBAAkB,MAAM,KAAK,EAAE,cAAc;AAAA;AAInD,WAAO,EAAE,iBAAiB,KAAK,KAAK;AAAA,KACnC;AAAA;AAvDW;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
-
import vm from "vm";
|
|
4
|
-
import generate from "@babel/generator";
|
|
5
|
-
import * as t from "@babel/types";
|
|
6
|
-
import { FAILED_EVAL } from "./createExtractor";
|
|
7
|
-
import { evaluateAstNode } from "./evaluateAstNode";
|
|
8
|
-
import { isValidThemeHook } from "./extractHelpers";
|
|
9
|
-
function createEvaluator({
|
|
10
|
-
tamaguiConfig,
|
|
11
|
-
staticNamespace,
|
|
12
|
-
sourcePath,
|
|
13
|
-
traversePath,
|
|
14
|
-
shouldPrintDebug
|
|
15
|
-
}) {
|
|
16
|
-
const evalFn = /* @__PURE__ */ __name((n) => {
|
|
17
|
-
if (t.isMemberExpression(n) && t.isIdentifier(n.property) && isValidThemeHook(traversePath, n, sourcePath)) {
|
|
18
|
-
const key = n.property.name;
|
|
19
|
-
if (shouldPrintDebug) {
|
|
20
|
-
console.log(" > found theme prop", key);
|
|
21
|
-
}
|
|
22
|
-
console.log("SHOULD FIND THEME (NESTED NOW)", key);
|
|
23
|
-
return `var(--${key})`;
|
|
24
|
-
}
|
|
25
|
-
if (t.isIdentifier(n) && staticNamespace.hasOwnProperty(n.name)) {
|
|
26
|
-
return staticNamespace[n.name];
|
|
27
|
-
}
|
|
28
|
-
const evalContext = vm.createContext(staticNamespace);
|
|
29
|
-
const code = `(${generate(n).code})`;
|
|
30
|
-
return vm.runInContext(code, evalContext);
|
|
31
|
-
}, "evalFn");
|
|
32
|
-
return (n) => {
|
|
33
|
-
return evaluateAstNode(n, evalFn);
|
|
34
|
-
};
|
|
35
|
-
}
|
|
36
|
-
__name(createEvaluator, "createEvaluator");
|
|
37
|
-
function createSafeEvaluator(attemptEval) {
|
|
38
|
-
return (n) => {
|
|
39
|
-
try {
|
|
40
|
-
return attemptEval(n);
|
|
41
|
-
} catch (err) {
|
|
42
|
-
return FAILED_EVAL;
|
|
43
|
-
}
|
|
44
|
-
};
|
|
45
|
-
}
|
|
46
|
-
__name(createSafeEvaluator, "createSafeEvaluator");
|
|
47
|
-
export {
|
|
48
|
-
createEvaluator,
|
|
49
|
-
createSafeEvaluator
|
|
50
|
-
};
|
|
51
|
-
//# sourceMappingURL=createEvaluator.js.map
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../src/extractor/createEvaluator.ts"],
|
|
4
|
-
"sourcesContent": ["import vm from 'vm'\n\nimport generate from '@babel/generator'\nimport { NodePath } from '@babel/traverse'\nimport * as t from '@babel/types'\nimport type { TamaguiConfig } from '@tamagui/core'\n\nimport { FAILED_EVAL } from './createExtractor'\nimport { evaluateAstNode } from './evaluateAstNode'\nimport { isValidThemeHook } from './extractHelpers'\n\nexport function createEvaluator({\n tamaguiConfig,\n staticNamespace,\n sourcePath,\n traversePath,\n shouldPrintDebug,\n}: {\n tamaguiConfig: TamaguiConfig\n staticNamespace: Record<string, any>\n sourcePath: string\n traversePath: NodePath<t.JSXElement>\n shouldPrintDebug: boolean\n}) {\n // called when evaluateAstNode encounters a dynamic-looking prop\n const evalFn = (n: t.Node) => {\n // themes\n if (\n t.isMemberExpression(n) &&\n t.isIdentifier(n.property) &&\n isValidThemeHook(traversePath, n, sourcePath)\n ) {\n const key = n.property.name\n if (shouldPrintDebug) {\n console.log(' > found theme prop', key)\n }\n console.log('SHOULD FIND THEME (NESTED NOW)', key) // tamaguiConfig.themes)\n // if (!themeKeys.has(key)) {\n // throw new Error(` > accessing non-existent theme key: ${key}`)\n // }\n return `var(--${key})`\n }\n // variable\n if (t.isIdentifier(n) && staticNamespace.hasOwnProperty(n.name)) {\n return staticNamespace[n.name]\n }\n const evalContext = vm.createContext(staticNamespace)\n const code = `(${generate(n as any).code})`\n // if (shouldPrintDebug) {\n // console.log('evaluating', { n, code, evalContext })\n // }\n return vm.runInContext(code, evalContext)\n }\n\n return (n: t.Node) => {\n return evaluateAstNode(n, evalFn)\n }\n}\n\nexport function createSafeEvaluator(attemptEval: (n: t.Node) => any) {\n return (n: t.Node) => {\n try {\n return attemptEval(n)\n } catch (err) {\n return FAILED_EVAL\n }\n }\n}\n"],
|
|
5
|
-
"mappings": ";;AAAA;AAEA;AAEA;AAGA;AACA;AACA;AAEO,yBAAyB;AAAA,EAC9B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,GAOC;AAED,QAAM,SAAS,wBAAC,MAAc;AAE5B,QACE,EAAE,mBAAmB,MACrB,EAAE,aAAa,EAAE,aACjB,iBAAiB,cAAc,GAAG,aAClC;AACA,YAAM,MAAM,EAAE,SAAS;AACvB,UAAI,kBAAkB;AACpB,gBAAQ,IAAI,0BAA0B;AAAA;AAExC,cAAQ,IAAI,kCAAkC;AAI9C,aAAO,SAAS;AAAA;AAGlB,QAAI,EAAE,aAAa,MAAM,gBAAgB,eAAe,EAAE,OAAO;AAC/D,aAAO,gBAAgB,EAAE;AAAA;AAE3B,UAAM,cAAc,GAAG,cAAc;AACrC,UAAM,OAAO,IAAI,SAAS,GAAU;AAIpC,WAAO,GAAG,aAAa,MAAM;AAAA,KA1BhB;AA6Bf,SAAO,CAAC,MAAc;AACpB,WAAO,gBAAgB,GAAG;AAAA;AAAA;AA5Cd;AAgDT,6BAA6B,aAAiC;AACnE,SAAO,CAAC,MAAc;AACpB,QAAI;AACF,aAAO,YAAY;AAAA,aACZ,KAAP;AACA,aAAO;AAAA;AAAA;AAAA;AALG;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|