@tamagui/static 1.0.0-beta.9 → 1.0.1-beta.101
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/extractor/accessSafe.js +0 -2
- package/dist/cjs/extractor/accessSafe.js.map +1 -1
- package/dist/cjs/extractor/babelParse.js +15 -16
- package/dist/cjs/extractor/babelParse.js.map +2 -2
- package/dist/cjs/extractor/buildClassName.js +0 -2
- package/dist/cjs/extractor/buildClassName.js.map +1 -1
- package/dist/cjs/extractor/createEvaluator.js +9 -7
- package/dist/cjs/extractor/createEvaluator.js.map +2 -2
- package/dist/cjs/extractor/createExtractor.js +318 -145
- package/dist/cjs/extractor/createExtractor.js.map +2 -2
- package/dist/cjs/extractor/ensureImportingConcat.js +0 -2
- package/dist/cjs/extractor/ensureImportingConcat.js.map +1 -1
- package/dist/cjs/extractor/evaluateAstNode.js +0 -2
- package/dist/cjs/extractor/evaluateAstNode.js.map +1 -1
- package/dist/cjs/extractor/extractHelpers.js +11 -16
- package/dist/cjs/extractor/extractHelpers.js.map +1 -1
- package/dist/cjs/extractor/extractMediaStyle.js +3 -8
- package/dist/cjs/extractor/extractMediaStyle.js.map +2 -2
- package/dist/cjs/extractor/extractToClassNames.js +27 -42
- package/dist/cjs/extractor/extractToClassNames.js.map +2 -2
- package/dist/cjs/extractor/findTopmostFunction.js +1 -3
- package/dist/cjs/extractor/findTopmostFunction.js.map +1 -1
- package/dist/cjs/extractor/generatedUid.js +0 -2
- package/dist/cjs/extractor/generatedUid.js.map +1 -1
- package/dist/cjs/extractor/getPrefixLogs.js +0 -2
- package/dist/cjs/extractor/getPrefixLogs.js.map +1 -1
- package/dist/cjs/extractor/getPropValueFromAttributes.js +0 -2
- package/dist/cjs/extractor/getPropValueFromAttributes.js.map +1 -1
- package/dist/cjs/extractor/getSourceModule.js +0 -2
- package/dist/cjs/extractor/getSourceModule.js.map +1 -1
- package/dist/cjs/extractor/getStaticBindingsForScope.js +1 -5
- package/dist/cjs/extractor/getStaticBindingsForScope.js.map +1 -1
- package/dist/cjs/extractor/hoistClassNames.js +0 -3
- package/dist/cjs/extractor/hoistClassNames.js.map +1 -1
- package/dist/cjs/extractor/literalToAst.js +0 -4
- package/dist/cjs/extractor/literalToAst.js.map +1 -1
- package/dist/cjs/extractor/loadTamagui.js +43 -10
- package/dist/cjs/extractor/loadTamagui.js.map +2 -2
- package/dist/cjs/extractor/logLines.js +2 -3
- package/dist/cjs/extractor/logLines.js.map +1 -1
- package/dist/cjs/extractor/normalizeTernaries.js +0 -2
- package/dist/cjs/extractor/normalizeTernaries.js.map +1 -1
- package/dist/cjs/extractor/removeUnusedHooks.js +2 -4
- package/dist/cjs/extractor/removeUnusedHooks.js.map +1 -1
- package/dist/cjs/extractor/timer.js +2 -3
- package/dist/cjs/extractor/timer.js.map +1 -1
- package/dist/cjs/extractor/validHTMLAttributes.js +51 -0
- package/dist/cjs/extractor/validHTMLAttributes.js.map +2 -2
- package/dist/cjs/index.js +2 -1
- package/dist/cjs/index.js.map +2 -2
- package/dist/cjs/types.js.map +1 -1
- package/dist/esm/extractor/accessSafe.js +0 -3
- package/dist/esm/extractor/accessSafe.js.map +1 -1
- package/dist/esm/extractor/babelParse.js +15 -17
- package/dist/esm/extractor/babelParse.js.map +2 -2
- package/dist/esm/extractor/buildClassName.js +0 -3
- package/dist/esm/extractor/buildClassName.js.map +1 -1
- package/dist/esm/extractor/createEvaluator.js +9 -8
- package/dist/esm/extractor/createEvaluator.js.map +2 -2
- package/dist/esm/extractor/createExtractor.js +405 -195
- package/dist/esm/extractor/createExtractor.js.map +2 -2
- package/dist/esm/extractor/ensureImportingConcat.js +0 -3
- package/dist/esm/extractor/ensureImportingConcat.js.map +1 -1
- package/dist/esm/extractor/evaluateAstNode.js +0 -3
- package/dist/esm/extractor/evaluateAstNode.js.map +1 -1
- package/dist/esm/extractor/extractHelpers.js +11 -17
- package/dist/esm/extractor/extractHelpers.js.map +1 -1
- package/dist/esm/extractor/extractMediaStyle.js +29 -20
- package/dist/esm/extractor/extractMediaStyle.js.map +2 -2
- package/dist/esm/extractor/extractToClassNames.js +53 -52
- package/dist/esm/extractor/extractToClassNames.js.map +2 -2
- package/dist/esm/extractor/findTopmostFunction.js +1 -4
- package/dist/esm/extractor/findTopmostFunction.js.map +1 -1
- package/dist/esm/extractor/generatedUid.js +0 -3
- package/dist/esm/extractor/generatedUid.js.map +1 -1
- package/dist/esm/extractor/getPrefixLogs.js +1 -5
- package/dist/esm/extractor/getPrefixLogs.js.map +1 -1
- package/dist/esm/extractor/getPropValueFromAttributes.js +0 -3
- package/dist/esm/extractor/getPropValueFromAttributes.js.map +1 -1
- package/dist/esm/extractor/getSourceModule.js +0 -3
- package/dist/esm/extractor/getSourceModule.js.map +1 -1
- package/dist/esm/extractor/getStaticBindingsForScope.js +1 -6
- package/dist/esm/extractor/getStaticBindingsForScope.js.map +1 -1
- package/dist/esm/extractor/hoistClassNames.js +0 -4
- package/dist/esm/extractor/hoistClassNames.js.map +1 -1
- package/dist/esm/extractor/literalToAst.js +21 -11
- package/dist/esm/extractor/literalToAst.js.map +1 -1
- package/dist/esm/extractor/loadTamagui.js +44 -11
- package/dist/esm/extractor/loadTamagui.js.map +2 -2
- package/dist/esm/extractor/logLines.js +2 -4
- package/dist/esm/extractor/logLines.js.map +1 -1
- package/dist/esm/extractor/normalizeTernaries.js +35 -9
- package/dist/esm/extractor/normalizeTernaries.js.map +1 -1
- package/dist/esm/extractor/removeUnusedHooks.js +5 -9
- package/dist/esm/extractor/removeUnusedHooks.js.map +1 -1
- package/dist/esm/extractor/timer.js +2 -4
- package/dist/esm/extractor/timer.js.map +1 -1
- package/dist/esm/extractor/validHTMLAttributes.js +50 -0
- package/dist/esm/extractor/validHTMLAttributes.js.map +2 -2
- package/dist/esm/index.js +2 -1
- package/dist/esm/index.js.map +2 -2
- package/dist/jsx/constants.js +1 -0
- package/dist/jsx/constants.js.map +7 -0
- package/dist/jsx/extractor/accessSafe.js +1 -3
- package/dist/jsx/extractor/accessSafe.js.map +7 -0
- package/dist/jsx/extractor/babelParse.js +16 -17
- package/dist/jsx/extractor/babelParse.js.map +7 -0
- package/dist/jsx/extractor/buildClassName.js +1 -3
- package/dist/jsx/extractor/buildClassName.js.map +7 -0
- package/dist/jsx/extractor/createEvaluator.js +10 -8
- package/dist/jsx/extractor/createEvaluator.js.map +7 -0
- package/dist/jsx/extractor/createExtractor.js +325 -150
- package/dist/jsx/extractor/createExtractor.js.map +7 -0
- package/dist/jsx/extractor/ensureImportingConcat.js +1 -3
- package/dist/jsx/extractor/ensureImportingConcat.js.map +7 -0
- package/dist/jsx/extractor/evaluateAstNode.js +1 -3
- package/dist/jsx/extractor/evaluateAstNode.js.map +7 -0
- package/dist/jsx/extractor/extractHelpers.js +12 -17
- package/dist/jsx/extractor/extractHelpers.js.map +7 -0
- package/dist/jsx/extractor/extractMediaStyle.js +4 -9
- package/dist/jsx/extractor/extractMediaStyle.js.map +7 -0
- package/dist/jsx/extractor/extractToClassNames.js +31 -43
- package/dist/jsx/extractor/extractToClassNames.js.map +7 -0
- package/dist/jsx/extractor/findTopmostFunction.js +2 -4
- package/dist/jsx/extractor/findTopmostFunction.js.map +7 -0
- package/dist/jsx/extractor/generatedUid.js +1 -3
- package/dist/jsx/extractor/generatedUid.js.map +7 -0
- package/dist/jsx/extractor/getPrefixLogs.js +1 -3
- package/dist/jsx/extractor/getPrefixLogs.js.map +7 -0
- package/dist/jsx/extractor/getPropValueFromAttributes.js +1 -3
- package/dist/jsx/extractor/getPropValueFromAttributes.js.map +7 -0
- package/dist/jsx/extractor/getSourceModule.js +1 -3
- package/dist/jsx/extractor/getSourceModule.js.map +7 -0
- package/dist/jsx/extractor/getStaticBindingsForScope.js +2 -6
- package/dist/jsx/extractor/getStaticBindingsForScope.js.map +7 -0
- package/dist/jsx/extractor/hoistClassNames.js +1 -4
- package/dist/jsx/extractor/hoistClassNames.js.map +7 -0
- package/dist/jsx/extractor/literalToAst.js +1 -5
- package/dist/jsx/extractor/literalToAst.js.map +7 -0
- package/dist/jsx/extractor/loadTamagui.js +30 -11
- package/dist/jsx/extractor/loadTamagui.js.map +7 -0
- package/dist/jsx/extractor/logLines.js +3 -4
- package/dist/jsx/extractor/logLines.js.map +7 -0
- package/dist/jsx/extractor/normalizeTernaries.js +1 -3
- package/dist/jsx/extractor/normalizeTernaries.js.map +7 -0
- package/dist/jsx/extractor/removeUnusedHooks.js +3 -5
- package/dist/jsx/extractor/removeUnusedHooks.js.map +7 -0
- package/dist/jsx/extractor/timer.js +3 -4
- package/dist/jsx/extractor/timer.js.map +7 -0
- package/dist/jsx/extractor/validHTMLAttributes.js +51 -0
- package/dist/jsx/extractor/validHTMLAttributes.js.map +7 -0
- package/dist/jsx/index.js +3 -1
- package/dist/jsx/index.js.map +7 -0
- package/dist/jsx/types.js +1 -0
- package/dist/jsx/types.js.map +7 -0
- package/package.json +28 -20
- package/src/constants.ts +13 -0
- package/src/extractor/accessSafe.ts +18 -0
- package/src/extractor/babelParse.ts +27 -0
- package/src/extractor/buildClassName.ts +61 -0
- package/src/extractor/createEvaluator.ts +75 -0
- package/src/extractor/createExtractor.ts +1928 -0
- package/src/extractor/ensureImportingConcat.ts +39 -0
- package/src/extractor/evaluateAstNode.ts +121 -0
- package/src/extractor/extractHelpers.ts +119 -0
- package/src/extractor/extractMediaStyle.ts +192 -0
- package/src/extractor/extractToClassNames.ts +393 -0
- package/src/extractor/findTopmostFunction.ts +22 -0
- package/src/extractor/generatedUid.ts +43 -0
- package/src/extractor/getPrefixLogs.ts +6 -0
- package/src/extractor/getPropValueFromAttributes.ts +92 -0
- package/src/extractor/getSourceModule.ts +101 -0
- package/src/extractor/getStaticBindingsForScope.ts +183 -0
- package/src/extractor/hoistClassNames.ts +45 -0
- package/src/extractor/literalToAst.ts +84 -0
- package/src/extractor/loadTamagui.ts +145 -0
- package/src/extractor/logLines.ts +16 -0
- package/src/extractor/normalizeTernaries.ts +63 -0
- package/src/extractor/removeUnusedHooks.ts +76 -0
- package/src/extractor/timer.ts +18 -0
- package/src/extractor/validHTMLAttributes.ts +99 -0
- package/src/index.ts +10 -0
- package/src/types.ts +96 -0
- package/types/constants.d.ts +0 -0
- package/types/constants.d.ts.map +0 -0
- package/types/extractor/accessSafe.d.ts +0 -0
- package/types/extractor/accessSafe.d.ts.map +0 -0
- package/types/extractor/babelParse.d.ts +0 -0
- package/types/extractor/babelParse.d.ts.map +1 -1
- package/types/extractor/buildClassName.d.ts +0 -0
- package/types/extractor/buildClassName.d.ts.map +0 -0
- package/types/extractor/createEvaluator.d.ts +1 -1
- package/types/extractor/createEvaluator.d.ts.map +1 -1
- package/types/extractor/createExtractor.d.ts +3 -4
- package/types/extractor/createExtractor.d.ts.map +1 -1
- package/types/extractor/ensureImportingConcat.d.ts +0 -0
- package/types/extractor/ensureImportingConcat.d.ts.map +0 -0
- package/types/extractor/evaluateAstNode.d.ts +0 -0
- package/types/extractor/evaluateAstNode.d.ts.map +0 -0
- package/types/extractor/extractHelpers.d.ts +1 -1
- package/types/extractor/extractHelpers.d.ts.map +1 -1
- package/types/extractor/extractMediaStyle.d.ts +0 -0
- package/types/extractor/extractMediaStyle.d.ts.map +1 -1
- package/types/extractor/extractToClassNames.d.ts +1 -6
- package/types/extractor/extractToClassNames.d.ts.map +1 -1
- package/types/extractor/findTopmostFunction.d.ts +0 -0
- package/types/extractor/findTopmostFunction.d.ts.map +0 -0
- package/types/extractor/generatedUid.d.ts +0 -0
- package/types/extractor/generatedUid.d.ts.map +0 -0
- package/types/extractor/getPrefixLogs.d.ts +0 -0
- package/types/extractor/getPrefixLogs.d.ts.map +0 -0
- package/types/extractor/getPropValueFromAttributes.d.ts +0 -0
- package/types/extractor/getPropValueFromAttributes.d.ts.map +0 -0
- package/types/extractor/getSourceModule.d.ts +0 -0
- package/types/extractor/getSourceModule.d.ts.map +0 -0
- package/types/extractor/getStaticBindingsForScope.d.ts +0 -0
- package/types/extractor/getStaticBindingsForScope.d.ts.map +0 -0
- package/types/extractor/hoistClassNames.d.ts +0 -0
- package/types/extractor/hoistClassNames.d.ts.map +0 -0
- package/types/extractor/literalToAst.d.ts +0 -0
- package/types/extractor/literalToAst.d.ts.map +0 -0
- package/types/extractor/loadTamagui.d.ts +10 -4
- package/types/extractor/loadTamagui.d.ts.map +1 -1
- package/types/extractor/logLines.d.ts +0 -0
- package/types/extractor/logLines.d.ts.map +0 -0
- package/types/extractor/normalizeTernaries.d.ts +0 -0
- package/types/extractor/normalizeTernaries.d.ts.map +0 -0
- package/types/extractor/removeUnusedHooks.d.ts +0 -0
- package/types/extractor/removeUnusedHooks.d.ts.map +0 -0
- package/types/extractor/timer.d.ts +0 -0
- package/types/extractor/timer.d.ts.map +0 -0
- package/types/extractor/validHTMLAttributes.d.ts +49 -0
- package/types/extractor/validHTMLAttributes.d.ts.map +1 -1
- package/types/index.d.ts +2 -1
- package/types/index.d.ts.map +1 -1
- package/types/types.d.ts +6 -7
- package/types/types.d.ts.map +1 -1
- package/dist/cjs/patchReactNativeWeb.js +0 -167
- package/dist/cjs/patchReactNativeWeb.js.map +0 -7
- package/dist/esm/patchReactNativeWeb.js +0 -142
- package/dist/esm/patchReactNativeWeb.js.map +0 -7
- package/dist/jsx/patchReactNativeWeb.js +0 -141
- package/types/patchReactNativeWeb.d.ts +0 -2
- package/types/patchReactNativeWeb.d.ts.map +0 -1
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
1
|
import * as t from "@babel/types";
|
|
4
2
|
import invariant from "invariant";
|
|
5
3
|
function generateUid(scope, name) {
|
|
@@ -21,7 +19,6 @@ function generateUid(scope, name) {
|
|
|
21
19
|
program.uids[uid] = true;
|
|
22
20
|
return uid;
|
|
23
21
|
}
|
|
24
|
-
__name(generateUid, "generateUid");
|
|
25
22
|
export {
|
|
26
23
|
generateUid
|
|
27
24
|
};
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/extractor/generatedUid.ts"],
|
|
4
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": "
|
|
5
|
+
"mappings": "AAAA;AACA;AAQO,qBAAqB,OAAY,MAAsB;AAC5D,YAAU,OAAO,UAAU,UAAU,2DAA2D;AAChG,YACE,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;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,11 +1,7 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
1
|
function getPrefixLogs(options) {
|
|
4
|
-
var _a;
|
|
5
2
|
const { TAMAGUI_TARGET } = process.env;
|
|
6
|
-
return (
|
|
3
|
+
return (options == null ? void 0 : options.prefixLogs) ?? ` ${TAMAGUI_TARGET} | `;
|
|
7
4
|
}
|
|
8
|
-
__name(getPrefixLogs, "getPrefixLogs");
|
|
9
5
|
export {
|
|
10
6
|
getPrefixLogs
|
|
11
7
|
};
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/extractor/getPrefixLogs.ts"],
|
|
4
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": "
|
|
5
|
+
"mappings": "AAEO,uBAAuB,SAA0B;AACtD,QAAM,EAAE,mBAAmB,QAAQ;AACnC,SAAO,oCAAS,eAAc,IAAI;AACpC;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
1
|
import generate from "@babel/generator";
|
|
4
2
|
import * as t from "@babel/types";
|
|
5
3
|
import { accessSafe } from "./accessSafe";
|
|
@@ -42,7 +40,6 @@ function getPropValueFromAttributes(propName, attrs) {
|
|
|
42
40
|
}
|
|
43
41
|
return propValue;
|
|
44
42
|
}
|
|
45
|
-
__name(getPropValueFromAttributes, "getPropValueFromAttributes");
|
|
46
43
|
export {
|
|
47
44
|
getPropValueFromAttributes
|
|
48
45
|
};
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/extractor/getPropValueFromAttributes.ts"],
|
|
4
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": "
|
|
5
|
+
"mappings": "AAAA;AACA;AAEA;AAkBO,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,SAAS,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,WAAW,KAAK,QAAQ,GAAG,GAAG,GACtE,SACF;AAAA,EACF;AAEA,SAAO;AACT;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
1
|
import * as t from "@babel/types";
|
|
4
2
|
function getSourceModule(itemName, itemBinding) {
|
|
5
3
|
if (!itemBinding.constant) {
|
|
@@ -62,7 +60,6 @@ function getSourceModule(itemName, itemBinding) {
|
|
|
62
60
|
usesImportSyntax
|
|
63
61
|
};
|
|
64
62
|
}
|
|
65
|
-
__name(getSourceModule, "getSourceModule");
|
|
66
63
|
export {
|
|
67
64
|
getSourceModule
|
|
68
65
|
};
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/extractor/getSourceModule.ts"],
|
|
4
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": "
|
|
5
|
+
"mappings": "AAAA;AAUO,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;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,11 +1,9 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
1
|
import { dirname, extname, resolve } from "path";
|
|
4
2
|
import * as t from "@babel/types";
|
|
5
3
|
import { existsSync } from "fs-extra";
|
|
6
4
|
import { evaluateAstNode } from "./evaluateAstNode";
|
|
7
5
|
import { getSourceModule } from "./getSourceModule";
|
|
8
|
-
const isLocalImport =
|
|
6
|
+
const isLocalImport = (path) => path.startsWith(".") || path.startsWith("/");
|
|
9
7
|
function resolveImportPath(sourcePath, path) {
|
|
10
8
|
const sourceDir = dirname(sourcePath);
|
|
11
9
|
if (isLocalImport(path)) {
|
|
@@ -16,7 +14,6 @@ function resolveImportPath(sourcePath, path) {
|
|
|
16
14
|
}
|
|
17
15
|
return path;
|
|
18
16
|
}
|
|
19
|
-
__name(resolveImportPath, "resolveImportPath");
|
|
20
17
|
function importModule(path) {
|
|
21
18
|
const filenames = [path.replace(".js", ".tsx"), path.replace(".js", ".ts"), path];
|
|
22
19
|
for (const file of filenames) {
|
|
@@ -35,7 +32,6 @@ function importModule(path) {
|
|
|
35
32
|
}
|
|
36
33
|
return null;
|
|
37
34
|
}
|
|
38
|
-
__name(importModule, "importModule");
|
|
39
35
|
function getStaticBindingsForScope(scope, whitelist = [], sourcePath, bindingCache, shouldPrintDebug) {
|
|
40
36
|
const bindings = scope.getAllBindings();
|
|
41
37
|
const ret = {};
|
|
@@ -130,7 +126,6 @@ function getStaticBindingsForScope(scope, whitelist = [], sourcePath, bindingCac
|
|
|
130
126
|
}
|
|
131
127
|
return ret;
|
|
132
128
|
}
|
|
133
|
-
__name(getStaticBindingsForScope, "getStaticBindingsForScope");
|
|
134
129
|
export {
|
|
135
130
|
getStaticBindingsForScope
|
|
136
131
|
};
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/extractor/getStaticBindingsForScope.ts"],
|
|
4
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 const { unregister } = require('esbuild-register/dist/node').register({\n target: 'es2019',\n format: 'cjs',\n })\n try {\n // TODO we can clear this when we see updates on it later on\n return require(file)\n } catch {\n // doesn't exists\n } finally {\n unregister()\n }\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": "
|
|
5
|
+
"mappings": "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",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
1
|
import * as t from "@babel/types";
|
|
4
2
|
function hoistClassNames(path, existing, expr) {
|
|
5
3
|
const hoist = hoistClassNames.bind(null, path, existing);
|
|
@@ -35,9 +33,7 @@ function hoistClassNames(path, existing, expr) {
|
|
|
35
33
|
parent.unshiftContainer("body", variable);
|
|
36
34
|
return uid;
|
|
37
35
|
}
|
|
38
|
-
__name(replaceStringWithVariable, "replaceStringWithVariable");
|
|
39
36
|
}
|
|
40
|
-
__name(hoistClassNames, "hoistClassNames");
|
|
41
37
|
export {
|
|
42
38
|
hoistClassNames
|
|
43
39
|
};
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/extractor/hoistClassNames.ts"],
|
|
4
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": "
|
|
5
|
+
"mappings": "AACA;AAEO,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;AACF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,5 +1,22 @@
|
|
|
1
1
|
var __defProp = Object.defineProperty;
|
|
2
|
-
var
|
|
2
|
+
var __defProps = Object.defineProperties;
|
|
3
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
4
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
7
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
|
+
var __spreadValues = (a, b) => {
|
|
9
|
+
for (var prop in b || (b = {}))
|
|
10
|
+
if (__hasOwnProp.call(b, prop))
|
|
11
|
+
__defNormalProp(a, prop, b[prop]);
|
|
12
|
+
if (__getOwnPropSymbols)
|
|
13
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
14
|
+
if (__propIsEnum.call(b, prop))
|
|
15
|
+
__defNormalProp(a, prop, b[prop]);
|
|
16
|
+
}
|
|
17
|
+
return a;
|
|
18
|
+
};
|
|
19
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
3
20
|
import * as t from "@babel/types";
|
|
4
21
|
function literalToAst(literal) {
|
|
5
22
|
if (literal === null) {
|
|
@@ -27,7 +44,6 @@ function literalToAst(literal) {
|
|
|
27
44
|
}));
|
|
28
45
|
}
|
|
29
46
|
}
|
|
30
|
-
__name(literalToAst, "literalToAst");
|
|
31
47
|
const easyPeasies = ["BooleanLiteral", "StringLiteral", "NumericLiteral"];
|
|
32
48
|
function astToLiteral(node) {
|
|
33
49
|
if (!node) {
|
|
@@ -52,27 +68,21 @@ function astToLiteral(node) {
|
|
|
52
68
|
], []);
|
|
53
69
|
}
|
|
54
70
|
}
|
|
55
|
-
__name(astToLiteral, "astToLiteral");
|
|
56
71
|
function computeProps(props) {
|
|
57
72
|
return props.reduce((acc, prop) => {
|
|
58
73
|
if (prop.type === "SpreadElement") {
|
|
59
|
-
return {
|
|
60
|
-
...acc,
|
|
61
|
-
...astToLiteral(prop.argument)
|
|
62
|
-
};
|
|
74
|
+
return __spreadValues(__spreadValues({}, acc), astToLiteral(prop.argument));
|
|
63
75
|
} else if (prop.type !== "ObjectMethod") {
|
|
64
76
|
const val = astToLiteral(prop.value);
|
|
65
77
|
if (val !== void 0) {
|
|
66
|
-
return {
|
|
67
|
-
...acc,
|
|
78
|
+
return __spreadProps(__spreadValues({}, acc), {
|
|
68
79
|
[prop.key.name]: val
|
|
69
|
-
};
|
|
80
|
+
});
|
|
70
81
|
}
|
|
71
82
|
}
|
|
72
83
|
return acc;
|
|
73
84
|
}, {});
|
|
74
85
|
}
|
|
75
|
-
__name(computeProps, "computeProps");
|
|
76
86
|
export {
|
|
77
87
|
astToLiteral,
|
|
78
88
|
literalToAst
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/extractor/literalToAst.ts"],
|
|
4
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": "
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;AAAA;AAEO,sBAAsB,SAA4B;AACvD,MAAI,YAAY,MAAM;AACpB,WAAO,EAAE,YAAY;AAAA,EACvB;AACA,UAAQ,OAAO;AAAA,SACR;AACH,YAAM,IAAI,MAAM,aAAa;AAAA,SAC1B;AACH,aAAO,EAAE,eAAe,OAAO;AAAA,SAC5B;AACH,aAAO,EAAE,cAAc,OAAO;AAAA,SAC3B;AACH,aAAO,EAAE,eAAe,OAAO;AAAA,SAC5B;AACH,aAAO,EAAE,gBAAgB,QAAQ,EAAE,eAAe,CAAC,GAAG,IAAI;AAAA;AAE1D,UAAI,MAAM,QAAQ,OAAO,GAAG;AAC1B,eAAO,EAAE,gBAAgB,QAAQ,IAAI,YAAY,CAAC;AAAA,MACpD;AACA,aAAO,EAAE,iBACP,OAAO,KAAK,OAAO,EAChB,OAAO,CAAC,MAAM;AACb,eAAO,OAAO,QAAQ,OAAO;AAAA,MAC/B,CAAC,EACA,IAAI,CAAC,MAAM;AACV,eAAO,EAAE,eAAe,EAAE,cAAc,CAAC,GAAG,aAAa,QAAQ,EAAE,CAAC;AAAA,MACtE,CAAC,CACL;AAAA;AAEN;AAEA,MAAM,cAAc,CAAC,kBAAkB,iBAAiB,gBAAgB;AAEjE,sBAAsB,MAAW;AACtC,MAAI,CAAC,MAAM;AACT;AAAA,EACF;AACA,MAAI,YAAY,SAAS,KAAK,IAAI,GAAG;AACnC,WAAO,KAAK;AAAA,EACd;AACA,MAAI,KAAK,SAAS,eAAe,CAAC,KAAK,OAAO;AAC5C,WAAO;AAAA,EACT;AACA,MAAI,EAAE,cAAc,IAAI,GAAG;AACzB,WAAO;AAAA,EACT;AACA,MAAI,EAAE,mBAAmB,IAAI,GAAG;AAC9B,WAAO,aAAa,KAAK,UAAU;AAAA,EACrC;AACA,MAAI,EAAE,kBAAkB,IAAI,GAAG;AAC7B,WAAO,KAAK,SAAS,OAEnB,CAAC,KAAK,YAAY;AAAA,MAChB,GAAG;AAAA,MACH,GAAI,oCAAS,UAAS,kBAClB,aAAa,QAAQ,QAAQ,IAC7B,CAAC,aAAa,OAAO,CAAC;AAAA,IAC5B,GACA,CAAC,CACH;AAAA,EACF;AACF;AAEA,sBAAsB,OAAO;AAC3B,SAAO,MAAM,OAAO,CAAC,KAAK,SAAS;AACjC,QAAI,KAAK,SAAS,iBAAiB;AACjC,aAAO,kCACF,MACA,aAAa,KAAK,QAAQ;AAAA,IAEjC,WAAW,KAAK,SAAS,gBAAgB;AACvC,YAAM,MAAM,aAAa,KAAK,KAAK;AACnC,UAAI,QAAQ,QAAW;AACrB,eAAO,iCACF,MADE;AAAA,UAEL,CAAC,KAAK,IAAI,OAAO;AAAA,QACnB;AAAA,MACF;AAAA,IACF;AACA,WAAO;AAAA,EACT,GAAG,CAAC,CAAC;AACP;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,5 +1,18 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
1
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
2
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
3
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
4
|
+
var __objRest = (source, exclude) => {
|
|
5
|
+
var target = {};
|
|
6
|
+
for (var prop in source)
|
|
7
|
+
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
8
|
+
target[prop] = source[prop];
|
|
9
|
+
if (source != null && __getOwnPropSymbols)
|
|
10
|
+
for (var prop of __getOwnPropSymbols(source)) {
|
|
11
|
+
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|
12
|
+
target[prop] = source[prop];
|
|
13
|
+
}
|
|
14
|
+
return target;
|
|
15
|
+
};
|
|
3
16
|
import { join } from "path";
|
|
4
17
|
import { createTamagui } from "@tamagui/core-node";
|
|
5
18
|
let loadedTamagui = null;
|
|
@@ -21,23 +34,41 @@ function loadTamagui(props) {
|
|
|
21
34
|
const rnw = require("react-native-web");
|
|
22
35
|
const Mod = require("module");
|
|
23
36
|
const og = Mod.prototype.require;
|
|
37
|
+
const nameToPaths = {};
|
|
24
38
|
Mod.prototype.require = function(path) {
|
|
39
|
+
var _a2;
|
|
25
40
|
if (path.endsWith(".css")) {
|
|
26
41
|
return {};
|
|
27
42
|
}
|
|
28
|
-
if (path === "@gorhom/bottom-sheet" || path.startsWith("react-native-reanimated")) {
|
|
43
|
+
if (path === "@gorhom/bottom-sheet" || path.startsWith("react-native-reanimated") || path === "expo-linear-gradient") {
|
|
29
44
|
return proxyWorm;
|
|
30
45
|
}
|
|
31
46
|
if (path.startsWith("react-native") && !path.startsWith("react-native-web/dist/cjs/exports")) {
|
|
32
47
|
return rnw;
|
|
33
48
|
}
|
|
34
49
|
try {
|
|
35
|
-
|
|
50
|
+
const out = og.apply(this, arguments);
|
|
51
|
+
if (!nameToPaths[path]) {
|
|
52
|
+
if (out && typeof out === "object") {
|
|
53
|
+
for (const key in out) {
|
|
54
|
+
try {
|
|
55
|
+
const conf = (_a2 = out[key]) == null ? void 0 : _a2.staticConfig;
|
|
56
|
+
if (conf) {
|
|
57
|
+
if (conf.componentName) {
|
|
58
|
+
nameToPaths[conf.componentName] ??= /* @__PURE__ */ new Set();
|
|
59
|
+
const fullName = path.startsWith(".") ? join(`${this.path.replace(/dist(\/cjs)?/, "src")}`, path) : path;
|
|
60
|
+
nameToPaths[conf.componentName].add(fullName);
|
|
61
|
+
} else {
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
} catch {
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
return out;
|
|
36
70
|
} catch (err) {
|
|
37
|
-
console.error("Tamagui error loading file:\n");
|
|
38
|
-
console.log(" ", path, "\n");
|
|
39
|
-
console.log(err.message);
|
|
40
|
-
console.log(err.stack);
|
|
71
|
+
console.error("Tamagui error loading file:\n", path, err.message, "\n", err.stack);
|
|
41
72
|
process.exit(1);
|
|
42
73
|
}
|
|
43
74
|
};
|
|
@@ -59,7 +90,8 @@ function loadTamagui(props) {
|
|
|
59
90
|
const val = exported[Name];
|
|
60
91
|
const staticConfig = val == null ? void 0 : val.staticConfig;
|
|
61
92
|
if (staticConfig) {
|
|
62
|
-
|
|
93
|
+
const _a = staticConfig, { Component, reactNativeWebComponent } = _a, sc = __objRest(_a, ["Component", "reactNativeWebComponent"]);
|
|
94
|
+
Object.assign(components, { [Name]: { staticConfig: sc } });
|
|
63
95
|
}
|
|
64
96
|
}
|
|
65
97
|
}
|
|
@@ -68,16 +100,17 @@ function loadTamagui(props) {
|
|
|
68
100
|
createTamagui(tamaguiConfig);
|
|
69
101
|
loadedTamagui = {
|
|
70
102
|
components,
|
|
71
|
-
tamaguiConfig
|
|
103
|
+
tamaguiConfig,
|
|
104
|
+
nameToPaths
|
|
72
105
|
};
|
|
73
106
|
return loadedTamagui;
|
|
74
107
|
} catch (err) {
|
|
108
|
+
console.log("Error loading Tamagui", err);
|
|
75
109
|
throw err;
|
|
76
110
|
} finally {
|
|
77
111
|
unregister();
|
|
78
112
|
}
|
|
79
113
|
}
|
|
80
|
-
__name(loadTamagui, "loadTamagui");
|
|
81
114
|
export {
|
|
82
115
|
loadTamagui
|
|
83
116
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/extractor/loadTamagui.ts"],
|
|
4
|
-
"sourcesContent": ["import { join } from 'path'\n\nimport type { TamaguiComponent, TamaguiInternalConfig } from '@tamagui/core'\nimport { createTamagui } from '@tamagui/core-node'\n\nlet loadedTamagui: any = null\n\
|
|
5
|
-
"mappings": "
|
|
4
|
+
"sourcesContent": ["import { join } from 'path'\n\nimport type { StaticConfig, TamaguiComponent, TamaguiInternalConfig } from '@tamagui/core'\nimport { createTamagui } from '@tamagui/core-node'\n\nlet loadedTamagui: any = null\n\ntype NameToPaths = {\n [key: string]: Set<string>\n}\n\nexport type TamaguiProjectInfo = {\n components: Record<string, TamaguiComponent>\n tamaguiConfig: TamaguiInternalConfig\n nameToPaths: NameToPaths\n}\n\nexport function loadTamagui(props: { components: string[]; config: string }): TamaguiProjectInfo {\n if (loadedTamagui) {\n return loadedTamagui\n }\n\n const configPath = join(process.cwd(), props.config)\n\n const { unregister } = require('esbuild-register/dist/node').register({\n target: 'es2019',\n format: 'cjs',\n })\n\n try {\n // lets shim require and avoid importing react-native + react-native-web\n // we just need to read the config around them\n process.env.IS_STATIC = 'is_static'\n // @ts-ignore\n if (typeof globalThis['__DEV__'] === 'undefined') {\n // @ts-ignore\n globalThis['__DEV__'] = process.env.NODE_ENV === 'development'\n }\n\n const proxyWorm = require('@tamagui/proxy-worm')\n const rnw = require('react-native-web')\n const Mod = require('module')\n const og = Mod.prototype.require\n const nameToPaths: NameToPaths = {}\n\n Mod.prototype.require = function (path: string) {\n if (path.endsWith('.css')) {\n return {}\n }\n if (\n path === '@gorhom/bottom-sheet' ||\n path.startsWith('react-native-reanimated') ||\n path === 'expo-linear-gradient'\n ) {\n return proxyWorm\n }\n if (\n path.startsWith('react-native') &&\n // allow our rnw.tsx imports through\n !path.startsWith('react-native-web/dist/cjs/exports')\n ) {\n return rnw\n }\n try {\n const out = og.apply(this, arguments)\n if (!nameToPaths[path]) {\n if (out && typeof out === 'object') {\n for (const key in out) {\n try {\n const conf = out[key]?.staticConfig as StaticConfig\n if (conf) {\n if (conf.componentName) {\n nameToPaths[conf.componentName] ??= new Set()\n const fullName = path.startsWith('.')\n ? join(`${this.path.replace(/dist(\\/cjs)?/, 'src')}`, path)\n : path\n nameToPaths[conf.componentName].add(fullName)\n } else {\n // console.log('no name component', path)\n }\n }\n } catch {\n // ok\n }\n }\n }\n }\n return out\n } catch (err: any) {\n console.error('Tamagui error loading file:\\n', path, err.message, '\\n', err.stack)\n // avoid infinite loops\n process.exit(1)\n }\n }\n\n // import config\n const exp = require(configPath)\n const tamaguiConfig = (exp['default'] || exp) as TamaguiInternalConfig\n\n if (!tamaguiConfig || !tamaguiConfig.parsed) {\n try {\n const confPath = require.resolve(configPath)\n console.log(`Received:`, tamaguiConfig)\n throw new Error(`Can't find valid config in ${confPath}`)\n } catch (err) {\n throw err\n }\n }\n\n // import components\n const components = {}\n for (const moduleName of props.components) {\n const exported = require(moduleName)\n for (const Name in exported) {\n const val = exported[Name]\n const staticConfig = val?.staticConfig as StaticConfig | undefined\n if (staticConfig) {\n // remove non-stringifyable\n const { Component, reactNativeWebComponent, ...sc } = staticConfig\n Object.assign(components, { [Name]: { staticConfig: sc } })\n }\n }\n }\n\n // undo shims\n process.env.IS_STATIC = undefined\n Mod.prototype.require = og\n\n // set up core-node\n createTamagui(tamaguiConfig as any)\n\n loadedTamagui = {\n components,\n tamaguiConfig,\n nameToPaths,\n }\n\n return loadedTamagui\n } catch (err) {\n console.log('Error loading Tamagui', err)\n throw err\n } finally {\n unregister()\n }\n}\n"],
|
|
5
|
+
"mappings": "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",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
1
|
const prefix = " ";
|
|
4
|
-
const logLines =
|
|
2
|
+
const logLines = (str, singleLine = false) => {
|
|
5
3
|
if (singleLine) {
|
|
6
4
|
return prefix + str.split(" ").join(`
|
|
7
5
|
${prefix}`);
|
|
@@ -15,7 +13,7 @@ ${prefix}`);
|
|
|
15
13
|
lines[lines.length - 1] += item + " ";
|
|
16
14
|
}
|
|
17
15
|
return lines.map((line, i) => prefix + (i == 0 ? "" : " ") + line.trim()).join("\n");
|
|
18
|
-
}
|
|
16
|
+
};
|
|
19
17
|
export {
|
|
20
18
|
logLines
|
|
21
19
|
};
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/extractor/logLines.ts"],
|
|
4
4
|
"sourcesContent": ["const prefix = ' '\n\nexport const logLines = (str: string, singleLine = false) => {\n if (singleLine) {\n return prefix + str.split(' ').join(`\\n${prefix}`)\n }\n let lines: string[] = ['']\n const items = str.split(' ')\n for (const item of items) {\n if (item.length + lines[lines.length - 1].length > 85) {\n lines.push('')\n }\n lines[lines.length - 1] += item + ' '\n }\n return lines.map((line, i) => prefix + (i == 0 ? '' : ' ') + line.trim()).join('\\n')\n}\n"],
|
|
5
|
-
"mappings": "
|
|
5
|
+
"mappings": "AAAA,MAAM,SAAS;AAER,MAAM,WAAW,CAAC,KAAa,aAAa,UAAU;AAC3D,MAAI,YAAY;AACd,WAAO,SAAS,IAAI,MAAM,GAAG,EAAE,KAAK;AAAA,EAAK,QAAQ;AAAA,EACnD;AACA,MAAI,QAAkB,CAAC,EAAE;AACzB,QAAM,QAAQ,IAAI,MAAM,GAAG;AAC3B,aAAW,QAAQ,OAAO;AACxB,QAAI,KAAK,SAAS,MAAM,MAAM,SAAS,GAAG,SAAS,IAAI;AACrD,YAAM,KAAK,EAAE;AAAA,IACf;AACA,UAAM,MAAM,SAAS,MAAM,OAAO;AAAA,EACpC;AACA,SAAO,MAAM,IAAI,CAAC,MAAM,MAAM,SAAU,MAAK,IAAI,KAAK,OAAO,KAAK,KAAK,CAAC,EAAE,KAAK,IAAI;AACrF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,17 +1,45 @@
|
|
|
1
1
|
var __defProp = Object.defineProperty;
|
|
2
|
-
var
|
|
2
|
+
var __defProps = Object.defineProperties;
|
|
3
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
4
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
7
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
|
+
var __spreadValues = (a, b) => {
|
|
9
|
+
for (var prop in b || (b = {}))
|
|
10
|
+
if (__hasOwnProp.call(b, prop))
|
|
11
|
+
__defNormalProp(a, prop, b[prop]);
|
|
12
|
+
if (__getOwnPropSymbols)
|
|
13
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
14
|
+
if (__propIsEnum.call(b, prop))
|
|
15
|
+
__defNormalProp(a, prop, b[prop]);
|
|
16
|
+
}
|
|
17
|
+
return a;
|
|
18
|
+
};
|
|
19
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
20
|
+
var __objRest = (source, exclude) => {
|
|
21
|
+
var target = {};
|
|
22
|
+
for (var prop in source)
|
|
23
|
+
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
24
|
+
target[prop] = source[prop];
|
|
25
|
+
if (source != null && __getOwnPropSymbols)
|
|
26
|
+
for (var prop of __getOwnPropSymbols(source)) {
|
|
27
|
+
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|
28
|
+
target[prop] = source[prop];
|
|
29
|
+
}
|
|
30
|
+
return target;
|
|
31
|
+
};
|
|
3
32
|
import generate from "@babel/generator";
|
|
4
33
|
import * as t from "@babel/types";
|
|
5
34
|
import invariant from "invariant";
|
|
6
35
|
function normalizeTernaries(ternaries) {
|
|
7
|
-
var _a, _b;
|
|
8
36
|
invariant(Array.isArray(ternaries), "extractStaticTernaries expects param 1 to be an array of ternaries");
|
|
9
37
|
if (ternaries.length === 0) {
|
|
10
38
|
return [];
|
|
11
39
|
}
|
|
12
40
|
const ternariesByKey = {};
|
|
13
41
|
for (let idx = -1, len = ternaries.length; ++idx < len; ) {
|
|
14
|
-
const { test, consequent, alternate, remove,
|
|
42
|
+
const _a = ternaries[idx], { test, consequent, alternate, remove } = _a, rest = __objRest(_a, ["test", "consequent", "alternate", "remove"]);
|
|
15
43
|
let ternaryTest = test;
|
|
16
44
|
if (t.isExpressionStatement(test)) {
|
|
17
45
|
ternaryTest = test.expression;
|
|
@@ -28,16 +56,15 @@ function normalizeTernaries(ternaries) {
|
|
|
28
56
|
}
|
|
29
57
|
const key = generate(ternaryTest).code;
|
|
30
58
|
if (!ternariesByKey[key]) {
|
|
31
|
-
ternariesByKey[key] = {
|
|
32
|
-
...rest,
|
|
59
|
+
ternariesByKey[key] = __spreadProps(__spreadValues({}, rest), {
|
|
33
60
|
alternate: {},
|
|
34
61
|
consequent: {},
|
|
35
62
|
test: ternaryTest,
|
|
36
63
|
remove
|
|
37
|
-
};
|
|
64
|
+
});
|
|
38
65
|
}
|
|
39
|
-
const altStyle = (
|
|
40
|
-
const consStyle = (
|
|
66
|
+
const altStyle = (shouldSwap ? consequent : alternate) ?? {};
|
|
67
|
+
const consStyle = (shouldSwap ? alternate : consequent) ?? {};
|
|
41
68
|
Object.assign(ternariesByKey[key].alternate, altStyle);
|
|
42
69
|
Object.assign(ternariesByKey[key].consequent, consStyle);
|
|
43
70
|
}
|
|
@@ -46,7 +73,6 @@ function normalizeTernaries(ternaries) {
|
|
|
46
73
|
});
|
|
47
74
|
return ternaryExpression;
|
|
48
75
|
}
|
|
49
|
-
__name(normalizeTernaries, "normalizeTernaries");
|
|
50
76
|
export {
|
|
51
77
|
normalizeTernaries
|
|
52
78
|
};
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/extractor/normalizeTernaries.ts"],
|
|
4
4
|
"sourcesContent": ["import generate from '@babel/generator'\nimport * as t from '@babel/types'\nimport invariant from 'invariant'\n\nimport { Ternary } from '../types'\n\nexport function normalizeTernaries(ternaries: Ternary[]) {\n invariant(\n Array.isArray(ternaries),\n 'extractStaticTernaries expects param 1 to be an array of ternaries'\n )\n\n if (ternaries.length === 0) {\n return []\n }\n\n const ternariesByKey: { [key: string]: Ternary } = {}\n\n for (let idx = -1, len = ternaries.length; ++idx < len; ) {\n const { test, consequent, alternate, remove, ...rest } = ternaries[idx]\n\n let ternaryTest = test\n\n // strip parens\n if (t.isExpressionStatement(test)) {\n ternaryTest = (test as any).expression\n }\n\n // convert `!thing` to `thing` with swapped consequent and alternate\n let shouldSwap = false\n if (t.isUnaryExpression(test) && test.operator === '!') {\n ternaryTest = test.argument\n shouldSwap = true\n } else if (t.isBinaryExpression(test)) {\n if (test.operator === '!==' || test.operator === '!=') {\n ternaryTest = t.binaryExpression(test.operator, test.left, test.right)\n shouldSwap = true\n }\n }\n\n const key = generate(ternaryTest).code\n\n if (!ternariesByKey[key]) {\n ternariesByKey[key] = {\n ...rest,\n alternate: {},\n consequent: {},\n test: ternaryTest,\n remove,\n }\n }\n const altStyle = (shouldSwap ? consequent : alternate) ?? {}\n const consStyle = (shouldSwap ? alternate : consequent) ?? {}\n Object.assign(ternariesByKey[key].alternate!, altStyle)\n Object.assign(ternariesByKey[key].consequent!, consStyle)\n }\n\n const ternaryExpression = Object.keys(ternariesByKey).map((key) => {\n return ternariesByKey[key]\n })\n\n return ternaryExpression\n}\n"],
|
|
5
|
-
"mappings": "
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AACA;AACA;AAIO,4BAA4B,WAAsB;AACvD,YACE,MAAM,QAAQ,SAAS,GACvB,oEACF;AAEA,MAAI,UAAU,WAAW,GAAG;AAC1B,WAAO,CAAC;AAAA,EACV;AAEA,QAAM,iBAA6C,CAAC;AAEpD,WAAS,MAAM,IAAI,MAAM,UAAU,QAAQ,EAAE,MAAM,OAAO;AACxD,UAAyD,eAAU,MAA3D,QAAM,YAAY,WAAW,WAAoB,IAAT,iBAAS,IAAT,CAAxC,QAAM,cAAY,aAAW;AAErC,QAAI,cAAc;AAGlB,QAAI,EAAE,sBAAsB,IAAI,GAAG;AACjC,oBAAe,KAAa;AAAA,IAC9B;AAGA,QAAI,aAAa;AACjB,QAAI,EAAE,kBAAkB,IAAI,KAAK,KAAK,aAAa,KAAK;AACtD,oBAAc,KAAK;AACnB,mBAAa;AAAA,IACf,WAAW,EAAE,mBAAmB,IAAI,GAAG;AACrC,UAAI,KAAK,aAAa,SAAS,KAAK,aAAa,MAAM;AACrD,sBAAc,EAAE,iBAAiB,KAAK,UAAU,KAAK,MAAM,KAAK,KAAK;AACrE,qBAAa;AAAA,MACf;AAAA,IACF;AAEA,UAAM,MAAM,SAAS,WAAW,EAAE;AAElC,QAAI,CAAC,eAAe,MAAM;AACxB,qBAAe,OAAO,iCACjB,OADiB;AAAA,QAEpB,WAAW,CAAC;AAAA,QACZ,YAAY,CAAC;AAAA,QACb,MAAM;AAAA,QACN;AAAA,MACF;AAAA,IACF;AACA,UAAM,WAAY,cAAa,aAAa,cAAc,CAAC;AAC3D,UAAM,YAAa,cAAa,YAAY,eAAe,CAAC;AAC5D,WAAO,OAAO,eAAe,KAAK,WAAY,QAAQ;AACtD,WAAO,OAAO,eAAe,KAAK,YAAa,SAAS;AAAA,EAC1D;AAEA,QAAM,oBAAoB,OAAO,KAAK,cAAc,EAAE,IAAI,CAAC,QAAQ;AACjE,WAAO,eAAe;AAAA,EACxB,CAAC;AAED,SAAO;AACT;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,12 +1,9 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
1
|
import * as t from "@babel/types";
|
|
4
2
|
const hooks = {
|
|
5
3
|
useMedia: true,
|
|
6
4
|
useTheme: true
|
|
7
5
|
};
|
|
8
6
|
function removeUnusedHooks(compFn, shouldPrintDebug) {
|
|
9
|
-
var _a;
|
|
10
7
|
compFn.scope.crawl();
|
|
11
8
|
let bodyStatements = compFn == null ? void 0 : compFn.get("body");
|
|
12
9
|
if (!bodyStatements) {
|
|
@@ -32,10 +29,10 @@ function removeUnusedHooks(compFn, shouldPrintDebug) {
|
|
|
32
29
|
if (!Array.isArray(declarations)) {
|
|
33
30
|
continue;
|
|
34
31
|
}
|
|
35
|
-
const isBindingReferenced =
|
|
36
|
-
var
|
|
37
|
-
return !!((
|
|
38
|
-
}
|
|
32
|
+
const isBindingReferenced = (name) => {
|
|
33
|
+
var _a;
|
|
34
|
+
return !!((_a = statement.scope.getBinding(name)) == null ? void 0 : _a.referenced);
|
|
35
|
+
};
|
|
39
36
|
for (const declarator of declarations) {
|
|
40
37
|
const id = declarator.get("id");
|
|
41
38
|
const init = declarator.node.init;
|
|
@@ -67,13 +64,12 @@ function removeUnusedHooks(compFn, shouldPrintDebug) {
|
|
|
67
64
|
if (shouldRemove) {
|
|
68
65
|
declarator.remove();
|
|
69
66
|
if (shouldPrintDebug) {
|
|
70
|
-
console.log(` [\u{1FA9D}] removed ${
|
|
67
|
+
console.log(` [\u{1FA9D}] removed ${id.node["name"] ?? ""}`);
|
|
71
68
|
}
|
|
72
69
|
}
|
|
73
70
|
}
|
|
74
71
|
}
|
|
75
72
|
}
|
|
76
|
-
__name(removeUnusedHooks, "removeUnusedHooks");
|
|
77
73
|
export {
|
|
78
74
|
removeUnusedHooks
|
|
79
75
|
};
|