@tamagui/static 1.2.9 → 1.2.10

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.
Files changed (67) hide show
  1. package/dist/esm/constants.mjs +15 -0
  2. package/dist/esm/constants.mjs.map +7 -0
  3. package/dist/esm/extractor/accessSafe.mjs +19 -0
  4. package/dist/esm/extractor/accessSafe.mjs.map +7 -0
  5. package/dist/esm/extractor/babelParse.mjs +32 -0
  6. package/dist/esm/extractor/babelParse.mjs.map +7 -0
  7. package/dist/esm/extractor/buildClassName.mjs +65 -0
  8. package/dist/esm/extractor/buildClassName.mjs.map +7 -0
  9. package/dist/esm/extractor/bundle.mjs +86 -0
  10. package/dist/esm/extractor/bundle.mjs.map +7 -0
  11. package/dist/esm/extractor/createEvaluator.mjs +52 -0
  12. package/dist/esm/extractor/createEvaluator.mjs.map +7 -0
  13. package/dist/esm/extractor/createExtractor.mjs +1610 -0
  14. package/dist/esm/extractor/createExtractor.mjs.map +7 -0
  15. package/dist/esm/extractor/ensureImportingConcat.mjs +31 -0
  16. package/dist/esm/extractor/ensureImportingConcat.mjs.map +7 -0
  17. package/dist/esm/extractor/evaluateAstNode.mjs +97 -0
  18. package/dist/esm/extractor/evaluateAstNode.mjs.map +7 -0
  19. package/dist/esm/extractor/extractHelpers.mjs +162 -0
  20. package/dist/esm/extractor/extractHelpers.mjs.map +7 -0
  21. package/dist/esm/extractor/extractMediaStyle.mjs +159 -0
  22. package/dist/esm/extractor/extractMediaStyle.mjs.map +7 -0
  23. package/dist/esm/extractor/extractToClassNames.mjs +381 -0
  24. package/dist/esm/extractor/extractToClassNames.mjs.map +7 -0
  25. package/dist/esm/extractor/findTopmostFunction.mjs +20 -0
  26. package/dist/esm/extractor/findTopmostFunction.mjs.map +7 -0
  27. package/dist/esm/extractor/generatedUid.mjs +26 -0
  28. package/dist/esm/extractor/generatedUid.mjs.map +7 -0
  29. package/dist/esm/extractor/getPrefixLogs.mjs +8 -0
  30. package/dist/esm/extractor/getPrefixLogs.mjs.map +7 -0
  31. package/dist/esm/extractor/getPropValueFromAttributes.mjs +56 -0
  32. package/dist/esm/extractor/getPropValueFromAttributes.mjs.map +7 -0
  33. package/dist/esm/extractor/getSourceModule.mjs +70 -0
  34. package/dist/esm/extractor/getSourceModule.mjs.map +7 -0
  35. package/dist/esm/extractor/getStaticBindingsForScope.mjs +191 -0
  36. package/dist/esm/extractor/getStaticBindingsForScope.mjs.map +7 -0
  37. package/dist/esm/extractor/hoistClassNames.mjs +41 -0
  38. package/dist/esm/extractor/hoistClassNames.mjs.map +7 -0
  39. package/dist/esm/extractor/literalToAst.mjs +81 -0
  40. package/dist/esm/extractor/literalToAst.mjs.map +7 -0
  41. package/dist/esm/extractor/loadFile.mjs +20 -0
  42. package/dist/esm/extractor/loadFile.mjs.map +7 -0
  43. package/dist/esm/extractor/loadTamagui.mjs +411 -0
  44. package/dist/esm/extractor/loadTamagui.mjs.map +7 -0
  45. package/dist/esm/extractor/logLines.mjs +20 -0
  46. package/dist/esm/extractor/logLines.mjs.map +7 -0
  47. package/dist/esm/extractor/normalizeTernaries.mjs +52 -0
  48. package/dist/esm/extractor/normalizeTernaries.mjs.map +7 -0
  49. package/dist/esm/extractor/removeUnusedHooks.mjs +76 -0
  50. package/dist/esm/extractor/removeUnusedHooks.mjs.map +7 -0
  51. package/dist/esm/extractor/timer.mjs +29 -0
  52. package/dist/esm/extractor/timer.mjs.map +7 -0
  53. package/dist/esm/extractor/validHTMLAttributes.mjs +102 -0
  54. package/dist/esm/extractor/validHTMLAttributes.mjs.map +7 -0
  55. package/dist/esm/getPragmaOptions.mjs +44 -0
  56. package/dist/esm/getPragmaOptions.mjs.map +7 -0
  57. package/dist/esm/helpers/memoize.mjs +22 -0
  58. package/dist/esm/helpers/memoize.mjs.map +7 -0
  59. package/dist/esm/index.mjs +16 -0
  60. package/dist/esm/index.mjs.map +7 -0
  61. package/dist/esm/require.mjs +61 -0
  62. package/dist/esm/require.mjs.map +7 -0
  63. package/dist/esm/types.mjs +1 -0
  64. package/dist/esm/types.mjs.map +7 -0
  65. package/dist/esm/webpackPlugin.mjs +11 -0
  66. package/dist/esm/webpackPlugin.mjs.map +7 -0
  67. package/package.json +14 -14
