@tamagui/static 1.0.0-alpha.9 → 1.0.0-beta.172
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/README.md +3 -19
- package/dist/cjs/constants.js +36 -0
- package/dist/cjs/constants.js.map +7 -0
- package/dist/cjs/extractor/accessSafe.js +32 -0
- package/dist/cjs/extractor/accessSafe.js.map +7 -0
- package/dist/cjs/extractor/babelParse.js +51 -0
- package/dist/cjs/extractor/babelParse.js.map +7 -0
- package/dist/cjs/extractor/buildClassName.js +61 -0
- package/dist/cjs/extractor/buildClassName.js.map +7 -0
- package/dist/cjs/extractor/createEvaluator.js +73 -0
- package/dist/cjs/extractor/createEvaluator.js.map +7 -0
- package/dist/cjs/extractor/createExtractor.js +1100 -0
- package/dist/cjs/extractor/createExtractor.js.map +7 -0
- package/dist/cjs/extractor/ensureImportingConcat.js +45 -0
- package/dist/cjs/extractor/ensureImportingConcat.js.map +7 -0
- package/dist/cjs/extractor/evaluateAstNode.js +115 -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 +186 -0
- package/dist/cjs/extractor/extractMediaStyle.js.map +7 -0
- package/dist/cjs/extractor/extractToClassNames.js +324 -0
- package/dist/cjs/extractor/extractToClassNames.js.map +7 -0
- package/dist/cjs/extractor/findTopmostFunction.js +41 -0
- package/dist/cjs/extractor/findTopmostFunction.js.map +7 -0
- package/dist/cjs/extractor/generatedUid.js +49 -0
- package/dist/cjs/extractor/generatedUid.js.map +7 -0
- package/dist/cjs/extractor/getPrefixLogs.js +29 -0
- package/dist/cjs/extractor/getPrefixLogs.js.map +7 -0
- package/dist/cjs/extractor/getPropValueFromAttributes.js +70 -0
- package/dist/cjs/extractor/getPropValueFromAttributes.js.map +7 -0
- package/dist/cjs/extractor/getSourceModule.js +90 -0
- package/dist/cjs/extractor/getSourceModule.js.map +7 -0
- package/dist/cjs/extractor/getStaticBindingsForScope.js +149 -0
- package/dist/cjs/extractor/getStaticBindingsForScope.js.map +7 -0
- package/dist/cjs/extractor/hoistClassNames.js +65 -0
- package/dist/cjs/extractor/hoistClassNames.js.map +7 -0
- package/dist/cjs/extractor/literalToAst.js +114 -0
- package/dist/cjs/extractor/literalToAst.js.map +7 -0
- package/dist/cjs/extractor/loadTamagui.js +83 -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 +101 -0
- package/dist/cjs/extractor/normalizeTernaries.js.map +7 -0
- package/dist/cjs/extractor/removeUnusedHooks.js +100 -0
- package/dist/cjs/extractor/removeUnusedHooks.js.map +7 -0
- package/dist/cjs/extractor/validHTMLAttributes.js +71 -0
- package/dist/cjs/extractor/validHTMLAttributes.js.map +7 -0
- package/dist/cjs/index.js +34 -0
- package/dist/cjs/index.js.map +7 -0
- package/dist/cjs/patchReactNativeWeb.js +151 -0
- package/dist/cjs/patchReactNativeWeb.js.map +7 -0
- package/dist/cjs/types.js +16 -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 +2 -2
- package/dist/{extractor → esm/extractor}/babelParse.js +0 -0
- package/dist/{extractor → esm/extractor}/babelParse.js.map +2 -2
- package/dist/{extractor → esm/extractor}/buildClassName.js +0 -0
- package/dist/{extractor → esm/extractor}/buildClassName.js.map +2 -2
- package/dist/{extractor → esm/extractor}/createEvaluator.js +3 -2
- package/dist/esm/extractor/createEvaluator.js.map +7 -0
- package/dist/{extractor → esm/extractor}/createExtractor.js +412 -189
- 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/esm/extractor/evaluateAstNode.js.map +7 -0
- package/dist/{extractor → esm/extractor}/extractHelpers.js +20 -11
- package/dist/esm/extractor/extractHelpers.js.map +7 -0
- package/dist/{extractor → esm/extractor}/extractMediaStyle.js +3 -2
- package/dist/esm/extractor/extractMediaStyle.js.map +7 -0
- package/dist/{extractor → esm/extractor}/extractToClassNames.js +99 -44
- 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 +2 -2
- package/dist/{extractor → esm/extractor}/generatedUid.js +0 -0
- package/dist/{extractor → esm/extractor}/generatedUid.js.map +2 -2
- package/dist/esm/extractor/getPrefixLogs.js +12 -0
- package/dist/esm/extractor/getPrefixLogs.js.map +7 -0
- package/dist/{extractor → esm/extractor}/getPropValueFromAttributes.js +0 -0
- package/dist/{extractor → esm/extractor}/getPropValueFromAttributes.js.map +2 -2
- package/dist/{extractor → esm/extractor}/getSourceModule.js +0 -0
- package/dist/{extractor → esm/extractor}/getSourceModule.js.map +2 -2
- package/dist/{extractor → esm/extractor}/getStaticBindingsForScope.js +0 -0
- package/dist/esm/extractor/getStaticBindingsForScope.js.map +7 -0
- package/dist/{extractor → esm/extractor}/hoistClassNames.js +0 -0
- package/dist/{extractor → esm/extractor}/hoistClassNames.js.map +2 -2
- package/dist/esm/extractor/literalToAst.js +80 -0
- package/dist/esm/extractor/literalToAst.js.map +7 -0
- package/dist/{extractor → esm/extractor}/loadTamagui.js +27 -3
- package/dist/esm/extractor/loadTamagui.js.map +7 -0
- package/dist/{extractor → esm/extractor}/logLines.js +8 -3
- package/dist/esm/extractor/logLines.js.map +7 -0
- package/dist/{extractor → esm/extractor}/normalizeTernaries.js +3 -2
- package/dist/esm/extractor/normalizeTernaries.js.map +7 -0
- package/dist/{extractor → esm/extractor}/removeUnusedHooks.js +5 -3
- package/dist/esm/extractor/removeUnusedHooks.js.map +7 -0
- package/dist/esm/extractor/validHTMLAttributes.js +52 -0
- package/dist/esm/extractor/validHTMLAttributes.js.map +7 -0
- 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} +37 -14
- 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 +51 -0
- package/dist/jsx/extractor/createExtractor.js +1050 -0
- package/dist/jsx/extractor/ensureImportingConcat.js +23 -0
- package/dist/jsx/extractor/evaluateAstNode.js +93 -0
- package/dist/jsx/extractor/extractHelpers.js +102 -0
- package/dist/jsx/extractor/extractMediaStyle.js +151 -0
- package/dist/jsx/extractor/extractToClassNames.js +287 -0
- package/dist/jsx/extractor/findTopmostFunction.js +22 -0
- package/dist/jsx/extractor/generatedUid.js +27 -0
- package/dist/jsx/extractor/getPrefixLogs.js +11 -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 +79 -0
- package/dist/jsx/extractor/loadTamagui.js +64 -0
- package/dist/jsx/extractor/logLines.js +21 -0
- package/dist/jsx/extractor/normalizeTernaries.js +52 -0
- package/dist/jsx/extractor/removeUnusedHooks.js +79 -0
- package/dist/jsx/extractor/validHTMLAttributes.js +51 -0
- package/dist/jsx/index.js +13 -0
- package/{src/patchReactNativeWeb.ts → dist/jsx/patchReactNativeWeb.js} +65 -59
- package/dist/jsx/types.js +0 -0
- package/package.json +26 -23
- 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 +27 -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 +23 -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/getPrefixLogs.d.ts +3 -0
- package/types/extractor/getPrefixLogs.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 +4 -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/extractor/validHTMLAttributes.d.ts +49 -0
- package/types/extractor/validHTMLAttributes.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 +85 -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/evaluateAstNode.js.map +0 -7
- package/dist/extractor/extractHelpers.js.map +0 -7
- package/dist/extractor/extractMediaStyle.js.map +0 -7
- package/dist/extractor/extractToClassNames.js.map +0 -7
- package/dist/extractor/getStaticBindingsForScope.js.map +0 -7
- package/dist/extractor/literalToAst.js +0 -34
- package/dist/extractor/literalToAst.js.map +0 -7
- package/dist/extractor/loadTamagui.js.map +0 -7
- package/dist/extractor/logLines.js.map +0 -7
- package/dist/extractor/normalizeTernaries.js.map +0 -7
- package/dist/extractor/removeUnusedHooks.js.map +0 -7
- package/dist/index.cjs +0 -2126
- 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 -1138
- 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 -323
- 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/logLines.ts +0 -11
- package/src/extractor/normalizeTernaries.ts +0 -60
- package/src/extractor/removeUnusedHooks.ts +0 -76
- package/src/index.ts +0 -9
- package/src/types.ts +0 -89
- package/types.d.ts +0 -219
|
@@ -0,0 +1,49 @@
|
|
|
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 __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod));
|
|
21
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
22
|
+
var generatedUid_exports = {};
|
|
23
|
+
__export(generatedUid_exports, {
|
|
24
|
+
generateUid: () => generateUid
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(generatedUid_exports);
|
|
27
|
+
var t = __toESM(require("@babel/types"));
|
|
28
|
+
var import_invariant = __toESM(require("invariant"));
|
|
29
|
+
function generateUid(scope, name) {
|
|
30
|
+
(0, import_invariant.default)(typeof scope === "object", "generateUid expects a scope object as its first parameter");
|
|
31
|
+
(0, import_invariant.default)(typeof name === "string" && name !== "", "generateUid expects a valid name as its second parameter");
|
|
32
|
+
name = t.toIdentifier(name).replace(/^_+/, "").replace(/[0-9]+$/g, "");
|
|
33
|
+
let uid;
|
|
34
|
+
let i = 0;
|
|
35
|
+
do {
|
|
36
|
+
if (i > 1) {
|
|
37
|
+
uid = name + i;
|
|
38
|
+
} else {
|
|
39
|
+
uid = name;
|
|
40
|
+
}
|
|
41
|
+
i++;
|
|
42
|
+
} while (scope.hasLabel(uid) || scope.hasBinding(uid) || scope.hasGlobal(uid) || scope.hasReference(uid));
|
|
43
|
+
const program = scope.getProgramParent();
|
|
44
|
+
program.references[uid] = true;
|
|
45
|
+
program.uids[uid] = true;
|
|
46
|
+
return uid;
|
|
47
|
+
}
|
|
48
|
+
__name(generateUid, "generateUid");
|
|
49
|
+
//# sourceMappingURL=generatedUid.js.map
|
|
@@ -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;AAAA,QAAmB;AACnB,uBAAsB;AAQf,qBAAqB,OAAY,MAAsB;AAC5D,gCAAU,OAAO,UAAU,UAAU,2DAA2D;AAChG,gCACE,OAAO,SAAS,YAAY,SAAS,IACrC,0DACF;AAEA,SAAO,EACJ,aAAa,IAAI,EACjB,QAAQ,OAAO,EAAE,EACjB,QAAQ,YAAY,EAAE;AAEzB,MAAI;AACJ,MAAI,IAAI;AACR,KAAG;AACD,QAAI,IAAI,GAAG;AACT,YAAM,OAAO;AAAA,IACf,OAAO;AACL,YAAM;AAAA,IACR;AACA;AAAA,EACF,SACE,MAAM,SAAS,GAAG,KAClB,MAAM,WAAW,GAAG,KACpB,MAAM,UAAU,GAAG,KACnB,MAAM,aAAa,GAAG;AAGxB,QAAM,UAAU,MAAM,iBAAiB;AACvC,UAAQ,WAAW,OAAO;AAC1B,UAAQ,KAAK,OAAO;AAEpB,SAAO;AACT;AAjCgB;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var getPrefixLogs_exports = {};
|
|
20
|
+
__export(getPrefixLogs_exports, {
|
|
21
|
+
getPrefixLogs: () => getPrefixLogs
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(getPrefixLogs_exports);
|
|
24
|
+
function getPrefixLogs(options) {
|
|
25
|
+
const { TAMAGUI_TARGET } = process.env;
|
|
26
|
+
return (options == null ? void 0 : options.prefixLogs) ?? ` ${TAMAGUI_TARGET} | `;
|
|
27
|
+
}
|
|
28
|
+
__name(getPrefixLogs, "getPrefixLogs");
|
|
29
|
+
//# sourceMappingURL=getPrefixLogs.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/extractor/getPrefixLogs.ts"],
|
|
4
|
+
"sourcesContent": ["import { TamaguiOptions } from '../types'\n\nexport function getPrefixLogs(options?: TamaguiOptions) {\n const { TAMAGUI_TARGET } = process.env\n return options?.prefixLogs ?? ` ${TAMAGUI_TARGET} | `\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEO,uBAAuB,SAA0B;AACtD,QAAM,EAAE,mBAAmB,QAAQ;AACnC,SAAO,oCAAS,eAAc,IAAI;AACpC;AAHgB;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
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 __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod));
|
|
21
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
22
|
+
var getPropValueFromAttributes_exports = {};
|
|
23
|
+
__export(getPropValueFromAttributes_exports, {
|
|
24
|
+
getPropValueFromAttributes: () => getPropValueFromAttributes
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(getPropValueFromAttributes_exports);
|
|
27
|
+
var import_generator = __toESM(require("@babel/generator"));
|
|
28
|
+
var t = __toESM(require("@babel/types"));
|
|
29
|
+
var import_accessSafe = require("./accessSafe");
|
|
30
|
+
function getPropValueFromAttributes(propName, attrs) {
|
|
31
|
+
let propIndex = -1;
|
|
32
|
+
let jsxAttr = null;
|
|
33
|
+
for (let idx = -1, len = attrs.length; ++idx < len; ) {
|
|
34
|
+
const attr = attrs[idx];
|
|
35
|
+
if (t.isJSXAttribute(attr) && attr.name && attr.name.name === propName) {
|
|
36
|
+
propIndex = idx;
|
|
37
|
+
jsxAttr = attr;
|
|
38
|
+
break;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
if (!jsxAttr || jsxAttr.value == null) {
|
|
42
|
+
return null;
|
|
43
|
+
}
|
|
44
|
+
let propValue = jsxAttr.value;
|
|
45
|
+
if (t.isJSXExpressionContainer(propValue)) {
|
|
46
|
+
propValue = propValue.expression;
|
|
47
|
+
}
|
|
48
|
+
if (t.isJSXEmptyExpression(propValue)) {
|
|
49
|
+
console.error("encountered JSXEmptyExpression");
|
|
50
|
+
return null;
|
|
51
|
+
}
|
|
52
|
+
const applicableSpreads = attrs.filter((attr, idx) => {
|
|
53
|
+
if (t.isJSXSpreadAttribute(attr)) {
|
|
54
|
+
if (t.isIdentifier(attr.argument) || t.isMemberExpression(attr.argument)) {
|
|
55
|
+
return idx > propIndex;
|
|
56
|
+
}
|
|
57
|
+
if (t.isLogicalExpression(attr.argument)) {
|
|
58
|
+
return false;
|
|
59
|
+
}
|
|
60
|
+
throw new Error(`unsupported spread of type "${attr.argument.type}": ${(0, import_generator.default)(attr).code}`);
|
|
61
|
+
}
|
|
62
|
+
return false;
|
|
63
|
+
}).map((attr) => attr.argument);
|
|
64
|
+
if (applicableSpreads.length > 0) {
|
|
65
|
+
propValue = applicableSpreads.reduce((acc, val) => t.logicalExpression("||", (0, import_accessSafe.accessSafe)(val, propName), acc), propValue);
|
|
66
|
+
}
|
|
67
|
+
return propValue;
|
|
68
|
+
}
|
|
69
|
+
__name(getPropValueFromAttributes, "getPropValueFromAttributes");
|
|
70
|
+
//# 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;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,IAAI,KAAK,KAAK,QAAQ,KAAK,KAAK,SAAS,UAAU;AACtE,kBAAY;AACZ,gBAAU;AACV;AAAA,IACF;AAAA,EACF;AAEA,MAAI,CAAC,WAAW,QAAQ,SAAS,MAAM;AACrC,WAAO;AAAA,EACT;AAEA,MAAI,YAMe,QAAQ;AAE3B,MAAI,EAAE,yBAAyB,SAAS,GAAG;AACzC,gBAAY,UAAU;AAAA,EACxB;AAGA,MAAI,EAAE,qBAAqB,SAAS,GAAG;AACrC,YAAQ,MAAM,gCAAgC;AAC9C,WAAO;AAAA,EACT;AAGA,QAAM,oBAAoB,MACvB,OAGC,CAAC,MAAM,QAAsC;AAC3C,QAAI,EAAE,qBAAqB,IAAI,GAAG;AAChC,UAAI,EAAE,aAAa,KAAK,QAAQ,KAAK,EAAE,mBAAmB,KAAK,QAAQ,GAAG;AACxE,eAAO,MAAM;AAAA,MACf;AACA,UAAI,EAAE,oBAAoB,KAAK,QAAQ,GAAG;AACxC,eAAO;AAAA,MACT;AACA,YAAM,IAAI,MACR,+BAA+B,KAAK,SAAS,UAAU,8BAAS,IAAI,EAAE,MACxE;AAAA,IACF;AACA,WAAO;AAAA,EACT,CACF,EACC,IAAI,CAAC,SAAS,KAAK,QAAQ;AAK9B,MAAI,kBAAkB,SAAS,GAAG;AAChC,gBAAY,kBAAkB,OAC5B,CAAC,KAAK,QAAQ,EAAE,kBAAkB,MAAM,kCAAW,KAAK,QAAQ,GAAG,GAAG,GACtE,SACF;AAAA,EACF;AAEA,SAAO;AACT;AAtEgB;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,90 @@
|
|
|
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 __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod));
|
|
21
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
22
|
+
var getSourceModule_exports = {};
|
|
23
|
+
__export(getSourceModule_exports, {
|
|
24
|
+
getSourceModule: () => getSourceModule
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(getSourceModule_exports);
|
|
27
|
+
var t = __toESM(require("@babel/types"));
|
|
28
|
+
function getSourceModule(itemName, itemBinding) {
|
|
29
|
+
if (!itemBinding.constant) {
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
32
|
+
let sourceModule;
|
|
33
|
+
let imported;
|
|
34
|
+
let local;
|
|
35
|
+
let destructured;
|
|
36
|
+
let usesImportSyntax = false;
|
|
37
|
+
const itemNode = itemBinding.path.node;
|
|
38
|
+
if (t.isImportDefaultSpecifier(itemNode) || t.isImportSpecifier(itemNode)) {
|
|
39
|
+
if (t.isImportDeclaration(itemBinding.path.parent)) {
|
|
40
|
+
sourceModule = itemBinding.path.parent.source.value;
|
|
41
|
+
local = itemNode.local.name;
|
|
42
|
+
usesImportSyntax = true;
|
|
43
|
+
if (t.isImportSpecifier(itemNode)) {
|
|
44
|
+
imported = itemNode.imported["name"];
|
|
45
|
+
destructured = true;
|
|
46
|
+
} else {
|
|
47
|
+
imported = itemNode.local.name;
|
|
48
|
+
destructured = false;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
} 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) {
|
|
52
|
+
const firstArg = itemNode.init.arguments[0];
|
|
53
|
+
if (!t.isStringLiteral(firstArg)) {
|
|
54
|
+
return null;
|
|
55
|
+
}
|
|
56
|
+
sourceModule = firstArg.value;
|
|
57
|
+
if (t.isIdentifier(itemNode.id)) {
|
|
58
|
+
local = itemNode.id.name;
|
|
59
|
+
imported = itemNode.id.name;
|
|
60
|
+
destructured = false;
|
|
61
|
+
} else if (t.isObjectPattern(itemNode.id)) {
|
|
62
|
+
for (const objProp of itemNode.id.properties) {
|
|
63
|
+
if (t.isObjectProperty(objProp) && t.isIdentifier(objProp.value) && objProp.value.name === itemName) {
|
|
64
|
+
local = objProp.value.name;
|
|
65
|
+
imported = objProp.key.name;
|
|
66
|
+
destructured = true;
|
|
67
|
+
break;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
if (!local || !imported) {
|
|
71
|
+
console.error("could not find prop with value `%s`", itemName);
|
|
72
|
+
return null;
|
|
73
|
+
}
|
|
74
|
+
} else {
|
|
75
|
+
console.error("Unhandled id type: %s", itemNode.id.type);
|
|
76
|
+
return null;
|
|
77
|
+
}
|
|
78
|
+
} else {
|
|
79
|
+
return null;
|
|
80
|
+
}
|
|
81
|
+
return {
|
|
82
|
+
destructured,
|
|
83
|
+
imported,
|
|
84
|
+
local,
|
|
85
|
+
sourceModule,
|
|
86
|
+
usesImportSyntax
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
__name(getSourceModule, "getSourceModule");
|
|
90
|
+
//# 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;AAAA,QAAmB;AAUZ,yBACL,UACA,aAIqB;AAErB,MAAI,CAAC,YAAY,UAAU;AACzB,WAAO;AAAA,EACT;AAEA,MAAI;AACJ,MAAI;AACJ,MAAI;AACJ,MAAI;AACJ,MAAI,mBAAmB;AAEvB,QAAM,WAAW,YAAY,KAAK;AAElC,MAEE,EAAE,yBAAyB,QAAQ,KAEnC,EAAE,kBAAkB,QAAQ,GAC5B;AACA,QAAI,EAAE,oBAAoB,YAAY,KAAK,MAAM,GAAG;AAClD,qBAAe,YAAY,KAAK,OAAO,OAAO;AAC9C,cAAQ,SAAS,MAAM;AACvB,yBAAmB;AACnB,UAAI,EAAE,kBAAkB,QAAQ,GAAG;AACjC,mBAAW,SAAS,SAAS;AAC7B,uBAAe;AAAA,MACjB,OAAO;AACL,mBAAW,SAAS,MAAM;AAC1B,uBAAe;AAAA,MACjB;AAAA,IACF;AAAA,EACF,WACE,EAAE,qBAAqB,QAAQ,KAC/B,SAAS,QAAQ,QACjB,EAAE,iBAAiB,SAAS,IAAI,KAChC,EAAE,aAAa,SAAS,KAAK,MAAM,KACnC,SAAS,KAAK,OAAO,SAAS,aAC9B,SAAS,KAAK,UAAU,WAAW,GACnC;AACA,UAAM,WAAW,SAAS,KAAK,UAAU;AACzC,QAAI,CAAC,EAAE,gBAAgB,QAAQ,GAAG;AAChC,aAAO;AAAA,IACT;AACA,mBAAe,SAAS;AAExB,QAAI,EAAE,aAAa,SAAS,EAAE,GAAG;AAC/B,cAAQ,SAAS,GAAG;AACpB,iBAAW,SAAS,GAAG;AACvB,qBAAe;AAAA,IACjB,WAAW,EAAE,gBAAgB,SAAS,EAAE,GAAG;AACzC,iBAAW,WAAW,SAAS,GAAG,YAAY;AAC5C,YACE,EAAE,iBAAiB,OAAO,KAC1B,EAAE,aAAa,QAAQ,KAAK,KAC5B,QAAQ,MAAM,SAAS,UACvB;AACA,kBAAQ,QAAQ,MAAM;AAEtB,qBAAW,QAAQ,IAAI;AACvB,yBAAe;AACf;AAAA,QACF;AAAA,MACF;AAEA,UAAI,CAAC,SAAS,CAAC,UAAU;AACvB,gBAAQ,MAAM,uCAAuC,QAAQ;AAC7D,eAAO;AAAA,MACT;AAAA,IACF,OAAO;AACL,cAAQ,MAAM,yBAAyB,SAAS,GAAG,IAAI;AACvD,aAAO;AAAA,IACT;AAAA,EACF,OAAO;AACL,WAAO;AAAA,EACT;AAEA,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;AA1FgB;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,149 @@
|
|
|
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 __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod));
|
|
21
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
22
|
+
var getStaticBindingsForScope_exports = {};
|
|
23
|
+
__export(getStaticBindingsForScope_exports, {
|
|
24
|
+
getStaticBindingsForScope: () => getStaticBindingsForScope
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(getStaticBindingsForScope_exports);
|
|
27
|
+
var import_path = require("path");
|
|
28
|
+
var t = __toESM(require("@babel/types"));
|
|
29
|
+
var import_fs_extra = require("fs-extra");
|
|
30
|
+
var import_evaluateAstNode = require("./evaluateAstNode");
|
|
31
|
+
var import_getSourceModule = require("./getSourceModule");
|
|
32
|
+
const isLocalImport = /* @__PURE__ */ __name((path) => path.startsWith(".") || path.startsWith("/"), "isLocalImport");
|
|
33
|
+
function resolveImportPath(sourcePath, path) {
|
|
34
|
+
const sourceDir = (0, import_path.dirname)(sourcePath);
|
|
35
|
+
if (isLocalImport(path)) {
|
|
36
|
+
if ((0, import_path.extname)(path) === "") {
|
|
37
|
+
path += ".js";
|
|
38
|
+
}
|
|
39
|
+
return (0, import_path.resolve)(sourceDir, path);
|
|
40
|
+
}
|
|
41
|
+
return path;
|
|
42
|
+
}
|
|
43
|
+
__name(resolveImportPath, "resolveImportPath");
|
|
44
|
+
function importModule(path) {
|
|
45
|
+
const filenames = [path.replace(".js", ".tsx"), path.replace(".js", ".ts"), path];
|
|
46
|
+
for (const file of filenames) {
|
|
47
|
+
if ((0, import_fs_extra.existsSync)(file)) {
|
|
48
|
+
return require(file);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return null;
|
|
52
|
+
}
|
|
53
|
+
__name(importModule, "importModule");
|
|
54
|
+
function getStaticBindingsForScope(scope, whitelist = [], sourcePath, bindingCache, shouldPrintDebug) {
|
|
55
|
+
const bindings = scope.getAllBindings();
|
|
56
|
+
const ret = {};
|
|
57
|
+
if (shouldPrintDebug) {
|
|
58
|
+
console.log(" ", Object.keys(bindings).length, "variables in scope");
|
|
59
|
+
}
|
|
60
|
+
const program = scope.getProgramParent().block;
|
|
61
|
+
for (const node of program.body) {
|
|
62
|
+
if (t.isImportDeclaration(node)) {
|
|
63
|
+
const importPath = node.source.value;
|
|
64
|
+
if (!node.specifiers.length)
|
|
65
|
+
continue;
|
|
66
|
+
if (!isLocalImport(importPath)) {
|
|
67
|
+
continue;
|
|
68
|
+
}
|
|
69
|
+
const moduleName = resolveImportPath(sourcePath, importPath);
|
|
70
|
+
const isOnWhitelist = whitelist.some((test) => moduleName.endsWith(test));
|
|
71
|
+
if (!isOnWhitelist)
|
|
72
|
+
continue;
|
|
73
|
+
const src = importModule(moduleName);
|
|
74
|
+
if (!src)
|
|
75
|
+
continue;
|
|
76
|
+
for (const specifier of node.specifiers) {
|
|
77
|
+
if (t.isImportSpecifier(specifier) && t.isIdentifier(specifier.imported)) {
|
|
78
|
+
if (typeof src[specifier.imported.name] !== "undefined") {
|
|
79
|
+
const val = src[specifier.local.name];
|
|
80
|
+
ret[specifier.local.name] = val;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
if (!bindingCache) {
|
|
87
|
+
throw new Error("bindingCache is a required param");
|
|
88
|
+
}
|
|
89
|
+
for (const k in bindings) {
|
|
90
|
+
const binding = bindings[k];
|
|
91
|
+
const sourceModule = (0, import_getSourceModule.getSourceModule)(k, binding);
|
|
92
|
+
if (sourceModule) {
|
|
93
|
+
if (!sourceModule.sourceModule) {
|
|
94
|
+
continue;
|
|
95
|
+
}
|
|
96
|
+
const moduleName = resolveImportPath(sourcePath, sourceModule.sourceModule);
|
|
97
|
+
const isOnWhitelist = whitelist.some((test) => moduleName.endsWith(test));
|
|
98
|
+
if (isOnWhitelist) {
|
|
99
|
+
const src = importModule(moduleName);
|
|
100
|
+
if (!src) {
|
|
101
|
+
console.log(`\u26A0\uFE0F missing file ${moduleName} via ${sourcePath} import ${sourceModule.sourceModule}?`);
|
|
102
|
+
return {};
|
|
103
|
+
}
|
|
104
|
+
if (sourceModule.destructured) {
|
|
105
|
+
if (sourceModule.imported) {
|
|
106
|
+
ret[k] = src[sourceModule.imported];
|
|
107
|
+
}
|
|
108
|
+
} else {
|
|
109
|
+
ret[k] = src;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
continue;
|
|
113
|
+
}
|
|
114
|
+
const { parent, parentPath } = binding.path;
|
|
115
|
+
if (!t.isVariableDeclaration(parent) || parent.kind !== "const") {
|
|
116
|
+
continue;
|
|
117
|
+
}
|
|
118
|
+
const dec = parent.declarations.find((d) => t.isIdentifier(d.id) && d.id.name === k);
|
|
119
|
+
if (!dec || !dec.init) {
|
|
120
|
+
continue;
|
|
121
|
+
}
|
|
122
|
+
if (typeof dec.id.start !== "number" || typeof dec.id.end !== "number") {
|
|
123
|
+
console.error("dec.id.start/end is not a number");
|
|
124
|
+
continue;
|
|
125
|
+
}
|
|
126
|
+
if (!t.isIdentifier(dec.id)) {
|
|
127
|
+
console.error("dec is not an identifier");
|
|
128
|
+
continue;
|
|
129
|
+
}
|
|
130
|
+
const cacheKey = `${dec.id.name}_${dec.id.start}-${dec.id.end}`;
|
|
131
|
+
if (bindingCache.hasOwnProperty(cacheKey)) {
|
|
132
|
+
ret[k] = bindingCache[cacheKey];
|
|
133
|
+
continue;
|
|
134
|
+
}
|
|
135
|
+
if (bindingCache.hasOwnProperty(cacheKey)) {
|
|
136
|
+
ret[k] = bindingCache[cacheKey];
|
|
137
|
+
continue;
|
|
138
|
+
}
|
|
139
|
+
try {
|
|
140
|
+
ret[k] = (0, import_evaluateAstNode.evaluateAstNode)(dec.init, void 0, shouldPrintDebug);
|
|
141
|
+
bindingCache[cacheKey] = ret[k];
|
|
142
|
+
continue;
|
|
143
|
+
} catch (e) {
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
return ret;
|
|
147
|
+
}
|
|
148
|
+
__name(getStaticBindingsForScope, "getStaticBindingsForScope");
|
|
149
|
+
//# 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 | 'verbose'\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": "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",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
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 __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod));
|
|
21
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
22
|
+
var hoistClassNames_exports = {};
|
|
23
|
+
__export(hoistClassNames_exports, {
|
|
24
|
+
hoistClassNames: () => hoistClassNames
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(hoistClassNames_exports);
|
|
27
|
+
var t = __toESM(require("@babel/types"));
|
|
28
|
+
function hoistClassNames(path, existing, expr) {
|
|
29
|
+
const hoist = hoistClassNames.bind(null, path, existing);
|
|
30
|
+
if (t.isStringLiteral(expr)) {
|
|
31
|
+
if (expr.value.trim() === "") {
|
|
32
|
+
return expr;
|
|
33
|
+
}
|
|
34
|
+
if (existing[expr.value]) {
|
|
35
|
+
return existing[expr.value];
|
|
36
|
+
}
|
|
37
|
+
const identifier = replaceStringWithVariable(expr);
|
|
38
|
+
existing[expr.value] = identifier;
|
|
39
|
+
return identifier;
|
|
40
|
+
}
|
|
41
|
+
if (t.isBinaryExpression(expr)) {
|
|
42
|
+
return t.binaryExpression(expr.operator, hoist(expr.left), hoist(expr.right));
|
|
43
|
+
}
|
|
44
|
+
if (t.isLogicalExpression(expr)) {
|
|
45
|
+
return t.logicalExpression(expr.operator, hoist(expr.left), hoist(expr.right));
|
|
46
|
+
}
|
|
47
|
+
if (t.isConditionalExpression(expr)) {
|
|
48
|
+
return t.conditionalExpression(expr.test, hoist(expr.consequent), hoist(expr.alternate));
|
|
49
|
+
}
|
|
50
|
+
return expr;
|
|
51
|
+
function replaceStringWithVariable(str) {
|
|
52
|
+
const uid = path.scope.generateUidIdentifier("cn");
|
|
53
|
+
const parent = path.findParent((path2) => path2.isProgram());
|
|
54
|
+
if (!parent)
|
|
55
|
+
throw new Error(`no program?`);
|
|
56
|
+
const variable = t.variableDeclaration("const", [
|
|
57
|
+
t.variableDeclarator(uid, t.stringLiteral(` ${str.value}`))
|
|
58
|
+
]);
|
|
59
|
+
parent.unshiftContainer("body", variable);
|
|
60
|
+
return uid;
|
|
61
|
+
}
|
|
62
|
+
__name(replaceStringWithVariable, "replaceStringWithVariable");
|
|
63
|
+
}
|
|
64
|
+
__name(hoistClassNames, "hoistClassNames");
|
|
65
|
+
//# 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;AAAA;AACA,QAAmB;AAEZ,yBACL,MACA,UACA,MACA;AACA,QAAM,QAAQ,gBAAgB,KAAK,MAAM,MAAM,QAAQ;AACvD,MAAI,EAAE,gBAAgB,IAAI,GAAG;AAC3B,QAAI,KAAK,MAAM,KAAK,MAAM,IAAI;AAC5B,aAAO;AAAA,IACT;AACA,QAAI,SAAS,KAAK,QAAQ;AACxB,aAAO,SAAS,KAAK;AAAA,IACvB;AACA,UAAM,aAAa,0BAA0B,IAAI;AACjD,aAAS,KAAK,SAAS;AACvB,WAAO;AAAA,EACT;AACA,MAAI,EAAE,mBAAmB,IAAI,GAAG;AAC9B,WAAO,EAAE,iBAAiB,KAAK,UAAU,MAAM,KAAK,IAAI,GAAG,MAAM,KAAK,KAAK,CAAC;AAAA,EAC9E;AACA,MAAI,EAAE,oBAAoB,IAAI,GAAG;AAC/B,WAAO,EAAE,kBAAkB,KAAK,UAAU,MAAM,KAAK,IAAI,GAAG,MAAM,KAAK,KAAK,CAAC;AAAA,EAC/E;AACA,MAAI,EAAE,wBAAwB,IAAI,GAAG;AACnC,WAAO,EAAE,sBAAsB,KAAK,MAAM,MAAM,KAAK,UAAU,GAAG,MAAM,KAAK,SAAS,CAAC;AAAA,EACzF;AACA,SAAO;AAEP,qCAAmC,KAAoC;AAErE,UAAM,MAAM,KAAK,MAAM,sBAAsB,IAAI;AACjD,UAAM,SAAS,KAAK,WAAW,CAAC,UAAS,MAAK,UAAU,CAAC;AACzD,QAAI,CAAC;AAAQ,YAAM,IAAI,MAAM,aAAa;AAC1C,UAAM,WAAW,EAAE,oBAAoB,SAAS;AAAA,MAE9C,EAAE,mBAAmB,KAAK,EAAE,cAAc,IAAI,IAAI,OAAO,CAAC;AAAA,IAC5D,CAAC;AAED,WAAO,iBAAiB,QAAQ,QAAQ;AACxC,WAAO;AAAA,EACT;AAZS;AAaX;AAzCgB;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __defProps = Object.defineProperties;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
8
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
9
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
10
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
11
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
12
|
+
var __spreadValues = (a, b) => {
|
|
13
|
+
for (var prop in b || (b = {}))
|
|
14
|
+
if (__hasOwnProp.call(b, prop))
|
|
15
|
+
__defNormalProp(a, prop, b[prop]);
|
|
16
|
+
if (__getOwnPropSymbols)
|
|
17
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
18
|
+
if (__propIsEnum.call(b, prop))
|
|
19
|
+
__defNormalProp(a, prop, b[prop]);
|
|
20
|
+
}
|
|
21
|
+
return a;
|
|
22
|
+
};
|
|
23
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
24
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
25
|
+
var __export = (target, all) => {
|
|
26
|
+
for (var name in all)
|
|
27
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
28
|
+
};
|
|
29
|
+
var __copyProps = (to, from, except, desc) => {
|
|
30
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
31
|
+
for (let key of __getOwnPropNames(from))
|
|
32
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
33
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
34
|
+
}
|
|
35
|
+
return to;
|
|
36
|
+
};
|
|
37
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod));
|
|
38
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
39
|
+
var literalToAst_exports = {};
|
|
40
|
+
__export(literalToAst_exports, {
|
|
41
|
+
astToLiteral: () => astToLiteral,
|
|
42
|
+
literalToAst: () => literalToAst
|
|
43
|
+
});
|
|
44
|
+
module.exports = __toCommonJS(literalToAst_exports);
|
|
45
|
+
var t = __toESM(require("@babel/types"));
|
|
46
|
+
function literalToAst(literal) {
|
|
47
|
+
if (literal === null) {
|
|
48
|
+
return t.nullLiteral();
|
|
49
|
+
}
|
|
50
|
+
switch (typeof literal) {
|
|
51
|
+
case "function":
|
|
52
|
+
throw new Error("Unsupported");
|
|
53
|
+
case "number":
|
|
54
|
+
return t.numericLiteral(literal);
|
|
55
|
+
case "string":
|
|
56
|
+
return t.stringLiteral(literal);
|
|
57
|
+
case "boolean":
|
|
58
|
+
return t.booleanLiteral(literal);
|
|
59
|
+
case "undefined":
|
|
60
|
+
return t.unaryExpression("void", t.numericLiteral(0), true);
|
|
61
|
+
default:
|
|
62
|
+
if (Array.isArray(literal)) {
|
|
63
|
+
return t.arrayExpression(literal.map(literalToAst));
|
|
64
|
+
}
|
|
65
|
+
return t.objectExpression(Object.keys(literal).filter((k) => {
|
|
66
|
+
return typeof literal[k] !== "undefined";
|
|
67
|
+
}).map((k) => {
|
|
68
|
+
return t.objectProperty(t.stringLiteral(k), literalToAst(literal[k]));
|
|
69
|
+
}));
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
__name(literalToAst, "literalToAst");
|
|
73
|
+
const easyPeasies = ["BooleanLiteral", "StringLiteral", "NumericLiteral"];
|
|
74
|
+
function astToLiteral(node) {
|
|
75
|
+
if (!node) {
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
if (easyPeasies.includes(node.type)) {
|
|
79
|
+
return node.value;
|
|
80
|
+
}
|
|
81
|
+
if (node.name === "undefined" && !node.value) {
|
|
82
|
+
return void 0;
|
|
83
|
+
}
|
|
84
|
+
if (t.isNullLiteral(node)) {
|
|
85
|
+
return null;
|
|
86
|
+
}
|
|
87
|
+
if (t.isObjectExpression(node)) {
|
|
88
|
+
return computeProps(node.properties);
|
|
89
|
+
}
|
|
90
|
+
if (t.isArrayExpression(node)) {
|
|
91
|
+
return node.elements.reduce((acc, element) => [
|
|
92
|
+
...acc,
|
|
93
|
+
...(element == null ? void 0 : element.type) === "SpreadElement" ? astToLiteral(element.argument) : [astToLiteral(element)]
|
|
94
|
+
], []);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
__name(astToLiteral, "astToLiteral");
|
|
98
|
+
function computeProps(props) {
|
|
99
|
+
return props.reduce((acc, prop) => {
|
|
100
|
+
if (prop.type === "SpreadElement") {
|
|
101
|
+
return __spreadValues(__spreadValues({}, acc), astToLiteral(prop.argument));
|
|
102
|
+
} else if (prop.type !== "ObjectMethod") {
|
|
103
|
+
const val = astToLiteral(prop.value);
|
|
104
|
+
if (val !== void 0) {
|
|
105
|
+
return __spreadProps(__spreadValues({}, acc), {
|
|
106
|
+
[prop.key.name]: val
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
return acc;
|
|
111
|
+
}, {});
|
|
112
|
+
}
|
|
113
|
+
__name(computeProps, "computeProps");
|
|
114
|
+
//# sourceMappingURL=literalToAst.js.map
|