@tamagui/static 1.0.0-alpha.6 → 1.0.0-alpha.60
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/constants.js +43 -0
- package/dist/cjs/constants.js.map +7 -0
- package/dist/cjs/extractor/accessSafe.js +39 -0
- package/dist/cjs/extractor/accessSafe.js.map +7 -0
- package/dist/cjs/extractor/babelParse.js +58 -0
- package/dist/cjs/extractor/babelParse.js.map +7 -0
- package/dist/cjs/extractor/buildClassName.js +68 -0
- package/dist/cjs/extractor/buildClassName.js.map +7 -0
- package/dist/cjs/extractor/createEvaluator.js +79 -0
- package/dist/cjs/extractor/createEvaluator.js.map +7 -0
- package/dist/cjs/extractor/createExtractor.js +952 -0
- package/dist/cjs/extractor/createExtractor.js.map +7 -0
- package/dist/cjs/extractor/ensureImportingConcat.js +52 -0
- package/dist/cjs/extractor/ensureImportingConcat.js.map +7 -0
- package/dist/cjs/extractor/evaluateAstNode.js +122 -0
- package/dist/cjs/extractor/evaluateAstNode.js.map +7 -0
- package/dist/cjs/extractor/extractHelpers.js +124 -0
- package/dist/cjs/extractor/extractHelpers.js.map +7 -0
- package/dist/cjs/extractor/extractMediaStyle.js +193 -0
- package/dist/cjs/extractor/extractMediaStyle.js.map +7 -0
- package/dist/cjs/extractor/extractToClassNames.js +291 -0
- package/dist/cjs/extractor/extractToClassNames.js.map +7 -0
- package/dist/cjs/extractor/findTopmostFunction.js +46 -0
- package/dist/cjs/extractor/findTopmostFunction.js.map +7 -0
- package/dist/cjs/extractor/generatedUid.js +56 -0
- package/dist/cjs/extractor/generatedUid.js.map +7 -0
- package/dist/cjs/extractor/getPropValueFromAttributes.js +77 -0
- package/dist/cjs/extractor/getPropValueFromAttributes.js.map +7 -0
- package/dist/cjs/extractor/getSourceModule.js +97 -0
- package/dist/cjs/extractor/getSourceModule.js.map +7 -0
- package/dist/cjs/extractor/getStaticBindingsForScope.js +156 -0
- package/dist/cjs/extractor/getStaticBindingsForScope.js.map +7 -0
- package/dist/cjs/extractor/hoistClassNames.js +72 -0
- package/dist/cjs/extractor/hoistClassNames.js.map +7 -0
- package/dist/cjs/extractor/literalToAst.js +62 -0
- package/dist/cjs/extractor/literalToAst.js.map +7 -0
- package/dist/cjs/extractor/loadTamagui.js +70 -0
- package/dist/cjs/extractor/loadTamagui.js.map +7 -0
- package/dist/cjs/extractor/logLines.js +40 -0
- package/dist/cjs/extractor/logLines.js.map +7 -0
- package/dist/cjs/extractor/normalizeTernaries.js +108 -0
- package/dist/cjs/extractor/normalizeTernaries.js.map +7 -0
- package/dist/cjs/extractor/removeUnusedHooks.js +107 -0
- package/dist/cjs/extractor/removeUnusedHooks.js.map +7 -0
- package/dist/cjs/index.js +38 -0
- package/dist/cjs/index.js.map +7 -0
- package/dist/cjs/patchReactNativeWeb.js +157 -0
- package/dist/cjs/patchReactNativeWeb.js.map +7 -0
- package/dist/cjs/types.js +21 -0
- package/dist/cjs/types.js.map +7 -0
- package/dist/{constants.js → esm/constants.js} +4 -0
- package/dist/{constants.js.map → esm/constants.js.map} +3 -3
- package/dist/{extractor → esm/extractor}/accessSafe.js +0 -0
- package/dist/{extractor → esm/extractor}/accessSafe.js.map +1 -1
- package/dist/{extractor → esm/extractor}/babelParse.js +0 -0
- package/dist/{extractor → esm/extractor}/babelParse.js.map +1 -1
- package/dist/{extractor → esm/extractor}/buildClassName.js +0 -0
- package/dist/{extractor → esm/extractor}/buildClassName.js.map +1 -1
- package/dist/{extractor → esm/extractor}/createEvaluator.js +1 -1
- package/dist/esm/extractor/createEvaluator.js.map +7 -0
- package/dist/{extractor → esm/extractor}/createExtractor.js +151 -79
- package/dist/esm/extractor/createExtractor.js.map +7 -0
- package/dist/{extractor → esm/extractor}/ensureImportingConcat.js +1 -1
- package/dist/esm/extractor/ensureImportingConcat.js.map +7 -0
- package/dist/{extractor → esm/extractor}/evaluateAstNode.js +0 -0
- package/dist/{extractor → esm/extractor}/evaluateAstNode.js.map +1 -1
- package/dist/{extractor → esm/extractor}/extractHelpers.js +6 -4
- package/dist/{extractor → esm/extractor}/extractHelpers.js.map +3 -3
- package/dist/{extractor → esm/extractor}/extractMediaStyle.js +3 -2
- package/dist/{extractor → esm/extractor}/extractMediaStyle.js.map +2 -2
- package/dist/{extractor → esm/extractor}/extractToClassNames.js +35 -22
- package/dist/esm/extractor/extractToClassNames.js.map +7 -0
- package/dist/{extractor → esm/extractor}/findTopmostFunction.js +0 -0
- package/dist/{extractor → esm/extractor}/findTopmostFunction.js.map +1 -1
- package/dist/{extractor → esm/extractor}/generatedUid.js +0 -0
- package/dist/{extractor → esm/extractor}/generatedUid.js.map +1 -1
- package/dist/{extractor → esm/extractor}/getPropValueFromAttributes.js +0 -0
- package/dist/{extractor → esm/extractor}/getPropValueFromAttributes.js.map +1 -1
- package/dist/{extractor → esm/extractor}/getSourceModule.js +0 -0
- package/dist/{extractor → esm/extractor}/getSourceModule.js.map +1 -1
- package/dist/{extractor → esm/extractor}/getStaticBindingsForScope.js +0 -0
- package/dist/{extractor → esm/extractor}/getStaticBindingsForScope.js.map +1 -1
- package/dist/{extractor → esm/extractor}/hoistClassNames.js +0 -0
- package/dist/{extractor → esm/extractor}/hoistClassNames.js.map +1 -1
- package/dist/{extractor → esm/extractor}/literalToAst.js +0 -0
- package/dist/{extractor → esm/extractor}/literalToAst.js.map +1 -1
- package/dist/{extractor → esm/extractor}/loadTamagui.js +8 -2
- package/dist/esm/extractor/loadTamagui.js.map +7 -0
- package/dist/esm/extractor/logLines.js +17 -0
- package/dist/esm/extractor/logLines.js.map +7 -0
- package/dist/{extractor → esm/extractor}/normalizeTernaries.js +3 -2
- package/dist/{extractor → esm/extractor}/normalizeTernaries.js.map +2 -2
- package/dist/{extractor → esm/extractor}/removeUnusedHooks.js +5 -3
- package/dist/{extractor → esm/extractor}/removeUnusedHooks.js.map +2 -2
- package/dist/{index.js → esm/index.js} +0 -0
- package/dist/{index.js.map → esm/index.js.map} +1 -1
- package/dist/{patchReactNativeWeb.js → esm/patchReactNativeWeb.js} +22 -0
- package/dist/esm/patchReactNativeWeb.js.map +7 -0
- package/dist/{types.js → esm/types.js} +0 -0
- package/dist/{types.js.map → esm/types.js.map} +0 -0
- package/dist/jsx/constants.js +13 -0
- package/dist/jsx/extractor/accessSafe.js +10 -0
- package/dist/jsx/extractor/babelParse.js +29 -0
- package/dist/jsx/extractor/buildClassName.js +39 -0
- package/dist/jsx/extractor/createEvaluator.js +50 -0
- package/dist/jsx/extractor/createExtractor.js +890 -0
- package/dist/jsx/extractor/ensureImportingConcat.js +23 -0
- package/dist/jsx/extractor/evaluateAstNode.js +93 -0
- package/dist/jsx/extractor/extractHelpers.js +95 -0
- package/dist/jsx/extractor/extractMediaStyle.js +151 -0
- package/dist/jsx/extractor/extractToClassNames.js +247 -0
- package/dist/jsx/extractor/findTopmostFunction.js +22 -0
- package/dist/jsx/extractor/generatedUid.js +27 -0
- package/dist/jsx/extractor/getPropValueFromAttributes.js +48 -0
- package/dist/jsx/extractor/getSourceModule.js +68 -0
- package/dist/jsx/extractor/getStaticBindingsForScope.js +127 -0
- package/dist/jsx/extractor/hoistClassNames.js +43 -0
- package/dist/jsx/extractor/literalToAst.js +33 -0
- package/dist/jsx/extractor/loadTamagui.js +46 -0
- package/dist/jsx/extractor/logLines.js +16 -0
- package/dist/jsx/extractor/normalizeTernaries.js +52 -0
- package/dist/jsx/extractor/removeUnusedHooks.js +79 -0
- package/dist/jsx/index.js +13 -0
- package/dist/jsx/patchReactNativeWeb.js +128 -0
- package/dist/jsx/types.js +0 -0
- package/package.json +27 -19
- package/types/constants.d.ts +6 -0
- package/types/constants.d.ts.map +1 -0
- package/types/extractor/accessSafe.d.ts +3 -0
- package/types/extractor/accessSafe.d.ts.map +1 -0
- package/types/extractor/babelParse.d.ts +5 -0
- package/types/extractor/babelParse.d.ts.map +1 -0
- package/types/extractor/buildClassName.d.ts +4 -0
- package/types/extractor/buildClassName.d.ts.map +1 -0
- package/types/extractor/createEvaluator.d.ts +12 -0
- package/types/extractor/createEvaluator.d.ts.map +1 -0
- package/types/extractor/createExtractor.d.ts +33 -0
- package/types/extractor/createExtractor.d.ts.map +1 -0
- package/types/extractor/ensureImportingConcat.d.ts +4 -0
- package/types/extractor/ensureImportingConcat.d.ts.map +1 -0
- package/types/extractor/evaluateAstNode.d.ts +3 -0
- package/types/extractor/evaluateAstNode.d.ts.map +1 -0
- package/types/extractor/extractHelpers.d.ts +12 -0
- package/types/extractor/extractHelpers.d.ts.map +1 -0
- package/types/extractor/extractMediaStyle.d.ts +10 -0
- package/types/extractor/extractMediaStyle.d.ts.map +1 -0
- package/types/extractor/extractToClassNames.d.ts +21 -0
- package/types/extractor/extractToClassNames.d.ts.map +1 -0
- package/types/extractor/findTopmostFunction.d.ts +4 -0
- package/types/extractor/findTopmostFunction.d.ts.map +1 -0
- package/types/extractor/generatedUid.d.ts +5 -0
- package/types/extractor/generatedUid.d.ts.map +1 -0
- package/types/extractor/getPropValueFromAttributes.d.ts +3 -0
- package/types/extractor/getPropValueFromAttributes.d.ts.map +1 -0
- package/types/extractor/getSourceModule.d.ts +16 -0
- package/types/extractor/getSourceModule.d.ts.map +1 -0
- package/types/extractor/getStaticBindingsForScope.d.ts +4 -0
- package/types/extractor/getStaticBindingsForScope.d.ts.map +1 -0
- package/types/extractor/hoistClassNames.d.ts +6 -0
- package/types/extractor/hoistClassNames.d.ts.map +1 -0
- package/types/extractor/literalToAst.d.ts +3 -0
- package/types/extractor/literalToAst.d.ts.map +1 -0
- package/types/extractor/loadTamagui.d.ts +9 -0
- package/types/extractor/loadTamagui.d.ts.map +1 -0
- package/types/extractor/logLines.d.ts +2 -0
- package/types/extractor/logLines.d.ts.map +1 -0
- package/types/extractor/normalizeTernaries.d.ts +3 -0
- package/types/extractor/normalizeTernaries.d.ts.map +1 -0
- package/types/extractor/removeUnusedHooks.d.ts +3 -0
- package/types/extractor/removeUnusedHooks.d.ts.map +1 -0
- package/types/index.d.ts +8 -0
- package/types/index.d.ts.map +1 -0
- package/types/patchReactNativeWeb.d.ts +2 -0
- package/types/patchReactNativeWeb.d.ts.map +1 -0
- package/types/types.d.ts +79 -0
- package/types/types.d.ts.map +1 -0
- package/dist/extractor/createEvaluator.js.map +0 -7
- package/dist/extractor/createExtractor.js.map +0 -7
- package/dist/extractor/ensureImportingConcat.js.map +0 -7
- package/dist/extractor/extractToClassNames.js.map +0 -7
- package/dist/extractor/loadTamagui.js.map +0 -7
- package/dist/index.cjs +0 -2107
- package/dist/index.cjs.map +0 -7
- package/dist/patchReactNativeWeb.js.map +0 -7
- package/src/constants.ts +0 -10
- package/src/extractor/accessSafe.ts +0 -18
- package/src/extractor/babelParse.ts +0 -27
- package/src/extractor/buildClassName.ts +0 -61
- package/src/extractor/createEvaluator.ts +0 -68
- package/src/extractor/createExtractor.ts +0 -1132
- package/src/extractor/ensureImportingConcat.ts +0 -33
- package/src/extractor/evaluateAstNode.ts +0 -121
- package/src/extractor/extractHelpers.ts +0 -102
- package/src/extractor/extractMediaStyle.ts +0 -191
- package/src/extractor/extractToClassNames.ts +0 -326
- package/src/extractor/findTopmostFunction.ts +0 -22
- package/src/extractor/generatedUid.ts +0 -43
- package/src/extractor/getPropValueFromAttributes.ts +0 -92
- package/src/extractor/getSourceModule.ts +0 -101
- package/src/extractor/getStaticBindingsForScope.ts +0 -173
- package/src/extractor/hoistClassNames.ts +0 -45
- package/src/extractor/literalToAst.ts +0 -32
- package/src/extractor/loadTamagui.ts +0 -61
- package/src/extractor/normalizeTernaries.ts +0 -60
- package/src/extractor/removeUnusedHooks.ts +0 -76
- package/src/index.ts +0 -9
- package/src/patchReactNativeWeb.ts +0 -123
- package/src/types.ts +0 -83
- package/types.d.ts +0 -215
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/extractor/generatedUid.ts"],
|
|
4
|
+
"sourcesContent": ["import * as t from '@babel/types'\nimport invariant from 'invariant'\n\n// TODO: open a PR upstream\ndeclare module '@babel/types' {\n export function toIdentifier(input: string): string\n}\n\n// A clone of path.scope.generateUid that doesn't prepend underscores\nexport function generateUid(scope: any, name: string): string {\n invariant(typeof scope === 'object', 'generateUid expects a scope object as its first parameter')\n invariant(\n typeof name === 'string' && name !== '',\n 'generateUid expects a valid name as its second parameter'\n )\n\n name = t\n .toIdentifier(name)\n .replace(/^_+/, '')\n .replace(/[0-9]+$/g, '')\n\n let uid\n let i = 0\n do {\n if (i > 1) {\n uid = name + i\n } else {\n uid = name\n }\n i++\n } while (\n scope.hasLabel(uid) ||\n scope.hasBinding(uid) ||\n scope.hasGlobal(uid) ||\n scope.hasReference(uid)\n )\n\n const program = scope.getProgramParent()\n program.references[uid] = true\n program.uids[uid] = true\n\n return uid\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA,QAAmB;AACnB,uBAAsB;AAQf,qBAAqB,OAAY,MAAsB;AAC5D,gCAAU,OAAO,UAAU,UAAU;AACrC,gCACE,OAAO,SAAS,YAAY,SAAS,IACrC;AAGF,SAAO,EACJ,aAAa,MACb,QAAQ,OAAO,IACf,QAAQ,YAAY;AAEvB,MAAI;AACJ,MAAI,IAAI;AACR,KAAG;AACD,QAAI,IAAI,GAAG;AACT,YAAM,OAAO;AAAA,WACR;AACL,YAAM;AAAA;AAER;AAAA,WAEA,MAAM,SAAS,QACf,MAAM,WAAW,QACjB,MAAM,UAAU,QAChB,MAAM,aAAa;AAGrB,QAAM,UAAU,MAAM;AACtB,UAAQ,WAAW,OAAO;AAC1B,UAAQ,KAAK,OAAO;AAEpB,SAAO;AAAA;AAhCO;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __markAsModule = (target) => __defProp(target, "__esModule", { value: true });
|
|
8
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
9
|
+
var __export = (target, all) => {
|
|
10
|
+
for (var name in all)
|
|
11
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
12
|
+
};
|
|
13
|
+
var __reExport = (target, module2, copyDefault, desc) => {
|
|
14
|
+
if (module2 && typeof module2 === "object" || typeof module2 === "function") {
|
|
15
|
+
for (let key of __getOwnPropNames(module2))
|
|
16
|
+
if (!__hasOwnProp.call(target, key) && (copyDefault || key !== "default"))
|
|
17
|
+
__defProp(target, key, { get: () => module2[key], enumerable: !(desc = __getOwnPropDesc(module2, key)) || desc.enumerable });
|
|
18
|
+
}
|
|
19
|
+
return target;
|
|
20
|
+
};
|
|
21
|
+
var __toESM = (module2, isNodeMode) => {
|
|
22
|
+
return __reExport(__markAsModule(__defProp(module2 != null ? __create(__getProtoOf(module2)) : {}, "default", !isNodeMode && module2 && module2.__esModule ? { get: () => module2.default, enumerable: true } : { value: module2, enumerable: true })), module2);
|
|
23
|
+
};
|
|
24
|
+
var __toCommonJS = /* @__PURE__ */ ((cache) => {
|
|
25
|
+
return (module2, temp) => {
|
|
26
|
+
return cache && cache.get(module2) || (temp = __reExport(__markAsModule({}), module2, 1), cache && cache.set(module2, temp), temp);
|
|
27
|
+
};
|
|
28
|
+
})(typeof WeakMap !== "undefined" ? /* @__PURE__ */ new WeakMap() : 0);
|
|
29
|
+
var getPropValueFromAttributes_exports = {};
|
|
30
|
+
__export(getPropValueFromAttributes_exports, {
|
|
31
|
+
getPropValueFromAttributes: () => getPropValueFromAttributes
|
|
32
|
+
});
|
|
33
|
+
var import_generator = __toESM(require("@babel/generator"));
|
|
34
|
+
var t = __toESM(require("@babel/types"));
|
|
35
|
+
var import_accessSafe = require("./accessSafe");
|
|
36
|
+
function getPropValueFromAttributes(propName, attrs) {
|
|
37
|
+
let propIndex = -1;
|
|
38
|
+
let jsxAttr = null;
|
|
39
|
+
for (let idx = -1, len = attrs.length; ++idx < len; ) {
|
|
40
|
+
const attr = attrs[idx];
|
|
41
|
+
if (t.isJSXAttribute(attr) && attr.name && attr.name.name === propName) {
|
|
42
|
+
propIndex = idx;
|
|
43
|
+
jsxAttr = attr;
|
|
44
|
+
break;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
if (!jsxAttr || jsxAttr.value == null) {
|
|
48
|
+
return null;
|
|
49
|
+
}
|
|
50
|
+
let propValue = jsxAttr.value;
|
|
51
|
+
if (t.isJSXExpressionContainer(propValue)) {
|
|
52
|
+
propValue = propValue.expression;
|
|
53
|
+
}
|
|
54
|
+
if (t.isJSXEmptyExpression(propValue)) {
|
|
55
|
+
console.error("encountered JSXEmptyExpression");
|
|
56
|
+
return null;
|
|
57
|
+
}
|
|
58
|
+
const applicableSpreads = attrs.filter((attr, idx) => {
|
|
59
|
+
if (t.isJSXSpreadAttribute(attr)) {
|
|
60
|
+
if (t.isIdentifier(attr.argument) || t.isMemberExpression(attr.argument)) {
|
|
61
|
+
return idx > propIndex;
|
|
62
|
+
}
|
|
63
|
+
if (t.isLogicalExpression(attr.argument)) {
|
|
64
|
+
return false;
|
|
65
|
+
}
|
|
66
|
+
throw new Error(`unsupported spread of type "${attr.argument.type}": ${(0, import_generator.default)(attr).code}`);
|
|
67
|
+
}
|
|
68
|
+
return false;
|
|
69
|
+
}).map((attr) => attr.argument);
|
|
70
|
+
if (applicableSpreads.length > 0) {
|
|
71
|
+
propValue = applicableSpreads.reduce((acc, val) => t.logicalExpression("||", (0, import_accessSafe.accessSafe)(val, propName), acc), propValue);
|
|
72
|
+
}
|
|
73
|
+
return propValue;
|
|
74
|
+
}
|
|
75
|
+
__name(getPropValueFromAttributes, "getPropValueFromAttributes");
|
|
76
|
+
module.exports = __toCommonJS(getPropValueFromAttributes_exports);
|
|
77
|
+
//# sourceMappingURL=getPropValueFromAttributes.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/extractor/getPropValueFromAttributes.ts"],
|
|
4
|
+
"sourcesContent": ["import generate from '@babel/generator'\nimport * as t from '@babel/types'\n\nimport { accessSafe } from './accessSafe'\n\n/**\n * getPropValueFromAttributes gets a prop by name from a list of attributes and accounts for potential spread operators.\n * Here's an example. Given this component:\n * ```\n * <Block coolProp=\"wow\" {...spread1} neatProp=\"ok\" {...spread2} />```\n * getPropValueFromAttributes will return the following:\n * - for propName `coolProp`:\n * ```\n * accessSafe(spread1, 'coolProp') || accessSafe(spread2, 'coolProp') || 'wow'```\n * - for propName `neatProp`:\n * ```\n * accessSafe(spread2, 'neatProp') || 'ok'```\n * - for propName `notPresent`: `null`\n *\n * The returned value should (obviously) be placed after spread operators.\n */\nexport function getPropValueFromAttributes(\n propName: string,\n attrs: (t.JSXAttribute | t.JSXSpreadAttribute)[]\n): t.Expression | null {\n let propIndex: number = -1\n let jsxAttr: t.JSXAttribute | null = null\n for (let idx = -1, len = attrs.length; ++idx < len; ) {\n const attr = attrs[idx]\n if (t.isJSXAttribute(attr) && attr.name && attr.name.name === propName) {\n propIndex = idx\n jsxAttr = attr\n break\n }\n }\n\n if (!jsxAttr || jsxAttr.value == null) {\n return null\n }\n\n let propValue:\n | t.JSXElement\n | t.JSXFragment\n | t.StringLiteral\n | t.JSXExpressionContainer\n | t.JSXEmptyExpression\n | t.Expression = jsxAttr.value\n\n if (t.isJSXExpressionContainer(propValue)) {\n propValue = propValue.expression\n }\n\n // TODO how to handle this??\n if (t.isJSXEmptyExpression(propValue)) {\n console.error('encountered JSXEmptyExpression')\n return null\n }\n\n // filter out spread props that occur before propValue\n const applicableSpreads = attrs\n .filter(\n // 1. idx is greater than propValue prop index\n // 2. attr is a spread operator\n (attr, idx): attr is t.JSXSpreadAttribute => {\n if (t.isJSXSpreadAttribute(attr)) {\n if (t.isIdentifier(attr.argument) || t.isMemberExpression(attr.argument)) {\n return idx > propIndex\n }\n if (t.isLogicalExpression(attr.argument)) {\n return false\n }\n throw new Error(\n `unsupported spread of type \"${attr.argument.type}\": ${generate(attr).code}`\n )\n }\n return false\n }\n )\n .map((attr) => attr.argument)\n\n // if spread operators occur after propValue, create a binary expression for each operator\n // i.e. before1.propValue || before2.propValue || propValue\n // TODO: figure out how to do this without all the extra parens\n if (applicableSpreads.length > 0) {\n propValue = applicableSpreads.reduce<t.Expression>(\n (acc, val) => t.logicalExpression('||', accessSafe(val, propName), acc),\n propValue\n )\n }\n\n return propValue\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA,uBAAqB;AACrB,QAAmB;AAEnB,wBAA2B;AAkBpB,oCACL,UACA,OACqB;AACrB,MAAI,YAAoB;AACxB,MAAI,UAAiC;AACrC,WAAS,MAAM,IAAI,MAAM,MAAM,QAAQ,EAAE,MAAM,OAAO;AACpD,UAAM,OAAO,MAAM;AACnB,QAAI,EAAE,eAAe,SAAS,KAAK,QAAQ,KAAK,KAAK,SAAS,UAAU;AACtE,kBAAY;AACZ,gBAAU;AACV;AAAA;AAAA;AAIJ,MAAI,CAAC,WAAW,QAAQ,SAAS,MAAM;AACrC,WAAO;AAAA;AAGT,MAAI,YAMe,QAAQ;AAE3B,MAAI,EAAE,yBAAyB,YAAY;AACzC,gBAAY,UAAU;AAAA;AAIxB,MAAI,EAAE,qBAAqB,YAAY;AACrC,YAAQ,MAAM;AACd,WAAO;AAAA;AAIT,QAAM,oBAAoB,MACvB,OAGC,CAAC,MAAM,QAAsC;AAC3C,QAAI,EAAE,qBAAqB,OAAO;AAChC,UAAI,EAAE,aAAa,KAAK,aAAa,EAAE,mBAAmB,KAAK,WAAW;AACxE,eAAO,MAAM;AAAA;AAEf,UAAI,EAAE,oBAAoB,KAAK,WAAW;AACxC,eAAO;AAAA;AAET,YAAM,IAAI,MACR,+BAA+B,KAAK,SAAS,UAAU,8BAAS,MAAM;AAAA;AAG1E,WAAO;AAAA,KAGV,IAAI,CAAC,SAAS,KAAK;AAKtB,MAAI,kBAAkB,SAAS,GAAG;AAChC,gBAAY,kBAAkB,OAC5B,CAAC,KAAK,QAAQ,EAAE,kBAAkB,MAAM,kCAAW,KAAK,WAAW,MACnE;AAAA;AAIJ,SAAO;AAAA;AArEO;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __markAsModule = (target) => __defProp(target, "__esModule", { value: true });
|
|
8
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
9
|
+
var __export = (target, all) => {
|
|
10
|
+
for (var name in all)
|
|
11
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
12
|
+
};
|
|
13
|
+
var __reExport = (target, module2, copyDefault, desc) => {
|
|
14
|
+
if (module2 && typeof module2 === "object" || typeof module2 === "function") {
|
|
15
|
+
for (let key of __getOwnPropNames(module2))
|
|
16
|
+
if (!__hasOwnProp.call(target, key) && (copyDefault || key !== "default"))
|
|
17
|
+
__defProp(target, key, { get: () => module2[key], enumerable: !(desc = __getOwnPropDesc(module2, key)) || desc.enumerable });
|
|
18
|
+
}
|
|
19
|
+
return target;
|
|
20
|
+
};
|
|
21
|
+
var __toESM = (module2, isNodeMode) => {
|
|
22
|
+
return __reExport(__markAsModule(__defProp(module2 != null ? __create(__getProtoOf(module2)) : {}, "default", !isNodeMode && module2 && module2.__esModule ? { get: () => module2.default, enumerable: true } : { value: module2, enumerable: true })), module2);
|
|
23
|
+
};
|
|
24
|
+
var __toCommonJS = /* @__PURE__ */ ((cache) => {
|
|
25
|
+
return (module2, temp) => {
|
|
26
|
+
return cache && cache.get(module2) || (temp = __reExport(__markAsModule({}), module2, 1), cache && cache.set(module2, temp), temp);
|
|
27
|
+
};
|
|
28
|
+
})(typeof WeakMap !== "undefined" ? /* @__PURE__ */ new WeakMap() : 0);
|
|
29
|
+
var getSourceModule_exports = {};
|
|
30
|
+
__export(getSourceModule_exports, {
|
|
31
|
+
getSourceModule: () => getSourceModule
|
|
32
|
+
});
|
|
33
|
+
var t = __toESM(require("@babel/types"));
|
|
34
|
+
function getSourceModule(itemName, itemBinding) {
|
|
35
|
+
if (!itemBinding.constant) {
|
|
36
|
+
return null;
|
|
37
|
+
}
|
|
38
|
+
let sourceModule;
|
|
39
|
+
let imported;
|
|
40
|
+
let local;
|
|
41
|
+
let destructured;
|
|
42
|
+
let usesImportSyntax = false;
|
|
43
|
+
const itemNode = itemBinding.path.node;
|
|
44
|
+
if (t.isImportDefaultSpecifier(itemNode) || t.isImportSpecifier(itemNode)) {
|
|
45
|
+
if (t.isImportDeclaration(itemBinding.path.parent)) {
|
|
46
|
+
sourceModule = itemBinding.path.parent.source.value;
|
|
47
|
+
local = itemNode.local.name;
|
|
48
|
+
usesImportSyntax = true;
|
|
49
|
+
if (t.isImportSpecifier(itemNode)) {
|
|
50
|
+
imported = itemNode.imported["name"];
|
|
51
|
+
destructured = true;
|
|
52
|
+
} else {
|
|
53
|
+
imported = itemNode.local.name;
|
|
54
|
+
destructured = false;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
} else if (t.isVariableDeclarator(itemNode) && itemNode.init != null && t.isCallExpression(itemNode.init) && t.isIdentifier(itemNode.init.callee) && itemNode.init.callee.name === "require" && itemNode.init.arguments.length === 1) {
|
|
58
|
+
const firstArg = itemNode.init.arguments[0];
|
|
59
|
+
if (!t.isStringLiteral(firstArg)) {
|
|
60
|
+
return null;
|
|
61
|
+
}
|
|
62
|
+
sourceModule = firstArg.value;
|
|
63
|
+
if (t.isIdentifier(itemNode.id)) {
|
|
64
|
+
local = itemNode.id.name;
|
|
65
|
+
imported = itemNode.id.name;
|
|
66
|
+
destructured = false;
|
|
67
|
+
} else if (t.isObjectPattern(itemNode.id)) {
|
|
68
|
+
for (const objProp of itemNode.id.properties) {
|
|
69
|
+
if (t.isObjectProperty(objProp) && t.isIdentifier(objProp.value) && objProp.value.name === itemName) {
|
|
70
|
+
local = objProp.value.name;
|
|
71
|
+
imported = objProp.key.name;
|
|
72
|
+
destructured = true;
|
|
73
|
+
break;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
if (!local || !imported) {
|
|
77
|
+
console.error("could not find prop with value `%s`", itemName);
|
|
78
|
+
return null;
|
|
79
|
+
}
|
|
80
|
+
} else {
|
|
81
|
+
console.error("Unhandled id type: %s", itemNode.id.type);
|
|
82
|
+
return null;
|
|
83
|
+
}
|
|
84
|
+
} else {
|
|
85
|
+
return null;
|
|
86
|
+
}
|
|
87
|
+
return {
|
|
88
|
+
destructured,
|
|
89
|
+
imported,
|
|
90
|
+
local,
|
|
91
|
+
sourceModule,
|
|
92
|
+
usesImportSyntax
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
__name(getSourceModule, "getSourceModule");
|
|
96
|
+
module.exports = __toCommonJS(getSourceModule_exports);
|
|
97
|
+
//# sourceMappingURL=getSourceModule.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/extractor/getSourceModule.ts"],
|
|
4
|
+
"sourcesContent": ["import * as t from '@babel/types'\n\nexport interface SourceModule {\n sourceModule?: string\n imported?: string\n local?: string\n destructured?: boolean\n usesImportSyntax: boolean\n}\n\nexport function getSourceModule(\n itemName: string,\n itemBinding: {\n constant?: boolean\n path: { node: t.Node; parent: any }\n }\n): SourceModule | null {\n // TODO: deal with reassignment\n if (!itemBinding.constant) {\n return null\n }\n\n let sourceModule: string | undefined\n let imported: string | undefined\n let local: string | undefined\n let destructured: boolean | undefined\n let usesImportSyntax = false\n\n const itemNode = itemBinding.path.node\n\n if (\n // import x from 'y';\n t.isImportDefaultSpecifier(itemNode) ||\n // import {x} from 'y';\n t.isImportSpecifier(itemNode)\n ) {\n if (t.isImportDeclaration(itemBinding.path.parent)) {\n sourceModule = itemBinding.path.parent.source.value\n local = itemNode.local.name\n usesImportSyntax = true\n if (t.isImportSpecifier(itemNode)) {\n imported = itemNode.imported['name']\n destructured = true\n } else {\n imported = itemNode.local.name\n destructured = false\n }\n }\n } else if (\n t.isVariableDeclarator(itemNode) &&\n itemNode.init != null &&\n t.isCallExpression(itemNode.init) &&\n t.isIdentifier(itemNode.init.callee) &&\n itemNode.init.callee.name === 'require' &&\n itemNode.init.arguments.length === 1\n ) {\n const firstArg = itemNode.init.arguments[0]\n if (!t.isStringLiteral(firstArg)) {\n return null\n }\n sourceModule = firstArg.value\n\n if (t.isIdentifier(itemNode.id)) {\n local = itemNode.id.name\n imported = itemNode.id.name\n destructured = false\n } else if (t.isObjectPattern(itemNode.id)) {\n for (const objProp of itemNode.id.properties) {\n if (\n t.isObjectProperty(objProp) &&\n t.isIdentifier(objProp.value) &&\n objProp.value.name === itemName\n ) {\n local = objProp.value.name\n // @ts-ignore TODO remove this is only an issue on CI\n imported = objProp.key.name\n destructured = true\n break\n }\n }\n\n if (!local || !imported) {\n console.error('could not find prop with value `%s`', itemName)\n return null\n }\n } else {\n console.error('Unhandled id type: %s', itemNode.id.type)\n return null\n }\n } else {\n return null\n }\n\n return {\n destructured,\n imported,\n local,\n sourceModule,\n usesImportSyntax,\n }\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA,QAAmB;AAUZ,yBACL,UACA,aAIqB;AAErB,MAAI,CAAC,YAAY,UAAU;AACzB,WAAO;AAAA;AAGT,MAAI;AACJ,MAAI;AACJ,MAAI;AACJ,MAAI;AACJ,MAAI,mBAAmB;AAEvB,QAAM,WAAW,YAAY,KAAK;AAElC,MAEE,EAAE,yBAAyB,aAE3B,EAAE,kBAAkB,WACpB;AACA,QAAI,EAAE,oBAAoB,YAAY,KAAK,SAAS;AAClD,qBAAe,YAAY,KAAK,OAAO,OAAO;AAC9C,cAAQ,SAAS,MAAM;AACvB,yBAAmB;AACnB,UAAI,EAAE,kBAAkB,WAAW;AACjC,mBAAW,SAAS,SAAS;AAC7B,uBAAe;AAAA,aACV;AACL,mBAAW,SAAS,MAAM;AAC1B,uBAAe;AAAA;AAAA;AAAA,aAInB,EAAE,qBAAqB,aACvB,SAAS,QAAQ,QACjB,EAAE,iBAAiB,SAAS,SAC5B,EAAE,aAAa,SAAS,KAAK,WAC7B,SAAS,KAAK,OAAO,SAAS,aAC9B,SAAS,KAAK,UAAU,WAAW,GACnC;AACA,UAAM,WAAW,SAAS,KAAK,UAAU;AACzC,QAAI,CAAC,EAAE,gBAAgB,WAAW;AAChC,aAAO;AAAA;AAET,mBAAe,SAAS;AAExB,QAAI,EAAE,aAAa,SAAS,KAAK;AAC/B,cAAQ,SAAS,GAAG;AACpB,iBAAW,SAAS,GAAG;AACvB,qBAAe;AAAA,eACN,EAAE,gBAAgB,SAAS,KAAK;AACzC,iBAAW,WAAW,SAAS,GAAG,YAAY;AAC5C,YACE,EAAE,iBAAiB,YACnB,EAAE,aAAa,QAAQ,UACvB,QAAQ,MAAM,SAAS,UACvB;AACA,kBAAQ,QAAQ,MAAM;AAEtB,qBAAW,QAAQ,IAAI;AACvB,yBAAe;AACf;AAAA;AAAA;AAIJ,UAAI,CAAC,SAAS,CAAC,UAAU;AACvB,gBAAQ,MAAM,uCAAuC;AACrD,eAAO;AAAA;AAAA,WAEJ;AACL,cAAQ,MAAM,yBAAyB,SAAS,GAAG;AACnD,aAAO;AAAA;AAAA,SAEJ;AACL,WAAO;AAAA;AAGT,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA;AAAA;AAxFY;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __markAsModule = (target) => __defProp(target, "__esModule", { value: true });
|
|
8
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
9
|
+
var __export = (target, all) => {
|
|
10
|
+
for (var name in all)
|
|
11
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
12
|
+
};
|
|
13
|
+
var __reExport = (target, module2, copyDefault, desc) => {
|
|
14
|
+
if (module2 && typeof module2 === "object" || typeof module2 === "function") {
|
|
15
|
+
for (let key of __getOwnPropNames(module2))
|
|
16
|
+
if (!__hasOwnProp.call(target, key) && (copyDefault || key !== "default"))
|
|
17
|
+
__defProp(target, key, { get: () => module2[key], enumerable: !(desc = __getOwnPropDesc(module2, key)) || desc.enumerable });
|
|
18
|
+
}
|
|
19
|
+
return target;
|
|
20
|
+
};
|
|
21
|
+
var __toESM = (module2, isNodeMode) => {
|
|
22
|
+
return __reExport(__markAsModule(__defProp(module2 != null ? __create(__getProtoOf(module2)) : {}, "default", !isNodeMode && module2 && module2.__esModule ? { get: () => module2.default, enumerable: true } : { value: module2, enumerable: true })), module2);
|
|
23
|
+
};
|
|
24
|
+
var __toCommonJS = /* @__PURE__ */ ((cache) => {
|
|
25
|
+
return (module2, temp) => {
|
|
26
|
+
return cache && cache.get(module2) || (temp = __reExport(__markAsModule({}), module2, 1), cache && cache.set(module2, temp), temp);
|
|
27
|
+
};
|
|
28
|
+
})(typeof WeakMap !== "undefined" ? /* @__PURE__ */ new WeakMap() : 0);
|
|
29
|
+
var getStaticBindingsForScope_exports = {};
|
|
30
|
+
__export(getStaticBindingsForScope_exports, {
|
|
31
|
+
getStaticBindingsForScope: () => getStaticBindingsForScope
|
|
32
|
+
});
|
|
33
|
+
var import_path = require("path");
|
|
34
|
+
var t = __toESM(require("@babel/types"));
|
|
35
|
+
var import_fs_extra = require("fs-extra");
|
|
36
|
+
var import_evaluateAstNode = require("./evaluateAstNode");
|
|
37
|
+
var import_getSourceModule = require("./getSourceModule");
|
|
38
|
+
const isLocalImport = /* @__PURE__ */ __name((path) => path.startsWith(".") || path.startsWith("/"), "isLocalImport");
|
|
39
|
+
function resolveImportPath(sourcePath, path) {
|
|
40
|
+
const sourceDir = (0, import_path.dirname)(sourcePath);
|
|
41
|
+
if (isLocalImport(path)) {
|
|
42
|
+
if ((0, import_path.extname)(path) === "") {
|
|
43
|
+
path += ".js";
|
|
44
|
+
}
|
|
45
|
+
return (0, import_path.resolve)(sourceDir, path);
|
|
46
|
+
}
|
|
47
|
+
return path;
|
|
48
|
+
}
|
|
49
|
+
__name(resolveImportPath, "resolveImportPath");
|
|
50
|
+
function importModule(path) {
|
|
51
|
+
const filenames = [path.replace(".js", ".tsx"), path.replace(".js", ".ts"), path];
|
|
52
|
+
for (const file of filenames) {
|
|
53
|
+
if ((0, import_fs_extra.existsSync)(file)) {
|
|
54
|
+
return require(file);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
return null;
|
|
58
|
+
}
|
|
59
|
+
__name(importModule, "importModule");
|
|
60
|
+
function getStaticBindingsForScope(scope, whitelist = [], sourcePath, bindingCache, shouldPrintDebug) {
|
|
61
|
+
const bindings = scope.getAllBindings();
|
|
62
|
+
const ret = {};
|
|
63
|
+
if (shouldPrintDebug) {
|
|
64
|
+
console.log(" ", Object.keys(bindings).length, "variables in scope");
|
|
65
|
+
}
|
|
66
|
+
const program = scope.getProgramParent().block;
|
|
67
|
+
for (const node of program.body) {
|
|
68
|
+
if (t.isImportDeclaration(node)) {
|
|
69
|
+
const importPath = node.source.value;
|
|
70
|
+
if (!node.specifiers.length)
|
|
71
|
+
continue;
|
|
72
|
+
if (!isLocalImport(importPath)) {
|
|
73
|
+
continue;
|
|
74
|
+
}
|
|
75
|
+
const moduleName = resolveImportPath(sourcePath, importPath);
|
|
76
|
+
const isOnWhitelist = whitelist.some((test) => moduleName.endsWith(test));
|
|
77
|
+
if (!isOnWhitelist)
|
|
78
|
+
continue;
|
|
79
|
+
const src = importModule(moduleName);
|
|
80
|
+
if (!src)
|
|
81
|
+
continue;
|
|
82
|
+
for (const specifier of node.specifiers) {
|
|
83
|
+
if (t.isImportSpecifier(specifier) && t.isIdentifier(specifier.imported)) {
|
|
84
|
+
if (typeof src[specifier.imported.name] !== "undefined") {
|
|
85
|
+
const val = src[specifier.local.name];
|
|
86
|
+
ret[specifier.local.name] = val;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
if (!bindingCache) {
|
|
93
|
+
throw new Error("bindingCache is a required param");
|
|
94
|
+
}
|
|
95
|
+
for (const k in bindings) {
|
|
96
|
+
const binding = bindings[k];
|
|
97
|
+
const sourceModule = (0, import_getSourceModule.getSourceModule)(k, binding);
|
|
98
|
+
if (sourceModule) {
|
|
99
|
+
if (!sourceModule.sourceModule) {
|
|
100
|
+
continue;
|
|
101
|
+
}
|
|
102
|
+
const moduleName = resolveImportPath(sourcePath, sourceModule.sourceModule);
|
|
103
|
+
const isOnWhitelist = whitelist.some((test) => moduleName.endsWith(test));
|
|
104
|
+
if (isOnWhitelist) {
|
|
105
|
+
const src = importModule(moduleName);
|
|
106
|
+
if (!src) {
|
|
107
|
+
console.log(`\u26A0\uFE0F missing file ${moduleName} via ${sourcePath} import ${sourceModule.sourceModule}?`);
|
|
108
|
+
return {};
|
|
109
|
+
}
|
|
110
|
+
if (sourceModule.destructured) {
|
|
111
|
+
if (sourceModule.imported) {
|
|
112
|
+
ret[k] = src[sourceModule.imported];
|
|
113
|
+
}
|
|
114
|
+
} else {
|
|
115
|
+
ret[k] = src;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
continue;
|
|
119
|
+
}
|
|
120
|
+
const { parent, parentPath } = binding.path;
|
|
121
|
+
if (!t.isVariableDeclaration(parent) || parent.kind !== "const") {
|
|
122
|
+
continue;
|
|
123
|
+
}
|
|
124
|
+
const dec = parent.declarations.find((d) => t.isIdentifier(d.id) && d.id.name === k);
|
|
125
|
+
if (!dec || !dec.init) {
|
|
126
|
+
continue;
|
|
127
|
+
}
|
|
128
|
+
if (typeof dec.id.start !== "number" || typeof dec.id.end !== "number") {
|
|
129
|
+
console.error("dec.id.start/end is not a number");
|
|
130
|
+
continue;
|
|
131
|
+
}
|
|
132
|
+
if (!t.isIdentifier(dec.id)) {
|
|
133
|
+
console.error("dec is not an identifier");
|
|
134
|
+
continue;
|
|
135
|
+
}
|
|
136
|
+
const cacheKey = `${dec.id.name}_${dec.id.start}-${dec.id.end}`;
|
|
137
|
+
if (bindingCache.hasOwnProperty(cacheKey)) {
|
|
138
|
+
ret[k] = bindingCache[cacheKey];
|
|
139
|
+
continue;
|
|
140
|
+
}
|
|
141
|
+
if (bindingCache.hasOwnProperty(cacheKey)) {
|
|
142
|
+
ret[k] = bindingCache[cacheKey];
|
|
143
|
+
continue;
|
|
144
|
+
}
|
|
145
|
+
try {
|
|
146
|
+
ret[k] = (0, import_evaluateAstNode.evaluateAstNode)(dec.init, void 0, shouldPrintDebug);
|
|
147
|
+
bindingCache[cacheKey] = ret[k];
|
|
148
|
+
continue;
|
|
149
|
+
} catch (e) {
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
return ret;
|
|
153
|
+
}
|
|
154
|
+
__name(getStaticBindingsForScope, "getStaticBindingsForScope");
|
|
155
|
+
module.exports = __toCommonJS(getStaticBindingsForScope_exports);
|
|
156
|
+
//# sourceMappingURL=getStaticBindingsForScope.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/extractor/getStaticBindingsForScope.ts"],
|
|
4
|
+
"sourcesContent": ["import { dirname, extname, resolve } from 'path'\n\nimport { Binding, NodePath } from '@babel/traverse'\nimport * as t from '@babel/types'\nimport { existsSync } from 'fs-extra'\n\nimport { evaluateAstNode } from './evaluateAstNode'\nimport { getSourceModule } from './getSourceModule'\n\nconst isLocalImport = (path: string) => path.startsWith('.') || path.startsWith('/')\n\nfunction resolveImportPath(sourcePath: string, path: string) {\n const sourceDir = dirname(sourcePath)\n if (isLocalImport(path)) {\n if (extname(path) === '') {\n path += '.js'\n }\n return resolve(sourceDir, path)\n }\n return path\n}\n\nfunction importModule(path: string) {\n const filenames = [path.replace('.js', '.tsx'), path.replace('.js', '.ts'), path]\n for (const file of filenames) {\n if (existsSync(file)) {\n // TODO we can clear this when we see updates on it later on\n return require(file)\n }\n }\n return null\n}\n\nexport function getStaticBindingsForScope(\n scope: NodePath<t.JSXElement>['scope'],\n whitelist: string[] = [],\n sourcePath: string,\n bindingCache: Record<string, string | null>,\n shouldPrintDebug: boolean\n): Record<string, any> {\n const bindings: Record<string, Binding> = scope.getAllBindings() as any\n const ret: Record<string, any> = {}\n\n if (shouldPrintDebug) {\n // prettier-ignore\n console.log(' ', Object.keys(bindings).length, 'variables in scope')\n // .map(x => bindings[x].identifier?.name).join(', ')\n }\n\n // on react native at least it doesnt find some bindings? not sure why\n // lets add in whitelisted imports if they exist\n const program = scope.getProgramParent().block as t.Program\n for (const node of program.body) {\n if (t.isImportDeclaration(node)) {\n const importPath = node.source.value\n if (!node.specifiers.length) continue\n if (!isLocalImport(importPath)) {\n continue\n }\n const moduleName = resolveImportPath(sourcePath, importPath)\n const isOnWhitelist = whitelist.some((test) => moduleName.endsWith(test))\n if (!isOnWhitelist) continue\n const src = importModule(moduleName)\n if (!src) continue\n for (const specifier of node.specifiers) {\n if (t.isImportSpecifier(specifier) && t.isIdentifier(specifier.imported)) {\n if (typeof src[specifier.imported.name] !== 'undefined') {\n const val = src[specifier.local.name]\n ret[specifier.local.name] = val\n }\n }\n }\n }\n }\n\n if (!bindingCache) {\n throw new Error('bindingCache is a required param')\n }\n\n for (const k in bindings) {\n const binding = bindings[k]\n\n // check to see if the item is a module\n const sourceModule = getSourceModule(k, binding)\n if (sourceModule) {\n if (!sourceModule.sourceModule) {\n continue\n }\n\n const moduleName = resolveImportPath(sourcePath, sourceModule.sourceModule)\n const isOnWhitelist = whitelist.some((test) => moduleName.endsWith(test))\n\n // TODO we could cache this at the file level.. and check if its been touched since\n\n if (isOnWhitelist) {\n const src = importModule(moduleName)\n if (!src) {\n console.log(\n `\u26A0\uFE0F missing file ${moduleName} via ${sourcePath} import ${sourceModule.sourceModule}?`\n )\n return {}\n }\n if (sourceModule.destructured) {\n if (sourceModule.imported) {\n ret[k] = src[sourceModule.imported]\n }\n } else {\n // crude esmodule check\n // TODO: make sure this actually works\n // if (src && src.__esModule) {\n // ret[k] = src.default\n // } else {\n ret[k] = src\n // }\n }\n }\n continue\n }\n\n const { parent, parentPath } = binding.path\n\n if (!t.isVariableDeclaration(parent) || parent.kind !== 'const') {\n continue\n }\n\n // pick out the right variable declarator\n const dec = parent.declarations.find((d) => t.isIdentifier(d.id) && d.id.name === k)\n\n // if init is not set, there's nothing to evaluate\n // TODO: handle spread syntax\n if (!dec || !dec.init) {\n continue\n }\n\n // missing start/end will break caching\n if (typeof dec.id.start !== 'number' || typeof dec.id.end !== 'number') {\n console.error('dec.id.start/end is not a number')\n continue\n }\n\n if (!t.isIdentifier(dec.id)) {\n console.error('dec is not an identifier')\n continue\n }\n\n const cacheKey = `${dec.id.name}_${dec.id.start}-${dec.id.end}`\n\n // retrieve value from cache\n if (bindingCache.hasOwnProperty(cacheKey)) {\n ret[k] = bindingCache[cacheKey]\n continue\n }\n // retrieve value from cache\n if (bindingCache.hasOwnProperty(cacheKey)) {\n ret[k] = bindingCache[cacheKey]\n continue\n }\n\n // evaluate\n try {\n ret[k] = evaluateAstNode(dec.init, undefined, shouldPrintDebug)\n bindingCache[cacheKey] = ret[k]\n continue\n } catch (e) {\n // skip\n // if (shouldPrintDebug) {\n // console.error('[\uD83D\uDC07] cant eval, skipping', cacheKey) //, e.message)\n // }\n }\n }\n\n return ret\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA,kBAA0C;AAG1C,QAAmB;AACnB,sBAA2B;AAE3B,6BAAgC;AAChC,6BAAgC;AAEhC,MAAM,gBAAgB,wBAAC,SAAiB,KAAK,WAAW,QAAQ,KAAK,WAAW,MAA1D;AAEtB,2BAA2B,YAAoB,MAAc;AAC3D,QAAM,YAAY,yBAAQ;AAC1B,MAAI,cAAc,OAAO;AACvB,QAAI,yBAAQ,UAAU,IAAI;AACxB,cAAQ;AAAA;AAEV,WAAO,yBAAQ,WAAW;AAAA;AAE5B,SAAO;AAAA;AARA;AAWT,sBAAsB,MAAc;AAClC,QAAM,YAAY,CAAC,KAAK,QAAQ,OAAO,SAAS,KAAK,QAAQ,OAAO,QAAQ;AAC5E,aAAW,QAAQ,WAAW;AAC5B,QAAI,gCAAW,OAAO;AAEpB,aAAO,QAAQ;AAAA;AAAA;AAGnB,SAAO;AAAA;AARA;AAWF,mCACL,OACA,YAAsB,IACtB,YACA,cACA,kBACqB;AACrB,QAAM,WAAoC,MAAM;AAChD,QAAM,MAA2B;AAEjC,MAAI,kBAAkB;AAEpB,YAAQ,IAAI,MAAM,OAAO,KAAK,UAAU,QAAQ;AAAA;AAMlD,QAAM,UAAU,MAAM,mBAAmB;AACzC,aAAW,QAAQ,QAAQ,MAAM;AAC/B,QAAI,EAAE,oBAAoB,OAAO;AAC/B,YAAM,aAAa,KAAK,OAAO;AAC/B,UAAI,CAAC,KAAK,WAAW;AAAQ;AAC7B,UAAI,CAAC,cAAc,aAAa;AAC9B;AAAA;AAEF,YAAM,aAAa,kBAAkB,YAAY;AACjD,YAAM,gBAAgB,UAAU,KAAK,CAAC,SAAS,WAAW,SAAS;AACnE,UAAI,CAAC;AAAe;AACpB,YAAM,MAAM,aAAa;AACzB,UAAI,CAAC;AAAK;AACV,iBAAW,aAAa,KAAK,YAAY;AACvC,YAAI,EAAE,kBAAkB,cAAc,EAAE,aAAa,UAAU,WAAW;AACxE,cAAI,OAAO,IAAI,UAAU,SAAS,UAAU,aAAa;AACvD,kBAAM,MAAM,IAAI,UAAU,MAAM;AAChC,gBAAI,UAAU,MAAM,QAAQ;AAAA;AAAA;AAAA;AAAA;AAAA;AAOtC,MAAI,CAAC,cAAc;AACjB,UAAM,IAAI,MAAM;AAAA;AAGlB,aAAW,KAAK,UAAU;AACxB,UAAM,UAAU,SAAS;AAGzB,UAAM,eAAe,4CAAgB,GAAG;AACxC,QAAI,cAAc;AAChB,UAAI,CAAC,aAAa,cAAc;AAC9B;AAAA;AAGF,YAAM,aAAa,kBAAkB,YAAY,aAAa;AAC9D,YAAM,gBAAgB,UAAU,KAAK,CAAC,SAAS,WAAW,SAAS;AAInE,UAAI,eAAe;AACjB,cAAM,MAAM,aAAa;AACzB,YAAI,CAAC,KAAK;AACR,kBAAQ,IACN,6BAAmB,kBAAkB,qBAAqB,aAAa;AAEzE,iBAAO;AAAA;AAET,YAAI,aAAa,cAAc;AAC7B,cAAI,aAAa,UAAU;AACzB,gBAAI,KAAK,IAAI,aAAa;AAAA;AAAA,eAEvB;AAML,cAAI,KAAK;AAAA;AAAA;AAIb;AAAA;AAGF,UAAM,EAAE,QAAQ,eAAe,QAAQ;AAEvC,QAAI,CAAC,EAAE,sBAAsB,WAAW,OAAO,SAAS,SAAS;AAC/D;AAAA;AAIF,UAAM,MAAM,OAAO,aAAa,KAAK,CAAC,MAAM,EAAE,aAAa,EAAE,OAAO,EAAE,GAAG,SAAS;AAIlF,QAAI,CAAC,OAAO,CAAC,IAAI,MAAM;AACrB;AAAA;AAIF,QAAI,OAAO,IAAI,GAAG,UAAU,YAAY,OAAO,IAAI,GAAG,QAAQ,UAAU;AACtE,cAAQ,MAAM;AACd;AAAA;AAGF,QAAI,CAAC,EAAE,aAAa,IAAI,KAAK;AAC3B,cAAQ,MAAM;AACd;AAAA;AAGF,UAAM,WAAW,GAAG,IAAI,GAAG,QAAQ,IAAI,GAAG,SAAS,IAAI,GAAG;AAG1D,QAAI,aAAa,eAAe,WAAW;AACzC,UAAI,KAAK,aAAa;AACtB;AAAA;AAGF,QAAI,aAAa,eAAe,WAAW;AACzC,UAAI,KAAK,aAAa;AACtB;AAAA;AAIF,QAAI;AACF,UAAI,KAAK,4CAAgB,IAAI,MAAM,QAAW;AAC9C,mBAAa,YAAY,IAAI;AAC7B;AAAA,aACO,GAAP;AAAA;AAAA;AAQJ,SAAO;AAAA;AA1IO;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __markAsModule = (target) => __defProp(target, "__esModule", { value: true });
|
|
8
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
9
|
+
var __export = (target, all) => {
|
|
10
|
+
for (var name in all)
|
|
11
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
12
|
+
};
|
|
13
|
+
var __reExport = (target, module2, copyDefault, desc) => {
|
|
14
|
+
if (module2 && typeof module2 === "object" || typeof module2 === "function") {
|
|
15
|
+
for (let key of __getOwnPropNames(module2))
|
|
16
|
+
if (!__hasOwnProp.call(target, key) && (copyDefault || key !== "default"))
|
|
17
|
+
__defProp(target, key, { get: () => module2[key], enumerable: !(desc = __getOwnPropDesc(module2, key)) || desc.enumerable });
|
|
18
|
+
}
|
|
19
|
+
return target;
|
|
20
|
+
};
|
|
21
|
+
var __toESM = (module2, isNodeMode) => {
|
|
22
|
+
return __reExport(__markAsModule(__defProp(module2 != null ? __create(__getProtoOf(module2)) : {}, "default", !isNodeMode && module2 && module2.__esModule ? { get: () => module2.default, enumerable: true } : { value: module2, enumerable: true })), module2);
|
|
23
|
+
};
|
|
24
|
+
var __toCommonJS = /* @__PURE__ */ ((cache) => {
|
|
25
|
+
return (module2, temp) => {
|
|
26
|
+
return cache && cache.get(module2) || (temp = __reExport(__markAsModule({}), module2, 1), cache && cache.set(module2, temp), temp);
|
|
27
|
+
};
|
|
28
|
+
})(typeof WeakMap !== "undefined" ? /* @__PURE__ */ new WeakMap() : 0);
|
|
29
|
+
var hoistClassNames_exports = {};
|
|
30
|
+
__export(hoistClassNames_exports, {
|
|
31
|
+
hoistClassNames: () => hoistClassNames
|
|
32
|
+
});
|
|
33
|
+
var t = __toESM(require("@babel/types"));
|
|
34
|
+
function hoistClassNames(path, existing, expr) {
|
|
35
|
+
const hoist = hoistClassNames.bind(null, path, existing);
|
|
36
|
+
if (t.isStringLiteral(expr)) {
|
|
37
|
+
if (expr.value.trim() === "") {
|
|
38
|
+
return expr;
|
|
39
|
+
}
|
|
40
|
+
if (existing[expr.value]) {
|
|
41
|
+
return existing[expr.value];
|
|
42
|
+
}
|
|
43
|
+
const identifier = replaceStringWithVariable(expr);
|
|
44
|
+
existing[expr.value] = identifier;
|
|
45
|
+
return identifier;
|
|
46
|
+
}
|
|
47
|
+
if (t.isBinaryExpression(expr)) {
|
|
48
|
+
return t.binaryExpression(expr.operator, hoist(expr.left), hoist(expr.right));
|
|
49
|
+
}
|
|
50
|
+
if (t.isLogicalExpression(expr)) {
|
|
51
|
+
return t.logicalExpression(expr.operator, hoist(expr.left), hoist(expr.right));
|
|
52
|
+
}
|
|
53
|
+
if (t.isConditionalExpression(expr)) {
|
|
54
|
+
return t.conditionalExpression(expr.test, hoist(expr.consequent), hoist(expr.alternate));
|
|
55
|
+
}
|
|
56
|
+
return expr;
|
|
57
|
+
function replaceStringWithVariable(str) {
|
|
58
|
+
const uid = path.scope.generateUidIdentifier("cn");
|
|
59
|
+
const parent = path.findParent((path2) => path2.isProgram());
|
|
60
|
+
if (!parent)
|
|
61
|
+
throw new Error(`no program?`);
|
|
62
|
+
const variable = t.variableDeclaration("const", [
|
|
63
|
+
t.variableDeclarator(uid, t.stringLiteral(` ${str.value}`))
|
|
64
|
+
]);
|
|
65
|
+
parent.unshiftContainer("body", variable);
|
|
66
|
+
return uid;
|
|
67
|
+
}
|
|
68
|
+
__name(replaceStringWithVariable, "replaceStringWithVariable");
|
|
69
|
+
}
|
|
70
|
+
__name(hoistClassNames, "hoistClassNames");
|
|
71
|
+
module.exports = __toCommonJS(hoistClassNames_exports);
|
|
72
|
+
//# sourceMappingURL=hoistClassNames.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/extractor/hoistClassNames.ts"],
|
|
4
|
+
"sourcesContent": ["import { NodePath } from '@babel/traverse'\nimport * as t from '@babel/types'\n\nexport function hoistClassNames(\n path: NodePath<t.JSXElement>,\n existing: { [key: string]: t.Identifier },\n expr: t.Expression\n) {\n const hoist = hoistClassNames.bind(null, path, existing)\n if (t.isStringLiteral(expr)) {\n if (expr.value.trim() === '') {\n return expr\n }\n if (existing[expr.value]) {\n return existing[expr.value]\n }\n const identifier = replaceStringWithVariable(expr)\n existing[expr.value] = identifier\n return identifier\n }\n if (t.isBinaryExpression(expr)) {\n return t.binaryExpression(expr.operator, hoist(expr.left), hoist(expr.right))\n }\n if (t.isLogicalExpression(expr)) {\n return t.logicalExpression(expr.operator, hoist(expr.left), hoist(expr.right))\n }\n if (t.isConditionalExpression(expr)) {\n return t.conditionalExpression(expr.test, hoist(expr.consequent), hoist(expr.alternate))\n }\n return expr\n\n function replaceStringWithVariable(str: t.StringLiteral): t.Identifier {\n // hoist outside fn!\n const uid = path.scope.generateUidIdentifier('cn')\n const parent = path.findParent((path) => path.isProgram())\n if (!parent) throw new Error(`no program?`)\n const variable = t.variableDeclaration('const', [\n // adding a space for extra safety\n t.variableDeclarator(uid, t.stringLiteral(` ${str.value}`)),\n ])\n // @ts-ignore\n parent.unshiftContainer('body', variable)\n return uid\n }\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AACA,QAAmB;AAEZ,yBACL,MACA,UACA,MACA;AACA,QAAM,QAAQ,gBAAgB,KAAK,MAAM,MAAM;AAC/C,MAAI,EAAE,gBAAgB,OAAO;AAC3B,QAAI,KAAK,MAAM,WAAW,IAAI;AAC5B,aAAO;AAAA;AAET,QAAI,SAAS,KAAK,QAAQ;AACxB,aAAO,SAAS,KAAK;AAAA;AAEvB,UAAM,aAAa,0BAA0B;AAC7C,aAAS,KAAK,SAAS;AACvB,WAAO;AAAA;AAET,MAAI,EAAE,mBAAmB,OAAO;AAC9B,WAAO,EAAE,iBAAiB,KAAK,UAAU,MAAM,KAAK,OAAO,MAAM,KAAK;AAAA;AAExE,MAAI,EAAE,oBAAoB,OAAO;AAC/B,WAAO,EAAE,kBAAkB,KAAK,UAAU,MAAM,KAAK,OAAO,MAAM,KAAK;AAAA;AAEzE,MAAI,EAAE,wBAAwB,OAAO;AACnC,WAAO,EAAE,sBAAsB,KAAK,MAAM,MAAM,KAAK,aAAa,MAAM,KAAK;AAAA;AAE/E,SAAO;AAEP,qCAAmC,KAAoC;AAErE,UAAM,MAAM,KAAK,MAAM,sBAAsB;AAC7C,UAAM,SAAS,KAAK,WAAW,CAAC,UAAS,MAAK;AAC9C,QAAI,CAAC;AAAQ,YAAM,IAAI,MAAM;AAC7B,UAAM,WAAW,EAAE,oBAAoB,SAAS;AAAA,MAE9C,EAAE,mBAAmB,KAAK,EAAE,cAAc,IAAI,IAAI;AAAA;AAGpD,WAAO,iBAAiB,QAAQ;AAChC,WAAO;AAAA;AAXA;AAAA;AA5BK;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __markAsModule = (target) => __defProp(target, "__esModule", { value: true });
|
|
8
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
9
|
+
var __export = (target, all) => {
|
|
10
|
+
for (var name in all)
|
|
11
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
12
|
+
};
|
|
13
|
+
var __reExport = (target, module2, copyDefault, desc) => {
|
|
14
|
+
if (module2 && typeof module2 === "object" || typeof module2 === "function") {
|
|
15
|
+
for (let key of __getOwnPropNames(module2))
|
|
16
|
+
if (!__hasOwnProp.call(target, key) && (copyDefault || key !== "default"))
|
|
17
|
+
__defProp(target, key, { get: () => module2[key], enumerable: !(desc = __getOwnPropDesc(module2, key)) || desc.enumerable });
|
|
18
|
+
}
|
|
19
|
+
return target;
|
|
20
|
+
};
|
|
21
|
+
var __toESM = (module2, isNodeMode) => {
|
|
22
|
+
return __reExport(__markAsModule(__defProp(module2 != null ? __create(__getProtoOf(module2)) : {}, "default", !isNodeMode && module2 && module2.__esModule ? { get: () => module2.default, enumerable: true } : { value: module2, enumerable: true })), module2);
|
|
23
|
+
};
|
|
24
|
+
var __toCommonJS = /* @__PURE__ */ ((cache) => {
|
|
25
|
+
return (module2, temp) => {
|
|
26
|
+
return cache && cache.get(module2) || (temp = __reExport(__markAsModule({}), module2, 1), cache && cache.set(module2, temp), temp);
|
|
27
|
+
};
|
|
28
|
+
})(typeof WeakMap !== "undefined" ? /* @__PURE__ */ new WeakMap() : 0);
|
|
29
|
+
var literalToAst_exports = {};
|
|
30
|
+
__export(literalToAst_exports, {
|
|
31
|
+
literalToAst: () => literalToAst
|
|
32
|
+
});
|
|
33
|
+
var t = __toESM(require("@babel/types"));
|
|
34
|
+
function literalToAst(literal) {
|
|
35
|
+
if (literal === null) {
|
|
36
|
+
return t.nullLiteral();
|
|
37
|
+
}
|
|
38
|
+
switch (typeof literal) {
|
|
39
|
+
case "function":
|
|
40
|
+
throw new Error("Unsupported");
|
|
41
|
+
case "number":
|
|
42
|
+
return t.numericLiteral(literal);
|
|
43
|
+
case "string":
|
|
44
|
+
return t.stringLiteral(literal);
|
|
45
|
+
case "boolean":
|
|
46
|
+
return t.booleanLiteral(literal);
|
|
47
|
+
case "undefined":
|
|
48
|
+
return t.unaryExpression("void", t.numericLiteral(0), true);
|
|
49
|
+
default:
|
|
50
|
+
if (Array.isArray(literal)) {
|
|
51
|
+
return t.arrayExpression(literal.map(literalToAst));
|
|
52
|
+
}
|
|
53
|
+
return t.objectExpression(Object.keys(literal).filter((k) => {
|
|
54
|
+
return typeof literal[k] !== "undefined";
|
|
55
|
+
}).map((k) => {
|
|
56
|
+
return t.objectProperty(t.stringLiteral(k), literalToAst(literal[k]));
|
|
57
|
+
}));
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
__name(literalToAst, "literalToAst");
|
|
61
|
+
module.exports = __toCommonJS(literalToAst_exports);
|
|
62
|
+
//# sourceMappingURL=literalToAst.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/extractor/literalToAst.ts"],
|
|
4
|
+
"sourcesContent": ["import * as t from '@babel/types'\n\nexport function literalToAst(literal: any): t.Expression {\n if (literal === null) {\n return t.nullLiteral()\n }\n switch (typeof literal) {\n case 'function':\n throw new Error('Unsupported')\n case 'number':\n return t.numericLiteral(literal)\n case 'string':\n return t.stringLiteral(literal)\n case 'boolean':\n return t.booleanLiteral(literal)\n case 'undefined':\n return t.unaryExpression('void', t.numericLiteral(0), true)\n default:\n if (Array.isArray(literal)) {\n return t.arrayExpression(literal.map(literalToAst))\n }\n return t.objectExpression(\n Object.keys(literal)\n .filter((k) => {\n return typeof literal[k] !== 'undefined'\n })\n .map((k) => {\n return t.objectProperty(t.stringLiteral(k), literalToAst(literal[k]))\n })\n )\n }\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA,QAAmB;AAEZ,sBAAsB,SAA4B;AACvD,MAAI,YAAY,MAAM;AACpB,WAAO,EAAE;AAAA;AAEX,UAAQ,OAAO;AAAA,SACR;AACH,YAAM,IAAI,MAAM;AAAA,SACb;AACH,aAAO,EAAE,eAAe;AAAA,SACrB;AACH,aAAO,EAAE,cAAc;AAAA,SACpB;AACH,aAAO,EAAE,eAAe;AAAA,SACrB;AACH,aAAO,EAAE,gBAAgB,QAAQ,EAAE,eAAe,IAAI;AAAA;AAEtD,UAAI,MAAM,QAAQ,UAAU;AAC1B,eAAO,EAAE,gBAAgB,QAAQ,IAAI;AAAA;AAEvC,aAAO,EAAE,iBACP,OAAO,KAAK,SACT,OAAO,CAAC,MAAM;AACb,eAAO,OAAO,QAAQ,OAAO;AAAA,SAE9B,IAAI,CAAC,MAAM;AACV,eAAO,EAAE,eAAe,EAAE,cAAc,IAAI,aAAa,QAAQ;AAAA;AAAA;AAAA;AAzB7D;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __markAsModule = (target) => __defProp(target, "__esModule", { value: true });
|
|
6
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __reExport = (target, module2, copyDefault, desc) => {
|
|
12
|
+
if (module2 && typeof module2 === "object" || typeof module2 === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(module2))
|
|
14
|
+
if (!__hasOwnProp.call(target, key) && (copyDefault || key !== "default"))
|
|
15
|
+
__defProp(target, key, { get: () => module2[key], enumerable: !(desc = __getOwnPropDesc(module2, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return target;
|
|
18
|
+
};
|
|
19
|
+
var __toCommonJS = /* @__PURE__ */ ((cache) => {
|
|
20
|
+
return (module2, temp) => {
|
|
21
|
+
return cache && cache.get(module2) || (temp = __reExport(__markAsModule({}), module2, 1), cache && cache.set(module2, temp), temp);
|
|
22
|
+
};
|
|
23
|
+
})(typeof WeakMap !== "undefined" ? /* @__PURE__ */ new WeakMap() : 0);
|
|
24
|
+
var loadTamagui_exports = {};
|
|
25
|
+
__export(loadTamagui_exports, {
|
|
26
|
+
loadTamagui: () => loadTamagui
|
|
27
|
+
});
|
|
28
|
+
var import_path = require("path");
|
|
29
|
+
var import_core_node = require("@tamagui/core-node");
|
|
30
|
+
let loadedTamagui = null;
|
|
31
|
+
function loadTamagui(props) {
|
|
32
|
+
if (loadedTamagui) {
|
|
33
|
+
return loadedTamagui;
|
|
34
|
+
}
|
|
35
|
+
process.env.IS_STATIC = "is_static";
|
|
36
|
+
const rnw = require("react-native-web");
|
|
37
|
+
const Mod = require("module");
|
|
38
|
+
const og = Mod.prototype.require;
|
|
39
|
+
Mod.prototype.require = function(path) {
|
|
40
|
+
if (path.endsWith(".css")) {
|
|
41
|
+
return {};
|
|
42
|
+
}
|
|
43
|
+
if (path === "@gorhom/bottom-sheet") {
|
|
44
|
+
return {};
|
|
45
|
+
}
|
|
46
|
+
if (path.startsWith("react-native") && !path.startsWith("react-native-web/dist/cjs/exports")) {
|
|
47
|
+
return rnw;
|
|
48
|
+
}
|
|
49
|
+
return og.apply(this, arguments);
|
|
50
|
+
};
|
|
51
|
+
const configPath = (0, import_path.join)(process.cwd(), props.config);
|
|
52
|
+
const tamaguiConfigExport = require(configPath);
|
|
53
|
+
const tamaguiConfig = tamaguiConfigExport["default"] || tamaguiConfigExport;
|
|
54
|
+
const components = {};
|
|
55
|
+
for (const module2 of props.components) {
|
|
56
|
+
const exported = require(module2);
|
|
57
|
+
Object.assign(components, exported);
|
|
58
|
+
}
|
|
59
|
+
process.env.IS_STATIC = void 0;
|
|
60
|
+
Mod.prototype.require = og;
|
|
61
|
+
(0, import_core_node.createTamagui)(tamaguiConfig);
|
|
62
|
+
loadedTamagui = {
|
|
63
|
+
components,
|
|
64
|
+
tamaguiConfig
|
|
65
|
+
};
|
|
66
|
+
return loadedTamagui;
|
|
67
|
+
}
|
|
68
|
+
__name(loadTamagui, "loadTamagui");
|
|
69
|
+
module.exports = __toCommonJS(loadTamagui_exports);
|
|
70
|
+
//# sourceMappingURL=loadTamagui.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/extractor/loadTamagui.ts"],
|
|
4
|
+
"sourcesContent": ["import { join } from 'path'\n\nimport type { StaticComponent, TamaguiInternalConfig } from '@tamagui/core'\nimport { createTamagui } from '@tamagui/core-node'\n\nlet loadedTamagui: any = null\n\nexport function loadTamagui(props: { components: string[]; config: string }): {\n components: Record<string, StaticComponent>\n tamaguiConfig: TamaguiInternalConfig\n} {\n if (loadedTamagui) {\n return loadedTamagui\n }\n\n // lets shim require and avoid importing react-native + react-native-web\n // we just need to read the config around them\n process.env.IS_STATIC = 'is_static'\n const rnw = require('react-native-web')\n const Mod = require('module')\n const og = Mod.prototype.require\n Mod.prototype.require = function (path: string) {\n if (path.endsWith('.css')) {\n return {}\n }\n if (path === '@gorhom/bottom-sheet') {\n return {}\n }\n if (\n path.startsWith('react-native') &&\n // allow our rnw.tsx imports through\n !path.startsWith('react-native-web/dist/cjs/exports')\n ) {\n return rnw\n }\n return og.apply(this, arguments)\n }\n\n // import config\n const configPath = join(process.cwd(), props.config)\n const tamaguiConfigExport = require(configPath)\n const tamaguiConfig = (tamaguiConfigExport['default'] ||\n tamaguiConfigExport) as TamaguiInternalConfig\n\n // import components\n const components = {}\n for (const module of props.components) {\n const exported = require(module)\n Object.assign(components, exported)\n }\n\n // undo shims\n process.env.IS_STATIC = undefined\n Mod.prototype.require = og\n\n // set up core-node\n createTamagui(tamaguiConfig)\n\n loadedTamagui = {\n components,\n tamaguiConfig,\n }\n\n return loadedTamagui\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA,kBAAqB;AAGrB,uBAA8B;AAE9B,IAAI,gBAAqB;AAElB,qBAAqB,OAG1B;AACA,MAAI,eAAe;AACjB,WAAO;AAAA;AAKT,UAAQ,IAAI,YAAY;AACxB,QAAM,MAAM,QAAQ;AACpB,QAAM,MAAM,QAAQ;AACpB,QAAM,KAAK,IAAI,UAAU;AACzB,MAAI,UAAU,UAAU,SAAU,MAAc;AAC9C,QAAI,KAAK,SAAS,SAAS;AACzB,aAAO;AAAA;AAET,QAAI,SAAS,wBAAwB;AACnC,aAAO;AAAA;AAET,QACE,KAAK,WAAW,mBAEhB,CAAC,KAAK,WAAW,sCACjB;AACA,aAAO;AAAA;AAET,WAAO,GAAG,MAAM,MAAM;AAAA;AAIxB,QAAM,aAAa,sBAAK,QAAQ,OAAO,MAAM;AAC7C,QAAM,sBAAsB,QAAQ;AACpC,QAAM,gBAAiB,oBAAoB,cACzC;AAGF,QAAM,aAAa;AACnB,aAAW,WAAU,MAAM,YAAY;AACrC,UAAM,WAAW,QAAQ;AACzB,WAAO,OAAO,YAAY;AAAA;AAI5B,UAAQ,IAAI,YAAY;AACxB,MAAI,UAAU,UAAU;AAGxB,sCAAc;AAEd,kBAAgB;AAAA,IACd;AAAA,IACA;AAAA;AAGF,SAAO;AAAA;AAxDO;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|