@tamagui/static 1.13.3 → 1.14.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/constants.js +1 -52
- package/dist/cjs/constants.js.map +2 -2
- package/dist/cjs/extractor/accessSafe.js +1 -52
- package/dist/cjs/extractor/accessSafe.js.map +2 -2
- package/dist/cjs/extractor/babelParse.js +1 -66
- package/dist/cjs/extractor/babelParse.js.map +2 -2
- package/dist/cjs/extractor/buildClassName.js +1 -99
- package/dist/cjs/extractor/buildClassName.js.map +2 -2
- package/dist/cjs/extractor/bundle.js +1 -126
- package/dist/cjs/extractor/bundle.js.map +2 -2
- package/dist/cjs/extractor/createEvaluator.js +1 -86
- package/dist/cjs/extractor/createEvaluator.js.map +2 -2
- package/dist/cjs/extractor/createExtractor.js +15 -1630
- package/dist/cjs/extractor/createExtractor.js.map +2 -2
- package/dist/cjs/extractor/ensureImportingConcat.js +1 -64
- package/dist/cjs/extractor/ensureImportingConcat.js.map +2 -2
- package/dist/cjs/extractor/evaluateAstNode.js +1 -130
- package/dist/cjs/extractor/evaluateAstNode.js.map +2 -2
- package/dist/cjs/extractor/extractHelpers.js +1 -207
- package/dist/cjs/extractor/extractHelpers.js.map +2 -2
- package/dist/cjs/extractor/extractMediaStyle.js +1 -193
- package/dist/cjs/extractor/extractMediaStyle.js.map +2 -2
- package/dist/cjs/extractor/extractToClassNames.js +13 -413
- package/dist/cjs/extractor/extractToClassNames.js.map +2 -2
- package/dist/cjs/extractor/findTopmostFunction.js +1 -43
- package/dist/cjs/extractor/findTopmostFunction.js.map +2 -2
- package/dist/cjs/extractor/generatedUid.js +1 -59
- package/dist/cjs/extractor/generatedUid.js.map +2 -2
- package/dist/cjs/extractor/getPrefixLogs.js +1 -31
- package/dist/cjs/extractor/getPrefixLogs.js.map +2 -2
- package/dist/cjs/extractor/getPropValueFromAttributes.js +1 -89
- package/dist/cjs/extractor/getPropValueFromAttributes.js.map +2 -2
- package/dist/cjs/extractor/getSourceModule.js +1 -103
- package/dist/cjs/extractor/getSourceModule.js.map +2 -2
- package/dist/cjs/extractor/getStaticBindingsForScope.js +1 -225
- package/dist/cjs/extractor/getStaticBindingsForScope.js.map +2 -2
- package/dist/cjs/extractor/hoistClassNames.js +1 -74
- package/dist/cjs/extractor/hoistClassNames.js.map +2 -2
- package/dist/cjs/extractor/literalToAst.js +1 -115
- package/dist/cjs/extractor/literalToAst.js.map +2 -2
- package/dist/cjs/extractor/loadFile.js +2 -20
- package/dist/cjs/extractor/loadFile.js.map +2 -2
- package/dist/cjs/extractor/loadTamagui.js +15 -432
- package/dist/cjs/extractor/loadTamagui.js.map +2 -2
- package/dist/cjs/extractor/logLines.js +3 -43
- package/dist/cjs/extractor/logLines.js.map +2 -2
- package/dist/cjs/extractor/normalizeTernaries.js +1 -85
- package/dist/cjs/extractor/normalizeTernaries.js.map +2 -2
- package/dist/cjs/extractor/removeUnusedHooks.js +1 -109
- package/dist/cjs/extractor/removeUnusedHooks.js.map +2 -2
- package/dist/cjs/extractor/timer.js +1 -52
- package/dist/cjs/extractor/timer.js.map +2 -2
- package/dist/cjs/extractor/validHTMLAttributes.js +1 -126
- package/dist/cjs/extractor/validHTMLAttributes.js.map +2 -2
- package/dist/cjs/getPragmaOptions.js +2 -67
- package/dist/cjs/getPragmaOptions.js.map +2 -2
- package/dist/cjs/helpers/memoize.js +1 -45
- package/dist/cjs/helpers/memoize.js.map +2 -2
- package/dist/cjs/index.js +1 -42
- package/dist/cjs/index.js.map +2 -2
- package/dist/cjs/require.js +5 -81
- package/dist/cjs/require.js.map +2 -2
- package/dist/cjs/types.js +1 -16
- package/dist/cjs/types.js.map +2 -2
- package/dist/cjs/webpackPlugin.js +1 -34
- package/dist/cjs/webpackPlugin.js.map +2 -2
- package/dist/esm/constants.js +1 -14
- package/dist/esm/constants.js.map +2 -2
- package/dist/esm/constants.mjs +1 -14
- package/dist/esm/constants.mjs.map +2 -2
- package/dist/esm/extractor/accessSafe.js +1 -18
- package/dist/esm/extractor/accessSafe.js.map +2 -2
- package/dist/esm/extractor/accessSafe.mjs +1 -18
- package/dist/esm/extractor/accessSafe.mjs.map +2 -2
- package/dist/esm/extractor/babelParse.js +1 -31
- package/dist/esm/extractor/babelParse.js.map +2 -2
- package/dist/esm/extractor/babelParse.mjs +1 -31
- package/dist/esm/extractor/babelParse.mjs.map +2 -2
- package/dist/esm/extractor/buildClassName.js +1 -64
- package/dist/esm/extractor/buildClassName.js.map +2 -2
- package/dist/esm/extractor/buildClassName.mjs +1 -64
- package/dist/esm/extractor/buildClassName.mjs.map +2 -2
- package/dist/esm/extractor/bundle.js +1 -91
- package/dist/esm/extractor/bundle.js.map +2 -2
- package/dist/esm/extractor/bundle.mjs +1 -91
- package/dist/esm/extractor/bundle.mjs.map +2 -2
- package/dist/esm/extractor/createEvaluator.js +1 -51
- package/dist/esm/extractor/createEvaluator.js.map +2 -2
- package/dist/esm/extractor/createEvaluator.mjs +1 -51
- package/dist/esm/extractor/createEvaluator.mjs.map +2 -2
- package/dist/esm/extractor/createExtractor.js +15 -1613
- package/dist/esm/extractor/createExtractor.js.map +2 -2
- package/dist/esm/extractor/createExtractor.mjs +15 -1613
- package/dist/esm/extractor/createExtractor.mjs.map +2 -2
- package/dist/esm/extractor/ensureImportingConcat.js +1 -30
- package/dist/esm/extractor/ensureImportingConcat.js.map +2 -2
- package/dist/esm/extractor/ensureImportingConcat.mjs +1 -30
- package/dist/esm/extractor/ensureImportingConcat.mjs.map +2 -2
- package/dist/esm/extractor/evaluateAstNode.js +1 -96
- package/dist/esm/extractor/evaluateAstNode.js.map +2 -2
- package/dist/esm/extractor/evaluateAstNode.mjs +1 -96
- package/dist/esm/extractor/evaluateAstNode.mjs.map +2 -2
- package/dist/esm/extractor/extractHelpers.js +1 -161
- package/dist/esm/extractor/extractHelpers.js.map +2 -2
- package/dist/esm/extractor/extractHelpers.mjs +1 -161
- package/dist/esm/extractor/extractHelpers.mjs.map +2 -2
- package/dist/esm/extractor/extractMediaStyle.js +1 -158
- package/dist/esm/extractor/extractMediaStyle.js.map +2 -2
- package/dist/esm/extractor/extractMediaStyle.mjs +1 -158
- package/dist/esm/extractor/extractMediaStyle.mjs.map +2 -2
- package/dist/esm/extractor/extractToClassNames.js +13 -379
- package/dist/esm/extractor/extractToClassNames.js.map +2 -2
- package/dist/esm/extractor/extractToClassNames.mjs +13 -379
- package/dist/esm/extractor/extractToClassNames.mjs.map +2 -2
- package/dist/esm/extractor/findTopmostFunction.js +1 -19
- package/dist/esm/extractor/findTopmostFunction.js.map +2 -2
- package/dist/esm/extractor/findTopmostFunction.mjs +1 -19
- package/dist/esm/extractor/findTopmostFunction.mjs.map +2 -2
- package/dist/esm/extractor/generatedUid.js +1 -25
- package/dist/esm/extractor/generatedUid.js.map +2 -2
- package/dist/esm/extractor/generatedUid.mjs +1 -25
- package/dist/esm/extractor/generatedUid.mjs.map +2 -2
- package/dist/esm/extractor/getPrefixLogs.js +1 -7
- package/dist/esm/extractor/getPrefixLogs.js.map +2 -2
- package/dist/esm/extractor/getPrefixLogs.mjs +1 -7
- package/dist/esm/extractor/getPrefixLogs.mjs.map +2 -2
- package/dist/esm/extractor/getPropValueFromAttributes.js +1 -55
- package/dist/esm/extractor/getPropValueFromAttributes.js.map +2 -2
- package/dist/esm/extractor/getPropValueFromAttributes.mjs +1 -55
- package/dist/esm/extractor/getPropValueFromAttributes.mjs.map +2 -2
- package/dist/esm/extractor/getSourceModule.js +1 -69
- package/dist/esm/extractor/getSourceModule.js.map +2 -2
- package/dist/esm/extractor/getSourceModule.mjs +1 -69
- package/dist/esm/extractor/getSourceModule.mjs.map +2 -2
- package/dist/esm/extractor/getStaticBindingsForScope.js +1 -190
- package/dist/esm/extractor/getStaticBindingsForScope.js.map +2 -2
- package/dist/esm/extractor/getStaticBindingsForScope.mjs +1 -190
- package/dist/esm/extractor/getStaticBindingsForScope.mjs.map +2 -2
- package/dist/esm/extractor/hoistClassNames.js +1 -40
- package/dist/esm/extractor/hoistClassNames.js.map +2 -2
- package/dist/esm/extractor/hoistClassNames.mjs +1 -40
- package/dist/esm/extractor/hoistClassNames.mjs.map +2 -2
- package/dist/esm/extractor/literalToAst.js +1 -80
- package/dist/esm/extractor/literalToAst.js.map +2 -2
- package/dist/esm/extractor/literalToAst.mjs +1 -80
- package/dist/esm/extractor/literalToAst.mjs.map +2 -2
- package/dist/esm/extractor/loadFile.js +2 -19
- package/dist/esm/extractor/loadFile.js.map +2 -2
- package/dist/esm/extractor/loadFile.mjs +2 -19
- package/dist/esm/extractor/loadFile.mjs.map +2 -2
- package/dist/esm/extractor/loadTamagui.js +15 -396
- package/dist/esm/extractor/loadTamagui.js.map +2 -2
- package/dist/esm/extractor/loadTamagui.mjs +15 -396
- package/dist/esm/extractor/loadTamagui.mjs.map +2 -2
- package/dist/esm/extractor/logLines.js +3 -19
- package/dist/esm/extractor/logLines.js.map +2 -2
- package/dist/esm/extractor/logLines.mjs +3 -19
- package/dist/esm/extractor/logLines.mjs.map +2 -2
- package/dist/esm/extractor/normalizeTernaries.js +1 -51
- package/dist/esm/extractor/normalizeTernaries.js.map +2 -2
- package/dist/esm/extractor/normalizeTernaries.mjs +1 -51
- package/dist/esm/extractor/normalizeTernaries.mjs.map +2 -2
- package/dist/esm/extractor/removeUnusedHooks.js +1 -75
- package/dist/esm/extractor/removeUnusedHooks.js.map +2 -2
- package/dist/esm/extractor/removeUnusedHooks.mjs +1 -75
- package/dist/esm/extractor/removeUnusedHooks.mjs.map +2 -2
- package/dist/esm/extractor/timer.js +1 -28
- package/dist/esm/extractor/timer.js.map +2 -2
- package/dist/esm/extractor/timer.mjs +1 -28
- package/dist/esm/extractor/timer.mjs.map +2 -2
- package/dist/esm/extractor/validHTMLAttributes.js +1 -101
- package/dist/esm/extractor/validHTMLAttributes.js.map +2 -2
- package/dist/esm/extractor/validHTMLAttributes.mjs +1 -101
- package/dist/esm/extractor/validHTMLAttributes.mjs.map +2 -2
- package/dist/esm/getPragmaOptions.js +2 -43
- package/dist/esm/getPragmaOptions.js.map +2 -2
- package/dist/esm/getPragmaOptions.mjs +2 -43
- package/dist/esm/getPragmaOptions.mjs.map +2 -2
- package/dist/esm/helpers/memoize.js +1 -21
- package/dist/esm/helpers/memoize.js.map +2 -2
- package/dist/esm/helpers/memoize.mjs +1 -21
- package/dist/esm/helpers/memoize.mjs.map +2 -2
- package/dist/esm/index.js +1 -15
- package/dist/esm/index.js.map +2 -2
- package/dist/esm/index.mjs +1 -15
- package/dist/esm/index.mjs.map +2 -2
- package/dist/esm/require.js +5 -55
- package/dist/esm/require.js.map +2 -2
- package/dist/esm/require.mjs +5 -55
- package/dist/esm/require.mjs.map +2 -2
- package/dist/esm/webpackPlugin.js +1 -10
- package/dist/esm/webpackPlugin.js.map +2 -2
- package/dist/esm/webpackPlugin.mjs +1 -10
- package/dist/esm/webpackPlugin.mjs.map +2 -2
- package/package.json +14 -14
|
@@ -1,97 +1,2 @@
|
|
|
1
|
-
import
|
|
2
|
-
function evaluateAstNode(exprNode, evalFn, shouldPrintDebug) {
|
|
3
|
-
if (exprNode === void 0) {
|
|
4
|
-
return void 0;
|
|
5
|
-
}
|
|
6
|
-
if (exprNode === null) {
|
|
7
|
-
return true;
|
|
8
|
-
}
|
|
9
|
-
if (t.isJSXExpressionContainer(exprNode)) {
|
|
10
|
-
return evaluateAstNode(exprNode.expression);
|
|
11
|
-
}
|
|
12
|
-
if (t.isObjectExpression(exprNode)) {
|
|
13
|
-
const ret = {};
|
|
14
|
-
for (let idx = -1, len = exprNode.properties.length; ++idx < len; ) {
|
|
15
|
-
const value = exprNode.properties[idx];
|
|
16
|
-
if (!t.isObjectProperty(value)) {
|
|
17
|
-
throw new Error("evaluateAstNode can only evaluate object properties");
|
|
18
|
-
}
|
|
19
|
-
let key;
|
|
20
|
-
if (value.computed) {
|
|
21
|
-
if (typeof evalFn !== "function") {
|
|
22
|
-
throw new Error(
|
|
23
|
-
"evaluateAstNode does not support computed keys unless an eval function is provided"
|
|
24
|
-
);
|
|
25
|
-
}
|
|
26
|
-
key = evaluateAstNode(value.key, evalFn);
|
|
27
|
-
} else if (t.isIdentifier(value.key)) {
|
|
28
|
-
key = value.key.name;
|
|
29
|
-
} else if (t.isStringLiteral(value.key) || t.isNumericLiteral(value.key)) {
|
|
30
|
-
key = value.key.value;
|
|
31
|
-
} else {
|
|
32
|
-
throw new Error("Unsupported key type: " + value.key.type);
|
|
33
|
-
}
|
|
34
|
-
if (typeof key !== "string" && typeof key !== "number") {
|
|
35
|
-
throw new Error("key must be either a string or a number");
|
|
36
|
-
}
|
|
37
|
-
ret[key] = evaluateAstNode(value.value, evalFn);
|
|
38
|
-
}
|
|
39
|
-
return ret;
|
|
40
|
-
}
|
|
41
|
-
if (t.isArrayExpression(exprNode)) {
|
|
42
|
-
return exprNode.elements.map((x) => {
|
|
43
|
-
return evaluateAstNode(x, evalFn);
|
|
44
|
-
});
|
|
45
|
-
}
|
|
46
|
-
if (t.isUnaryExpression(exprNode) && exprNode.operator === "-") {
|
|
47
|
-
const ret = evaluateAstNode(exprNode.argument, evalFn);
|
|
48
|
-
if (ret == null) {
|
|
49
|
-
return null;
|
|
50
|
-
}
|
|
51
|
-
return -ret;
|
|
52
|
-
}
|
|
53
|
-
if (t.isTemplateLiteral(exprNode)) {
|
|
54
|
-
if (typeof evalFn !== "function") {
|
|
55
|
-
throw new Error(
|
|
56
|
-
"evaluateAstNode does not support template literals unless an eval function is provided"
|
|
57
|
-
);
|
|
58
|
-
}
|
|
59
|
-
let ret = "";
|
|
60
|
-
for (let idx = -1, len = exprNode.quasis.length; ++idx < len; ) {
|
|
61
|
-
const quasi = exprNode.quasis[idx];
|
|
62
|
-
const expr = exprNode.expressions[idx];
|
|
63
|
-
ret += quasi.value.raw;
|
|
64
|
-
if (expr) {
|
|
65
|
-
ret += evaluateAstNode(expr, evalFn);
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
return ret;
|
|
69
|
-
}
|
|
70
|
-
if (t.isNullLiteral(exprNode)) {
|
|
71
|
-
return null;
|
|
72
|
-
}
|
|
73
|
-
if (t.isNumericLiteral(exprNode) || t.isStringLiteral(exprNode) || t.isBooleanLiteral(exprNode)) {
|
|
74
|
-
return exprNode.value;
|
|
75
|
-
}
|
|
76
|
-
if (t.isBinaryExpression(exprNode)) {
|
|
77
|
-
if (exprNode.operator === "+") {
|
|
78
|
-
return evaluateAstNode(exprNode.left, evalFn) + evaluateAstNode(exprNode.right, evalFn);
|
|
79
|
-
} else if (exprNode.operator === "-") {
|
|
80
|
-
return evaluateAstNode(exprNode.left, evalFn) - evaluateAstNode(exprNode.right, evalFn);
|
|
81
|
-
} else if (exprNode.operator === "*") {
|
|
82
|
-
return evaluateAstNode(exprNode.left, evalFn) * evaluateAstNode(exprNode.right, evalFn);
|
|
83
|
-
} else if (exprNode.operator === "/") {
|
|
84
|
-
return evaluateAstNode(exprNode.left, evalFn) / evaluateAstNode(exprNode.right, evalFn);
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
if (typeof evalFn !== "function") {
|
|
88
|
-
throw new Error(
|
|
89
|
-
"evaluateAstNode does not support non-literal values unless an eval function is provided"
|
|
90
|
-
);
|
|
91
|
-
}
|
|
92
|
-
return evalFn(exprNode);
|
|
93
|
-
}
|
|
94
|
-
export {
|
|
95
|
-
evaluateAstNode
|
|
96
|
-
};
|
|
1
|
+
import*as i from"@babel/types";function e(t,r,f){if(t!==void 0){if(t===null)return!0;if(i.isJSXExpressionContainer(t))return e(t.expression);if(i.isObjectExpression(t)){const s={};for(let o=-1,l=t.properties.length;++o<l;){const n=t.properties[o];if(!i.isObjectProperty(n))throw new Error("evaluateAstNode can only evaluate object properties");let u;if(n.computed){if(typeof r!="function")throw new Error("evaluateAstNode does not support computed keys unless an eval function is provided");u=e(n.key,r)}else if(i.isIdentifier(n.key))u=n.key.name;else if(i.isStringLiteral(n.key)||i.isNumericLiteral(n.key))u=n.key.value;else throw new Error("Unsupported key type: "+n.key.type);if(typeof u!="string"&&typeof u!="number")throw new Error("key must be either a string or a number");s[u]=e(n.value,r)}return s}if(i.isArrayExpression(t))return t.elements.map(s=>e(s,r));if(i.isUnaryExpression(t)&&t.operator==="-"){const s=e(t.argument,r);return s==null?null:-s}if(i.isTemplateLiteral(t)){if(typeof r!="function")throw new Error("evaluateAstNode does not support template literals unless an eval function is provided");let s="";for(let o=-1,l=t.quasis.length;++o<l;){const n=t.quasis[o],u=t.expressions[o];s+=n.value.raw,u&&(s+=e(u,r))}return s}if(i.isNullLiteral(t))return null;if(i.isNumericLiteral(t)||i.isStringLiteral(t)||i.isBooleanLiteral(t))return t.value;if(i.isBinaryExpression(t)){if(t.operator==="+")return e(t.left,r)+e(t.right,r);if(t.operator==="-")return e(t.left,r)-e(t.right,r);if(t.operator==="*")return e(t.left,r)*e(t.right,r);if(t.operator==="/")return e(t.left,r)/e(t.right,r)}if(typeof r!="function")throw new Error("evaluateAstNode does not support non-literal values unless an eval function is provided");return r(t)}}export{e as evaluateAstNode};
|
|
97
2
|
//# sourceMappingURL=evaluateAstNode.mjs.map
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/extractor/evaluateAstNode.ts"],
|
|
4
4
|
"sourcesContent": ["import * as t from '@babel/types'\n\nexport function evaluateAstNode(\n exprNode: t.Node | undefined | null,\n evalFn?: (node: t.Node) => any,\n shouldPrintDebug?: boolean | 'verbose'\n): any {\n if (exprNode === undefined) {\n return undefined\n }\n\n // null === boolean true (at least in our use cases for jsx eval)\n if (exprNode === null) {\n return true\n }\n\n if (t.isJSXExpressionContainer(exprNode)) {\n return evaluateAstNode(exprNode.expression)\n }\n\n // loop through ObjectExpression keys\n if (t.isObjectExpression(exprNode)) {\n const ret: Record<string, any> = {}\n for (let idx = -1, len = exprNode.properties.length; ++idx < len; ) {\n const value = exprNode.properties[idx]\n\n if (!t.isObjectProperty(value)) {\n throw new Error('evaluateAstNode can only evaluate object properties')\n }\n\n let key: string | number | null | undefined | boolean\n if (value.computed) {\n if (typeof evalFn !== 'function') {\n throw new Error(\n 'evaluateAstNode does not support computed keys unless an eval function is provided'\n )\n }\n key = evaluateAstNode(value.key, evalFn)\n } else if (t.isIdentifier(value.key)) {\n key = value.key.name\n } else if (t.isStringLiteral(value.key) || t.isNumericLiteral(value.key)) {\n key = value.key.value\n } else {\n throw new Error('Unsupported key type: ' + value.key.type)\n }\n\n if (typeof key !== 'string' && typeof key !== 'number') {\n throw new Error('key must be either a string or a number')\n }\n\n ret[key] = evaluateAstNode(value.value, evalFn)\n }\n return ret\n }\n\n if (t.isArrayExpression(exprNode)) {\n return exprNode.elements.map((x) => {\n return evaluateAstNode(x as any, evalFn)\n })\n }\n\n if (t.isUnaryExpression(exprNode) && exprNode.operator === '-') {\n const ret = evaluateAstNode(exprNode.argument, evalFn)\n if (ret == null) {\n return null\n }\n return -ret\n }\n\n if (t.isTemplateLiteral(exprNode)) {\n if (typeof evalFn !== 'function') {\n throw new Error(\n 'evaluateAstNode does not support template literals unless an eval function is provided'\n )\n }\n\n let ret = ''\n for (let idx = -1, len = exprNode.quasis.length; ++idx < len; ) {\n const quasi = exprNode.quasis[idx]\n const expr = exprNode.expressions[idx]\n ret += quasi.value.raw\n if (expr) {\n ret += evaluateAstNode(expr, evalFn)\n }\n }\n return ret\n }\n\n // In the interest of representing the \"evaluated\" prop\n // as the user intended, we support negative null. Why not.\n if (t.isNullLiteral(exprNode)) {\n return null\n }\n\n if (t.isNumericLiteral(exprNode) || t.isStringLiteral(exprNode) || t.isBooleanLiteral(exprNode)) {\n // In the interest of representing the \"evaluated\" prop\n // as the user intended, we support negative null. Why not.\n return exprNode.value\n }\n\n if (t.isBinaryExpression(exprNode)) {\n if (exprNode.operator === '+') {\n return evaluateAstNode(exprNode.left, evalFn) + evaluateAstNode(exprNode.right, evalFn)\n } else if (exprNode.operator === '-') {\n return evaluateAstNode(exprNode.left, evalFn) - evaluateAstNode(exprNode.right, evalFn)\n } else if (exprNode.operator === '*') {\n return evaluateAstNode(exprNode.left, evalFn) * evaluateAstNode(exprNode.right, evalFn)\n } else if (exprNode.operator === '/') {\n return evaluateAstNode(exprNode.left, evalFn) / evaluateAstNode(exprNode.right, evalFn)\n }\n }\n\n // if we've made it this far, the value has to be evaluated\n if (typeof evalFn !== 'function') {\n throw new Error(\n 'evaluateAstNode does not support non-literal values unless an eval function is provided'\n )\n }\n\n return evalFn(exprNode)\n}\n"],
|
|
5
|
-
"mappings": "AAAA,
|
|
6
|
-
"names": []
|
|
5
|
+
"mappings": "AAAA,UAAYA,MAAO,eAEZ,SAASC,EACdC,EACAC,EACAC,EACK,CACL,GAAIF,IAAa,OAKjB,IAAIA,IAAa,KACf,MAAO,GAGT,GAAIF,EAAE,yBAAyBE,CAAQ,EACrC,OAAOD,EAAgBC,EAAS,UAAU,EAI5C,GAAIF,EAAE,mBAAmBE,CAAQ,EAAG,CAClC,MAAMG,EAA2B,CAAC,EAClC,QAASC,EAAM,GAAIC,EAAML,EAAS,WAAW,OAAQ,EAAEI,EAAMC,GAAO,CAClE,MAAMC,EAAQN,EAAS,WAAWI,CAAG,EAErC,GAAI,CAACN,EAAE,iBAAiBQ,CAAK,EAC3B,MAAM,IAAI,MAAM,qDAAqD,EAGvE,IAAIC,EACJ,GAAID,EAAM,SAAU,CAClB,GAAI,OAAOL,GAAW,WACpB,MAAM,IAAI,MACR,oFACF,EAEFM,EAAMR,EAAgBO,EAAM,IAAKL,CAAM,CACzC,SAAWH,EAAE,aAAaQ,EAAM,GAAG,EACjCC,EAAMD,EAAM,IAAI,aACPR,EAAE,gBAAgBQ,EAAM,GAAG,GAAKR,EAAE,iBAAiBQ,EAAM,GAAG,EACrEC,EAAMD,EAAM,IAAI,UAEhB,OAAM,IAAI,MAAM,yBAA2BA,EAAM,IAAI,IAAI,EAG3D,GAAI,OAAOC,GAAQ,UAAY,OAAOA,GAAQ,SAC5C,MAAM,IAAI,MAAM,yCAAyC,EAG3DJ,EAAII,CAAG,EAAIR,EAAgBO,EAAM,MAAOL,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,EAAS,MAAOC,CAAM,CAE1F,CAGA,GAAI,OAAOA,GAAW,WACpB,MAAM,IAAI,MACR,yFACF,EAGF,OAAOA,EAAOD,CAAQ,EACxB",
|
|
6
|
+
"names": ["t", "evaluateAstNode", "exprNode", "evalFn", "shouldPrintDebug", "ret", "idx", "len", "value", "key", "x", "quasi", "expr"]
|
|
7
7
|
}
|
|
@@ -1,162 +1,2 @@
|
|
|
1
|
-
import
|
|
2
|
-
import generate from "@babel/generator";
|
|
3
|
-
import * as t from "@babel/types";
|
|
4
|
-
import findRoot from "find-root";
|
|
5
|
-
import { memoize } from "../helpers/memoize.js";
|
|
6
|
-
function isPresent(input) {
|
|
7
|
-
return input != null;
|
|
8
|
-
}
|
|
9
|
-
function isSimpleSpread(node) {
|
|
10
|
-
return t.isIdentifier(node.argument) || t.isMemberExpression(node.argument);
|
|
11
|
-
}
|
|
12
|
-
const attrStr = (attr) => {
|
|
13
|
-
return !attr ? "" : attr.type === "attr" ? getNameAttr(attr.value) : attr.type === "ternary" ? `...${ternaryStr(attr.value)}` : `${attr.type}(${objToStr(attr.value)})`;
|
|
14
|
-
};
|
|
15
|
-
const objToStr = (obj, spacer = ", ") => {
|
|
16
|
-
if (!obj) {
|
|
17
|
-
return `${obj}`;
|
|
18
|
-
}
|
|
19
|
-
return `{${Object.entries(obj).map(
|
|
20
|
-
([k, v]) => `${k}:${Array.isArray(v) ? `[...]` : v && typeof v === "object" ? `${objToStr(v, ",")}` : JSON.stringify(v)}`
|
|
21
|
-
).join(spacer)}}`;
|
|
22
|
-
};
|
|
23
|
-
const getNameAttr = (attr) => {
|
|
24
|
-
if (t.isJSXSpreadAttribute(attr)) {
|
|
25
|
-
return `...${attr.argument["name"]}`;
|
|
26
|
-
}
|
|
27
|
-
return "name" in attr ? attr.name.name : `unknown-${attr["type"]}`;
|
|
28
|
-
};
|
|
29
|
-
const ternaryStr = (x) => {
|
|
30
|
-
const conditional = t.isIdentifier(x.test) ? x.test.name : t.isMemberExpression(x.test) ? [x.test.object["name"], x.test.property["name"]] : (
|
|
31
|
-
// @ts-ignore
|
|
32
|
-
generate(x.test).code
|
|
33
|
-
);
|
|
34
|
-
return [
|
|
35
|
-
"ternary(",
|
|
36
|
-
conditional,
|
|
37
|
-
isFilledObj(x.consequent) ? ` ? ${objToStr(x.consequent)}` : " ? \u{1F6AB}",
|
|
38
|
-
isFilledObj(x.alternate) ? ` : ${objToStr(x.alternate)}` : " : \u{1F6AB}",
|
|
39
|
-
")"
|
|
40
|
-
].flat().join("");
|
|
41
|
-
};
|
|
42
|
-
const isFilledObj = (obj) => obj && Object.keys(obj).length;
|
|
43
|
-
function findComponentName(scope) {
|
|
44
|
-
var _a;
|
|
45
|
-
const componentName = "";
|
|
46
|
-
let cur = scope.path;
|
|
47
|
-
while (cur.parentPath && !t.isProgram(cur.parentPath.parent)) {
|
|
48
|
-
cur = cur.parentPath;
|
|
49
|
-
}
|
|
50
|
-
let node = cur.parent;
|
|
51
|
-
if (t.isExportNamedDeclaration(node)) {
|
|
52
|
-
node = node.declaration;
|
|
53
|
-
}
|
|
54
|
-
if (t.isVariableDeclaration(node)) {
|
|
55
|
-
const [dec] = node.declarations;
|
|
56
|
-
if (t.isVariableDeclarator(dec) && t.isIdentifier(dec.id)) {
|
|
57
|
-
return dec.id.name;
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
if (t.isFunctionDeclaration(node)) {
|
|
61
|
-
return (_a = node.id) == null ? void 0 : _a.name;
|
|
62
|
-
}
|
|
63
|
-
return componentName;
|
|
64
|
-
}
|
|
65
|
-
function isValidThemeHook(props, jsxPath, n, sourcePath) {
|
|
66
|
-
var _a;
|
|
67
|
-
if (!t.isIdentifier(n.object) || !t.isIdentifier(n.property))
|
|
68
|
-
return false;
|
|
69
|
-
const bindings = jsxPath.scope.getAllBindings();
|
|
70
|
-
const binding = bindings[n.object.name];
|
|
71
|
-
if (!(binding == null ? void 0 : binding.path))
|
|
72
|
-
return false;
|
|
73
|
-
if (!binding.path.isVariableDeclarator())
|
|
74
|
-
return false;
|
|
75
|
-
const init = binding.path.node.init;
|
|
76
|
-
if (!t.isCallExpression(init))
|
|
77
|
-
return false;
|
|
78
|
-
if (!t.isIdentifier(init.callee))
|
|
79
|
-
return false;
|
|
80
|
-
if (init.callee.name !== "useTheme")
|
|
81
|
-
return false;
|
|
82
|
-
const importNode = (_a = binding.scope.getBinding("useTheme")) == null ? void 0 : _a.path.parent;
|
|
83
|
-
if (!t.isImportDeclaration(importNode))
|
|
84
|
-
return false;
|
|
85
|
-
if (sourcePath && !isValidImport(props, sourcePath)) {
|
|
86
|
-
return false;
|
|
87
|
-
}
|
|
88
|
-
return true;
|
|
89
|
-
}
|
|
90
|
-
const isInsideComponentPackage = (props, moduleName) => {
|
|
91
|
-
return getValidComponentsPaths(props).some((path) => {
|
|
92
|
-
return moduleName.startsWith(path);
|
|
93
|
-
});
|
|
94
|
-
};
|
|
95
|
-
const isComponentPackage = (props, srcName) => {
|
|
96
|
-
return getValidComponentsPaths(props).some((path) => {
|
|
97
|
-
return srcName.startsWith(path);
|
|
98
|
-
});
|
|
99
|
-
};
|
|
100
|
-
function getValidComponent(props, moduleName, componentName) {
|
|
101
|
-
if (componentName[0].toUpperCase() !== componentName[0]) {
|
|
102
|
-
return false;
|
|
103
|
-
}
|
|
104
|
-
for (const loaded of props.allLoadedComponents) {
|
|
105
|
-
if (!loaded)
|
|
106
|
-
continue;
|
|
107
|
-
const isInModule = moduleName === "*" || moduleName.startsWith(loaded.moduleName);
|
|
108
|
-
const foundComponent = loaded.nameToInfo[componentName];
|
|
109
|
-
if (isInModule && foundComponent) {
|
|
110
|
-
return foundComponent;
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
return null;
|
|
114
|
-
}
|
|
115
|
-
const isValidModule = (props, moduleName) => {
|
|
116
|
-
if (typeof moduleName !== "string") {
|
|
117
|
-
throw new Error(`No module name`);
|
|
118
|
-
}
|
|
119
|
-
const isLocal = moduleName.startsWith(".");
|
|
120
|
-
return {
|
|
121
|
-
isLocal,
|
|
122
|
-
isValid: isLocal ? isInsideComponentPackage(props, moduleName) : isComponentPackage(props, moduleName)
|
|
123
|
-
};
|
|
124
|
-
};
|
|
125
|
-
const getValidImport = (props, moduleName, componentName) => {
|
|
126
|
-
const { isValid, isLocal } = isValidModule(props, moduleName);
|
|
127
|
-
if (!isValid || !componentName) {
|
|
128
|
-
return null;
|
|
129
|
-
}
|
|
130
|
-
return getValidComponent(props, isLocal ? "*" : moduleName, componentName) || null;
|
|
131
|
-
};
|
|
132
|
-
const isValidImport = (props, moduleName, componentName) => {
|
|
133
|
-
if (!componentName) {
|
|
134
|
-
return isValidModule(props, moduleName).isValid;
|
|
135
|
-
}
|
|
136
|
-
return Boolean(getValidImport(props, moduleName, componentName));
|
|
137
|
-
};
|
|
138
|
-
const getValidComponentPackages = memoize((props) => {
|
|
139
|
-
return [.../* @__PURE__ */ new Set(["@tamagui/core", "tamagui", ...props.components])];
|
|
140
|
-
});
|
|
141
|
-
const getValidComponentsPaths = memoize((props) => {
|
|
142
|
-
return getValidComponentPackages(props).map((pkg) => {
|
|
143
|
-
const root = findRoot(pkg);
|
|
144
|
-
return basename(root);
|
|
145
|
-
});
|
|
146
|
-
});
|
|
147
|
-
export {
|
|
148
|
-
attrStr,
|
|
149
|
-
findComponentName,
|
|
150
|
-
getValidComponent,
|
|
151
|
-
getValidImport,
|
|
152
|
-
isComponentPackage,
|
|
153
|
-
isInsideComponentPackage,
|
|
154
|
-
isPresent,
|
|
155
|
-
isSimpleSpread,
|
|
156
|
-
isValidImport,
|
|
157
|
-
isValidModule,
|
|
158
|
-
isValidThemeHook,
|
|
159
|
-
objToStr,
|
|
160
|
-
ternaryStr
|
|
161
|
-
};
|
|
1
|
+
import{basename as g}from"path";import h from"@babel/generator";import*as r from"@babel/types";import y from"find-root";import{memoize as p}from"../helpers/memoize.js";function P(t){return t!=null}function j(t){return r.isIdentifier(t.argument)||r.isMemberExpression(t.argument)}const E=t=>t?t.type==="attr"?I(t.value):t.type==="ternary"?`...${b(t.value)}`:`${t.type}(${s(t.value)})`:"",s=(t,n=", ")=>t?`{${Object.entries(t).map(([e,i])=>`${e}:${Array.isArray(i)?"[...]":i&&typeof i=="object"?`${s(i,",")}`:JSON.stringify(i)}`).join(n)}}`:`${t}`,I=t=>r.isJSXSpreadAttribute(t)?`...${t.argument.name}`:"name"in t?t.name.name:`unknown-${t.type}`,b=t=>["ternary(",r.isIdentifier(t.test)?t.test.name:r.isMemberExpression(t.test)?[t.test.object.name,t.test.property.name]:h(t.test).code,f(t.consequent)?` ? ${s(t.consequent)}`:" ? \u{1F6AB}",f(t.alternate)?` : ${s(t.alternate)}`:" : \u{1F6AB}",")"].flat().join(""),f=t=>t&&Object.keys(t).length;function k(t){var a;const n="";let e=t.path;for(;e.parentPath&&!r.isProgram(e.parentPath.parent);)e=e.parentPath;let i=e.parent;if(r.isExportNamedDeclaration(i)&&(i=i.declaration),r.isVariableDeclaration(i)){const[o]=i.declarations;if(r.isVariableDeclarator(o)&&r.isIdentifier(o.id))return o.id.name}return r.isFunctionDeclaration(i)?(a=i.id)==null?void 0:a.name:n}function D(t,n,e,i){var u;if(!r.isIdentifier(e.object)||!r.isIdentifier(e.property))return!1;const o=n.scope.getAllBindings()[e.object.name];if(!(o!=null&&o.path)||!o.path.isVariableDeclarator())return!1;const l=o.path.node.init;if(!r.isCallExpression(l)||!r.isIdentifier(l.callee)||l.callee.name!=="useTheme")return!1;const d=(u=o.scope.getBinding("useTheme"))==null?void 0:u.path.parent;return!(!r.isImportDeclaration(d)||i&&!V(t,i))}const T=(t,n)=>m(t).some(e=>n.startsWith(e)),O=(t,n)=>m(t).some(e=>n.startsWith(e));function S(t,n,e){if(e[0].toUpperCase()!==e[0])return!1;for(const i of t.allLoadedComponents){if(!i)continue;const a=n==="*"||n.startsWith(i.moduleName),o=i.nameToInfo[e];if(a&&o)return o}return null}const c=(t,n)=>{if(typeof n!="string")throw new Error("No module name");const e=n.startsWith(".");return{isLocal:e,isValid:e?T(t,n):O(t,n)}},W=(t,n,e)=>{const{isValid:i,isLocal:a}=c(t,n);return!i||!e?null:S(t,a?"*":n,e)||null},V=(t,n,e)=>e?Boolean(W(t,n,e)):c(t,n).isValid,x=p(t=>[...new Set(["@tamagui/core","tamagui",...t.components])]),m=p(t=>x(t).map(n=>{const e=y(n);return g(e)}));export{E as attrStr,k as findComponentName,S as getValidComponent,W as getValidImport,O as isComponentPackage,T as isInsideComponentPackage,P as isPresent,j as isSimpleSpread,V as isValidImport,c as isValidModule,D as isValidThemeHook,s as objToStr,b as ternaryStr};
|
|
162
2
|
//# sourceMappingURL=extractHelpers.js.map
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/extractor/extractHelpers.ts"],
|
|
4
4
|
"sourcesContent": ["import { basename } from 'path'\n\nimport generate from '@babel/generator'\nimport type { NodePath } from '@babel/traverse'\nimport * as t from '@babel/types'\nimport findRoot from 'find-root'\n\nimport { memoize } from '../helpers/memoize.js'\nimport type { ExtractedAttr, TamaguiOptionsWithFileInfo, Ternary } from '../types.js'\n\n// import { astToLiteral } from './literalToAst'\n\nexport function isPresent<T extends Object>(\n input: null | void | undefined | T\n): input is T {\n return input != null\n}\n\nexport function isSimpleSpread(node: t.JSXSpreadAttribute) {\n return t.isIdentifier(node.argument) || t.isMemberExpression(node.argument)\n}\n\nexport const attrStr = (attr?: ExtractedAttr) => {\n return !attr\n ? ''\n : attr.type === 'attr'\n ? getNameAttr(attr.value)\n : attr.type === 'ternary'\n ? `...${ternaryStr(attr.value)}`\n : `${attr.type}(${objToStr(attr.value)})`\n}\n\nexport const objToStr = (obj: any, spacer = ', ') => {\n if (!obj) {\n return `${obj}`\n }\n return `{${Object.entries(obj)\n .map(\n ([k, v]) =>\n `${k}:${\n Array.isArray(v)\n ? `[...]`\n : v && typeof v === 'object'\n ? `${objToStr(v, ',')}`\n : JSON.stringify(v)\n }`\n )\n .join(spacer)}}`\n}\n\nconst getNameAttr = (attr: t.JSXAttribute | t.JSXSpreadAttribute) => {\n if (t.isJSXSpreadAttribute(attr)) {\n return `...${attr.argument['name']}`\n }\n return 'name' in attr ? attr.name.name : `unknown-${attr['type']}`\n}\n\nexport const ternaryStr = (x: Ternary) => {\n const conditional = t.isIdentifier(x.test)\n ? x.test.name\n : t.isMemberExpression(x.test)\n ? [x.test.object['name'], x.test.property['name']]\n : // @ts-ignore\n generate(x.test as any).code\n return [\n 'ternary(',\n conditional,\n isFilledObj(x.consequent) ? ` ? ${objToStr(x.consequent)}` : ' ? \uD83D\uDEAB',\n isFilledObj(x.alternate) ? ` : ${objToStr(x.alternate)}` : ' : \uD83D\uDEAB',\n ')',\n ]\n .flat()\n .join('')\n}\n\nconst isFilledObj = (obj: any) => obj && Object.keys(obj).length\n\nexport function findComponentName(scope) {\n const componentName = ''\n let cur = scope.path\n while (cur.parentPath && !t.isProgram(cur.parentPath.parent)) {\n cur = cur.parentPath\n }\n let node = cur.parent\n if (t.isExportNamedDeclaration(node)) {\n node = node.declaration\n }\n if (t.isVariableDeclaration(node)) {\n const [dec] = node.declarations\n if (t.isVariableDeclarator(dec) && t.isIdentifier(dec.id)) {\n return dec.id.name\n }\n }\n if (t.isFunctionDeclaration(node)) {\n return node.id?.name\n }\n return componentName\n}\n\nexport function isValidThemeHook(\n props: TamaguiOptionsWithFileInfo,\n jsxPath: NodePath<t.JSXElement>,\n n: t.MemberExpression,\n sourcePath?: string\n) {\n if (!t.isIdentifier(n.object) || !t.isIdentifier(n.property)) return false\n const bindings = jsxPath.scope.getAllBindings()\n const binding = bindings[n.object.name]\n if (!binding?.path) return false\n if (!binding.path.isVariableDeclarator()) return false\n const init = binding.path.node.init\n if (!t.isCallExpression(init)) return false\n if (!t.isIdentifier(init.callee)) return false\n // TODO could support renaming useTheme by looking up import first\n if (init.callee.name !== 'useTheme') return false\n const importNode = binding.scope.getBinding('useTheme')?.path.parent\n if (!t.isImportDeclaration(importNode)) return false\n if (sourcePath && !isValidImport(props, sourcePath)) {\n return false\n }\n return true\n}\n\nexport const isInsideComponentPackage = (\n props: TamaguiOptionsWithFileInfo,\n moduleName: string\n) => {\n return getValidComponentsPaths(props).some((path) => {\n return moduleName.startsWith(path)\n })\n}\n\nexport const isComponentPackage = (\n props: TamaguiOptionsWithFileInfo,\n srcName: string\n) => {\n return getValidComponentsPaths(props).some((path) => {\n return srcName.startsWith(path)\n })\n}\n\nexport function getValidComponent(\n props: TamaguiOptionsWithFileInfo,\n moduleName: string,\n componentName: string\n) {\n // must be uppercase of course\n if (componentName[0].toUpperCase() !== componentName[0]) {\n return false\n }\n\n for (const loaded of props.allLoadedComponents) {\n if (!loaded) continue\n const isInModule = moduleName === '*' || moduleName.startsWith(loaded.moduleName)\n const foundComponent = loaded.nameToInfo[componentName]\n // eslint-disable-next-line no-console\n if (isInModule && foundComponent) {\n return foundComponent\n }\n }\n\n return null\n}\n\nexport const isValidModule = (props: TamaguiOptionsWithFileInfo, moduleName: string) => {\n if (typeof moduleName !== 'string') {\n throw new Error(`No module name`)\n }\n const isLocal = moduleName.startsWith('.')\n return {\n isLocal,\n isValid: isLocal\n ? isInsideComponentPackage(props, moduleName)\n : isComponentPackage(props, moduleName),\n }\n}\n\nexport const getValidImport = (\n props: TamaguiOptionsWithFileInfo,\n moduleName: string,\n componentName?: string\n) => {\n const { isValid, isLocal } = isValidModule(props, moduleName)\n if (!isValid || !componentName) {\n return null\n }\n return getValidComponent(props, isLocal ? '*' : moduleName, componentName) || null\n}\n\nexport const isValidImport = (\n props: TamaguiOptionsWithFileInfo,\n moduleName: string,\n componentName?: string\n) => {\n if (!componentName) {\n return isValidModule(props, moduleName).isValid\n }\n return Boolean(getValidImport(props, moduleName, componentName))\n}\n\nconst getValidComponentPackages = memoize((props: TamaguiOptionsWithFileInfo) => {\n // just always look for `tamagui` and `@tamagui/core`\n return [...new Set(['@tamagui/core', 'tamagui', ...props.components])]\n})\n\nconst getValidComponentsPaths = memoize((props: TamaguiOptionsWithFileInfo) => {\n return getValidComponentPackages(props).map((pkg) => {\n const root = findRoot(pkg)\n return basename(root)\n })\n})\n"],
|
|
5
|
-
"mappings": "AAAA,
|
|
6
|
-
"names": []
|
|
5
|
+
"mappings": "AAAA,OAAS,YAAAA,MAAgB,OAEzB,OAAOC,MAAc,mBAErB,UAAYC,MAAO,eACnB,OAAOC,MAAc,YAErB,OAAS,WAAAC,MAAe,wBAKjB,SAASC,EACdC,EACY,CACZ,OAAOA,GAAS,IAClB,CAEO,SAASC,EAAeC,EAA4B,CACzD,OAAON,EAAE,aAAaM,EAAK,QAAQ,GAAKN,EAAE,mBAAmBM,EAAK,QAAQ,CAC5E,CAEO,MAAMC,EAAWC,GACdA,EAEJA,EAAK,OAAS,OACdC,EAAYD,EAAK,KAAK,EACtBA,EAAK,OAAS,UACd,MAAME,EAAWF,EAAK,KAAK,IAC3B,GAAGA,EAAK,QAAQG,EAASH,EAAK,KAAK,KALnC,GAQOG,EAAW,CAACC,EAAUC,EAAS,OACrCD,EAGE,IAAI,OAAO,QAAQA,CAAG,EAC1B,IACC,CAAC,CAACE,EAAGC,CAAC,IACJ,GAAGD,KACD,MAAM,QAAQC,CAAC,EACX,QACAA,GAAK,OAAOA,GAAM,SAClB,GAAGJ,EAASI,EAAG,GAAG,IAClB,KAAK,UAAUA,CAAC,GAE1B,EACC,KAAKF,CAAM,KAbL,GAAGD,IAgBRH,EAAeD,GACfR,EAAE,qBAAqBQ,CAAI,EACtB,MAAMA,EAAK,SAAS,OAEtB,SAAUA,EAAOA,EAAK,KAAK,KAAO,WAAWA,EAAK,OAG9CE,EAAcM,GAOlB,CACL,WAPkBhB,EAAE,aAAagB,EAAE,IAAI,EACrCA,EAAE,KAAK,KACPhB,EAAE,mBAAmBgB,EAAE,IAAI,EAC3B,CAACA,EAAE,KAAK,OAAO,KAASA,EAAE,KAAK,SAAS,IAAO,EAE/CjB,EAASiB,EAAE,IAAW,EAAE,KAI1BC,EAAYD,EAAE,UAAU,EAAI,MAAML,E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AASuB,GAElC,CAAC,GAAG,IAAI,IAAI,CAAC,gBAAiB,UAAW,GAAGA,EAAM,UAAU,CAAC,CAAC,CACtE,EAEKU,EAA0BjC,EAASuB,GAChCsB,EAA0BtB,CAAK,EAAE,IAAKuB,GAAQ,CACnD,MAAMC,EAAOhD,EAAS+C,CAAG,EACzB,OAAOlD,EAASmD,CAAI,CACtB,CAAC,CACF",
|
|
6
|
+
"names": ["basename", "generate", "t", "findRoot", "memoize", "isPresent", "input", "isSimpleSpread", "node", "attrStr", "attr", "getNameAttr", "ternaryStr", "objToStr", "obj", "spacer", "k", "v", "x", "isFilledObj", "findComponentName", "scope", "_a", "componentName", "cur", "dec", "isValidThemeHook", "props", "jsxPath", "n", "sourcePath", "binding", "init", "importNode", "isValidImport", "isInsideComponentPackage", "moduleName", "getValidComponentsPaths", "path", "isComponentPackage", "srcName", "getValidComponent", "loaded", "isInModule", "foundComponent", "isValidModule", "isLocal", "getValidImport", "isValid", "getValidComponentPackages", "pkg", "root"]
|
|
7
7
|
}
|
|
@@ -1,162 +1,2 @@
|
|
|
1
|
-
import
|
|
2
|
-
import generate from "@babel/generator";
|
|
3
|
-
import * as t from "@babel/types";
|
|
4
|
-
import findRoot from "find-root";
|
|
5
|
-
import { memoize } from "../helpers/memoize.js";
|
|
6
|
-
function isPresent(input) {
|
|
7
|
-
return input != null;
|
|
8
|
-
}
|
|
9
|
-
function isSimpleSpread(node) {
|
|
10
|
-
return t.isIdentifier(node.argument) || t.isMemberExpression(node.argument);
|
|
11
|
-
}
|
|
12
|
-
const attrStr = (attr) => {
|
|
13
|
-
return !attr ? "" : attr.type === "attr" ? getNameAttr(attr.value) : attr.type === "ternary" ? `...${ternaryStr(attr.value)}` : `${attr.type}(${objToStr(attr.value)})`;
|
|
14
|
-
};
|
|
15
|
-
const objToStr = (obj, spacer = ", ") => {
|
|
16
|
-
if (!obj) {
|
|
17
|
-
return `${obj}`;
|
|
18
|
-
}
|
|
19
|
-
return `{${Object.entries(obj).map(
|
|
20
|
-
([k, v]) => `${k}:${Array.isArray(v) ? `[...]` : v && typeof v === "object" ? `${objToStr(v, ",")}` : JSON.stringify(v)}`
|
|
21
|
-
).join(spacer)}}`;
|
|
22
|
-
};
|
|
23
|
-
const getNameAttr = (attr) => {
|
|
24
|
-
if (t.isJSXSpreadAttribute(attr)) {
|
|
25
|
-
return `...${attr.argument["name"]}`;
|
|
26
|
-
}
|
|
27
|
-
return "name" in attr ? attr.name.name : `unknown-${attr["type"]}`;
|
|
28
|
-
};
|
|
29
|
-
const ternaryStr = (x) => {
|
|
30
|
-
const conditional = t.isIdentifier(x.test) ? x.test.name : t.isMemberExpression(x.test) ? [x.test.object["name"], x.test.property["name"]] : (
|
|
31
|
-
// @ts-ignore
|
|
32
|
-
generate(x.test).code
|
|
33
|
-
);
|
|
34
|
-
return [
|
|
35
|
-
"ternary(",
|
|
36
|
-
conditional,
|
|
37
|
-
isFilledObj(x.consequent) ? ` ? ${objToStr(x.consequent)}` : " ? \u{1F6AB}",
|
|
38
|
-
isFilledObj(x.alternate) ? ` : ${objToStr(x.alternate)}` : " : \u{1F6AB}",
|
|
39
|
-
")"
|
|
40
|
-
].flat().join("");
|
|
41
|
-
};
|
|
42
|
-
const isFilledObj = (obj) => obj && Object.keys(obj).length;
|
|
43
|
-
function findComponentName(scope) {
|
|
44
|
-
var _a;
|
|
45
|
-
const componentName = "";
|
|
46
|
-
let cur = scope.path;
|
|
47
|
-
while (cur.parentPath && !t.isProgram(cur.parentPath.parent)) {
|
|
48
|
-
cur = cur.parentPath;
|
|
49
|
-
}
|
|
50
|
-
let node = cur.parent;
|
|
51
|
-
if (t.isExportNamedDeclaration(node)) {
|
|
52
|
-
node = node.declaration;
|
|
53
|
-
}
|
|
54
|
-
if (t.isVariableDeclaration(node)) {
|
|
55
|
-
const [dec] = node.declarations;
|
|
56
|
-
if (t.isVariableDeclarator(dec) && t.isIdentifier(dec.id)) {
|
|
57
|
-
return dec.id.name;
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
if (t.isFunctionDeclaration(node)) {
|
|
61
|
-
return (_a = node.id) == null ? void 0 : _a.name;
|
|
62
|
-
}
|
|
63
|
-
return componentName;
|
|
64
|
-
}
|
|
65
|
-
function isValidThemeHook(props, jsxPath, n, sourcePath) {
|
|
66
|
-
var _a;
|
|
67
|
-
if (!t.isIdentifier(n.object) || !t.isIdentifier(n.property))
|
|
68
|
-
return false;
|
|
69
|
-
const bindings = jsxPath.scope.getAllBindings();
|
|
70
|
-
const binding = bindings[n.object.name];
|
|
71
|
-
if (!(binding == null ? void 0 : binding.path))
|
|
72
|
-
return false;
|
|
73
|
-
if (!binding.path.isVariableDeclarator())
|
|
74
|
-
return false;
|
|
75
|
-
const init = binding.path.node.init;
|
|
76
|
-
if (!t.isCallExpression(init))
|
|
77
|
-
return false;
|
|
78
|
-
if (!t.isIdentifier(init.callee))
|
|
79
|
-
return false;
|
|
80
|
-
if (init.callee.name !== "useTheme")
|
|
81
|
-
return false;
|
|
82
|
-
const importNode = (_a = binding.scope.getBinding("useTheme")) == null ? void 0 : _a.path.parent;
|
|
83
|
-
if (!t.isImportDeclaration(importNode))
|
|
84
|
-
return false;
|
|
85
|
-
if (sourcePath && !isValidImport(props, sourcePath)) {
|
|
86
|
-
return false;
|
|
87
|
-
}
|
|
88
|
-
return true;
|
|
89
|
-
}
|
|
90
|
-
const isInsideComponentPackage = (props, moduleName) => {
|
|
91
|
-
return getValidComponentsPaths(props).some((path) => {
|
|
92
|
-
return moduleName.startsWith(path);
|
|
93
|
-
});
|
|
94
|
-
};
|
|
95
|
-
const isComponentPackage = (props, srcName) => {
|
|
96
|
-
return getValidComponentsPaths(props).some((path) => {
|
|
97
|
-
return srcName.startsWith(path);
|
|
98
|
-
});
|
|
99
|
-
};
|
|
100
|
-
function getValidComponent(props, moduleName, componentName) {
|
|
101
|
-
if (componentName[0].toUpperCase() !== componentName[0]) {
|
|
102
|
-
return false;
|
|
103
|
-
}
|
|
104
|
-
for (const loaded of props.allLoadedComponents) {
|
|
105
|
-
if (!loaded)
|
|
106
|
-
continue;
|
|
107
|
-
const isInModule = moduleName === "*" || moduleName.startsWith(loaded.moduleName);
|
|
108
|
-
const foundComponent = loaded.nameToInfo[componentName];
|
|
109
|
-
if (isInModule && foundComponent) {
|
|
110
|
-
return foundComponent;
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
return null;
|
|
114
|
-
}
|
|
115
|
-
const isValidModule = (props, moduleName) => {
|
|
116
|
-
if (typeof moduleName !== "string") {
|
|
117
|
-
throw new Error(`No module name`);
|
|
118
|
-
}
|
|
119
|
-
const isLocal = moduleName.startsWith(".");
|
|
120
|
-
return {
|
|
121
|
-
isLocal,
|
|
122
|
-
isValid: isLocal ? isInsideComponentPackage(props, moduleName) : isComponentPackage(props, moduleName)
|
|
123
|
-
};
|
|
124
|
-
};
|
|
125
|
-
const getValidImport = (props, moduleName, componentName) => {
|
|
126
|
-
const { isValid, isLocal } = isValidModule(props, moduleName);
|
|
127
|
-
if (!isValid || !componentName) {
|
|
128
|
-
return null;
|
|
129
|
-
}
|
|
130
|
-
return getValidComponent(props, isLocal ? "*" : moduleName, componentName) || null;
|
|
131
|
-
};
|
|
132
|
-
const isValidImport = (props, moduleName, componentName) => {
|
|
133
|
-
if (!componentName) {
|
|
134
|
-
return isValidModule(props, moduleName).isValid;
|
|
135
|
-
}
|
|
136
|
-
return Boolean(getValidImport(props, moduleName, componentName));
|
|
137
|
-
};
|
|
138
|
-
const getValidComponentPackages = memoize((props) => {
|
|
139
|
-
return [.../* @__PURE__ */ new Set(["@tamagui/core", "tamagui", ...props.components])];
|
|
140
|
-
});
|
|
141
|
-
const getValidComponentsPaths = memoize((props) => {
|
|
142
|
-
return getValidComponentPackages(props).map((pkg) => {
|
|
143
|
-
const root = findRoot(pkg);
|
|
144
|
-
return basename(root);
|
|
145
|
-
});
|
|
146
|
-
});
|
|
147
|
-
export {
|
|
148
|
-
attrStr,
|
|
149
|
-
findComponentName,
|
|
150
|
-
getValidComponent,
|
|
151
|
-
getValidImport,
|
|
152
|
-
isComponentPackage,
|
|
153
|
-
isInsideComponentPackage,
|
|
154
|
-
isPresent,
|
|
155
|
-
isSimpleSpread,
|
|
156
|
-
isValidImport,
|
|
157
|
-
isValidModule,
|
|
158
|
-
isValidThemeHook,
|
|
159
|
-
objToStr,
|
|
160
|
-
ternaryStr
|
|
161
|
-
};
|
|
1
|
+
import{basename as g}from"path";import h from"@babel/generator";import*as r from"@babel/types";import y from"find-root";import{memoize as p}from"../helpers/memoize.js";function P(t){return t!=null}function j(t){return r.isIdentifier(t.argument)||r.isMemberExpression(t.argument)}const E=t=>t?t.type==="attr"?I(t.value):t.type==="ternary"?`...${b(t.value)}`:`${t.type}(${s(t.value)})`:"",s=(t,n=", ")=>t?`{${Object.entries(t).map(([e,i])=>`${e}:${Array.isArray(i)?"[...]":i&&typeof i=="object"?`${s(i,",")}`:JSON.stringify(i)}`).join(n)}}`:`${t}`,I=t=>r.isJSXSpreadAttribute(t)?`...${t.argument.name}`:"name"in t?t.name.name:`unknown-${t.type}`,b=t=>["ternary(",r.isIdentifier(t.test)?t.test.name:r.isMemberExpression(t.test)?[t.test.object.name,t.test.property.name]:h(t.test).code,f(t.consequent)?` ? ${s(t.consequent)}`:" ? \u{1F6AB}",f(t.alternate)?` : ${s(t.alternate)}`:" : \u{1F6AB}",")"].flat().join(""),f=t=>t&&Object.keys(t).length;function k(t){var a;const n="";let e=t.path;for(;e.parentPath&&!r.isProgram(e.parentPath.parent);)e=e.parentPath;let i=e.parent;if(r.isExportNamedDeclaration(i)&&(i=i.declaration),r.isVariableDeclaration(i)){const[o]=i.declarations;if(r.isVariableDeclarator(o)&&r.isIdentifier(o.id))return o.id.name}return r.isFunctionDeclaration(i)?(a=i.id)==null?void 0:a.name:n}function D(t,n,e,i){var u;if(!r.isIdentifier(e.object)||!r.isIdentifier(e.property))return!1;const o=n.scope.getAllBindings()[e.object.name];if(!(o!=null&&o.path)||!o.path.isVariableDeclarator())return!1;const l=o.path.node.init;if(!r.isCallExpression(l)||!r.isIdentifier(l.callee)||l.callee.name!=="useTheme")return!1;const d=(u=o.scope.getBinding("useTheme"))==null?void 0:u.path.parent;return!(!r.isImportDeclaration(d)||i&&!V(t,i))}const T=(t,n)=>m(t).some(e=>n.startsWith(e)),O=(t,n)=>m(t).some(e=>n.startsWith(e));function S(t,n,e){if(e[0].toUpperCase()!==e[0])return!1;for(const i of t.allLoadedComponents){if(!i)continue;const a=n==="*"||n.startsWith(i.moduleName),o=i.nameToInfo[e];if(a&&o)return o}return null}const c=(t,n)=>{if(typeof n!="string")throw new Error("No module name");const e=n.startsWith(".");return{isLocal:e,isValid:e?T(t,n):O(t,n)}},W=(t,n,e)=>{const{isValid:i,isLocal:a}=c(t,n);return!i||!e?null:S(t,a?"*":n,e)||null},V=(t,n,e)=>e?Boolean(W(t,n,e)):c(t,n).isValid,x=p(t=>[...new Set(["@tamagui/core","tamagui",...t.components])]),m=p(t=>x(t).map(n=>{const e=y(n);return g(e)}));export{E as attrStr,k as findComponentName,S as getValidComponent,W as getValidImport,O as isComponentPackage,T as isInsideComponentPackage,P as isPresent,j as isSimpleSpread,V as isValidImport,c as isValidModule,D as isValidThemeHook,s as objToStr,b as ternaryStr};
|
|
162
2
|
//# sourceMappingURL=extractHelpers.mjs.map
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/extractor/extractHelpers.ts"],
|
|
4
4
|
"sourcesContent": ["import { basename } from 'path'\n\nimport generate from '@babel/generator'\nimport type { NodePath } from '@babel/traverse'\nimport * as t from '@babel/types'\nimport findRoot from 'find-root'\n\nimport { memoize } from '../helpers/memoize.js'\nimport type { ExtractedAttr, TamaguiOptionsWithFileInfo, Ternary } from '../types.js'\n\n// import { astToLiteral } from './literalToAst'\n\nexport function isPresent<T extends Object>(\n input: null | void | undefined | T\n): input is T {\n return input != null\n}\n\nexport function isSimpleSpread(node: t.JSXSpreadAttribute) {\n return t.isIdentifier(node.argument) || t.isMemberExpression(node.argument)\n}\n\nexport const attrStr = (attr?: ExtractedAttr) => {\n return !attr\n ? ''\n : attr.type === 'attr'\n ? getNameAttr(attr.value)\n : attr.type === 'ternary'\n ? `...${ternaryStr(attr.value)}`\n : `${attr.type}(${objToStr(attr.value)})`\n}\n\nexport const objToStr = (obj: any, spacer = ', ') => {\n if (!obj) {\n return `${obj}`\n }\n return `{${Object.entries(obj)\n .map(\n ([k, v]) =>\n `${k}:${\n Array.isArray(v)\n ? `[...]`\n : v && typeof v === 'object'\n ? `${objToStr(v, ',')}`\n : JSON.stringify(v)\n }`\n )\n .join(spacer)}}`\n}\n\nconst getNameAttr = (attr: t.JSXAttribute | t.JSXSpreadAttribute) => {\n if (t.isJSXSpreadAttribute(attr)) {\n return `...${attr.argument['name']}`\n }\n return 'name' in attr ? attr.name.name : `unknown-${attr['type']}`\n}\n\nexport const ternaryStr = (x: Ternary) => {\n const conditional = t.isIdentifier(x.test)\n ? x.test.name\n : t.isMemberExpression(x.test)\n ? [x.test.object['name'], x.test.property['name']]\n : // @ts-ignore\n generate(x.test as any).code\n return [\n 'ternary(',\n conditional,\n isFilledObj(x.consequent) ? ` ? ${objToStr(x.consequent)}` : ' ? \uD83D\uDEAB',\n isFilledObj(x.alternate) ? ` : ${objToStr(x.alternate)}` : ' : \uD83D\uDEAB',\n ')',\n ]\n .flat()\n .join('')\n}\n\nconst isFilledObj = (obj: any) => obj && Object.keys(obj).length\n\nexport function findComponentName(scope) {\n const componentName = ''\n let cur = scope.path\n while (cur.parentPath && !t.isProgram(cur.parentPath.parent)) {\n cur = cur.parentPath\n }\n let node = cur.parent\n if (t.isExportNamedDeclaration(node)) {\n node = node.declaration\n }\n if (t.isVariableDeclaration(node)) {\n const [dec] = node.declarations\n if (t.isVariableDeclarator(dec) && t.isIdentifier(dec.id)) {\n return dec.id.name\n }\n }\n if (t.isFunctionDeclaration(node)) {\n return node.id?.name\n }\n return componentName\n}\n\nexport function isValidThemeHook(\n props: TamaguiOptionsWithFileInfo,\n jsxPath: NodePath<t.JSXElement>,\n n: t.MemberExpression,\n sourcePath?: string\n) {\n if (!t.isIdentifier(n.object) || !t.isIdentifier(n.property)) return false\n const bindings = jsxPath.scope.getAllBindings()\n const binding = bindings[n.object.name]\n if (!binding?.path) return false\n if (!binding.path.isVariableDeclarator()) return false\n const init = binding.path.node.init\n if (!t.isCallExpression(init)) return false\n if (!t.isIdentifier(init.callee)) return false\n // TODO could support renaming useTheme by looking up import first\n if (init.callee.name !== 'useTheme') return false\n const importNode = binding.scope.getBinding('useTheme')?.path.parent\n if (!t.isImportDeclaration(importNode)) return false\n if (sourcePath && !isValidImport(props, sourcePath)) {\n return false\n }\n return true\n}\n\nexport const isInsideComponentPackage = (\n props: TamaguiOptionsWithFileInfo,\n moduleName: string\n) => {\n return getValidComponentsPaths(props).some((path) => {\n return moduleName.startsWith(path)\n })\n}\n\nexport const isComponentPackage = (\n props: TamaguiOptionsWithFileInfo,\n srcName: string\n) => {\n return getValidComponentsPaths(props).some((path) => {\n return srcName.startsWith(path)\n })\n}\n\nexport function getValidComponent(\n props: TamaguiOptionsWithFileInfo,\n moduleName: string,\n componentName: string\n) {\n // must be uppercase of course\n if (componentName[0].toUpperCase() !== componentName[0]) {\n return false\n }\n\n for (const loaded of props.allLoadedComponents) {\n if (!loaded) continue\n const isInModule = moduleName === '*' || moduleName.startsWith(loaded.moduleName)\n const foundComponent = loaded.nameToInfo[componentName]\n // eslint-disable-next-line no-console\n if (isInModule && foundComponent) {\n return foundComponent\n }\n }\n\n return null\n}\n\nexport const isValidModule = (props: TamaguiOptionsWithFileInfo, moduleName: string) => {\n if (typeof moduleName !== 'string') {\n throw new Error(`No module name`)\n }\n const isLocal = moduleName.startsWith('.')\n return {\n isLocal,\n isValid: isLocal\n ? isInsideComponentPackage(props, moduleName)\n : isComponentPackage(props, moduleName),\n }\n}\n\nexport const getValidImport = (\n props: TamaguiOptionsWithFileInfo,\n moduleName: string,\n componentName?: string\n) => {\n const { isValid, isLocal } = isValidModule(props, moduleName)\n if (!isValid || !componentName) {\n return null\n }\n return getValidComponent(props, isLocal ? '*' : moduleName, componentName) || null\n}\n\nexport const isValidImport = (\n props: TamaguiOptionsWithFileInfo,\n moduleName: string,\n componentName?: string\n) => {\n if (!componentName) {\n return isValidModule(props, moduleName).isValid\n }\n return Boolean(getValidImport(props, moduleName, componentName))\n}\n\nconst getValidComponentPackages = memoize((props: TamaguiOptionsWithFileInfo) => {\n // just always look for `tamagui` and `@tamagui/core`\n return [...new Set(['@tamagui/core', 'tamagui', ...props.components])]\n})\n\nconst getValidComponentsPaths = memoize((props: TamaguiOptionsWithFileInfo) => {\n return getValidComponentPackages(props).map((pkg) => {\n const root = findRoot(pkg)\n return basename(root)\n })\n})\n"],
|
|
5
|
-
"mappings": "AAAA,
|
|
6
|
-
"names": []
|
|
5
|
+
"mappings": "AAAA,OAAS,YAAAA,MAAgB,OAEzB,OAAOC,MAAc,mBAErB,UAAYC,MAAO,eACnB,OAAOC,MAAc,YAErB,OAAS,WAAAC,MAAe,wBAKjB,SAASC,EACdC,EACY,CACZ,OAAOA,GAAS,IAClB,CAEO,SAASC,EAAeC,EAA4B,CACzD,OAAON,EAAE,aAAaM,EAAK,QAAQ,GAAKN,EAAE,mBAAmBM,EAAK,QAAQ,CAC5E,CAEO,MAAMC,EAAWC,GACdA,EAEJA,EAAK,OAAS,OACdC,EAAYD,EAAK,KAAK,EACtBA,EAAK,OAAS,UACd,MAAME,EAAWF,EAAK,KAAK,IAC3B,GAAGA,EAAK,QAAQG,EAASH,EAAK,KAAK,KALnC,GAQOG,EAAW,CAACC,EAAUC,EAAS,OACrCD,EAGE,IAAI,OAAO,QAAQA,CAAG,EAC1B,IACC,CAAC,CAACE,EAAGC,CAAC,IACJ,GAAGD,KACD,MAAM,QAAQC,CAAC,EACX,QACAA,GAAK,OAAOA,GAAM,SAClB,GAAGJ,EAASI,EAAG,GAAG,IAClB,KAAK,UAAUA,CAAC,GAE1B,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CAAU,EAC1CG,EAAmBZ,EAAOS,CAAU,CAC1C,CACF,EAEaW,EAAiB,CAC5BpB,EACAS,EACAb,IACG,CACH,KAAM,CAAE,QAAAyB,EAAS,QAAAF,CAAQ,EAAID,EAAclB,EAAOS,CAAU,EAC5D,MAAI,CAACY,GAAW,CAACzB,EACR,KAEFkB,EAAkBd,EAAOmB,EAAU,IAAMV,EAAYb,CAAa,GAAK,IAChF,EAEaW,EAAgB,CAC3BP,EACAS,EACAb,IAEKA,EAGE,QAAQwB,EAAepB,EAAOS,EAAYb,CAAa,CAAC,EAFtDsB,EAAclB,EAAOS,CAAU,EAAE,QAKtCa,EAA4B7C,EAASuB,GAElC,CAAC,GAAG,IAAI,IAAI,CAAC,gBAAiB,UAAW,GAAGA,EAAM,UAAU,CAAC,CAAC,CACtE,EAEKU,EAA0BjC,EAASuB,GAChCsB,EAA0BtB,CAAK,EAAE,IAAKuB,GAAQ,CACnD,MAAMC,EAAOhD,EAAS+C,CAAG,EACzB,OAAOlD,EAASmD,CAAI,CACtB,CAAC,CACF",
|
|
6
|
+
"names": ["basename", "generate", "t", "findRoot", "memoize", "isPresent", "input", "isSimpleSpread", "node", "attrStr", "attr", "getNameAttr", "ternaryStr", "objToStr", "obj", "spacer", "k", "v", "x", "isFilledObj", "findComponentName", "scope", "_a", "componentName", "cur", "dec", "isValidThemeHook", "props", "jsxPath", "n", "sourcePath", "binding", "init", "importNode", "isValidImport", "isInsideComponentPackage", "moduleName", "getValidComponentsPaths", "path", "isComponentPackage", "srcName", "getValidComponent", "loaded", "isInModule", "foundComponent", "isValidModule", "isLocal", "getValidImport", "isValid", "getValidComponentPackages", "pkg", "root"]
|
|
7
7
|
}
|