@tamagui/static 1.0.0-beta.222 → 1.0.0-beta.3
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 +8 -0
- package/dist/cjs/extractor/accessSafe.js +4 -0
- package/dist/cjs/extractor/babelParse.js +5 -0
- package/dist/cjs/extractor/babelParse.js.map +2 -2
- package/dist/cjs/extractor/buildClassName.js +4 -0
- package/dist/cjs/extractor/createEvaluator.js +5 -0
- package/dist/cjs/extractor/createExtractor.js +830 -770
- package/dist/cjs/extractor/createExtractor.js.map +2 -2
- package/dist/cjs/extractor/ensureImportingConcat.js +4 -0
- package/dist/cjs/extractor/evaluateAstNode.js +4 -0
- package/dist/cjs/extractor/extractHelpers.js +11 -0
- package/dist/cjs/extractor/extractMediaStyle.js +5 -0
- package/dist/cjs/extractor/extractMediaStyle.js.map +2 -2
- package/dist/cjs/extractor/extractToClassNames.js +19 -7
- package/dist/cjs/extractor/extractToClassNames.js.map +2 -2
- package/dist/cjs/extractor/findTopmostFunction.js +4 -0
- package/dist/cjs/extractor/generatedUid.js +4 -0
- package/dist/cjs/extractor/getPrefixLogs.js +4 -0
- package/dist/cjs/extractor/getPropValueFromAttributes.js +4 -0
- package/dist/cjs/extractor/getSourceModule.js +4 -0
- package/dist/cjs/extractor/getStaticBindingsForScope.js +14 -1
- package/dist/cjs/extractor/getStaticBindingsForScope.js.map +2 -2
- package/dist/cjs/extractor/hoistClassNames.js +4 -0
- package/dist/cjs/extractor/literalToAst.js +5 -0
- package/dist/cjs/extractor/loadTamagui.js +67 -47
- package/dist/cjs/extractor/loadTamagui.js.map +2 -2
- package/dist/cjs/extractor/logLines.js +4 -0
- package/dist/cjs/extractor/normalizeTernaries.js +4 -0
- package/dist/cjs/extractor/removeUnusedHooks.js +4 -0
- package/dist/cjs/extractor/timer.js +46 -0
- package/dist/cjs/extractor/timer.js.map +7 -0
- package/dist/cjs/extractor/validHTMLAttributes.js +4 -0
- package/dist/cjs/index.js +6 -0
- package/dist/cjs/patchReactNativeWeb.js +23 -7
- package/dist/cjs/patchReactNativeWeb.js.map +2 -2
- package/dist/esm/extractor/babelParse.js.map +2 -2
- package/dist/esm/extractor/createExtractor.js +838 -781
- package/dist/esm/extractor/createExtractor.js.map +2 -2
- package/dist/esm/extractor/extractMediaStyle.js.map +2 -2
- package/dist/esm/extractor/extractToClassNames.js +15 -7
- package/dist/esm/extractor/extractToClassNames.js.map +2 -2
- package/dist/esm/extractor/getStaticBindingsForScope.js +10 -1
- package/dist/esm/extractor/getStaticBindingsForScope.js.map +2 -2
- package/dist/esm/extractor/loadTamagui.js +63 -47
- package/dist/esm/extractor/loadTamagui.js.map +2 -2
- package/dist/esm/extractor/timer.js +24 -0
- package/dist/esm/extractor/timer.js.map +7 -0
- package/dist/esm/patchReactNativeWeb.js +19 -7
- package/dist/esm/patchReactNativeWeb.js.map +2 -2
- package/dist/jsx/extractor/createExtractor.js +838 -781
- package/dist/jsx/extractor/extractToClassNames.js +15 -7
- package/dist/jsx/extractor/getStaticBindingsForScope.js +10 -1
- package/dist/jsx/extractor/loadTamagui.js +63 -47
- package/dist/jsx/extractor/timer.js +23 -0
- package/dist/jsx/patchReactNativeWeb.js +19 -7
- package/package.json +25 -25
- package/types/extractor/babelParse.d.ts.map +1 -1
- package/types/extractor/createExtractor.d.ts +2 -0
- package/types/extractor/createExtractor.d.ts.map +1 -1
- package/types/extractor/extractMediaStyle.d.ts +1 -1
- package/types/extractor/extractMediaStyle.d.ts.map +1 -1
- package/types/extractor/extractToClassNames.d.ts +2 -1
- package/types/extractor/extractToClassNames.d.ts.map +1 -1
- package/types/extractor/getStaticBindingsForScope.d.ts.map +1 -1
- package/types/extractor/loadTamagui.d.ts.map +1 -1
- package/types/extractor/timer.d.ts +5 -0
- package/types/extractor/timer.d.ts.map +1 -0
- package/types/patchReactNativeWeb.d.ts.map +1 -1
- package/LICENSE +0 -21
|
@@ -59,6 +59,7 @@ var import_getPrefixLogs = require("./getPrefixLogs");
|
|
|
59
59
|
var import_hoistClassNames = require("./hoistClassNames");
|
|
60
60
|
var import_literalToAst = require("./literalToAst");
|
|
61
61
|
var import_logLines = require("./logLines");
|
|
62
|
+
var import_timer = require("./timer");
|
|
62
63
|
const mergeStyleGroups = {
|
|
63
64
|
shadowOpacity: true,
|
|
64
65
|
shadowRadius: true,
|
|
@@ -72,9 +73,11 @@ function extractToClassNames({
|
|
|
72
73
|
sourcePath,
|
|
73
74
|
options,
|
|
74
75
|
shouldPrintDebug,
|
|
76
|
+
cssLoaderPath,
|
|
75
77
|
threaded,
|
|
76
78
|
cssPath
|
|
77
79
|
}) {
|
|
80
|
+
const tm = (0, import_timer.timer)();
|
|
78
81
|
if (typeof source !== "string") {
|
|
79
82
|
throw new Error("`source` must be a string of javascript");
|
|
80
83
|
}
|
|
@@ -89,6 +92,7 @@ function extractToClassNames({
|
|
|
89
92
|
console.error("babel parse error:", sourcePath);
|
|
90
93
|
throw err;
|
|
91
94
|
}
|
|
95
|
+
tm.mark(`babel-parse`, shouldPrintDebug === "verbose");
|
|
92
96
|
const cssMap = /* @__PURE__ */ new Map();
|
|
93
97
|
const existingHoists = {};
|
|
94
98
|
let hasFlattened = false;
|
|
@@ -223,9 +227,6 @@ function extractToClassNames({
|
|
|
223
227
|
break;
|
|
224
228
|
}
|
|
225
229
|
}
|
|
226
|
-
if (shouldPrintDebug) {
|
|
227
|
-
console.log(" finalClassNames\n", (0, import_logLines.logLines)(finalClassNames.map((x) => x["value"]).join(" ")));
|
|
228
|
-
}
|
|
229
230
|
function addTernaryStyle(ternary, a, b) {
|
|
230
231
|
const cCN = a.map((x) => x.identifier).join(" ");
|
|
231
232
|
const aCN = b.map((x) => x.identifier).join(" ");
|
|
@@ -236,9 +237,15 @@ function extractToClassNames({
|
|
|
236
237
|
}
|
|
237
238
|
}
|
|
238
239
|
__name(addTernaryStyle, "addTernaryStyle");
|
|
240
|
+
if (shouldPrintDebug) {
|
|
241
|
+
console.log(" finalClassNames\n", (0, import_logLines.logLines)(finalClassNames.map((x) => x["value"]).join(" ")));
|
|
242
|
+
}
|
|
239
243
|
node.attributes = finalAttrs;
|
|
240
244
|
if (finalClassNames.length) {
|
|
241
|
-
|
|
245
|
+
let names = (0, import_buildClassName.buildClassName)(finalClassNames);
|
|
246
|
+
if (t.isStringLiteral(names)) {
|
|
247
|
+
names.value = (0, import_helpers.concatClassName)(names.value);
|
|
248
|
+
}
|
|
242
249
|
const nameExpr = names ? (0, import_hoistClassNames.hoistClassNames)(jsxPath, existingHoists, names) : null;
|
|
243
250
|
let expr = nameExpr;
|
|
244
251
|
if (nameExpr && !t.isIdentifier(nameExpr)) {
|
|
@@ -285,7 +292,7 @@ function extractToClassNames({
|
|
|
285
292
|
if (styles) {
|
|
286
293
|
const cssQuery = threaded ? `cssData=${Buffer.from(styles).toString("base64")}` : `cssPath=${cssPath}`;
|
|
287
294
|
const remReq = loader.remainingRequest;
|
|
288
|
-
const importPath = `${cssPath}
|
|
295
|
+
const importPath = `${cssPath}!=!${cssLoaderPath}?${cssQuery}!${remReq}`;
|
|
289
296
|
ast.program.body.unshift(t.importDeclaration([], t.stringLiteral(importPath)));
|
|
290
297
|
}
|
|
291
298
|
const result = (0, import_generator.default)(ast, {
|
|
@@ -301,13 +308,14 @@ function extractToClassNames({
|
|
|
301
308
|
}
|
|
302
309
|
if (shouldLogTiming) {
|
|
303
310
|
const memUsed = mem ? Math.round((process.memoryUsage().heapUsed - mem.heapUsed) / 1024 / 1204 * 10) / 10 : 0;
|
|
304
|
-
const timing = `${Date.now() - start}`.padStart(3);
|
|
305
311
|
const path2 = (0, import_path.basename)(sourcePath).replace(/\.[jt]sx?$/, "").slice(0, 22).trim().padStart(24);
|
|
306
312
|
const numOptimized = `${res.optimized}`.padStart(3);
|
|
307
313
|
const numFound = `${res.found}`.padStart(3);
|
|
308
314
|
const numFlattened = `${res.flattened}`.padStart(3);
|
|
309
315
|
const memory = process.env.DEBUG && memUsed > 10 ? ` ${memUsed}MB` : "";
|
|
310
|
-
const
|
|
316
|
+
const timing = Date.now() - start;
|
|
317
|
+
const timingWarning = timing > 50 ? "\u26A0\uFE0F" : timing > 150 ? "\u2622\uFE0F" : "";
|
|
318
|
+
const timingStr = `${timing}ms${timingWarning}`.padStart(6);
|
|
311
319
|
console.log(`${(0, import_getPrefixLogs.getPrefixLogs)(options)} ${path2} ${numFound} \xB7 ${numOptimized} \xB7 ${numFlattened} ${timingStr} ${memory ? `(${memory})` : ""}`);
|
|
312
320
|
}
|
|
313
321
|
return {
|
|
@@ -318,4 +326,8 @@ function extractToClassNames({
|
|
|
318
326
|
};
|
|
319
327
|
}
|
|
320
328
|
__name(extractToClassNames, "extractToClassNames");
|
|
329
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
330
|
+
0 && (module.exports = {
|
|
331
|
+
extractToClassNames
|
|
332
|
+
});
|
|
321
333
|
//# 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 { ViewStyle } from 'react-native'\nimport { LoaderContext } from 'webpack'\n\nimport { CONCAT_CLASSNAME_IMPORT } from '../constants'\nimport { ClassNameObject, StyleObject, TamaguiOptions, Ternary } 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 { getPrefixLogs } from './getPrefixLogs'\nimport { hoistClassNames } from './hoistClassNames'\nimport { literalToAst } from './literalToAst'\nimport { logLines } from './logLines'\n\nconst mergeStyleGroups = {\n shadowOpacity: true,\n shadowRadius: true,\n shadowColor: true,\n shadowOffset: true,\n}\n\nexport type ExtractedResponse = {\n js: string | Buffer\n styles: string\n stylesPath?: string\n ast: t.File\n map: any // RawSourceMap from 'source-map'\n}\n\nexport function extractToClassNames({\n loader,\n extractor,\n source,\n sourcePath,\n options,\n shouldPrintDebug,\n threaded,\n cssPath,\n}: {\n loader: LoaderContext<any>\n extractor: Extractor\n source: string | Buffer\n sourcePath: string\n options: TamaguiOptions\n shouldPrintDebug: boolean | 'verbose'\n cssPath: string\n threaded?: boolean\n}): ExtractedResponse | null {\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 let hasFlattened = false\n\n const res = extractor.parse(ast, {\n sourcePath,\n shouldPrintDebug,\n ...options,\n getFlattenedNode: ({ tag }) => {\n hasFlattened = true\n return tag\n },\n onExtractTag: ({\n attrs,\n node,\n attemptEval,\n jsxPath,\n originalNodeName,\n filePath,\n lineNumbers,\n programPath,\n isFlattened,\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): StyleObject[] => {\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 if (!isFlattened) {\n // only ever one at a time i believe so we can be lazy with this access\n const { hoverStyle, pressStyle, focusStyle } = attr.value\n const pseudos = [\n ['hoverStyle', hoverStyle],\n ['pressStyle', pressStyle],\n ['focusStyle', focusStyle],\n ] as const\n\n const styles = getStylesAtomic(attr.value, {\n splitTransforms: true,\n })\n\n finalStyles = [...finalStyles, ...styles]\n\n for (const [key, value] of pseudos) {\n if (value && Object.keys(value).length) {\n finalAttrs.push(\n t.jsxAttribute(\n t.jsxIdentifier(key),\n t.jsxExpressionContainer(literalToAst(value))\n )\n )\n }\n }\n\n for (const style of styles) {\n // leave them as attributes\n finalAttrs.push(\n t.jsxAttribute(t.jsxIdentifier(style.property), t.stringLiteral(style.identifier))\n )\n }\n } else {\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 }\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 (shouldPrintDebug) {\n if (mediaExtraction) {\n // prettier-ignore\n console.log('ternary (mediaStyles)', mediaExtraction.ternaryWithoutMedia?.inlineMediaQuery ?? '', mediaExtraction.mediaStyles.map((x) => x.identifier).join('.'))\n }\n }\n if (!mediaExtraction) {\n addTernaryStyle(\n attr.value,\n addStyles(attr.value.consequent),\n addStyles(attr.value.alternate)\n )\n continue\n }\n lastMediaImportance++\n if (mediaExtraction.mediaStyles) {\n finalStyles = [...finalStyles, ...mediaExtraction.mediaStyles]\n }\n if (mediaExtraction.ternaryWithoutMedia) {\n addTernaryStyle(mediaExtraction.ternaryWithoutMedia, mediaExtraction.mediaStyles, [])\n } else {\n finalClassNames = [\n ...finalClassNames,\n ...mediaExtraction.mediaStyles.map((x) => t.stringLiteral(x.identifier)),\n ]\n }\n break\n }\n }\n\n if (shouldPrintDebug) {\n // prettier-ignore\n console.log(' finalClassNames\\n', logLines(finalClassNames.map(x => x['value']).join(' ')))\n }\n\n function addTernaryStyle(ternary: Ternary, a: any, b: any) {\n const cCN = a.map((x) => x.identifier).join(' ')\n const aCN = b.map((x) => x.identifier).join(' ')\n if (a.length && b.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 }\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 if (!hasFlattened) {\n // not flat\n } else {\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\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, identifier, value } of finalStyles) {\n // console.log('backvalue', identifier, value)\n // ast.program.body.unshift(\n // t.expressionStatement(\n // t.callExpression(\n // t.memberExpression(\n // t.callExpression(t.identifier('require'), [t.stringLiteral('@tamagui/core')]),\n // t.identifier('setIdentifierValue')\n // ),\n // [t.stringLiteral(identifier), t.stringLiteral(value)]\n // )\n // )\n // )\n\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 = loader.remainingRequest\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)\n .replace(/\\.[jt]sx?$/, '')\n .slice(0, 22)\n .trim()\n .padStart(24)\n const numOptimized = `${res.optimized}`.padStart(3)\n const numFound = `${res.found}`.padStart(3)\n const numFlattened = `${res.flattened}`.padStart(3)\n const memory = process.env.DEBUG && memUsed > 10 ? ` ${memUsed}MB` : ''\n const timingStr = `${timing}ms`.padStart(6)\n console.log(\n `${getPrefixLogs(\n options\n )} ${path} ${numFound} \u00B7 ${numOptimized} \u00B7 ${numFlattened} ${timingStr} ${\n memory ? `(${memory})` : ''\n }`\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;AAAA,WAAsB;AACtB,kBAAyB;AACzB,WAAsB;AAEtB,uBAAqB;AACrB,QAAmB;AACnB,uBAAgC;AAChC,qBAAgC;AAChC,uBAAsB;AAItB,uBAAwC;AAExC,wBAA2B;AAC3B,4BAA+B;AAE/B,mCAAsC;AACtC,4BAA+B;AAC/B,+BAAkC;AAClC,2BAA8B;AAC9B,6BAAgC;AAChC,0BAA6B;AAC7B,sBAAyB;
|
|
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 { ViewStyle } from 'react-native'\nimport { LoaderContext } from 'webpack'\n\nimport { CONCAT_CLASSNAME_IMPORT } from '../constants'\nimport { ClassNameObject, StyleObject, TamaguiOptions, Ternary } 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 { getPrefixLogs } from './getPrefixLogs'\nimport { hoistClassNames } from './hoistClassNames'\nimport { literalToAst } from './literalToAst'\nimport { logLines } from './logLines'\nimport { timer } from './timer'\n\nconst mergeStyleGroups = {\n shadowOpacity: true,\n shadowRadius: true,\n shadowColor: true,\n shadowOffset: true,\n}\n\nexport type ExtractedResponse = {\n js: string | Buffer\n styles: string\n stylesPath?: string\n ast: t.File\n map: any // RawSourceMap from 'source-map'\n}\n\nexport function extractToClassNames({\n loader,\n extractor,\n source,\n sourcePath,\n options,\n shouldPrintDebug,\n cssLoaderPath,\n threaded,\n cssPath,\n}: {\n loader: LoaderContext<any>\n cssLoaderPath: string\n extractor: Extractor\n source: string | Buffer\n sourcePath: string\n options: TamaguiOptions\n shouldPrintDebug: boolean | 'verbose'\n cssPath: string\n threaded?: boolean\n}): ExtractedResponse | null {\n const tm = timer()\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 tm.mark(`babel-parse`, shouldPrintDebug === 'verbose')\n\n const cssMap = new Map<string, { css: string; commentTexts: string[] }>()\n const existingHoists: { [key: string]: t.Identifier } = {}\n\n let hasFlattened = false\n\n const res = extractor.parse(ast, {\n sourcePath,\n shouldPrintDebug,\n ...options,\n getFlattenedNode: ({ tag }) => {\n hasFlattened = true\n return tag\n },\n onExtractTag: ({\n attrs,\n node,\n attemptEval,\n jsxPath,\n originalNodeName,\n filePath,\n lineNumbers,\n programPath,\n isFlattened,\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): StyleObject[] => {\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 if (!isFlattened) {\n // only ever one at a time i believe so we can be lazy with this access\n const { hoverStyle, pressStyle, focusStyle } = attr.value\n const pseudos = [\n ['hoverStyle', hoverStyle],\n ['pressStyle', pressStyle],\n ['focusStyle', focusStyle],\n ] as const\n\n const styles = getStylesAtomic(attr.value, {\n splitTransforms: true,\n })\n finalStyles = [...finalStyles, ...styles]\n\n for (const [key, value] of pseudos) {\n if (value && Object.keys(value).length) {\n finalAttrs.push(\n t.jsxAttribute(\n t.jsxIdentifier(key),\n t.jsxExpressionContainer(literalToAst(value))\n )\n )\n }\n }\n\n for (const style of styles) {\n // leave them as attributes\n finalAttrs.push(\n t.jsxAttribute(t.jsxIdentifier(style.property), t.stringLiteral(style.identifier))\n )\n }\n\n // for (const key in attr.value) {\n // if (pseudos.some((x) => x[0] === key)) {\n // // we handled pseudos above...\n // continue\n // }\n // // leave them as attributes\n // finalAttrs.push(\n // t.jsxAttribute(t.jsxIdentifier(key), t.stringLiteral(attr.value[key]))\n // )\n // }\n } else {\n const styles = addStyles(attr.value)\n const newClassNames = concatClassName(styles.map((x) => x.identifier).join(' '))\n const existing = finalClassNames.find(\n (x) => x.type == 'StringLiteral'\n ) as t.StringLiteral | null\n\n // const newClassNames = concatClassName(Object.values(attr.value))\n // const existing = finalClassNames.find(\n // (x) => x.type == 'StringLiteral'\n // ) as t.StringLiteral | null\n\n if (existing) {\n existing.value = `${existing.value} ${newClassNames}`\n } else {\n finalClassNames = [...finalClassNames, t.stringLiteral(newClassNames)]\n }\n }\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 (shouldPrintDebug) {\n if (mediaExtraction) {\n // prettier-ignore\n console.log('ternary (mediaStyles)', mediaExtraction.ternaryWithoutMedia?.inlineMediaQuery ?? '', mediaExtraction.mediaStyles.map((x) => x.identifier).join('.'))\n }\n }\n if (!mediaExtraction) {\n addTernaryStyle(\n attr.value,\n addStyles(attr.value.consequent),\n addStyles(attr.value.alternate)\n )\n continue\n }\n lastMediaImportance++\n if (mediaExtraction.mediaStyles) {\n finalStyles = [...finalStyles, ...mediaExtraction.mediaStyles]\n }\n if (mediaExtraction.ternaryWithoutMedia) {\n addTernaryStyle(mediaExtraction.ternaryWithoutMedia, mediaExtraction.mediaStyles, [])\n } else {\n finalClassNames = [\n ...finalClassNames,\n ...mediaExtraction.mediaStyles.map((x) => t.stringLiteral(x.identifier)),\n ]\n }\n break\n }\n }\n\n function addTernaryStyle(ternary: Ternary, a: any, b: any) {\n const cCN = a.map((x) => x.identifier).join(' ')\n const aCN = b.map((x) => x.identifier).join(' ')\n if (a.length && b.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 }\n\n if (shouldPrintDebug) {\n // prettier-ignore\n console.log(' finalClassNames\\n', logLines(finalClassNames.map(x => x['value']).join(' ')))\n }\n\n node.attributes = finalAttrs\n\n if (finalClassNames.length) {\n // inserts the _cn variable and uses it for className\n let names = buildClassName(finalClassNames)\n if (t.isStringLiteral(names)) {\n names.value = concatClassName(names.value)\n }\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 if (!hasFlattened) {\n // not flat\n } else {\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\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, identifier, value } of finalStyles) {\n // console.log('backvalue', identifier, value)\n // ast.program.body.unshift(\n // t.expressionStatement(\n // t.callExpression(\n // t.memberExpression(\n // t.callExpression(t.identifier('require'), [t.stringLiteral('@tamagui/core')]),\n // t.identifier('setIdentifierValue')\n // ),\n // [t.stringLiteral(identifier), t.stringLiteral(value)]\n // )\n // )\n // )\n\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 = loader.remainingRequest\n const importPath = `${cssPath}!=!${cssLoaderPath}?${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 // this makes the debug output terrible, and i think sourcemap works already\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 path = basename(sourcePath)\n .replace(/\\.[jt]sx?$/, '')\n .slice(0, 22)\n .trim()\n .padStart(24)\n const numOptimized = `${res.optimized}`.padStart(3)\n const numFound = `${res.found}`.padStart(3)\n const numFlattened = `${res.flattened}`.padStart(3)\n const memory = process.env.DEBUG && memUsed > 10 ? ` ${memUsed}MB` : ''\n const timing = Date.now() - start\n const timingWarning = timing > 50 ? '\u26A0\uFE0F' : timing > 150 ? '\u2622\uFE0F' : ''\n const timingStr = `${timing}ms${timingWarning}`.padStart(6)\n console.log(\n `${getPrefixLogs(\n options\n )} ${path} ${numFound} \u00B7 ${numOptimized} \u00B7 ${numFlattened} ${timingStr} ${\n memory ? `(${memory})` : ''\n }`\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;AAAA,WAAsB;AACtB,kBAAyB;AACzB,WAAsB;AAEtB,uBAAqB;AACrB,QAAmB;AACnB,uBAAgC;AAChC,qBAAgC;AAChC,uBAAsB;AAItB,uBAAwC;AAExC,wBAA2B;AAC3B,4BAA+B;AAE/B,mCAAsC;AACtC,4BAA+B;AAC/B,+BAAkC;AAClC,2BAA8B;AAC9B,6BAAgC;AAChC,0BAA6B;AAC7B,sBAAyB;AACzB,mBAAsB;AAEtB,MAAM,mBAAmB;AAAA,EACvB,eAAe;AAAA,EACf,cAAc;AAAA,EACd,aAAa;AAAA,EACb,cAAc;AAChB;AAUO,6BAA6B;AAAA,EAClC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,GAW2B;AAC3B,QAAM,KAAK,wBAAM;AAEjB,MAAI,OAAO,WAAW,UAAU;AAC9B,UAAM,IAAI,MAAM,yCAAyC;AAAA,EAC3D;AACA,gCACE,OAAO,eAAe,YAAY,KAAK,WAAW,UAAU,GAC5D,qDACF;AAEA,QAAM,kBAAkB,QAAQ,cAAc;AA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OAAO;AAAA,EACd;AACF;AAtZgB;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -38,4 +38,8 @@ function findTopmostFunction(jsxPath) {
|
|
|
38
38
|
return compFn;
|
|
39
39
|
}
|
|
40
40
|
__name(findTopmostFunction, "findTopmostFunction");
|
|
41
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
42
|
+
0 && (module.exports = {
|
|
43
|
+
findTopmostFunction
|
|
44
|
+
});
|
|
41
45
|
//# sourceMappingURL=findTopmostFunction.js.map
|
|
@@ -26,4 +26,8 @@ function getPrefixLogs(options) {
|
|
|
26
26
|
return (options == null ? void 0 : options.prefixLogs) ?? ` ${TAMAGUI_TARGET} | `;
|
|
27
27
|
}
|
|
28
28
|
__name(getPrefixLogs, "getPrefixLogs");
|
|
29
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
30
|
+
0 && (module.exports = {
|
|
31
|
+
getPrefixLogs
|
|
32
|
+
});
|
|
29
33
|
//# sourceMappingURL=getPrefixLogs.js.map
|
|
@@ -67,4 +67,8 @@ function getPropValueFromAttributes(propName, attrs) {
|
|
|
67
67
|
return propValue;
|
|
68
68
|
}
|
|
69
69
|
__name(getPropValueFromAttributes, "getPropValueFromAttributes");
|
|
70
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
71
|
+
0 && (module.exports = {
|
|
72
|
+
getPropValueFromAttributes
|
|
73
|
+
});
|
|
70
74
|
//# sourceMappingURL=getPropValueFromAttributes.js.map
|
|
@@ -87,4 +87,8 @@ function getSourceModule(itemName, itemBinding) {
|
|
|
87
87
|
};
|
|
88
88
|
}
|
|
89
89
|
__name(getSourceModule, "getSourceModule");
|
|
90
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
91
|
+
0 && (module.exports = {
|
|
92
|
+
getSourceModule
|
|
93
|
+
});
|
|
90
94
|
//# sourceMappingURL=getSourceModule.js.map
|
|
@@ -45,7 +45,16 @@ function importModule(path) {
|
|
|
45
45
|
const filenames = [path.replace(".js", ".tsx"), path.replace(".js", ".ts"), path];
|
|
46
46
|
for (const file of filenames) {
|
|
47
47
|
if ((0, import_fs_extra.existsSync)(file)) {
|
|
48
|
-
|
|
48
|
+
const { unregister } = require("esbuild-register/dist/node").register({
|
|
49
|
+
target: "es2019",
|
|
50
|
+
format: "cjs"
|
|
51
|
+
});
|
|
52
|
+
try {
|
|
53
|
+
return require(file);
|
|
54
|
+
} catch {
|
|
55
|
+
} finally {
|
|
56
|
+
unregister();
|
|
57
|
+
}
|
|
49
58
|
}
|
|
50
59
|
}
|
|
51
60
|
return null;
|
|
@@ -146,4 +155,8 @@ function getStaticBindingsForScope(scope, whitelist = [], sourcePath, bindingCac
|
|
|
146
155
|
return ret;
|
|
147
156
|
}
|
|
148
157
|
__name(getStaticBindingsForScope, "getStaticBindingsForScope");
|
|
158
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
159
|
+
0 && (module.exports = {
|
|
160
|
+
getStaticBindingsForScope
|
|
161
|
+
});
|
|
149
162
|
//# sourceMappingURL=getStaticBindingsForScope.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/extractor/getStaticBindingsForScope.ts"],
|
|
4
|
-
"sourcesContent": ["import { dirname, extname, resolve } from 'path'\n\nimport { Binding, NodePath } from '@babel/traverse'\nimport * as t from '@babel/types'\nimport { existsSync } from 'fs-extra'\n\nimport { evaluateAstNode } from './evaluateAstNode'\nimport { getSourceModule } from './getSourceModule'\n\nconst isLocalImport = (path: string) => path.startsWith('.') || path.startsWith('/')\n\nfunction resolveImportPath(sourcePath: string, path: string) {\n const sourceDir = dirname(sourcePath)\n if (isLocalImport(path)) {\n if (extname(path) === '') {\n path += '.js'\n }\n return resolve(sourceDir, path)\n }\n return path\n}\n\nfunction importModule(path: string) {\n const filenames = [path.replace('.js', '.tsx'), path.replace('.js', '.ts'), path]\n for (const file of filenames) {\n if (existsSync(file)) {\n // TODO we can clear this when we see updates on it later on\n
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAA0C;AAG1C,QAAmB;AACnB,sBAA2B;AAE3B,6BAAgC;AAChC,6BAAgC;AAEhC,MAAM,gBAAgB,wBAAC,SAAiB,KAAK,WAAW,GAAG,KAAK,KAAK,WAAW,GAAG,GAA7D;AAEtB,2BAA2B,YAAoB,MAAc;AAC3D,QAAM,YAAY,yBAAQ,UAAU;AACpC,MAAI,cAAc,IAAI,GAAG;AACvB,QAAI,yBAAQ,IAAI,MAAM,IAAI;AACxB,cAAQ;AAAA,IACV;AACA,WAAO,yBAAQ,WAAW,IAAI;AAAA,EAChC;AACA,SAAO;AACT;AATS;AAWT,sBAAsB,MAAc;AAClC,QAAM,YAAY,CAAC,KAAK,QAAQ,OAAO,MAAM,GAAG,KAAK,QAAQ,OAAO,KAAK,GAAG,IAAI;AAChF,aAAW,QAAQ,WAAW;AAC5B,QAAI,gCAAW,IAAI,GAAG;
|
|
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": ";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAA0C;AAG1C,QAAmB;AACnB,sBAA2B;AAE3B,6BAAgC;AAChC,6BAAgC;AAEhC,MAAM,gBAAgB,wBAAC,SAAiB,KAAK,WAAW,GAAG,KAAK,KAAK,WAAW,GAAG,GAA7D;AAEtB,2BAA2B,YAAoB,MAAc;AAC3D,QAAM,YAAY,yBAAQ,UAAU;AACpC,MAAI,cAAc,IAAI,GAAG;AACvB,QAAI,yBAAQ,IAAI,MAAM,IAAI;AACxB,cAAQ;AAAA,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,CAAC,EAAE,aAAa,IAAI,EAAE,GAAG;AAC3B,cAAQ,MAAM,0BAA0B;AACxC;AAAA,IACF;AAEA,UAAM,WAAW,GAAG,IAAI,GAAG,QAAQ,IAAI,GAAG,SAAS,IAAI,GAAG;AAG1D,QAAI,aAAa,eAAe,QAAQ,GAAG;AACzC,UAAI,KAAK,aAAa;AACtB;AAAA,IACF;AAEA,QAAI,aAAa,eAAe,QAAQ,GAAG;AACzC,UAAI,KAAK,aAAa;AACtB;AAAA,IACF;AAGA,QAAI;AACF,UAAI,KAAK,4CAAgB,IAAI,MAAM,QAAW,gBAAgB;AAC9D,mBAAa,YAAY,IAAI;AAC7B;AAAA,IACF,SAAS,GAAP;AAAA,IAKF;AAAA,EACF;AAEA,SAAO;AACT;AA3IgB;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -62,4 +62,8 @@ function hoistClassNames(path, existing, expr) {
|
|
|
62
62
|
__name(replaceStringWithVariable, "replaceStringWithVariable");
|
|
63
63
|
}
|
|
64
64
|
__name(hoistClassNames, "hoistClassNames");
|
|
65
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
66
|
+
0 && (module.exports = {
|
|
67
|
+
hoistClassNames
|
|
68
|
+
});
|
|
65
69
|
//# sourceMappingURL=hoistClassNames.js.map
|
|
@@ -111,4 +111,9 @@ function computeProps(props) {
|
|
|
111
111
|
}, {});
|
|
112
112
|
}
|
|
113
113
|
__name(computeProps, "computeProps");
|
|
114
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
115
|
+
0 && (module.exports = {
|
|
116
|
+
astToLiteral,
|
|
117
|
+
literalToAst
|
|
118
|
+
});
|
|
114
119
|
//# sourceMappingURL=literalToAst.js.map
|
|
@@ -28,56 +28,76 @@ function loadTamagui(props) {
|
|
|
28
28
|
if (loadedTamagui) {
|
|
29
29
|
return loadedTamagui;
|
|
30
30
|
}
|
|
31
|
-
process.env.IS_STATIC = "is_static";
|
|
32
|
-
const proxyWorm = require("@tamagui/proxy-worm");
|
|
33
|
-
const rnw = require("react-native-web");
|
|
34
|
-
const Mod = require("module");
|
|
35
|
-
const og = Mod.prototype.require;
|
|
36
|
-
Mod.prototype.require = function(path) {
|
|
37
|
-
if (path.endsWith(".css")) {
|
|
38
|
-
return {};
|
|
39
|
-
}
|
|
40
|
-
if (path === "@gorhom/bottom-sheet" || path.startsWith("react-native-reanimated")) {
|
|
41
|
-
return proxyWorm;
|
|
42
|
-
}
|
|
43
|
-
if (path.startsWith("react-native") && !path.startsWith("react-native-web/dist/cjs/exports")) {
|
|
44
|
-
return rnw;
|
|
45
|
-
}
|
|
46
|
-
try {
|
|
47
|
-
return og.apply(this, arguments);
|
|
48
|
-
} catch (err) {
|
|
49
|
-
console.error("Tamagui error loading file:\n");
|
|
50
|
-
console.log(" ", path, "\n");
|
|
51
|
-
console.log(err.message);
|
|
52
|
-
console.log(err.stack);
|
|
53
|
-
process.exit(1);
|
|
54
|
-
}
|
|
55
|
-
};
|
|
56
31
|
const configPath = (0, import_path.join)(process.cwd(), props.config);
|
|
57
|
-
const
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
32
|
+
const { unregister } = require("esbuild-register/dist/node").register({
|
|
33
|
+
target: "es2019",
|
|
34
|
+
format: "cjs"
|
|
35
|
+
});
|
|
36
|
+
try {
|
|
37
|
+
process.env.IS_STATIC = "is_static";
|
|
38
|
+
const proxyWorm = require("@tamagui/proxy-worm");
|
|
39
|
+
const rnw = require("react-native-web");
|
|
40
|
+
const Mod = require("module");
|
|
41
|
+
const og = Mod.prototype.require;
|
|
42
|
+
Mod.prototype.require = function(path) {
|
|
43
|
+
if (path.endsWith(".css")) {
|
|
44
|
+
return {};
|
|
45
|
+
}
|
|
46
|
+
if (path === "@gorhom/bottom-sheet" || path.startsWith("react-native-reanimated")) {
|
|
47
|
+
return proxyWorm;
|
|
48
|
+
}
|
|
49
|
+
if (path.startsWith("react-native") && !path.startsWith("react-native-web/dist/cjs/exports")) {
|
|
50
|
+
return rnw;
|
|
51
|
+
}
|
|
52
|
+
try {
|
|
53
|
+
return og.apply(this, arguments);
|
|
54
|
+
} catch (err) {
|
|
55
|
+
console.error("Tamagui error loading file:\n");
|
|
56
|
+
console.log(" ", path, "\n");
|
|
57
|
+
console.log(err.message);
|
|
58
|
+
console.log(err.stack);
|
|
59
|
+
process.exit(1);
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
const exp = require(configPath);
|
|
63
|
+
const tamaguiConfig = exp["default"] || exp;
|
|
64
|
+
if (!tamaguiConfig || !tamaguiConfig.parsed) {
|
|
65
|
+
try {
|
|
66
|
+
const confPath = require.resolve(configPath);
|
|
67
|
+
console.log(`Received:`, tamaguiConfig);
|
|
68
|
+
throw new Error(`Can't find valid config in ${confPath}`);
|
|
69
|
+
} catch (err) {
|
|
70
|
+
throw err;
|
|
71
|
+
}
|
|
66
72
|
}
|
|
73
|
+
const components = {};
|
|
74
|
+
for (const moduleName of props.components) {
|
|
75
|
+
const exported = require(moduleName);
|
|
76
|
+
for (const Name in exported) {
|
|
77
|
+
const val = exported[Name];
|
|
78
|
+
const staticConfig = val == null ? void 0 : val.staticConfig;
|
|
79
|
+
if (staticConfig) {
|
|
80
|
+
Object.assign(components, { [Name]: { staticConfig } });
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
process.env.IS_STATIC = void 0;
|
|
85
|
+
Mod.prototype.require = og;
|
|
86
|
+
(0, import_core_node.createTamagui)(tamaguiConfig);
|
|
87
|
+
loadedTamagui = {
|
|
88
|
+
components,
|
|
89
|
+
tamaguiConfig
|
|
90
|
+
};
|
|
91
|
+
return loadedTamagui;
|
|
92
|
+
} catch (err) {
|
|
93
|
+
throw err;
|
|
94
|
+
} finally {
|
|
95
|
+
unregister();
|
|
67
96
|
}
|
|
68
|
-
const components = {};
|
|
69
|
-
for (const module2 of props.components) {
|
|
70
|
-
const exported = require(module2);
|
|
71
|
-
Object.assign(components, exported);
|
|
72
|
-
}
|
|
73
|
-
process.env.IS_STATIC = void 0;
|
|
74
|
-
Mod.prototype.require = og;
|
|
75
|
-
(0, import_core_node.createTamagui)(tamaguiConfig);
|
|
76
|
-
loadedTamagui = {
|
|
77
|
-
components,
|
|
78
|
-
tamaguiConfig
|
|
79
|
-
};
|
|
80
|
-
return loadedTamagui;
|
|
81
97
|
}
|
|
82
98
|
__name(loadTamagui, "loadTamagui");
|
|
99
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
100
|
+
0 && (module.exports = {
|
|
101
|
+
loadTamagui
|
|
102
|
+
});
|
|
83
103
|
//# sourceMappingURL=loadTamagui.js.map
|
|
@@ -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\nexport function loadTamagui(props: { components: string[]; config: string }): {\n components: Record<string, TamaguiComponent>\n tamaguiConfig: TamaguiInternalConfig\n} {\n if (loadedTamagui) {\n return loadedTamagui\n }\n\n // lets shim require and avoid importing react-native + react-native-web\n
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAAqB;AAGrB,uBAA8B;AAE9B,IAAI,gBAAqB;AAElB,qBAAqB,OAG1B;AACA,MAAI,eAAe;AACjB,WAAO;AAAA,EACT;
|
|
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\nexport function loadTamagui(props: { components: string[]; config: string }): {\n components: Record<string, TamaguiComponent>\n tamaguiConfig: TamaguiInternalConfig\n} {\n if (loadedTamagui) {\n return loadedTamagui\n }\n\n const configPath = join(process.cwd(), props.config)\n\n // threaded caching avoiding 1s loading of large configs every save\n // const cachePath = join(cacheDir, 'tamagui-conf-cached.json')\n // const confStat = statSync(configPath)\n\n // // TODO may want to disable, its pretty optimistic at caching...\n // try {\n // const confCache = readFileSync(cachePath, 'utf-8')\n // const confParsed = JSON.parse(confCache)\n // if (confParsed && confParsed.mtime === confStat.mtime) {\n // return confParsed.value\n // }\n // } catch {\n // // ok, no cache\n // }\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 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 Mod.prototype.require = function (path: string) {\n if (path.endsWith('.css')) {\n return {}\n }\n if (path === '@gorhom/bottom-sheet' || path.startsWith('react-native-reanimated')) {\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 return og.apply(this, arguments)\n } catch (err: any) {\n console.error('Tamagui error loading file:\\n')\n console.log(' ', path, '\\n')\n console.log(err.message)\n console.log(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\n if (staticConfig) {\n Object.assign(components, { [Name]: { staticConfig } })\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 }\n\n // save cache\n // try {\n // writeFileSync(\n // cachePath,\n // JSON.stringify({\n // value: loadedTamagui,\n // mtime: confStat.mtime,\n // })\n // )\n // } catch (err: any) {\n // console.log(`Error: tamagui config not stringifiable, caching disabled \"${err.message}\"`)\n // }\n\n return loadedTamagui\n } catch (err) {\n throw err\n } finally {\n unregister()\n }\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAAqB;AAGrB,uBAA8B;AAE9B,IAAI,gBAAqB;AAElB,qBAAqB,OAG1B;AACA,MAAI,eAAe;AACjB,WAAO;AAAA,EACT;AAEA,QAAM,aAAa,sBAAK,QAAQ,IAAI,GAAG,MAAM,MAAM;AAiBnD,QAAM,EAAE,eAAe,QAAQ,4BAA4B,EAAE,SAAS;AAAA,IACpE,QAAQ;AAAA,IACR,QAAQ;AAAA,EACV,CAAC;AAED,MAAI;AAGF,YAAQ,IAAI,YAAY;AACxB,UAAM,YAAY,QAAQ,qBAAqB;AAC/C,UAAM,MAAM,QAAQ,kBAAkB;AACtC,UAAM,MAAM,QAAQ,QAAQ;AAC5B,UAAM,KAAK,IAAI,UAAU;AACzB,QAAI,UAAU,UAAU,SAAU,MAAc;AAC9C,UAAI,KAAK,SAAS,MAAM,GAAG;AACzB,eAAO,CAAC;AAAA,MACV;AACA,UAAI,SAAS,0BAA0B,KAAK,WAAW,yBAAyB,GAAG;AACjF,eAAO;AAAA,MACT;AACA,UACE,KAAK,WAAW,cAAc,KAE9B,CAAC,KAAK,WAAW,mCAAmC,GACpD;AACA,eAAO;AAAA,MACT;AACA,UAAI;AACF,eAAO,GAAG,MAAM,MAAM,SAAS;AAAA,MACjC,SAAS,KAAP;AACA,gBAAQ,MAAM,+BAA+B;AAC7C,gBAAQ,IAAI,OAAO,MAAM,IAAI;AAC7B,gBAAQ,IAAI,IAAI,OAAO;AACvB,gBAAQ,IAAI,IAAI,KAAK;AAErB,gBAAQ,KAAK,CAAC;AAAA,MAChB;AAAA,IACF;AAGA,UAAM,MAAM,QAAQ,UAAU;AAC9B,UAAM,gBAAiB,IAAI,cAAc;AAEzC,QAAI,CAAC,iBAAiB,CAAC,cAAc,QAAQ;AAC3C,UAAI;AACF,cAAM,WAA2B,AAAhB,QAAQ,QAAQ;AACjC,gBAAQ,IAAI,aAAa,aAAa;AACtC,cAAM,IAAI,MAAM,8BAA8B,UAAU;AAAA,MAC1D,SAAS,KAAP;AACA,cAAM;AAAA,MACR;AAAA,IACF;AAGA,UAAM,aAAa,CAAC;AACpB,eAAW,cAAc,MAAM,YAAY;AACzC,YAAM,WAAW,QAAQ,UAAU;AACnC,iBAAW,QAAQ,UAAU;AAC3B,cAAM,MAAM,SAAS;AACrB,cAAM,eAAe,2BAAK;AAC1B,YAAI,cAAc;AAChB,iBAAO,OAAO,YAAY,GAAG,OAAO,EAAE,aAAa,EAAE,CAAC;AAAA,QACxD;AAAA,MACF;AAAA,IACF;AAGA,YAAQ,IAAI,YAAY;AACxB,QAAI,UAAU,UAAU;AAGxB,wCAAc,aAAoB;AAElC,oBAAgB;AAAA,MACd;AAAA,MACA;AAAA,IACF;AAeA,WAAO;AAAA,EACT,SAAS,KAAP;AACA,UAAM;AAAA,EACR,UAAE;AACA,eAAW;AAAA,EACb;AACF;AA1HgB;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -37,4 +37,8 @@ ${prefix}`);
|
|
|
37
37
|
}
|
|
38
38
|
return lines.map((line, i) => prefix + (i == 0 ? "" : " ") + line.trim()).join("\n");
|
|
39
39
|
}, "logLines");
|
|
40
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
41
|
+
0 && (module.exports = {
|
|
42
|
+
logLines
|
|
43
|
+
});
|
|
40
44
|
//# sourceMappingURL=logLines.js.map
|
|
@@ -98,4 +98,8 @@ function normalizeTernaries(ternaries) {
|
|
|
98
98
|
return ternaryExpression;
|
|
99
99
|
}
|
|
100
100
|
__name(normalizeTernaries, "normalizeTernaries");
|
|
101
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
102
|
+
0 && (module.exports = {
|
|
103
|
+
normalizeTernaries
|
|
104
|
+
});
|
|
101
105
|
//# sourceMappingURL=normalizeTernaries.js.map
|
|
@@ -97,4 +97,8 @@ function removeUnusedHooks(compFn, shouldPrintDebug) {
|
|
|
97
97
|
}
|
|
98
98
|
}
|
|
99
99
|
__name(removeUnusedHooks, "removeUnusedHooks");
|
|
100
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
101
|
+
0 && (module.exports = {
|
|
102
|
+
removeUnusedHooks
|
|
103
|
+
});
|
|
100
104
|
//# sourceMappingURL=removeUnusedHooks.js.map
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var timer_exports = {};
|
|
20
|
+
__export(timer_exports, {
|
|
21
|
+
timer: () => timer
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(timer_exports);
|
|
24
|
+
const timer = /* @__PURE__ */ __name(() => {
|
|
25
|
+
const start = Date.now();
|
|
26
|
+
let last = start;
|
|
27
|
+
return {
|
|
28
|
+
mark: (name, print = false) => {
|
|
29
|
+
if (print) {
|
|
30
|
+
const took = Date.now() - last;
|
|
31
|
+
last = Date.now();
|
|
32
|
+
console.log(`Time ${name}: ${took}ms`);
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
done: (print = false) => {
|
|
36
|
+
if (print) {
|
|
37
|
+
console.log(`Total time: ${Date.now() - start}ms`);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
}, "timer");
|
|
42
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
43
|
+
0 && (module.exports = {
|
|
44
|
+
timer
|
|
45
|
+
});
|
|
46
|
+
//# sourceMappingURL=timer.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/extractor/timer.ts"],
|
|
4
|
+
"sourcesContent": ["export const timer = () => {\n const start = Date.now()\n let last = start\n return {\n mark: (name: string, print = false) => {\n if (print) {\n const took = Date.now() - last\n last = Date.now()\n console.log(`Time ${name}: ${took}ms`)\n }\n },\n done: (print = false) => {\n if (print) {\n console.log(`Total time: ${Date.now() - start}ms`)\n }\n },\n }\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAO,MAAM,QAAQ,6BAAM;AACzB,QAAM,QAAQ,KAAK,IAAI;AACvB,MAAI,OAAO;AACX,SAAO;AAAA,IACL,MAAM,CAAC,MAAc,QAAQ,UAAU;AACrC,UAAI,OAAO;AACT,cAAM,OAAO,KAAK,IAAI,IAAI;AAC1B,eAAO,KAAK,IAAI;AAChB,gBAAQ,IAAI,QAAQ,SAAS,QAAQ;AAAA,MACvC;AAAA,IACF;AAAA,IACA,MAAM,CAAC,QAAQ,UAAU;AACvB,UAAI,OAAO;AACT,gBAAQ,IAAI,eAAe,KAAK,IAAI,IAAI,SAAS;AAAA,MACnD;AAAA,IACF;AAAA,EACF;AACF,GAjBqB;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
package/dist/cjs/index.js
CHANGED
|
@@ -31,4 +31,10 @@ __reExport(src_exports, require("./extractor/extractToClassNames"), module.expor
|
|
|
31
31
|
__reExport(src_exports, require("./extractor/extractHelpers"), module.exports);
|
|
32
32
|
__reExport(src_exports, require("./patchReactNativeWeb"), module.exports);
|
|
33
33
|
process.env.TAMAGUI_COMPILE_PROCESS = "1";
|
|
34
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
35
|
+
0 && (module.exports = {
|
|
36
|
+
TamaguiOptions,
|
|
37
|
+
createExtractor,
|
|
38
|
+
literalToAst
|
|
39
|
+
});
|
|
34
40
|
//# sourceMappingURL=index.js.map
|