@@ -0,0 +1,26 @@
1
+ import * as t from "@babel/types";
2
+ function generateUid(scope, name) {
3
+ if (!(typeof scope === "object"))
4
+ throw "generateUid expects a scope object as its first parameter";
5
+ if (!(typeof name === "string" && name !== ""))
6
+ throw "generateUid expects a valid name as its second parameter";
7
+ name = t.toIdentifier(name).replace(/^_+/, "").replace(/[0-9]+$/g, "");
8
+ let uid;
9
+ let i = 0;
10
+ do {
11
+ if (i > 1) {
12
+ uid = name + i;
13
+ } else {
14
+ uid = name;
15
+ }
16
+ i++;
17
+ } while (scope.hasLabel(uid) || scope.hasBinding(uid) || scope.hasGlobal(uid) || scope.hasReference(uid));
18
+ const program = scope.getProgramParent();
19
+ program.references[uid] = true;
20
+ program.uids[uid] = true;
21
+ return uid;
22
+ }
23
+ export {
24
+ generateUid
25
+ };
26
+ //# sourceMappingURL=generatedUid.mjs.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 if (!(typeof scope === 'object'))\n throw 'generateUid expects a scope object as its first parameter'\n if (!(typeof name === 'string' && name !== ''))\n throw 'generateUid expects a valid name as its second parameter'\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,YAAY,OAAO;AASZ,SAAS,YAAY,OAAY,MAAsB;AAC5D,MAAI,EAAE,OAAO,UAAU;AACrB,UAAM;AACR,MAAI,EAAE,OAAO,SAAS,YAAY,SAAS;AACzC,UAAM;AAER,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,GAAG,IAAI;AAC1B,UAAQ,KAAK,GAAG,IAAI;AAEpB,SAAO;AACT;",
6
+ "names": []
7
+ }
@@ -0,0 +1,8 @@
1
+ function getPrefixLogs(options) {
2
+ const { TAMAGUI_TARGET } = process.env;
3
+ return (options == null ? void 0 : options.prefixLogs) ?? ` ${TAMAGUI_TARGET} | `;
4
+ }
5
+ export {
6
+ getPrefixLogs
7
+ };
8
+ //# sourceMappingURL=getPrefixLogs.mjs.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/extractor/getPrefixLogs.ts"],
4
+ "sourcesContent": ["import { TamaguiOptions } from '../types.js'\n\nexport function getPrefixLogs(options?: TamaguiOptions) {\n const { TAMAGUI_TARGET } = process.env\n return options?.prefixLogs ?? ` ${TAMAGUI_TARGET} | `\n}\n"],
5
+ "mappings": "AAEO,SAAS,cAAc,SAA0B;AACtD,QAAM,EAAE,eAAe,IAAI,QAAQ;AACnC,UAAO,mCAAS,eAAc,IAAI;AACpC;",
6
+ "names": []
7
+ }
@@ -0,0 +1,56 @@
1
+ import generate from "@babel/generator";
2
+ import * as t from "@babel/types";
3
+ import { accessSafe } from "./accessSafe.js";
4
+ function getPropValueFromAttributes(propName, attrs) {
5
+ let propIndex = -1;
6
+ let jsxAttr = null;
7
+ for (let idx = -1, len = attrs.length; ++idx < len; ) {
8
+ const attr = attrs[idx];
9
+ if (t.isJSXAttribute(attr) && attr.name && attr.name.name === propName) {
10
+ propIndex = idx;
11
+ jsxAttr = attr;
12
+ break;
13
+ }
14
+ }
15
+ if (!jsxAttr || jsxAttr.value == null) {
16
+ return null;
17
+ }
18
+ let propValue = jsxAttr.value;
19
+ if (t.isJSXExpressionContainer(propValue)) {
20
+ propValue = propValue.expression;
21
+ }
22
+ if (t.isJSXEmptyExpression(propValue)) {
23
+ console.error("encountered JSXEmptyExpression");
24
+ return null;
25
+ }
26
+ const applicableSpreads = attrs.filter(
27
+ // 1. idx is greater than propValue prop index
28
+ // 2. attr is a spread operator
29
+ (attr, idx) => {
30
+ if (t.isJSXSpreadAttribute(attr)) {
31
+ if (t.isIdentifier(attr.argument) || t.isMemberExpression(attr.argument)) {
32
+ return idx > propIndex;
33
+ }
34
+ if (t.isLogicalExpression(attr.argument)) {
35
+ return false;
36
+ }
37
+ throw new Error(
38
+ `unsupported spread of type "${attr.argument.type}": ${// @ts-ignore
39
+ generate(attr).code}`
40
+ );
41
+ }
42
+ return false;
43
+ }
44
+ ).map((attr) => attr.argument);
45
+ if (applicableSpreads.length > 0) {
46
+ propValue = applicableSpreads.reduce(
47
+ (acc, val) => t.logicalExpression("||", accessSafe(val, propName), acc),
48
+ propValue
49
+ );
50
+ }
51
+ return propValue;
52
+ }
53
+ export {
54
+ getPropValueFromAttributes
55
+ };
56
+ //# sourceMappingURL=getPropValueFromAttributes.mjs.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.js'\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 = -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 // eslint-disable-next-line no-console\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}\": ${\n // @ts-ignore\n generate(attr as any).code\n }`\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,OAAO,cAAc;AACrB,YAAY,OAAO;AAEnB,SAAS,kBAAkB;AAkBpB,SAAS,2BACd,UACA,OACqB;AACrB,MAAI,YAAY;AAChB,MAAI,UAAiC;AACrC,WAAS,MAAM,IAAI,MAAM,MAAM,QAAQ,EAAE,MAAM,OAAO;AACpD,UAAM,OAAO,MAAM,GAAG;AACtB,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;AAErC,YAAQ,MAAM,gCAAgC;AAC9C,WAAO;AAAA,EACT;AAGA,QAAM,oBAAoB,MACvB;AAAA;AAAA;AAAA,IAGC,CAAC,MAAM,QAAsC;AAC3C,UAAI,EAAE,qBAAqB,IAAI,GAAG;AAChC,YAAI,EAAE,aAAa,KAAK,QAAQ,KAAK,EAAE,mBAAmB,KAAK,QAAQ,GAAG;AACxE,iBAAO,MAAM;AAAA,QACf;AACA,YAAI,EAAE,oBAAoB,KAAK,QAAQ,GAAG;AACxC,iBAAO;AAAA,QACT;AACA,cAAM,IAAI;AAAA,UACR,+BAA+B,KAAK,SAAS;AAAA,UAE3C,SAAS,IAAW,EAAE;AAAA,QAE1B;AAAA,MACF;AACA,aAAO;AAAA,IACT;AAAA,EACF,EACC,IAAI,CAAC,SAAS,KAAK,QAAQ;AAK9B,MAAI,kBAAkB,SAAS,GAAG;AAChC,gBAAY,kBAAkB;AAAA,MAC5B,CAAC,KAAK,QAAQ,EAAE,kBAAkB,MAAM,WAAW,KAAK,QAAQ,GAAG,GAAG;AAAA,MACtE;AAAA,IACF;AAAA,EACF;AAEA,SAAO;AACT;",
6
+ "names": []
7
+ }
@@ -0,0 +1,70 @@
1
+ import * as t from "@babel/types";
2
+ function getSourceModule(itemName, itemBinding) {
3
+ if (!itemBinding.constant) {
4
+ return null;
5
+ }
6
+ let sourceModule;
7
+ let imported;
8
+ let local;
9
+ let destructured;
10
+ let usesImportSyntax = false;
11
+ const itemNode = itemBinding.path.node;
12
+ if (
13
+ // import x from 'y';
14
+ t.isImportDefaultSpecifier(itemNode) || // import {x} from 'y';
15
+ t.isImportSpecifier(itemNode)
16
+ ) {
17
+ if (t.isImportDeclaration(itemBinding.path.parent)) {
18
+ sourceModule = itemBinding.path.parent.source.value;
19
+ local = itemNode.local.name;
20
+ usesImportSyntax = true;
21
+ if (t.isImportSpecifier(itemNode)) {
22
+ imported = itemNode.imported["name"];
23
+ destructured = true;
24
+ } else {
25
+ imported = itemNode.local.name;
26
+ destructured = false;
27
+ }
28
+ }
29
+ } 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) {
30
+ const firstArg = itemNode.init.arguments[0];
31
+ if (!t.isStringLiteral(firstArg)) {
32
+ return null;
33
+ }
34
+ sourceModule = firstArg.value;
35
+ if (t.isIdentifier(itemNode.id)) {
36
+ local = itemNode.id.name;
37
+ imported = itemNode.id.name;
38
+ destructured = false;
39
+ } else if (t.isObjectPattern(itemNode.id)) {
40
+ for (const objProp of itemNode.id.properties) {
41
+ if (t.isObjectProperty(objProp) && t.isIdentifier(objProp.value) && objProp.value.name === itemName) {
42
+ local = objProp.value.name;
43
+ imported = objProp.key.name;
44
+ destructured = true;
45
+ break;
46
+ }
47
+ }
48
+ if (!local || !imported) {
49
+ console.error("could not find prop with value `%s`", itemName);
50
+ return null;
51
+ }
52
+ } else {
53
+ console.error("Unhandled id type: %s", itemNode.id.type);
54
+ return null;
55
+ }
56
+ } else {
57
+ return null;
58
+ }
59
+ return {
60
+ destructured,
61
+ imported,
62
+ local,
63
+ sourceModule,
64
+ usesImportSyntax
65
+ };
66
+ }
67
+ export {
68
+ getSourceModule
69
+ };
70
+ //# sourceMappingURL=getSourceModule.mjs.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 // eslint-disable-next-line no-console\n console.error('could not find prop with value `%s`', itemName)\n return null\n }\n } else {\n // eslint-disable-next-line no-console\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,YAAY,OAAO;AAUZ,SAAS,gBACd,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;AAAA;AAAA,IAEE,EAAE,yBAAyB,QAAQ;AAAA,IAEnC,EAAE,kBAAkB,QAAQ;AAAA,IAC5B;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,MAAM;AACnC,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,CAAC;AAC1C,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;AAEvB,gBAAQ,MAAM,uCAAuC,QAAQ;AAC7D,eAAO;AAAA,MACT;AAAA,IACF,OAAO;AAEL,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;",
6
+ "names": []
7
+ }
@@ -0,0 +1,191 @@
1
+ import { fork } from "child_process";
2
+ import { dirname, extname, join, resolve } from "path";
3
+ import * as t from "@babel/types";
4
+ import { evaluateAstNode } from "./evaluateAstNode.js";
5
+ import { getSourceModule } from "./getSourceModule.js";
6
+ const isLocalImport = (path) => path.startsWith(".") || path.startsWith("/");
7
+ function resolveImportPath(sourcePath, path) {
8
+ const sourceDir = dirname(sourcePath);
9
+ if (isLocalImport(path)) {
10
+ if (extname(path) === "") {
11
+ path += ".js";
12
+ }
13
+ return resolve(sourceDir, path);
14
+ }
15
+ return path;
16
+ }
17
+ const cache = /* @__PURE__ */ new Map();
18
+ const pending = /* @__PURE__ */ new Map();
19
+ const loadCmd = `${join(__dirname, "loadFile.js")}`;
20
+ let exited = false;
21
+ let child = null;
22
+ function forkChild() {
23
+ child = fork(loadCmd, [], {
24
+ execArgv: ["-r", "esbuild-register"],
25
+ detached: false,
26
+ stdio: "ignore"
27
+ });
28
+ }
29
+ function cleanupBeforeExit() {
30
+ if (exited)
31
+ return;
32
+ if (!child)
33
+ return;
34
+ child.removeAllListeners();
35
+ child.unref();
36
+ child.disconnect();
37
+ child.kill();
38
+ exited = true;
39
+ }
40
+ process.once("SIGTERM", cleanupBeforeExit);
41
+ process.once("SIGINT", cleanupBeforeExit);
42
+ process.once("beforeExit", cleanupBeforeExit);
43
+ function importModule(path) {
44
+ if (!child) {
45
+ forkChild();
46
+ }
47
+ if (pending.has(path)) {
48
+ return pending.get(path);
49
+ }
50
+ const promise = new Promise((res, rej) => {
51
+ if (!child)
52
+ return;
53
+ if (cache.size > 2e3) {
54
+ cache.clear();
55
+ }
56
+ if (cache.has(path)) {
57
+ return cache.get(path);
58
+ }
59
+ const listener = (msg) => {
60
+ if (!child)
61
+ return;
62
+ if (!msg)
63
+ return;
64
+ if (typeof msg !== "string")
65
+ return;
66
+ if (msg[0] === "-") {
67
+ rej(new Error(msg.slice(1)));
68
+ return;
69
+ }
70
+ child.removeListener("message", listener);
71
+ const val = JSON.parse(msg);
72
+ cache.set(path, val);
73
+ res(val);
74
+ };
75
+ child.once("message", listener);
76
+ child.send(`${path.replace(".js", "")}`);
77
+ });
78
+ pending.set(path, promise);
79
+ return promise;
80
+ }
81
+ async function getStaticBindingsForScope(scope, whitelist = [], sourcePath, bindingCache, shouldPrintDebug) {
82
+ var _a;
83
+ const bindings = scope.getAllBindings();
84
+ const ret = {};
85
+ if (shouldPrintDebug) {
86
+ }
87
+ const program = scope.getProgramParent().block;
88
+ for (const node of program.body) {
89
+ if (t.isImportDeclaration(node)) {
90
+ const importPath = node.source.value;
91
+ if (!node.specifiers.length)
92
+ continue;
93
+ if (!isLocalImport(importPath)) {
94
+ continue;
95
+ }
96
+ const moduleName = resolveImportPath(sourcePath, importPath);
97
+ const isOnWhitelist = whitelist.some((test) => moduleName.endsWith(test));
98
+ if (!isOnWhitelist)
99
+ continue;
100
+ try {
101
+ const src = await importModule(moduleName);
102
+ if (!src)
103
+ continue;
104
+ for (const specifier of node.specifiers) {
105
+ if (t.isImportSpecifier(specifier) && t.isIdentifier(specifier.imported)) {
106
+ if (typeof src[specifier.imported.name] !== "undefined") {
107
+ const val = src[specifier.local.name];
108
+ ret[specifier.local.name] = val;
109
+ }
110
+ }
111
+ }
112
+ } catch (err) {
113
+ if (shouldPrintDebug) {
114
+ console.warn(
115
+ ` | Skipping partial evaluation of constant file: ${moduleName} (DEBUG=tamagui for more)`
116
+ );
117
+ } else if ((_a = process.env.DEBUG) == null ? void 0 : _a.startsWith("tamagui")) {
118
+ console.log(`Error in partial evaluation`, err.message, err.stack);
119
+ }
120
+ }
121
+ }
122
+ }
123
+ if (!bindingCache) {
124
+ throw new Error("BindingCache is a required param");
125
+ }
126
+ for (const k in bindings) {
127
+ const binding = bindings[k];
128
+ const sourceModule = getSourceModule(k, binding);
129
+ if (sourceModule) {
130
+ if (!sourceModule.sourceModule) {
131
+ continue;
132
+ }
133
+ const moduleName = resolveImportPath(sourcePath, sourceModule.sourceModule);
134
+ const isOnWhitelist = whitelist.some((test) => moduleName.endsWith(test));
135
+ if (isOnWhitelist) {
136
+ const src = importModule(moduleName);
137
+ if (!src) {
138
+ console.log(
139
+ ` | \u26A0\uFE0F Missing file ${moduleName} via ${sourcePath} import ${sourceModule.sourceModule}?`
140
+ );
141
+ return {};
142
+ }
143
+ if (sourceModule.destructured) {
144
+ if (sourceModule.imported) {
145
+ ret[k] = src[sourceModule.imported];
146
+ }
147
+ } else {
148
+ ret[k] = src;
149
+ }
150
+ }
151
+ continue;
152
+ }
153
+ const { parent } = binding.path;
154
+ if (!t.isVariableDeclaration(parent) || parent.kind !== "const") {
155
+ continue;
156
+ }
157
+ const dec = parent.declarations.find((d) => t.isIdentifier(d.id) && d.id.name === k);
158
+ if (!dec || !dec.init) {
159
+ continue;
160
+ }
161
+ if (typeof dec.id.start !== "number" || typeof dec.id.end !== "number") {
162
+ console.error("dec.id.start/end is not a number");
163
+ continue;
164
+ }
165
+ if (!t.isIdentifier(dec.id)) {
166
+ console.error("dec is not an identifier");
167
+ continue;
168
+ }
169
+ const cacheKey = `${dec.id.name}_${dec.id.start}-${dec.id.end}`;
170
+ if (Object.hasOwnProperty.call(bindingCache, cacheKey)) {
171
+ ret[k] = bindingCache[cacheKey];
172
+ continue;
173
+ }
174
+ if (Object.hasOwnProperty.call(bindingCache, cacheKey)) {
175
+ ret[k] = bindingCache[cacheKey];
176
+ continue;
177
+ }
178
+ try {
179
+ ret[k] = evaluateAstNode(dec.init, void 0, shouldPrintDebug);
180
+ bindingCache[cacheKey] = ret[k];
181
+ continue;
182
+ } catch {
183
+ }
184
+ }
185
+ return ret;
186
+ }
187
+ export {
188
+ cleanupBeforeExit,
189
+ getStaticBindingsForScope
190
+ };
191
+ //# sourceMappingURL=getStaticBindingsForScope.mjs.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/extractor/getStaticBindingsForScope.ts"],
4
+ "sourcesContent": ["import { ChildProcess, fork } from 'child_process'\nimport { dirname, extname, join, resolve } from 'path'\n\nimport { Binding, NodePath } from '@babel/traverse'\nimport * as t from '@babel/types'\n\nimport { evaluateAstNode } from './evaluateAstNode.js'\nimport { getSourceModule } from './getSourceModule.js'\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\nconst cache = new Map()\nconst pending = new Map<string, Promise<any>>()\n\nconst loadCmd = `${join(__dirname, 'loadFile.js')}`\n\nlet exited = false\n\nlet child: ChildProcess | null = null\n\nfunction forkChild() {\n child = fork(loadCmd, [], {\n execArgv: ['-r', 'esbuild-register'],\n detached: false,\n stdio: 'ignore',\n })\n}\n\nexport function cleanupBeforeExit() {\n if (exited) return\n if (!child) return\n child.removeAllListeners()\n child.unref()\n child.disconnect()\n child.kill()\n exited = true\n}\n\nprocess.once('SIGTERM', cleanupBeforeExit)\nprocess.once('SIGINT', cleanupBeforeExit)\nprocess.once('beforeExit', cleanupBeforeExit)\n\nfunction importModule(path: string) {\n if (!child) {\n forkChild()\n }\n if (pending.has(path)) {\n return pending.get(path)\n }\n const promise = new Promise((res, rej) => {\n if (!child) return\n if (cache.size > 2000) {\n cache.clear()\n }\n if (cache.has(path)) {\n return cache.get(path)\n }\n const listener = (msg: any) => {\n if (!child) return\n if (!msg) return\n if (typeof msg !== 'string') return\n if (msg[0] === '-') {\n rej(new Error(msg.slice(1)))\n return\n }\n child.removeListener('message', listener)\n const val = JSON.parse(msg)\n cache.set(path, val)\n res(val)\n }\n child.once('message', listener)\n child.send(`${path.replace('.js', '')}`)\n })\n pending.set(path, promise)\n return promise\n}\n\nexport async 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): Promise<Record<string, any>> {\n const bindings: Record<string, Binding> = scope.getAllBindings() as any\n const ret: Record<string, any> = {}\n\n if (\n shouldPrintDebug\n ) {\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 try {\n const src = await 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 } catch (err: any) {\n if (shouldPrintDebug) {\n // eslint-disable-next-line no-console\n console.warn(\n ` | Skipping partial evaluation of constant file: ${moduleName} (DEBUG=tamagui for more)`\n )\n } else if (process.env.DEBUG?.startsWith('tamagui')) {\n // eslint-disable-next-line no-console\n console.log(`Error in partial evaluation`, err.message, err.stack)\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 // eslint-disable-next-line no-console\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 ret[k] = src\n }\n }\n continue\n }\n\n const { parent } = 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 // eslint-disable-next-line no-console\n console.error('dec.id.start/end is not a number')\n continue\n }\n\n if (!t.isIdentifier(dec.id)) {\n // eslint-disable-next-line no-console\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 (Object.hasOwnProperty.call(bindingCache, cacheKey)) {\n ret[k] = bindingCache[cacheKey]\n continue\n }\n // retrieve value from cache\n if (Object.hasOwnProperty.call(bindingCache, 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 {\n // skip\n }\n }\n\n return ret\n}\n"],
5
+ "mappings": "AAAA,SAAuB,YAAY;AACnC,SAAS,SAAS,SAAS,MAAM,eAAe;AAGhD,YAAY,OAAO;AAEnB,SAAS,uBAAuB;AAChC,SAAS,uBAAuB;AAEhC,MAAM,gBAAgB,CAAC,SAAiB,KAAK,WAAW,GAAG,KAAK,KAAK,WAAW,GAAG;AAEnF,SAAS,kBAAkB,YAAoB,MAAc;AAC3D,QAAM,YAAY,QAAQ,UAAU;AACpC,MAAI,cAAc,IAAI,GAAG;AACvB,QAAI,QAAQ,IAAI,MAAM,IAAI;AACxB,cAAQ;AAAA,IACV;AACA,WAAO,QAAQ,WAAW,IAAI;AAAA,EAChC;AACA,SAAO;AACT;AAEA,MAAM,QAAQ,oBAAI,IAAI;AACtB,MAAM,UAAU,oBAAI,IAA0B;AAE9C,MAAM,UAAU,GAAG,KAAK,WAAW,aAAa;AAEhD,IAAI,SAAS;AAEb,IAAI,QAA6B;AAEjC,SAAS,YAAY;AACnB,UAAQ,KAAK,SAAS,CAAC,GAAG;AAAA,IACxB,UAAU,CAAC,MAAM,kBAAkB;AA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;AACtD,UAAI,CAAC,IAAI,aAAa,QAAQ;AAC9B;AAAA,IACF;AAGA,QAAI;AACF,UAAI,CAAC,IAAI,gBAAgB,IAAI,MAAM,QAAW,gBAAgB;AAC9D,mBAAa,QAAQ,IAAI,IAAI,CAAC;AAC9B;AAAA,IACF,QAAE;AAAA,IAEF;AAAA,EACF;AAEA,SAAO;AACT;",
6
+ "names": []
7
+ }
@@ -0,0 +1,41 @@
1
+ import * as t from "@babel/types";
2
+ function hoistClassNames(path, existing, expr) {
3
+ const hoist = hoistClassNames.bind(null, path, existing);
4
+ if (t.isStringLiteral(expr)) {
5
+ if (expr.value.trim() === "") {
6
+ return expr;
7
+ }
8
+ if (existing[expr.value]) {
9
+ return existing[expr.value];
10
+ }
11
+ const identifier = replaceStringWithVariable(expr);
12
+ existing[expr.value] = identifier;
13
+ return identifier;
14
+ }
15
+ if (t.isBinaryExpression(expr)) {
16
+ return t.binaryExpression(expr.operator, hoist(expr.left), hoist(expr.right));
17
+ }
18
+ if (t.isLogicalExpression(expr)) {
19
+ return t.logicalExpression(expr.operator, hoist(expr.left), hoist(expr.right));
20
+ }
21
+ if (t.isConditionalExpression(expr)) {
22
+ return t.conditionalExpression(expr.test, hoist(expr.consequent), hoist(expr.alternate));
23
+ }
24
+ return expr;
25
+ function replaceStringWithVariable(str) {
26
+ const uid = path.scope.generateUidIdentifier("cn");
27
+ const parent = path.findParent((path2) => path2.isProgram());
28
+ if (!parent)
29
+ throw new Error(`no program?`);
30
+ const variable = t.variableDeclaration("const", [
31
+ // adding a space for extra safety
32
+ t.variableDeclarator(uid, t.stringLiteral(` ${str.value}`))
33
+ ]);
34
+ parent.unshiftContainer("body", variable);
35
+ return uid;
36
+ }
37
+ }
38
+ export {
39
+ hoistClassNames
40
+ };
41
+ //# sourceMappingURL=hoistClassNames.mjs.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": "AACA,YAAY,OAAO;AAEZ,SAAS,gBACd,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,KAAK,GAAG;AACxB,aAAO,SAAS,KAAK,KAAK;AAAA,IAC5B;AACA,UAAM,aAAa,0BAA0B,IAAI;AACjD,aAAS,KAAK,KAAK,IAAI;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,WAAS,0BAA0B,KAAoC;AAErE,UAAM,MAAM,KAAK,MAAM,sBAAsB,IAAI;AACjD,UAAM,SAAS,KAAK,WAAW,CAACA,UAASA,MAAK,UAAU,CAAC;AACzD,QAAI,CAAC;AAAQ,YAAM,IAAI,MAAM,aAAa;AAC1C,UAAM,WAAW,EAAE,oBAAoB,SAAS;AAAA;AAAA,MAE9C,EAAE,mBAAmB,KAAK,EAAE,cAAc,IAAI,IAAI,OAAO,CAAC;AAAA,IAC5D,CAAC;AAED,WAAO,iBAAiB,QAAQ,QAAQ;AACxC,WAAO;AAAA,EACT;AACF;",
6
+ "names": ["path"]
7
+ }
@@ -0,0 +1,81 @@
1
+ import * as t from "@babel/types";
2
+ function literalToAst(literal) {
3
+ if (literal === null) {
4
+ return t.nullLiteral();
5
+ }
6
+ switch (typeof literal) {
7
+ case "function":
8
+ throw new Error("Unsupported");
9
+ case "number":
10
+ return t.numericLiteral(literal);
11
+ case "string":
12
+ return t.stringLiteral(literal);
13
+ case "boolean":
14
+ return t.booleanLiteral(literal);
15
+ case "undefined":
16
+ return t.unaryExpression("void", t.numericLiteral(0), true);
17
+ default:
18
+ if (Array.isArray(literal)) {
19
+ return t.arrayExpression(literal.map(literalToAst));
20
+ }
21
+ return t.objectExpression(
22
+ Object.keys(literal).filter((k) => {
23
+ return typeof literal[k] !== "undefined";
24
+ }).map((k) => {
25
+ return t.objectProperty(t.stringLiteral(k), literalToAst(literal[k]));
26
+ })
27
+ );
28
+ }
29
+ }
30
+ const easyPeasies = ["BooleanLiteral", "StringLiteral", "NumericLiteral"];
31
+ function astToLiteral(node) {
32
+ if (!node) {
33
+ return;
34
+ }
35
+ if (easyPeasies.includes(node.type)) {
36
+ return node.value;
37
+ }
38
+ if (node.name === "undefined" && !node.value) {
39
+ return void 0;
40
+ }
41
+ if (t.isNullLiteral(node)) {
42
+ return null;
43
+ }
44
+ if (t.isObjectExpression(node)) {
45
+ return computeProps(node.properties);
46
+ }
47
+ if (t.isArrayExpression(node)) {
48
+ return node.elements.reduce(
49
+ // @ts-ignore
50
+ (acc, element) => [
51
+ ...acc,
52
+ ...(element == null ? void 0 : element.type) === "SpreadElement" ? astToLiteral(element.argument) : [astToLiteral(element)]
53
+ ],
54
+ []
55
+ );
56
+ }
57
+ }
58
+ function computeProps(props) {
59
+ return props.reduce((acc, prop) => {
60
+ if (prop.type === "SpreadElement") {
61
+ return {
62
+ ...acc,
63
+ ...astToLiteral(prop.argument)
64
+ };
65
+ } else if (prop.type !== "ObjectMethod") {
66
+ const val = astToLiteral(prop.value);
67
+ if (val !== void 0) {
68
+ return {
69
+ ...acc,
70
+ [prop.key.name]: val
71
+ };
72
+ }
73
+ }
74
+ return acc;
75
+ }, {});
76
+ }
77
+ export {
78
+ astToLiteral,
79
+ literalToAst
80
+ };
81
+ //# sourceMappingURL=literalToAst.mjs.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\nconst easyPeasies = ['BooleanLiteral', 'StringLiteral', 'NumericLiteral']\n\nexport function astToLiteral(node: any) {\n if (!node) {\n return\n }\n if (easyPeasies.includes(node.type)) {\n return node.value\n }\n if (node.name === 'undefined' && !node.value) {\n return undefined\n }\n if (t.isNullLiteral(node)) {\n return null\n }\n if (t.isObjectExpression(node)) {\n return computeProps(node.properties)\n }\n if (t.isArrayExpression(node)) {\n return node.elements.reduce(\n // @ts-ignore\n (acc, element) => [\n ...acc,\n ...(element?.type === 'SpreadElement'\n ? astToLiteral(element.argument)\n : [astToLiteral(element)]),\n ],\n []\n )\n }\n}\n\nfunction computeProps(props) {\n return props.reduce((acc, prop) => {\n if (prop.type === 'SpreadElement') {\n return {\n ...acc,\n ...astToLiteral(prop.argument),\n }\n } else if (prop.type !== 'ObjectMethod') {\n const val = astToLiteral(prop.value)\n if (val !== undefined) {\n return {\n ...acc,\n [prop.key.name]: val,\n }\n }\n }\n return acc\n }, {})\n}\n"],
5
+ "mappings": "AAAA,YAAY,OAAO;AAEZ,SAAS,aAAa,SAA4B;AACvD,MAAI,YAAY,MAAM;AACpB,WAAO,EAAE,YAAY;AAAA,EACvB;AACA,UAAQ,OAAO,SAAS;AAAA,IACtB,KAAK;AACH,YAAM,IAAI,MAAM,aAAa;AAAA,IAC/B,KAAK;AACH,aAAO,EAAE,eAAe,OAAO;AAAA,IACjC,KAAK;AACH,aAAO,EAAE,cAAc,OAAO;AAAA,IAChC,KAAK;AACH,aAAO,EAAE,eAAe,OAAO;AAAA,IACjC,KAAK;AACH,aAAO,EAAE,gBAAgB,QAAQ,EAAE,eAAe,CAAC,GAAG,IAAI;AAAA,IAC5D;AACE,UAAI,MAAM,QAAQ,OAAO,GAAG;AAC1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AAK,KAAK;AACnC,UAAI,QAAQ,QAAW;AACrB,eAAO;AAAA,UACL,GAAG;AAAA,UACH,CAAC,KAAK,IAAI,IAAI,GAAG;AAAA,QACnB;AAAA,MACF;AAAA,IACF;AACA,WAAO;AAAA,EACT,GAAG,CAAC,CAAC;AACP;",
6
+ "names": []
7
+ }
@@ -0,0 +1,20 @@
1
+ process.on("message", (path) => {
2
+ var _a, _b, _c;
3
+ if (typeof path !== "string") {
4
+ throw new Error(`Not a string: ${path}`);
5
+ }
6
+ try {
7
+ const out = require(path);
8
+ (_a = process.send) == null ? void 0 : _a.call(process, JSON.stringify(out));
9
+ } catch (err) {
10
+ if (err instanceof Error) {
11
+ (_b = process.send) == null ? void 0 : _b.call(process, `-${err.message}
12
+ ${err.stack}`);
13
+ } else {
14
+ (_c = process.send) == null ? void 0 : _c.call(process, `-${err}`);
15
+ }
16
+ }
17
+ });
18
+ setInterval(() => {
19
+ }, 1e3);
20
+ //# sourceMappingURL=loadFile.mjs.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/extractor/loadFile.ts"],
4
+ "sourcesContent": ["process.on('message', (path) => {\n if (typeof path !== 'string') {\n throw new Error(`Not a string: ${path}`)\n }\n try {\n const out = require(path)\n process.send?.(JSON.stringify(out))\n } catch (err) {\n if (err instanceof Error) {\n process.send?.(`-${err.message}\\n${err.stack}`)\n } else {\n process.send?.(`-${err}`)\n }\n }\n})\n\nsetInterval(() => {}, 1000)\n"],
5
+ "mappings": "AAAA,QAAQ,GAAG,WAAW,CAAC,SAAS;AAAhC;AACE,MAAI,OAAO,SAAS,UAAU;AAC5B,UAAM,IAAI,MAAM,iBAAiB,MAAM;AAAA,EACzC;AACA,MAAI;AACF,UAAM,MAAM,QAAQ,IAAI;AACxB,kBAAQ,SAAR,iCAAe,KAAK,UAAU,GAAG;AAAA,EACnC,SAAS,KAAP;AACA,QAAI,eAAe,OAAO;AACxB,oBAAQ,SAAR,iCAAe,IAAI,IAAI;AAAA,EAAY,IAAI;AAAA,IACzC,OAAO;AACL,oBAAQ,SAAR,iCAAe,IAAI;AAAA,IACrB;AAAA,EACF;AACF,CAAC;AAED,YAAY,MAAM;AAAC,GAAG,GAAI;",
6
+ "names": []
7
+ }