@tamagui/static 1.0.0-alpha.39 → 1.0.0-alpha.42
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/constants.js +17 -7
- package/dist/cjs/constants.js.map +2 -2
- package/dist/cjs/extractor/accessSafe.js +13 -7
- package/dist/cjs/extractor/accessSafe.js.map +1 -1
- package/dist/cjs/extractor/babelParse.js +13 -7
- package/dist/cjs/extractor/babelParse.js.map +1 -1
- package/dist/cjs/extractor/buildClassName.js +13 -7
- package/dist/cjs/extractor/buildClassName.js.map +1 -1
- package/dist/cjs/extractor/createEvaluator.js +19 -13
- package/dist/cjs/extractor/createEvaluator.js.map +2 -2
- package/dist/cjs/extractor/createExtractor.js +44 -40
- package/dist/cjs/extractor/createExtractor.js.map +2 -2
- package/dist/cjs/extractor/ensureImportingConcat.js +17 -11
- package/dist/cjs/extractor/ensureImportingConcat.js.map +2 -2
- package/dist/cjs/extractor/evaluateAstNode.js +13 -7
- package/dist/cjs/extractor/evaluateAstNode.js.map +1 -1
- package/dist/cjs/extractor/extractHelpers.js +13 -7
- package/dist/cjs/extractor/extractHelpers.js.map +1 -1
- package/dist/cjs/extractor/extractMediaStyle.js +16 -10
- package/dist/cjs/extractor/extractMediaStyle.js.map +1 -1
- package/dist/cjs/extractor/extractToClassNames.js +31 -26
- package/dist/cjs/extractor/extractToClassNames.js.map +2 -2
- package/dist/cjs/extractor/findTopmostFunction.js +19 -2
- package/dist/cjs/extractor/findTopmostFunction.js.map +1 -1
- package/dist/cjs/extractor/generatedUid.js +14 -8
- package/dist/cjs/extractor/generatedUid.js.map +1 -1
- package/dist/cjs/extractor/getPropValueFromAttributes.js +15 -9
- package/dist/cjs/extractor/getPropValueFromAttributes.js.map +1 -1
- package/dist/cjs/extractor/getSourceModule.js +13 -7
- package/dist/cjs/extractor/getSourceModule.js.map +1 -1
- package/dist/cjs/extractor/getStaticBindingsForScope.js +17 -11
- package/dist/cjs/extractor/getStaticBindingsForScope.js.map +1 -1
- package/dist/cjs/extractor/hoistClassNames.js +13 -7
- package/dist/cjs/extractor/hoistClassNames.js.map +1 -1
- package/dist/cjs/extractor/literalToAst.js +13 -7
- package/dist/cjs/extractor/literalToAst.js.map +1 -1
- package/dist/cjs/extractor/loadTamagui.js +12 -11
- package/dist/cjs/extractor/loadTamagui.js.map +1 -1
- package/dist/cjs/extractor/logLines.js +19 -2
- package/dist/cjs/extractor/logLines.js.map +1 -1
- package/dist/cjs/extractor/normalizeTernaries.js +15 -9
- package/dist/cjs/extractor/normalizeTernaries.js.map +1 -1
- package/dist/cjs/extractor/removeUnusedHooks.js +13 -7
- package/dist/cjs/extractor/removeUnusedHooks.js.map +1 -1
- package/dist/cjs/index.js +17 -16
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/patchReactNativeWeb.js +14 -8
- package/dist/cjs/patchReactNativeWeb.js.map +1 -1
- package/dist/cjs/types.js +18 -1
- package/dist/cjs/types.js.map +1 -1
- package/dist/esm/constants.js +4 -0
- package/dist/esm/constants.js.map +2 -2
- package/dist/esm/extractor/createEvaluator.js +1 -1
- package/dist/esm/extractor/createEvaluator.js.map +1 -1
- package/dist/esm/extractor/createExtractor.js +9 -11
- package/dist/esm/extractor/createExtractor.js.map +2 -2
- package/dist/esm/extractor/ensureImportingConcat.js +1 -1
- package/dist/esm/extractor/ensureImportingConcat.js.map +2 -2
- package/dist/esm/extractor/extractToClassNames.js +2 -3
- package/dist/esm/extractor/extractToClassNames.js.map +2 -2
- package/dist/jsx/constants.js +4 -0
- package/dist/jsx/extractor/createEvaluator.js +1 -1
- package/dist/jsx/extractor/createExtractor.js +9 -11
- package/dist/jsx/extractor/ensureImportingConcat.js +1 -1
- package/dist/jsx/extractor/extractToClassNames.js +2 -3
- package/package.json +7 -7
- package/types/constants.d.ts +2 -0
- package/types/constants.d.ts.map +1 -1
- package/types/extractor/createExtractor.d.ts +0 -1
- package/types/extractor/createExtractor.d.ts.map +1 -1
- package/types/extractor/ensureImportingConcat.d.ts.map +1 -1
- package/types/extractor/extractToClassNames.d.ts +0 -1
- package/types/extractor/extractToClassNames.d.ts.map +1 -1
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/extractor/extractMediaStyle.ts"],
|
|
4
4
|
"sourcesContent": ["import { NodePath } from '@babel/traverse'\nimport * as t from '@babel/types'\nimport type { TamaguiInternalConfig } from '@tamagui/core'\nimport { getStylesAtomic, mediaObjectToString } from '@tamagui/core-node'\nimport { ViewStyle } from 'react-native'\n\nimport { MEDIA_SEP } from '../constants'\nimport { StyleObject, Ternary } from '../types'\nimport { isInsideTamagui, isPresent } from './extractHelpers'\n\nexport function extractMediaStyle(\n ternary: Ternary,\n jsxPath: NodePath<t.JSXElement>,\n tamaguiConfig: TamaguiInternalConfig,\n sourcePath: string,\n importance = 0,\n shouldPrintDebug = false\n) {\n const mt = getMediaQueryTernary(ternary, jsxPath, sourcePath)\n if (!mt) {\n return null\n }\n const { key } = mt\n const mq = tamaguiConfig.media[key]\n if (!mq) {\n console.error(`Media query \"${key}\" not found: ${Object.keys(tamaguiConfig.media)}`)\n return null\n }\n const getStyleObj = (styleObj: ViewStyle | null, negate = false) => {\n return styleObj ? { styleObj, negate } : null\n }\n const styleOpts = [\n getStyleObj(ternary.consequent, false),\n getStyleObj(ternary.alternate, true),\n ].filter(isPresent)\n if (shouldPrintDebug && !styleOpts.length) {\n console.log(' media query, no styles?')\n return null\n }\n // for now order first strongest\n const mediaKeys = Object.keys(tamaguiConfig.media)\n const mediaKeyPrecendence = mediaKeys.reduce((acc, cur, i) => {\n acc[cur] = new Array(importance + 1).fill(':root').join('')\n return acc\n }, {})\n let mediaStyles: StyleObject[] = []\n for (const { styleObj, negate } of styleOpts) {\n const styles = getStylesAtomic(styleObj)\n const singleMediaStyles = styles.map((style) => {\n const negKey = negate ? '0' : ''\n const ogPrefix = style.identifier.slice(0, style.identifier.indexOf('-') + 1)\n // adds an extra separator before and after to detect later in concatClassName\n // so it goes from: \"_f-[hash]\"\n // to: \"_f-_sm0_[hash]\" or \"_f-_sm_[hash]\"\n const identifier = `${style.identifier.replace(\n ogPrefix,\n `${ogPrefix}${MEDIA_SEP}${key}${negKey}${MEDIA_SEP}`\n )}`\n const className = `.${identifier}`\n const mediaSelector = mediaObjectToString(tamaguiConfig.media[key])\n const screenStr = negate ? 'not all' : 'screen'\n const mediaQuery = `${screenStr} and ${mediaSelector}`\n const precendencePrefix = mediaKeyPrecendence[key]\n const styleInner = style.rules[0].replace(style.identifier, identifier)\n // combines media queries if they already exist\n let styleRule = ''\n if (styleInner.includes('@media')) {\n // combine\n styleRule = styleInner.replace('{', ` and ${mediaQuery} {`)\n } else {\n styleRule = `@media ${mediaQuery} { ${precendencePrefix} ${styleInner} }`\n }\n return {\n ...style,\n identifier,\n className,\n rules: [styleRule],\n }\n })\n if (shouldPrintDebug) {\n // prettier-ignore\n console.log(' media styles:', importance, singleMediaStyles.map(x => x.identifier).join(', '))\n }\n // add to output\n mediaStyles = [...mediaStyles, ...singleMediaStyles]\n }\n // filter out\n ternary.remove()\n return { mediaStyles, ternaryWithoutMedia: mt.ternaryWithoutMedia }\n}\n\nfunction getMediaQueryTernary(\n ternary: Ternary,\n jsxPath: NodePath<t.JSXElement>,\n sourcePath: string\n): null | {\n key: string\n bindingName: string\n ternaryWithoutMedia: Ternary | null\n} {\n // this handles unwrapping logical && media query ternarys\n // first, unwrap if it has media logicalExpression\n if (t.isLogicalExpression(ternary.test) && ternary.test.operator === '&&') {\n // *should* be normalized to always be on left side, TODO verify\n const mediaLeft = getMediaInfoFromExpression(\n ternary.test.left,\n jsxPath,\n sourcePath,\n ternary.inlineMediaQuery\n )\n if (mediaLeft) {\n return {\n ...mediaLeft,\n ternaryWithoutMedia: {\n ...ternary,\n test: ternary.test.right,\n },\n }\n }\n }\n // const media = useMedia()\n // ... media.sm\n const result = getMediaInfoFromExpression(\n ternary.test,\n jsxPath,\n sourcePath,\n ternary.inlineMediaQuery\n )\n if (result) {\n return {\n ...result,\n ternaryWithoutMedia: null,\n }\n }\n return null\n}\n\nfunction getMediaInfoFromExpression(\n test: t.Expression,\n jsxPath: NodePath<t.JSXElement>,\n sourcePath: string,\n inlineMediaQuery?: string\n) {\n if (inlineMediaQuery) {\n return {\n key: inlineMediaQuery,\n bindingName: inlineMediaQuery,\n }\n }\n if (t.isMemberExpression(test) && t.isIdentifier(test.object) && t.isIdentifier(test.property)) {\n const name = test.object['name']\n const key = test.property['name']\n const bindings = jsxPath.scope.getAllBindings()\n const binding = bindings[name]\n if (!binding) return false\n const bindingNode = binding.path?.node\n if (!t.isVariableDeclarator(bindingNode) || !bindingNode.init) return false\n if (!isValidMediaCall(jsxPath, bindingNode.init, sourcePath)) return false\n return { key, bindingName: name }\n }\n if (t.isIdentifier(test)) {\n const key = test.name\n const node = jsxPath.scope.getBinding(test.name)?.path?.node\n if (!t.isVariableDeclarator(node)) return false\n if (!node.init || !isValidMediaCall(jsxPath, node.init, sourcePath)) return false\n return { key, bindingName: key }\n }\n return null\n}\n\nexport function isValidMediaCall(\n jsxPath: NodePath<t.JSXElement>,\n init: t.Expression,\n sourcePath: string\n) {\n if (!t.isCallExpression(init)) return false\n if (!t.isIdentifier(init.callee)) return false\n // TODO could support renaming useMedia by looking up import first\n if (init.callee.name !== 'useMedia') return false\n const bindings = jsxPath.scope.getAllBindings()\n const mediaBinding = bindings['useMedia']\n if (!mediaBinding) return false\n const useMediaImport = mediaBinding.path.parent\n if (!t.isImportDeclaration(useMediaImport)) return false\n if (useMediaImport.source.value !== 'tamagui') {\n if (!isInsideTamagui(sourcePath)) {\n return false\n }\n }\n return true\n}\n"],
|
|
5
|
-
"mappings": "
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,QAAmB;AAEnB,uBAAqD;AAGrD,uBAA0B;AAE1B,4BAA2C;AAEpC,2BACL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S,aAAO;AACrB,UAAM,cAAc,cAAQ,SAAR,mBAAc;AAClC,QAAI,CAAC,EAAE,qBAAqB,gBAAgB,CAAC,YAAY;AAAM,aAAO;AACtE,QAAI,CAAC,iBAAiB,SAAS,YAAY,MAAM;AAAa,aAAO;AACrE,WAAO,EAAE,KAAK,aAAa;AAAA;AAE7B,MAAI,EAAE,aAAa,OAAO;AACxB,UAAM,MAAM,KAAK;AACjB,UAAM,OAAO,oBAAQ,MAAM,WAAW,KAAK,UAA9B,mBAAqC,SAArC,mBAA2C;AACxD,QAAI,CAAC,EAAE,qBAAqB;AAAO,aAAO;AAC1C,QAAI,CAAC,KAAK,QAAQ,CAAC,iBAAiB,SAAS,KAAK,MAAM;AAAa,aAAO;AAC5E,WAAO,EAAE,KAAK,aAAa;AAAA;AAE7B,SAAO;AAAA;AA9BA;AAiCF,0BACL,SACA,MACA,YACA;AACA,MAAI,CAAC,EAAE,iBAAiB;AAAO,WAAO;AACtC,MAAI,CAAC,EAAE,aAAa,KAAK;AAAS,WAAO;AAEzC,MAAI,KAAK,OAAO,SAAS;AAAY,WAAO;AAC5C,QAAM,WAAW,QAAQ,MAAM;AAC/B,QAAM,eAAe,SAAS;AAC9B,MAAI,CAAC;AAAc,WAAO;AAC1B,QAAM,iBAAiB,aAAa,KAAK;AACzC,MAAI,CAAC,EAAE,oBAAoB;AAAiB,WAAO;AACnD,MAAI,eAAe,OAAO,UAAU,WAAW;AAC7C,QAAI,CAAC,2CAAgB,aAAa;AAChC,aAAO;AAAA;AAAA;AAGX,SAAO;AAAA;AAnBO;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -24,42 +24,46 @@ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
|
24
24
|
var __markAsModule = (target) => __defProp(target, "__esModule", { value: true });
|
|
25
25
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
26
26
|
var __export = (target, all) => {
|
|
27
|
-
__markAsModule(target);
|
|
28
27
|
for (var name in all)
|
|
29
28
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
30
29
|
};
|
|
31
|
-
var __reExport = (target, module2, desc) => {
|
|
30
|
+
var __reExport = (target, module2, copyDefault, desc) => {
|
|
32
31
|
if (module2 && typeof module2 === "object" || typeof module2 === "function") {
|
|
33
32
|
for (let key of __getOwnPropNames(module2))
|
|
34
|
-
if (!__hasOwnProp.call(target, key) && key !== "default")
|
|
33
|
+
if (!__hasOwnProp.call(target, key) && (copyDefault || key !== "default"))
|
|
35
34
|
__defProp(target, key, { get: () => module2[key], enumerable: !(desc = __getOwnPropDesc(module2, key)) || desc.enumerable });
|
|
36
35
|
}
|
|
37
36
|
return target;
|
|
38
37
|
};
|
|
39
|
-
var
|
|
40
|
-
return __reExport(__markAsModule(__defProp(module2 != null ? __create(__getProtoOf(module2)) : {}, "default",
|
|
38
|
+
var __toESM = (module2, isNodeMode) => {
|
|
39
|
+
return __reExport(__markAsModule(__defProp(module2 != null ? __create(__getProtoOf(module2)) : {}, "default", !isNodeMode && module2 && module2.__esModule ? { get: () => module2.default, enumerable: true } : { value: module2, enumerable: true })), module2);
|
|
41
40
|
};
|
|
42
|
-
|
|
43
|
-
|
|
41
|
+
var __toCommonJS = /* @__PURE__ */ ((cache) => {
|
|
42
|
+
return (module2, temp) => {
|
|
43
|
+
return cache && cache.get(module2) || (temp = __reExport(__markAsModule({}), module2, 1), cache && cache.set(module2, temp), temp);
|
|
44
|
+
};
|
|
45
|
+
})(typeof WeakMap !== "undefined" ? /* @__PURE__ */ new WeakMap() : 0);
|
|
46
|
+
var extractToClassNames_exports = {};
|
|
47
|
+
__export(extractToClassNames_exports, {
|
|
44
48
|
extractToClassNames: () => extractToClassNames
|
|
45
49
|
});
|
|
46
|
-
var path =
|
|
47
|
-
var import_path =
|
|
48
|
-
var util =
|
|
49
|
-
var import_generator =
|
|
50
|
-
var t =
|
|
51
|
-
var import_core_node =
|
|
52
|
-
var import_helpers =
|
|
53
|
-
var import_invariant =
|
|
54
|
-
var import_loader_utils =
|
|
55
|
-
var
|
|
56
|
-
var
|
|
57
|
-
var
|
|
58
|
-
var
|
|
59
|
-
var
|
|
60
|
-
var
|
|
61
|
-
var
|
|
62
|
-
|
|
50
|
+
var path = __toESM(require("path"));
|
|
51
|
+
var import_path = require("path");
|
|
52
|
+
var util = __toESM(require("util"));
|
|
53
|
+
var import_generator = __toESM(require("@babel/generator"));
|
|
54
|
+
var t = __toESM(require("@babel/types"));
|
|
55
|
+
var import_core_node = require("@tamagui/core-node");
|
|
56
|
+
var import_helpers = require("@tamagui/helpers");
|
|
57
|
+
var import_invariant = __toESM(require("invariant"));
|
|
58
|
+
var import_loader_utils = require("loader-utils");
|
|
59
|
+
var import_constants = require("../constants");
|
|
60
|
+
var import_babelParse = require("./babelParse");
|
|
61
|
+
var import_buildClassName = require("./buildClassName");
|
|
62
|
+
var import_ensureImportingConcat = require("./ensureImportingConcat");
|
|
63
|
+
var import_extractHelpers = require("./extractHelpers");
|
|
64
|
+
var import_extractMediaStyle = require("./extractMediaStyle");
|
|
65
|
+
var import_hoistClassNames = require("./hoistClassNames");
|
|
66
|
+
var import_logLines = require("./logLines");
|
|
63
67
|
const mergeStyleGroups = {
|
|
64
68
|
shadowOpacity: true,
|
|
65
69
|
shadowRadius: true,
|
|
@@ -90,7 +94,7 @@ function extractToClassNames({
|
|
|
90
94
|
console.error("babel parse error:", sourcePath);
|
|
91
95
|
throw err;
|
|
92
96
|
}
|
|
93
|
-
const cssMap = new Map();
|
|
97
|
+
const cssMap = /* @__PURE__ */ new Map();
|
|
94
98
|
const existingHoists = {};
|
|
95
99
|
const res = extractor.parse(ast, __spreadProps(__spreadValues({
|
|
96
100
|
sourcePath,
|
|
@@ -208,7 +212,7 @@ function extractToClassNames({
|
|
|
208
212
|
if (nameExpr && !t.isIdentifier(nameExpr)) {
|
|
209
213
|
(0, import_ensureImportingConcat.ensureImportingConcat)(programPath);
|
|
210
214
|
const simpleSpreads = attrs.filter((x) => t.isJSXSpreadAttribute(x.value) && (0, import_extractHelpers.isSimpleSpread)(x.value));
|
|
211
|
-
expr = t.callExpression(t.identifier(CONCAT_CLASSNAME_IMPORT), [
|
|
215
|
+
expr = t.callExpression(t.identifier(import_constants.CONCAT_CLASSNAME_IMPORT), [
|
|
212
216
|
expr,
|
|
213
217
|
...simpleSpreads.map((val) => val.value["argument"])
|
|
214
218
|
]);
|
|
@@ -276,4 +280,5 @@ function extractToClassNames({
|
|
|
276
280
|
};
|
|
277
281
|
}
|
|
278
282
|
__name(extractToClassNames, "extractToClassNames");
|
|
283
|
+
module.exports = __toCommonJS(extractToClassNames_exports);
|
|
279
284
|
//# sourceMappingURL=extractToClassNames.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/extractor/extractToClassNames.ts"],
|
|
4
|
-
"sourcesContent": ["import * as path from 'path'\nimport { basename } from 'path'\nimport * as util from 'util'\n\nimport generate from '@babel/generator'\nimport * as t from '@babel/types'\nimport { getStylesAtomic } from '@tamagui/core-node'\nimport { concatClassName } from '@tamagui/helpers'\nimport invariant from 'invariant'\nimport { getRemainingRequest } from 'loader-utils'\nimport { ViewStyle } from 'react-native'\n\nimport { ClassNameObject, StyleObject, TamaguiOptions } from '../types'\nimport { babelParse } from './babelParse'\nimport { buildClassName } from './buildClassName'\nimport { Extractor } from './createExtractor'\nimport { ensureImportingConcat } from './ensureImportingConcat'\nimport { isSimpleSpread } from './extractHelpers'\nimport { extractMediaStyle } from './extractMediaStyle'\nimport { hoistClassNames } from './hoistClassNames'\nimport { logLines } from './logLines'\n\nexport const CONCAT_CLASSNAME_IMPORT = 'concatClassName'\n\nconst mergeStyleGroups = {\n shadowOpacity: true,\n shadowRadius: true,\n shadowColor: true,\n shadowOffset: true,\n}\n\nexport function extractToClassNames({\n loader,\n extractor,\n source,\n sourcePath,\n options,\n shouldPrintDebug,\n threaded,\n cssPath,\n}: {\n loader: any\n extractor: Extractor\n source: string | Buffer\n sourcePath: string\n options: TamaguiOptions\n shouldPrintDebug: boolean\n cssPath: string\n threaded?: boolean\n}): null | {\n js: string | Buffer\n styles: string\n stylesPath?: string\n ast: t.File\n map: any // RawSourceMap from 'source-map'\n} {\n if (typeof source !== 'string') {\n throw new Error('`source` must be a string of javascript')\n }\n invariant(\n typeof sourcePath === 'string' && path.isAbsolute(sourcePath),\n '`sourcePath` must be an absolute path to a .js file'\n )\n\n const shouldLogTiming = options.logTimings ?? true\n const start = Date.now()\n const mem = shouldLogTiming ? process.memoryUsage() : null\n\n // Using a map for (officially supported) guaranteed insertion order\n let ast: t.File\n\n try {\n // @ts-ignore\n ast = babelParse(source)\n } catch (err) {\n console.error('babel parse error:', sourcePath)\n throw err\n }\n\n const cssMap = new Map<string, { css: string; commentTexts: string[] }>()\n const existingHoists: { [key: string]: t.Identifier } = {}\n\n const res = extractor.parse(ast, {\n sourcePath,\n shouldPrintDebug,\n ...options,\n getFlattenedNode: ({ tag }) => tag,\n onExtractTag: ({\n attrs,\n node,\n attemptEval,\n jsxPath,\n originalNodeName,\n filePath,\n lineNumbers,\n programPath,\n }) => {\n let finalClassNames: ClassNameObject[] = []\n let finalAttrs: (t.JSXAttribute | t.JSXSpreadAttribute)[] = []\n let finalStyles: StyleObject[] = []\n\n const viewStyles = {}\n for (const attr of attrs) {\n if (attr.type === 'style') {\n Object.assign(viewStyles, attr.value)\n }\n }\n\n const ensureNeededPrevStyle = (style: ViewStyle) => {\n // ensure all group keys are merged\n const keys = Object.keys(style)\n if (!keys.some((key) => mergeStyleGroups[key])) {\n return style\n }\n for (const k in mergeStyleGroups) {\n if (k in viewStyles) {\n style[k] = style[k] ?? viewStyles[k]\n }\n }\n return style\n }\n\n const addStyles = (style: ViewStyle | null) => {\n if (!style) return []\n const styleWithPrev = ensureNeededPrevStyle(style)\n const res = getStylesAtomic(styleWithPrev)\n if (res.length) {\n finalStyles = [...finalStyles, ...res]\n }\n return res\n }\n\n // 1 to start above any :hover styles\n let lastMediaImportance = 1\n for (const attr of attrs) {\n switch (attr.type) {\n case 'style':\n const styles = addStyles(attr.value)\n const newClassNames = concatClassName(styles.map((x) => x.identifier).join(' '))\n // prettier-ignore\n const existing = finalClassNames.find((x) => x.type == 'StringLiteral') as t.StringLiteral | null\n if (existing) {\n existing.value = `${existing.value} ${newClassNames}`\n } else {\n finalClassNames = [...finalClassNames, t.stringLiteral(newClassNames)]\n }\n if (shouldPrintDebug) {\n // prettier-ignore\n console.log(' classnames (after)\\n', logLines(finalClassNames.map(x => x['value']).join(' ')))\n }\n break\n case 'attr':\n const val = attr.value\n if (t.isJSXSpreadAttribute(val)) {\n if (isSimpleSpread(val)) {\n finalClassNames.push(\n t.logicalExpression(\n '&&',\n val.argument,\n t.memberExpression(val.argument, t.identifier('className'))\n )\n )\n }\n } else if (val.name.name === 'className') {\n const value = val.value\n if (value) {\n try {\n const evaluatedValue = attemptEval(value)\n finalClassNames.push(t.stringLiteral(evaluatedValue))\n } catch (e) {\n finalClassNames.push(value['expression'])\n }\n }\n continue\n }\n finalAttrs.push(val)\n break\n case 'ternary':\n const mediaExtraction = extractMediaStyle(\n attr.value,\n jsxPath,\n extractor.getTamagui(),\n sourcePath,\n lastMediaImportance,\n shouldPrintDebug\n )\n if (mediaExtraction) {\n lastMediaImportance++\n finalStyles = [...finalStyles, ...mediaExtraction.mediaStyles]\n finalClassNames = [\n ...finalClassNames,\n ...mediaExtraction.mediaStyles.map((x) => t.stringLiteral(x.identifier)),\n ]\n if (!mediaExtraction.ternaryWithoutMedia) {\n continue\n }\n }\n const ternary = mediaExtraction?.ternaryWithoutMedia || attr.value\n const consInfo = addStyles(ternary.consequent)\n const altInfo = addStyles(ternary.alternate)\n const cCN = consInfo.map((x) => x.identifier).join(' ')\n const aCN = altInfo.map((x) => x.identifier).join(' ')\n if (consInfo.length && altInfo.length) {\n finalClassNames.push(\n t.conditionalExpression(ternary.test, t.stringLiteral(cCN), t.stringLiteral(aCN))\n )\n } else {\n finalClassNames.push(\n t.conditionalExpression(\n ternary.test,\n t.stringLiteral(' ' + cCN),\n t.stringLiteral(' ' + aCN)\n )\n )\n }\n break\n }\n }\n\n node.attributes = finalAttrs\n\n if (finalClassNames.length) {\n // inserts the _cn variable and uses it for className\n const names = buildClassName(finalClassNames)\n const nameExpr = names ? hoistClassNames(jsxPath, existingHoists, names) : null\n let expr = nameExpr\n\n // if has some spreads, use concat helper\n if (nameExpr && !t.isIdentifier(nameExpr)) {\n ensureImportingConcat(programPath)\n const simpleSpreads = attrs.filter(\n (x) => t.isJSXSpreadAttribute(x.value) && isSimpleSpread(x.value)\n )\n expr = t.callExpression(t.identifier(CONCAT_CLASSNAME_IMPORT), [\n expr,\n ...simpleSpreads.map((val) => val.value['argument']),\n ])\n }\n\n node.attributes.push(\n t.jsxAttribute(t.jsxIdentifier('className'), t.jsxExpressionContainer(expr))\n )\n }\n\n const comment = util.format('/* %s:%s (%s) */', filePath, lineNumbers, originalNodeName)\n\n for (const { className, rules } of finalStyles) {\n if (cssMap.has(className)) {\n if (comment) {\n const val = cssMap.get(className)!\n val.commentTexts.push(comment)\n cssMap.set(className, val)\n }\n } else if (rules.length) {\n if (rules.length > 1) {\n console.log(' rules error', { rules })\n throw new Error(`Shouldn't have more than one rule`)\n }\n cssMap.set(className, {\n css: rules[0],\n commentTexts: [comment],\n })\n }\n }\n },\n })\n\n if (!res || (!res.modified && !res.optimized && !res.flattened)) {\n if (shouldPrintDebug) {\n console.log('no res or none modified', res)\n }\n return null\n }\n\n const styles = Array.from(cssMap.values())\n .map((x) => x.css)\n .join('\\n')\n .trim()\n\n if (styles) {\n const cssQuery = threaded\n ? `cssData=${Buffer.from(styles).toString('base64')}`\n : `cssPath=${cssPath}`\n const remReq = getRemainingRequest(loader)\n const importPath = `${cssPath}!=!tamagui-loader?${cssQuery}!${remReq}`\n ast.program.body.unshift(t.importDeclaration([], t.stringLiteral(importPath)))\n }\n\n const result = generate(\n ast,\n {\n concise: false,\n filename: sourcePath,\n retainLines: false,\n sourceFileName: sourcePath,\n sourceMaps: true,\n },\n source\n )\n\n if (shouldPrintDebug) {\n console.log(\n '\\n -------- output code ------- \\n\\n',\n result.code\n .split('\\n')\n .filter((x) => !x.startsWith('//'))\n .join('\\n')\n )\n console.log('\\n -------- output style -------- \\n\\n', styles)\n }\n\n if (shouldLogTiming) {\n const memUsed = mem\n ? Math.round(((process.memoryUsage().heapUsed - mem.heapUsed) / 1024 / 1204) * 10) / 10\n : 0\n const timing = `${Date.now() - start}`.padStart(3)\n const path = basename(sourcePath).padStart(40)\n const numOptimized = `${res.optimized}`.padStart(4)\n const memory = memUsed > 10 ? `used ${memUsed}MB` : ''\n console.log(\n ` \uD83E\uDD5A ${path} ${timing}ms \u05C1\u00B7 ${numOptimized} optimized \u00B7 ${res.flattened} flattened ${memory}`\n )\n }\n\n return {\n ast,\n styles,\n js: result.code,\n map: result.map,\n }\n}\n"],
|
|
5
|
-
"mappings": "
|
|
4
|
+
"sourcesContent": ["import * as path from 'path'\nimport { basename } from 'path'\nimport * as util from 'util'\n\nimport generate from '@babel/generator'\nimport * as t from '@babel/types'\nimport { getStylesAtomic } from '@tamagui/core-node'\nimport { concatClassName } from '@tamagui/helpers'\nimport invariant from 'invariant'\nimport { getRemainingRequest } from 'loader-utils'\nimport { ViewStyle } from 'react-native'\n\nimport { CONCAT_CLASSNAME_IMPORT } from '../constants'\nimport { ClassNameObject, StyleObject, TamaguiOptions } from '../types'\nimport { babelParse } from './babelParse'\nimport { buildClassName } from './buildClassName'\nimport { Extractor } from './createExtractor'\nimport { ensureImportingConcat } from './ensureImportingConcat'\nimport { isSimpleSpread } from './extractHelpers'\nimport { extractMediaStyle } from './extractMediaStyle'\nimport { hoistClassNames } from './hoistClassNames'\nimport { logLines } from './logLines'\n\nconst mergeStyleGroups = {\n shadowOpacity: true,\n shadowRadius: true,\n shadowColor: true,\n shadowOffset: true,\n}\n\nexport function extractToClassNames({\n loader,\n extractor,\n source,\n sourcePath,\n options,\n shouldPrintDebug,\n threaded,\n cssPath,\n}: {\n loader: any\n extractor: Extractor\n source: string | Buffer\n sourcePath: string\n options: TamaguiOptions\n shouldPrintDebug: boolean\n cssPath: string\n threaded?: boolean\n}): null | {\n js: string | Buffer\n styles: string\n stylesPath?: string\n ast: t.File\n map: any // RawSourceMap from 'source-map'\n} {\n if (typeof source !== 'string') {\n throw new Error('`source` must be a string of javascript')\n }\n invariant(\n typeof sourcePath === 'string' && path.isAbsolute(sourcePath),\n '`sourcePath` must be an absolute path to a .js file'\n )\n\n const shouldLogTiming = options.logTimings ?? true\n const start = Date.now()\n const mem = shouldLogTiming ? process.memoryUsage() : null\n\n // Using a map for (officially supported) guaranteed insertion order\n let ast: t.File\n\n try {\n // @ts-ignore\n ast = babelParse(source)\n } catch (err) {\n console.error('babel parse error:', sourcePath)\n throw err\n }\n\n const cssMap = new Map<string, { css: string; commentTexts: string[] }>()\n const existingHoists: { [key: string]: t.Identifier } = {}\n\n const res = extractor.parse(ast, {\n sourcePath,\n shouldPrintDebug,\n ...options,\n getFlattenedNode: ({ tag }) => tag,\n onExtractTag: ({\n attrs,\n node,\n attemptEval,\n jsxPath,\n originalNodeName,\n filePath,\n lineNumbers,\n programPath,\n }) => {\n let finalClassNames: ClassNameObject[] = []\n let finalAttrs: (t.JSXAttribute | t.JSXSpreadAttribute)[] = []\n let finalStyles: StyleObject[] = []\n\n const viewStyles = {}\n for (const attr of attrs) {\n if (attr.type === 'style') {\n Object.assign(viewStyles, attr.value)\n }\n }\n\n const ensureNeededPrevStyle = (style: ViewStyle) => {\n // ensure all group keys are merged\n const keys = Object.keys(style)\n if (!keys.some((key) => mergeStyleGroups[key])) {\n return style\n }\n for (const k in mergeStyleGroups) {\n if (k in viewStyles) {\n style[k] = style[k] ?? viewStyles[k]\n }\n }\n return style\n }\n\n const addStyles = (style: ViewStyle | null) => {\n if (!style) return []\n const styleWithPrev = ensureNeededPrevStyle(style)\n const res = getStylesAtomic(styleWithPrev)\n if (res.length) {\n finalStyles = [...finalStyles, ...res]\n }\n return res\n }\n\n // 1 to start above any :hover styles\n let lastMediaImportance = 1\n for (const attr of attrs) {\n switch (attr.type) {\n case 'style':\n const styles = addStyles(attr.value)\n const newClassNames = concatClassName(styles.map((x) => x.identifier).join(' '))\n // prettier-ignore\n const existing = finalClassNames.find((x) => x.type == 'StringLiteral') as t.StringLiteral | null\n if (existing) {\n existing.value = `${existing.value} ${newClassNames}`\n } else {\n finalClassNames = [...finalClassNames, t.stringLiteral(newClassNames)]\n }\n if (shouldPrintDebug) {\n // prettier-ignore\n console.log(' classnames (after)\\n', logLines(finalClassNames.map(x => x['value']).join(' ')))\n }\n break\n case 'attr':\n const val = attr.value\n if (t.isJSXSpreadAttribute(val)) {\n if (isSimpleSpread(val)) {\n finalClassNames.push(\n t.logicalExpression(\n '&&',\n val.argument,\n t.memberExpression(val.argument, t.identifier('className'))\n )\n )\n }\n } else if (val.name.name === 'className') {\n const value = val.value\n if (value) {\n try {\n const evaluatedValue = attemptEval(value)\n finalClassNames.push(t.stringLiteral(evaluatedValue))\n } catch (e) {\n finalClassNames.push(value['expression'])\n }\n }\n continue\n }\n finalAttrs.push(val)\n break\n case 'ternary':\n const mediaExtraction = extractMediaStyle(\n attr.value,\n jsxPath,\n extractor.getTamagui(),\n sourcePath,\n lastMediaImportance,\n shouldPrintDebug\n )\n if (mediaExtraction) {\n lastMediaImportance++\n finalStyles = [...finalStyles, ...mediaExtraction.mediaStyles]\n finalClassNames = [\n ...finalClassNames,\n ...mediaExtraction.mediaStyles.map((x) => t.stringLiteral(x.identifier)),\n ]\n if (!mediaExtraction.ternaryWithoutMedia) {\n continue\n }\n }\n const ternary = mediaExtraction?.ternaryWithoutMedia || attr.value\n const consInfo = addStyles(ternary.consequent)\n const altInfo = addStyles(ternary.alternate)\n const cCN = consInfo.map((x) => x.identifier).join(' ')\n const aCN = altInfo.map((x) => x.identifier).join(' ')\n if (consInfo.length && altInfo.length) {\n finalClassNames.push(\n t.conditionalExpression(ternary.test, t.stringLiteral(cCN), t.stringLiteral(aCN))\n )\n } else {\n finalClassNames.push(\n t.conditionalExpression(\n ternary.test,\n t.stringLiteral(' ' + cCN),\n t.stringLiteral(' ' + aCN)\n )\n )\n }\n break\n }\n }\n\n node.attributes = finalAttrs\n\n if (finalClassNames.length) {\n // inserts the _cn variable and uses it for className\n const names = buildClassName(finalClassNames)\n const nameExpr = names ? hoistClassNames(jsxPath, existingHoists, names) : null\n let expr = nameExpr\n\n // if has some spreads, use concat helper\n if (nameExpr && !t.isIdentifier(nameExpr)) {\n ensureImportingConcat(programPath)\n const simpleSpreads = attrs.filter(\n (x) => t.isJSXSpreadAttribute(x.value) && isSimpleSpread(x.value)\n )\n expr = t.callExpression(t.identifier(CONCAT_CLASSNAME_IMPORT), [\n expr,\n ...simpleSpreads.map((val) => val.value['argument']),\n ])\n }\n\n node.attributes.push(\n t.jsxAttribute(t.jsxIdentifier('className'), t.jsxExpressionContainer(expr))\n )\n }\n\n const comment = util.format('/* %s:%s (%s) */', filePath, lineNumbers, originalNodeName)\n\n for (const { className, rules } of finalStyles) {\n if (cssMap.has(className)) {\n if (comment) {\n const val = cssMap.get(className)!\n val.commentTexts.push(comment)\n cssMap.set(className, val)\n }\n } else if (rules.length) {\n if (rules.length > 1) {\n console.log(' rules error', { rules })\n throw new Error(`Shouldn't have more than one rule`)\n }\n cssMap.set(className, {\n css: rules[0],\n commentTexts: [comment],\n })\n }\n }\n },\n })\n\n if (!res || (!res.modified && !res.optimized && !res.flattened)) {\n if (shouldPrintDebug) {\n console.log('no res or none modified', res)\n }\n return null\n }\n\n const styles = Array.from(cssMap.values())\n .map((x) => x.css)\n .join('\\n')\n .trim()\n\n if (styles) {\n const cssQuery = threaded\n ? `cssData=${Buffer.from(styles).toString('base64')}`\n : `cssPath=${cssPath}`\n const remReq = getRemainingRequest(loader)\n const importPath = `${cssPath}!=!tamagui-loader?${cssQuery}!${remReq}`\n ast.program.body.unshift(t.importDeclaration([], t.stringLiteral(importPath)))\n }\n\n const result = generate(\n ast,\n {\n concise: false,\n filename: sourcePath,\n retainLines: false,\n sourceFileName: sourcePath,\n sourceMaps: true,\n },\n source\n )\n\n if (shouldPrintDebug) {\n console.log(\n '\\n -------- output code ------- \\n\\n',\n result.code\n .split('\\n')\n .filter((x) => !x.startsWith('//'))\n .join('\\n')\n )\n console.log('\\n -------- output style -------- \\n\\n', styles)\n }\n\n if (shouldLogTiming) {\n const memUsed = mem\n ? Math.round(((process.memoryUsage().heapUsed - mem.heapUsed) / 1024 / 1204) * 10) / 10\n : 0\n const timing = `${Date.now() - start}`.padStart(3)\n const path = basename(sourcePath).padStart(40)\n const numOptimized = `${res.optimized}`.padStart(4)\n const memory = memUsed > 10 ? `used ${memUsed}MB` : ''\n console.log(\n ` \uD83E\uDD5A ${path} ${timing}ms \u05C1\u00B7 ${numOptimized} optimized \u00B7 ${res.flattened} flattened ${memory}`\n )\n }\n\n return {\n ast,\n styles,\n js: result.code,\n map: result.map,\n }\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA,WAAsB;AACtB,kBAAyB;AACzB,WAAsB;AAEtB,uBAAqB;AACrB,QAAmB;AACnB,uBAAgC;AAChC,qBAAgC;AAChC,uBAAsB;AACtB,0BAAoC;AAGpC,uBAAwC;AAExC,wBAA2B;AAC3B,4BAA+B;AAE/B,mCAAsC;AACtC,4BAA+B;AAC/B,+BAAkC;AAClC,6BAAgC;AAChC,sBAAyB;AAEzB,MAAM,mBAAmB;AAAA,EACvB,eAAe;AAAA,EACf,cAAc;AAAA,EACd,aAAa;AAAA,EACb,cAAc;AAAA;AAGT,6BAA6B;AAAA,EAClC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,GAgBA;AACA,MAAI,OAAO,WAAW,UAAU;AAC9B,UAAM,IAAI,MAAM;AAAA;AAElB,gCACE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I,uBAAuB;AAAA;AAI1F,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA,IAAI,OAAO;AAAA,IACX,KAAK,OAAO;AAAA;AAAA;AAzSA;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,12 +1,28 @@
|
|
|
1
1
|
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
2
5
|
var __markAsModule = (target) => __defProp(target, "__esModule", { value: true });
|
|
3
6
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
4
7
|
var __export = (target, all) => {
|
|
5
|
-
__markAsModule(target);
|
|
6
8
|
for (var name in all)
|
|
7
9
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
10
|
};
|
|
9
|
-
|
|
11
|
+
var __reExport = (target, module2, copyDefault, desc) => {
|
|
12
|
+
if (module2 && typeof module2 === "object" || typeof module2 === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(module2))
|
|
14
|
+
if (!__hasOwnProp.call(target, key) && (copyDefault || key !== "default"))
|
|
15
|
+
__defProp(target, key, { get: () => module2[key], enumerable: !(desc = __getOwnPropDesc(module2, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return target;
|
|
18
|
+
};
|
|
19
|
+
var __toCommonJS = /* @__PURE__ */ ((cache) => {
|
|
20
|
+
return (module2, temp) => {
|
|
21
|
+
return cache && cache.get(module2) || (temp = __reExport(__markAsModule({}), module2, 1), cache && cache.set(module2, temp), temp);
|
|
22
|
+
};
|
|
23
|
+
})(typeof WeakMap !== "undefined" ? /* @__PURE__ */ new WeakMap() : 0);
|
|
24
|
+
var findTopmostFunction_exports = {};
|
|
25
|
+
__export(findTopmostFunction_exports, {
|
|
10
26
|
findTopmostFunction: () => findTopmostFunction
|
|
11
27
|
});
|
|
12
28
|
function findTopmostFunction(jsxPath) {
|
|
@@ -26,4 +42,5 @@ function findTopmostFunction(jsxPath) {
|
|
|
26
42
|
return compFn;
|
|
27
43
|
}
|
|
28
44
|
__name(findTopmostFunction, "findTopmostFunction");
|
|
45
|
+
module.exports = __toCommonJS(findTopmostFunction_exports);
|
|
29
46
|
//# sourceMappingURL=findTopmostFunction.js.map
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/extractor/findTopmostFunction.ts"],
|
|
4
4
|
"sourcesContent": ["import { NodePath } from '@babel/traverse'\nimport * as t from '@babel/types'\n\nexport function findTopmostFunction(jsxPath: NodePath<t.JSXElement>) {\n // get topmost fn\n const isFunction = (path: NodePath<any>) =>\n path.isArrowFunctionExpression() || path.isFunctionDeclaration() || path.isFunctionExpression()\n let compFn: NodePath<any> | null = jsxPath.findParent(isFunction)\n while (compFn) {\n const parent = compFn.findParent(isFunction)\n if (parent) {\n compFn = parent\n } else {\n break\n }\n }\n if (!compFn) {\n // console.error(`Couldn't find a topmost function for media query extraction`)\n return null\n }\n return compFn\n}\n"],
|
|
5
|
-
"mappings": "
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAGO,6BAA6B,SAAiC;AAEnE,QAAM,aAAa,wBAAC,SAClB,KAAK,+BAA+B,KAAK,2BAA2B,KAAK,wBADxD;AAEnB,MAAI,SAA+B,QAAQ,WAAW;AACtD,SAAO,QAAQ;AACb,UAAM,SAAS,OAAO,WAAW;AACjC,QAAI,QAAQ;AACV,eAAS;AAAA,WACJ;AACL;AAAA;AAAA;AAGJ,MAAI,CAAC,QAAQ;AAEX,WAAO;AAAA;AAET,SAAO;AAAA;AAjBO;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -7,26 +7,31 @@ var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
|
7
7
|
var __markAsModule = (target) => __defProp(target, "__esModule", { value: true });
|
|
8
8
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
9
9
|
var __export = (target, all) => {
|
|
10
|
-
__markAsModule(target);
|
|
11
10
|
for (var name in all)
|
|
12
11
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
13
12
|
};
|
|
14
|
-
var __reExport = (target, module2, desc) => {
|
|
13
|
+
var __reExport = (target, module2, copyDefault, desc) => {
|
|
15
14
|
if (module2 && typeof module2 === "object" || typeof module2 === "function") {
|
|
16
15
|
for (let key of __getOwnPropNames(module2))
|
|
17
|
-
if (!__hasOwnProp.call(target, key) && key !== "default")
|
|
16
|
+
if (!__hasOwnProp.call(target, key) && (copyDefault || key !== "default"))
|
|
18
17
|
__defProp(target, key, { get: () => module2[key], enumerable: !(desc = __getOwnPropDesc(module2, key)) || desc.enumerable });
|
|
19
18
|
}
|
|
20
19
|
return target;
|
|
21
20
|
};
|
|
22
|
-
var
|
|
23
|
-
return __reExport(__markAsModule(__defProp(module2 != null ? __create(__getProtoOf(module2)) : {}, "default",
|
|
21
|
+
var __toESM = (module2, isNodeMode) => {
|
|
22
|
+
return __reExport(__markAsModule(__defProp(module2 != null ? __create(__getProtoOf(module2)) : {}, "default", !isNodeMode && module2 && module2.__esModule ? { get: () => module2.default, enumerable: true } : { value: module2, enumerable: true })), module2);
|
|
24
23
|
};
|
|
25
|
-
|
|
24
|
+
var __toCommonJS = /* @__PURE__ */ ((cache) => {
|
|
25
|
+
return (module2, temp) => {
|
|
26
|
+
return cache && cache.get(module2) || (temp = __reExport(__markAsModule({}), module2, 1), cache && cache.set(module2, temp), temp);
|
|
27
|
+
};
|
|
28
|
+
})(typeof WeakMap !== "undefined" ? /* @__PURE__ */ new WeakMap() : 0);
|
|
29
|
+
var generatedUid_exports = {};
|
|
30
|
+
__export(generatedUid_exports, {
|
|
26
31
|
generateUid: () => generateUid
|
|
27
32
|
});
|
|
28
|
-
var t =
|
|
29
|
-
var import_invariant =
|
|
33
|
+
var t = __toESM(require("@babel/types"));
|
|
34
|
+
var import_invariant = __toESM(require("invariant"));
|
|
30
35
|
function generateUid(scope, name) {
|
|
31
36
|
(0, import_invariant.default)(typeof scope === "object", "generateUid expects a scope object as its first parameter");
|
|
32
37
|
(0, import_invariant.default)(typeof name === "string" && name !== "", "generateUid expects a valid name as its second parameter");
|
|
@@ -47,4 +52,5 @@ function generateUid(scope, name) {
|
|
|
47
52
|
return uid;
|
|
48
53
|
}
|
|
49
54
|
__name(generateUid, "generateUid");
|
|
55
|
+
module.exports = __toCommonJS(generatedUid_exports);
|
|
50
56
|
//# sourceMappingURL=generatedUid.js.map
|
|
@@ -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;AAAA;AAAA;AAAA;AAAA,QAAmB;AACnB,uBAAsB;AAQf,qBAAqB,OAAY,MAAsB;AAC5D,gCAAU,OAAO,UAAU,UAAU;AACrC,gCACE,OAAO,SAAS,YAAY,SAAS,IACrC;AAGF,SAAO,EACJ,aAAa,MACb,QAAQ,OAAO,IACf,QAAQ,YAAY;AAEvB,MAAI;AACJ,MAAI,IAAI;AACR,KAAG;AACD,QAAI,IAAI,GAAG;AACT,YAAM,OAAO;AAAA,WACR;AACL,YAAM;AAAA;AAER;AAAA,WAEA,MAAM,SAAS,QACf,MAAM,WAAW,QACjB,MAAM,UAAU,QAChB,MAAM,aAAa;AAGrB,QAAM,UAAU,MAAM;AACtB,UAAQ,WAAW,OAAO;AAC1B,UAAQ,KAAK,OAAO;AAEpB,SAAO;AAAA;AAhCO;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -7,27 +7,32 @@ var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
|
7
7
|
var __markAsModule = (target) => __defProp(target, "__esModule", { value: true });
|
|
8
8
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
9
9
|
var __export = (target, all) => {
|
|
10
|
-
__markAsModule(target);
|
|
11
10
|
for (var name in all)
|
|
12
11
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
13
12
|
};
|
|
14
|
-
var __reExport = (target, module2, desc) => {
|
|
13
|
+
var __reExport = (target, module2, copyDefault, desc) => {
|
|
15
14
|
if (module2 && typeof module2 === "object" || typeof module2 === "function") {
|
|
16
15
|
for (let key of __getOwnPropNames(module2))
|
|
17
|
-
if (!__hasOwnProp.call(target, key) && key !== "default")
|
|
16
|
+
if (!__hasOwnProp.call(target, key) && (copyDefault || key !== "default"))
|
|
18
17
|
__defProp(target, key, { get: () => module2[key], enumerable: !(desc = __getOwnPropDesc(module2, key)) || desc.enumerable });
|
|
19
18
|
}
|
|
20
19
|
return target;
|
|
21
20
|
};
|
|
22
|
-
var
|
|
23
|
-
return __reExport(__markAsModule(__defProp(module2 != null ? __create(__getProtoOf(module2)) : {}, "default",
|
|
21
|
+
var __toESM = (module2, isNodeMode) => {
|
|
22
|
+
return __reExport(__markAsModule(__defProp(module2 != null ? __create(__getProtoOf(module2)) : {}, "default", !isNodeMode && module2 && module2.__esModule ? { get: () => module2.default, enumerable: true } : { value: module2, enumerable: true })), module2);
|
|
24
23
|
};
|
|
25
|
-
|
|
24
|
+
var __toCommonJS = /* @__PURE__ */ ((cache) => {
|
|
25
|
+
return (module2, temp) => {
|
|
26
|
+
return cache && cache.get(module2) || (temp = __reExport(__markAsModule({}), module2, 1), cache && cache.set(module2, temp), temp);
|
|
27
|
+
};
|
|
28
|
+
})(typeof WeakMap !== "undefined" ? /* @__PURE__ */ new WeakMap() : 0);
|
|
29
|
+
var getPropValueFromAttributes_exports = {};
|
|
30
|
+
__export(getPropValueFromAttributes_exports, {
|
|
26
31
|
getPropValueFromAttributes: () => getPropValueFromAttributes
|
|
27
32
|
});
|
|
28
|
-
var import_generator =
|
|
29
|
-
var t =
|
|
30
|
-
var import_accessSafe =
|
|
33
|
+
var import_generator = __toESM(require("@babel/generator"));
|
|
34
|
+
var t = __toESM(require("@babel/types"));
|
|
35
|
+
var import_accessSafe = require("./accessSafe");
|
|
31
36
|
function getPropValueFromAttributes(propName, attrs) {
|
|
32
37
|
let propIndex = -1;
|
|
33
38
|
let jsxAttr = null;
|
|
@@ -68,4 +73,5 @@ function getPropValueFromAttributes(propName, attrs) {
|
|
|
68
73
|
return propValue;
|
|
69
74
|
}
|
|
70
75
|
__name(getPropValueFromAttributes, "getPropValueFromAttributes");
|
|
76
|
+
module.exports = __toCommonJS(getPropValueFromAttributes_exports);
|
|
71
77
|
//# sourceMappingURL=getPropValueFromAttributes.js.map
|
|
@@ -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;AAAA;AAAA;AAAA;AAAA,uBAAqB;AACrB,QAAmB;AAEnB,wBAA2B;AAkBpB,oCACL,UACA,OACqB;AACrB,MAAI,YAAoB;AACxB,MAAI,UAAiC;AACrC,WAAS,MAAM,IAAI,MAAM,MAAM,QAAQ,EAAE,MAAM,OAAO;AACpD,UAAM,OAAO,MAAM;AACnB,QAAI,EAAE,eAAe,SAAS,KAAK,QAAQ,KAAK,KAAK,SAAS,UAAU;AACtE,kBAAY;AACZ,gBAAU;AACV;AAAA;AAAA;AAIJ,MAAI,CAAC,WAAW,QAAQ,SAAS,MAAM;AACrC,WAAO;AAAA;AAGT,MAAI,YAMe,QAAQ;AAE3B,MAAI,EAAE,yBAAyB,YAAY;AACzC,gBAAY,UAAU;AAAA;AAIxB,MAAI,EAAE,qBAAqB,YAAY;AACrC,YAAQ,MAAM;AACd,WAAO;AAAA;AAIT,QAAM,oBAAoB,MACvB,OAGC,CAAC,MAAM,QAAsC;AAC3C,QAAI,EAAE,qBAAqB,OAAO;AAChC,UAAI,EAAE,aAAa,KAAK,aAAa,EAAE,mBAAmB,KAAK,WAAW;AACxE,eAAO,MAAM;AAAA;AAEf,UAAI,EAAE,oBAAoB,KAAK,WAAW;AACxC,eAAO;AAAA;AAET,YAAM,IAAI,MACR,+BAA+B,KAAK,SAAS,UAAU,8BAAS,MAAM;AAAA;AAG1E,WAAO;AAAA,KAGV,IAAI,CAAC,SAAS,KAAK;AAKtB,MAAI,kBAAkB,SAAS,GAAG;AAChC,gBAAY,kBAAkB,OAC5B,CAAC,KAAK,QAAQ,EAAE,kBAAkB,MAAM,kCAAW,KAAK,WAAW,MACnE;AAAA;AAIJ,SAAO;AAAA;AArEO;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -7,25 +7,30 @@ var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
|
7
7
|
var __markAsModule = (target) => __defProp(target, "__esModule", { value: true });
|
|
8
8
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
9
9
|
var __export = (target, all) => {
|
|
10
|
-
__markAsModule(target);
|
|
11
10
|
for (var name in all)
|
|
12
11
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
13
12
|
};
|
|
14
|
-
var __reExport = (target, module2, desc) => {
|
|
13
|
+
var __reExport = (target, module2, copyDefault, desc) => {
|
|
15
14
|
if (module2 && typeof module2 === "object" || typeof module2 === "function") {
|
|
16
15
|
for (let key of __getOwnPropNames(module2))
|
|
17
|
-
if (!__hasOwnProp.call(target, key) && key !== "default")
|
|
16
|
+
if (!__hasOwnProp.call(target, key) && (copyDefault || key !== "default"))
|
|
18
17
|
__defProp(target, key, { get: () => module2[key], enumerable: !(desc = __getOwnPropDesc(module2, key)) || desc.enumerable });
|
|
19
18
|
}
|
|
20
19
|
return target;
|
|
21
20
|
};
|
|
22
|
-
var
|
|
23
|
-
return __reExport(__markAsModule(__defProp(module2 != null ? __create(__getProtoOf(module2)) : {}, "default",
|
|
21
|
+
var __toESM = (module2, isNodeMode) => {
|
|
22
|
+
return __reExport(__markAsModule(__defProp(module2 != null ? __create(__getProtoOf(module2)) : {}, "default", !isNodeMode && module2 && module2.__esModule ? { get: () => module2.default, enumerable: true } : { value: module2, enumerable: true })), module2);
|
|
24
23
|
};
|
|
25
|
-
|
|
24
|
+
var __toCommonJS = /* @__PURE__ */ ((cache) => {
|
|
25
|
+
return (module2, temp) => {
|
|
26
|
+
return cache && cache.get(module2) || (temp = __reExport(__markAsModule({}), module2, 1), cache && cache.set(module2, temp), temp);
|
|
27
|
+
};
|
|
28
|
+
})(typeof WeakMap !== "undefined" ? /* @__PURE__ */ new WeakMap() : 0);
|
|
29
|
+
var getSourceModule_exports = {};
|
|
30
|
+
__export(getSourceModule_exports, {
|
|
26
31
|
getSourceModule: () => getSourceModule
|
|
27
32
|
});
|
|
28
|
-
var t =
|
|
33
|
+
var t = __toESM(require("@babel/types"));
|
|
29
34
|
function getSourceModule(itemName, itemBinding) {
|
|
30
35
|
if (!itemBinding.constant) {
|
|
31
36
|
return null;
|
|
@@ -88,4 +93,5 @@ function getSourceModule(itemName, itemBinding) {
|
|
|
88
93
|
};
|
|
89
94
|
}
|
|
90
95
|
__name(getSourceModule, "getSourceModule");
|
|
96
|
+
module.exports = __toCommonJS(getSourceModule_exports);
|
|
91
97
|
//# sourceMappingURL=getSourceModule.js.map
|
|
@@ -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;AAAA;AAAA;AAAA;AAAA,QAAmB;AAUZ,yBACL,UACA,aAIqB;AAErB,MAAI,CAAC,YAAY,UAAU;AACzB,WAAO;AAAA;AAGT,MAAI;AACJ,MAAI;AACJ,MAAI;AACJ,MAAI;AACJ,MAAI,mBAAmB;AAEvB,QAAM,WAAW,YAAY,KAAK;AAElC,MAEE,EAAE,yBAAyB,aAE3B,EAAE,kBAAkB,WACpB;AACA,QAAI,EAAE,oBAAoB,YAAY,KAAK,SAAS;AAClD,qBAAe,YAAY,KAAK,OAAO,OAAO;AAC9C,cAAQ,SAAS,MAAM;AACvB,yBAAmB;AACnB,UAAI,EAAE,kBAAkB,WAAW;AACjC,mBAAW,SAAS,SAAS;AAC7B,uBAAe;AAAA,aACV;AACL,mBAAW,SAAS,MAAM;AAC1B,uBAAe;AAAA;AAAA;AAAA,aAInB,EAAE,qBAAqB,aACvB,SAAS,QAAQ,QACjB,EAAE,iBAAiB,SAAS,SAC5B,EAAE,aAAa,SAAS,KAAK,WAC7B,SAAS,KAAK,OAAO,SAAS,aAC9B,SAAS,KAAK,UAAU,WAAW,GACnC;AACA,UAAM,WAAW,SAAS,KAAK,UAAU;AACzC,QAAI,CAAC,EAAE,gBAAgB,WAAW;AAChC,aAAO;AAAA;AAET,mBAAe,SAAS;AAExB,QAAI,EAAE,aAAa,SAAS,KAAK;AAC/B,cAAQ,SAAS,GAAG;AACpB,iBAAW,SAAS,GAAG;AACvB,qBAAe;AAAA,eACN,EAAE,gBAAgB,SAAS,KAAK;AACzC,iBAAW,WAAW,SAAS,GAAG,YAAY;AAC5C,YACE,EAAE,iBAAiB,YACnB,EAAE,aAAa,QAAQ,UACvB,QAAQ,MAAM,SAAS,UACvB;AACA,kBAAQ,QAAQ,MAAM;AAEtB,qBAAW,QAAQ,IAAI;AACvB,yBAAe;AACf;AAAA;AAAA;AAIJ,UAAI,CAAC,SAAS,CAAC,UAAU;AACvB,gBAAQ,MAAM,uCAAuC;AACrD,eAAO;AAAA;AAAA,WAEJ;AACL,cAAQ,MAAM,yBAAyB,SAAS,GAAG;AACnD,aAAO;AAAA;AAAA,SAEJ;AACL,WAAO;AAAA;AAGT,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA;AAAA;AAxFY;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -7,29 +7,34 @@ var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
|
7
7
|
var __markAsModule = (target) => __defProp(target, "__esModule", { value: true });
|
|
8
8
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
9
9
|
var __export = (target, all) => {
|
|
10
|
-
__markAsModule(target);
|
|
11
10
|
for (var name in all)
|
|
12
11
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
13
12
|
};
|
|
14
|
-
var __reExport = (target, module2, desc) => {
|
|
13
|
+
var __reExport = (target, module2, copyDefault, desc) => {
|
|
15
14
|
if (module2 && typeof module2 === "object" || typeof module2 === "function") {
|
|
16
15
|
for (let key of __getOwnPropNames(module2))
|
|
17
|
-
if (!__hasOwnProp.call(target, key) && key !== "default")
|
|
16
|
+
if (!__hasOwnProp.call(target, key) && (copyDefault || key !== "default"))
|
|
18
17
|
__defProp(target, key, { get: () => module2[key], enumerable: !(desc = __getOwnPropDesc(module2, key)) || desc.enumerable });
|
|
19
18
|
}
|
|
20
19
|
return target;
|
|
21
20
|
};
|
|
22
|
-
var
|
|
23
|
-
return __reExport(__markAsModule(__defProp(module2 != null ? __create(__getProtoOf(module2)) : {}, "default",
|
|
21
|
+
var __toESM = (module2, isNodeMode) => {
|
|
22
|
+
return __reExport(__markAsModule(__defProp(module2 != null ? __create(__getProtoOf(module2)) : {}, "default", !isNodeMode && module2 && module2.__esModule ? { get: () => module2.default, enumerable: true } : { value: module2, enumerable: true })), module2);
|
|
24
23
|
};
|
|
25
|
-
|
|
24
|
+
var __toCommonJS = /* @__PURE__ */ ((cache) => {
|
|
25
|
+
return (module2, temp) => {
|
|
26
|
+
return cache && cache.get(module2) || (temp = __reExport(__markAsModule({}), module2, 1), cache && cache.set(module2, temp), temp);
|
|
27
|
+
};
|
|
28
|
+
})(typeof WeakMap !== "undefined" ? /* @__PURE__ */ new WeakMap() : 0);
|
|
29
|
+
var getStaticBindingsForScope_exports = {};
|
|
30
|
+
__export(getStaticBindingsForScope_exports, {
|
|
26
31
|
getStaticBindingsForScope: () => getStaticBindingsForScope
|
|
27
32
|
});
|
|
28
|
-
var import_path =
|
|
29
|
-
var t =
|
|
30
|
-
var import_fs_extra =
|
|
31
|
-
var import_evaluateAstNode =
|
|
32
|
-
var import_getSourceModule =
|
|
33
|
+
var import_path = require("path");
|
|
34
|
+
var t = __toESM(require("@babel/types"));
|
|
35
|
+
var import_fs_extra = require("fs-extra");
|
|
36
|
+
var import_evaluateAstNode = require("./evaluateAstNode");
|
|
37
|
+
var import_getSourceModule = require("./getSourceModule");
|
|
33
38
|
const isLocalImport = /* @__PURE__ */ __name((path) => path.startsWith(".") || path.startsWith("/"), "isLocalImport");
|
|
34
39
|
function resolveImportPath(sourcePath, path) {
|
|
35
40
|
const sourceDir = (0, import_path.dirname)(sourcePath);
|
|
@@ -147,4 +152,5 @@ function getStaticBindingsForScope(scope, whitelist = [], sourcePath, bindingCac
|
|
|
147
152
|
return ret;
|
|
148
153
|
}
|
|
149
154
|
__name(getStaticBindingsForScope, "getStaticBindingsForScope");
|
|
155
|
+
module.exports = __toCommonJS(getStaticBindingsForScope_exports);
|
|
150
156
|
//# sourceMappingURL=getStaticBindingsForScope.js.map
|
|
@@ -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 // TODO we can clear this when we see updates on it later on\n return require(file)\n }\n }\n return null\n}\n\nexport function getStaticBindingsForScope(\n scope: NodePath<t.JSXElement>['scope'],\n whitelist: string[] = [],\n sourcePath: string,\n bindingCache: Record<string, string | null>,\n shouldPrintDebug: boolean\n): Record<string, any> {\n const bindings: Record<string, Binding> = scope.getAllBindings() as any\n const ret: Record<string, any> = {}\n\n if (shouldPrintDebug) {\n // prettier-ignore\n console.log(' ', Object.keys(bindings).length, 'variables in scope')\n // .map(x => bindings[x].identifier?.name).join(', ')\n }\n\n // on react native at least it doesnt find some bindings? not sure why\n // lets add in whitelisted imports if they exist\n const program = scope.getProgramParent().block as t.Program\n for (const node of program.body) {\n if (t.isImportDeclaration(node)) {\n const importPath = node.source.value\n if (!node.specifiers.length) continue\n if (!isLocalImport(importPath)) {\n continue\n }\n const moduleName = resolveImportPath(sourcePath, importPath)\n const isOnWhitelist = whitelist.some((test) => moduleName.endsWith(test))\n if (!isOnWhitelist) continue\n const src = importModule(moduleName)\n if (!src) continue\n for (const specifier of node.specifiers) {\n if (t.isImportSpecifier(specifier) && t.isIdentifier(specifier.imported)) {\n if (typeof src[specifier.imported.name] !== 'undefined') {\n const val = src[specifier.local.name]\n ret[specifier.local.name] = val\n }\n }\n }\n }\n }\n\n if (!bindingCache) {\n throw new Error('bindingCache is a required param')\n }\n\n for (const k in bindings) {\n const binding = bindings[k]\n\n // check to see if the item is a module\n const sourceModule = getSourceModule(k, binding)\n if (sourceModule) {\n if (!sourceModule.sourceModule) {\n continue\n }\n\n const moduleName = resolveImportPath(sourcePath, sourceModule.sourceModule)\n const isOnWhitelist = whitelist.some((test) => moduleName.endsWith(test))\n\n // TODO we could cache this at the file level.. and check if its been touched since\n\n if (isOnWhitelist) {\n const src = importModule(moduleName)\n if (!src) {\n console.log(\n `\u26A0\uFE0F missing file ${moduleName} via ${sourcePath} import ${sourceModule.sourceModule}?`\n )\n return {}\n }\n if (sourceModule.destructured) {\n if (sourceModule.imported) {\n ret[k] = src[sourceModule.imported]\n }\n } else {\n // crude esmodule check\n // TODO: make sure this actually works\n // if (src && src.__esModule) {\n // ret[k] = src.default\n // } else {\n ret[k] = src\n // }\n }\n }\n continue\n }\n\n const { parent, parentPath } = binding.path\n\n if (!t.isVariableDeclaration(parent) || parent.kind !== 'const') {\n continue\n }\n\n // pick out the right variable declarator\n const dec = parent.declarations.find((d) => t.isIdentifier(d.id) && d.id.name === k)\n\n // if init is not set, there's nothing to evaluate\n // TODO: handle spread syntax\n if (!dec || !dec.init) {\n continue\n }\n\n // missing start/end will break caching\n if (typeof dec.id.start !== 'number' || typeof dec.id.end !== 'number') {\n console.error('dec.id.start/end is not a number')\n continue\n }\n\n if (!t.isIdentifier(dec.id)) {\n console.error('dec is not an identifier')\n continue\n }\n\n const cacheKey = `${dec.id.name}_${dec.id.start}-${dec.id.end}`\n\n // retrieve value from cache\n if (bindingCache.hasOwnProperty(cacheKey)) {\n ret[k] = bindingCache[cacheKey]\n continue\n }\n // retrieve value from cache\n if (bindingCache.hasOwnProperty(cacheKey)) {\n ret[k] = bindingCache[cacheKey]\n continue\n }\n\n // evaluate\n try {\n ret[k] = evaluateAstNode(dec.init, undefined, shouldPrintDebug)\n bindingCache[cacheKey] = ret[k]\n continue\n } catch (e) {\n // skip\n // if (shouldPrintDebug) {\n // console.error('[\uD83D\uDC07] cant eval, skipping', cacheKey) //, e.message)\n // }\n }\n }\n\n return ret\n}\n"],
|
|
5
|
-
"mappings": "
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA,kBAA0C;AAG1C,QAAmB;AACnB,sBAA2B;AAE3B,6BAAgC;AAChC,6BAAgC;AAEhC,MAAM,gBAAgB,wBAAC,SAAiB,KAAK,WAAW,QAAQ,KAAK,WAAW,MAA1D;AAEtB,2BAA2B,YAAoB,MAAc;AAC3D,QAAM,YAAY,yBAAQ;AAC1B,MAAI,cAAc,OAAO;AACvB,QAAI,yBAAQ,UAAU,IAAI;AACxB,cAAQ;AAAA;AAEV,WAAO,yBAAQ,WAAW;AAAA;AAE5B,SAAO;AAAA;AARA;AAWT,sBAAsB,MAAc;AAClC,QAAM,YAAY,CAAC,KAAK,QAAQ,OAAO,SAAS,KAAK,QAAQ,OAAO,QAAQ;AAC5E,aAAW,QAAQ,WAAW;AAC5B,QAAI,gCAAW,OAAO;AAEpB,aAAO,QAAQ;AAAA;AAAA;AAGnB,SAAO;AAAA;AARA;AAWF,mCACL,OACA,YAAsB,IACtB,YACA,cACA,kBACqB;AACrB,QAAM,WAAoC,MAAM;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eAEvB;AAML,cAAI,KAAK;AAAA;AAAA;AAIb;AAAA;AAGF,UAAM,EAAE,QAAQ,eAAe,QAAQ;AAEvC,QAAI,CAAC,EAAE,sBAAsB,WAAW,OAAO,SAAS,SAAS;AAC/D;AAAA;AAIF,UAAM,MAAM,OAAO,aAAa,KAAK,CAAC,MAAM,EAAE,aAAa,EAAE,OAAO,EAAE,GAAG,SAAS;AAIlF,QAAI,CAAC,OAAO,CAAC,IAAI,MAAM;AACrB;AAAA;AAIF,QAAI,OAAO,IAAI,GAAG,UAAU,YAAY,OAAO,IAAI,GAAG,QAAQ,UAAU;AACtE,cAAQ,MAAM;AACd;AAAA;AAGF,QAAI,CAAC,EAAE,aAAa,IAAI,KAAK;AAC3B,cAAQ,MAAM;AACd;AAAA;AAGF,UAAM,WAAW,GAAG,IAAI,GAAG,QAAQ,IAAI,GAAG,SAAS,IAAI,GAAG;AAG1D,QAAI,aAAa,eAAe,WAAW;AACzC,UAAI,KAAK,aAAa;AACtB;AAAA;AAGF,QAAI,aAAa,eAAe,WAAW;AACzC,UAAI,KAAK,aAAa;AACtB;AAAA;AAIF,QAAI;AACF,UAAI,KAAK,4CAAgB,IAAI,MAAM,QAAW;AAC9C,mBAAa,YAAY,IAAI;AAC7B;AAAA,aACO,GAAP;AAAA;AAAA;AAQJ,SAAO;AAAA;AA1IO;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -7,25 +7,30 @@ var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
|
7
7
|
var __markAsModule = (target) => __defProp(target, "__esModule", { value: true });
|
|
8
8
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
9
9
|
var __export = (target, all) => {
|
|
10
|
-
__markAsModule(target);
|
|
11
10
|
for (var name in all)
|
|
12
11
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
13
12
|
};
|
|
14
|
-
var __reExport = (target, module2, desc) => {
|
|
13
|
+
var __reExport = (target, module2, copyDefault, desc) => {
|
|
15
14
|
if (module2 && typeof module2 === "object" || typeof module2 === "function") {
|
|
16
15
|
for (let key of __getOwnPropNames(module2))
|
|
17
|
-
if (!__hasOwnProp.call(target, key) && key !== "default")
|
|
16
|
+
if (!__hasOwnProp.call(target, key) && (copyDefault || key !== "default"))
|
|
18
17
|
__defProp(target, key, { get: () => module2[key], enumerable: !(desc = __getOwnPropDesc(module2, key)) || desc.enumerable });
|
|
19
18
|
}
|
|
20
19
|
return target;
|
|
21
20
|
};
|
|
22
|
-
var
|
|
23
|
-
return __reExport(__markAsModule(__defProp(module2 != null ? __create(__getProtoOf(module2)) : {}, "default",
|
|
21
|
+
var __toESM = (module2, isNodeMode) => {
|
|
22
|
+
return __reExport(__markAsModule(__defProp(module2 != null ? __create(__getProtoOf(module2)) : {}, "default", !isNodeMode && module2 && module2.__esModule ? { get: () => module2.default, enumerable: true } : { value: module2, enumerable: true })), module2);
|
|
24
23
|
};
|
|
25
|
-
|
|
24
|
+
var __toCommonJS = /* @__PURE__ */ ((cache) => {
|
|
25
|
+
return (module2, temp) => {
|
|
26
|
+
return cache && cache.get(module2) || (temp = __reExport(__markAsModule({}), module2, 1), cache && cache.set(module2, temp), temp);
|
|
27
|
+
};
|
|
28
|
+
})(typeof WeakMap !== "undefined" ? /* @__PURE__ */ new WeakMap() : 0);
|
|
29
|
+
var hoistClassNames_exports = {};
|
|
30
|
+
__export(hoistClassNames_exports, {
|
|
26
31
|
hoistClassNames: () => hoistClassNames
|
|
27
32
|
});
|
|
28
|
-
var t =
|
|
33
|
+
var t = __toESM(require("@babel/types"));
|
|
29
34
|
function hoistClassNames(path, existing, expr) {
|
|
30
35
|
const hoist = hoistClassNames.bind(null, path, existing);
|
|
31
36
|
if (t.isStringLiteral(expr)) {
|
|
@@ -63,4 +68,5 @@ function hoistClassNames(path, existing, expr) {
|
|
|
63
68
|
__name(replaceStringWithVariable, "replaceStringWithVariable");
|
|
64
69
|
}
|
|
65
70
|
__name(hoistClassNames, "hoistClassNames");
|
|
71
|
+
module.exports = __toCommonJS(hoistClassNames_exports);
|
|
66
72
|
//# sourceMappingURL=hoistClassNames.js.map
|
|
@@ -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": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AACA,QAAmB;AAEZ,yBACL,MACA,UACA,MACA;AACA,QAAM,QAAQ,gBAAgB,KAAK,MAAM,MAAM;AAC/C,MAAI,EAAE,gBAAgB,OAAO;AAC3B,QAAI,KAAK,MAAM,WAAW,IAAI;AAC5B,aAAO;AAAA;AAET,QAAI,SAAS,KAAK,QAAQ;AACxB,aAAO,SAAS,KAAK;AAAA;AAEvB,UAAM,aAAa,0BAA0B;AAC7C,aAAS,KAAK,SAAS;AACvB,WAAO;AAAA;AAET,MAAI,EAAE,mBAAmB,OAAO;AAC9B,WAAO,EAAE,iBAAiB,KAAK,UAAU,MAAM,KAAK,OAAO,MAAM,KAAK;AAAA;AAExE,MAAI,EAAE,oBAAoB,OAAO;AAC/B,WAAO,EAAE,kBAAkB,KAAK,UAAU,MAAM,KAAK,OAAO,MAAM,KAAK;AAAA;AAEzE,MAAI,EAAE,wBAAwB,OAAO;AACnC,WAAO,EAAE,sBAAsB,KAAK,MAAM,MAAM,KAAK,aAAa,MAAM,KAAK;AAAA;AAE/E,SAAO;AAEP,qCAAmC,KAAoC;AAErE,UAAM,MAAM,KAAK,MAAM,sBAAsB;AAC7C,UAAM,SAAS,KAAK,WAAW,CAAC,UAAS,MAAK;AAC9C,QAAI,CAAC;AAAQ,YAAM,IAAI,MAAM;AAC7B,UAAM,WAAW,EAAE,oBAAoB,SAAS;AAAA,MAE9C,EAAE,mBAAmB,KAAK,EAAE,cAAc,IAAI,IAAI;AAAA;AAGpD,WAAO,iBAAiB,QAAQ;AAChC,WAAO;AAAA;AAXA;AAAA;AA5BK;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|