@tamagui/static 1.0.0-alpha.62 → 1.0.0-alpha.66

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (63) hide show
  1. package/dist/cjs/extractor/createExtractor.js +36 -15
  2. package/dist/cjs/extractor/createExtractor.js.map +2 -2
  3. package/dist/cjs/extractor/extractHelpers.js +15 -5
  4. package/dist/cjs/extractor/extractHelpers.js.map +2 -2
  5. package/dist/cjs/extractor/extractMediaStyle.js.map +1 -1
  6. package/dist/cjs/extractor/extractToClassNames.js +27 -20
  7. package/dist/cjs/extractor/extractToClassNames.js.map +2 -2
  8. package/dist/cjs/extractor/getPrefixLogs.js +34 -0
  9. package/dist/cjs/extractor/getPrefixLogs.js.map +7 -0
  10. package/dist/cjs/extractor/literalToAst.js +59 -0
  11. package/dist/cjs/extractor/literalToAst.js.map +2 -2
  12. package/dist/cjs/patchReactNativeWeb.js +1 -1
  13. package/dist/cjs/patchReactNativeWeb.js.map +1 -1
  14. package/dist/cjs/types.js.map +1 -1
  15. package/dist/esm/extractor/createExtractor.js +35 -13
  16. package/dist/esm/extractor/createExtractor.js.map +2 -2
  17. package/dist/esm/extractor/extractHelpers.js +16 -5
  18. package/dist/esm/extractor/extractHelpers.js.map +2 -2
  19. package/dist/esm/extractor/extractMediaStyle.js.map +1 -1
  20. package/dist/esm/extractor/extractToClassNames.js +29 -22
  21. package/dist/esm/extractor/extractToClassNames.js.map +2 -2
  22. package/dist/esm/extractor/getPrefixLogs.js +12 -0
  23. package/dist/esm/extractor/getPrefixLogs.js.map +7 -0
  24. package/dist/esm/extractor/literalToAst.js +46 -0
  25. package/dist/esm/extractor/literalToAst.js.map +2 -2
  26. package/dist/esm/patchReactNativeWeb.js +1 -1
  27. package/dist/esm/patchReactNativeWeb.js.map +1 -1
  28. package/dist/jsx/extractor/createExtractor.js +35 -13
  29. package/dist/jsx/extractor/extractHelpers.js +16 -5
  30. package/dist/jsx/extractor/extractToClassNames.js +29 -22
  31. package/dist/jsx/extractor/getPrefixLogs.js +11 -0
  32. package/dist/jsx/extractor/literalToAst.js +46 -0
  33. package/dist/jsx/patchReactNativeWeb.js +1 -1
  34. package/package.json +7 -7
  35. package/types/extractor/createExtractor.d.ts +1 -1
  36. package/types/extractor/getPrefixLogs.d.ts +3 -0
  37. package/types/extractor/literalToAst.d.ts +1 -0
  38. package/types/types.d.ts +2 -0
  39. package/types/constants.d.ts.map +0 -1
  40. package/types/extractor/accessSafe.d.ts.map +0 -1
  41. package/types/extractor/babelParse.d.ts.map +0 -1
  42. package/types/extractor/buildClassName.d.ts.map +0 -1
  43. package/types/extractor/createEvaluator.d.ts.map +0 -1
  44. package/types/extractor/createExtractor.d.ts.map +0 -1
  45. package/types/extractor/ensureImportingConcat.d.ts.map +0 -1
  46. package/types/extractor/evaluateAstNode.d.ts.map +0 -1
  47. package/types/extractor/extractHelpers.d.ts.map +0 -1
  48. package/types/extractor/extractMediaStyle.d.ts.map +0 -1
  49. package/types/extractor/extractToClassNames.d.ts.map +0 -1
  50. package/types/extractor/findTopmostFunction.d.ts.map +0 -1
  51. package/types/extractor/generatedUid.d.ts.map +0 -1
  52. package/types/extractor/getPropValueFromAttributes.d.ts.map +0 -1
  53. package/types/extractor/getSourceModule.d.ts.map +0 -1
  54. package/types/extractor/getStaticBindingsForScope.d.ts.map +0 -1
  55. package/types/extractor/hoistClassNames.d.ts.map +0 -1
  56. package/types/extractor/literalToAst.d.ts.map +0 -1
  57. package/types/extractor/loadTamagui.d.ts.map +0 -1
  58. package/types/extractor/logLines.d.ts.map +0 -1
  59. package/types/extractor/normalizeTernaries.d.ts.map +0 -1
  60. package/types/extractor/removeUnusedHooks.d.ts.map +0 -1
  61. package/types/index.d.ts.map +0 -1
  62. package/types/patchReactNativeWeb.d.ts.map +0 -1
  63. package/types/types.d.ts.map +0 -1
@@ -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 { 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 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 }) => {\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 (shouldPrintDebug) {\n console.log('styleWithPrev', styleWithPrev, res)\n }\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 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 } 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;AACA;AACA;AAEA;AACA;AACA;AACA;AACA;AACA;AAGA;AAEA;AACA;AAEA;AACA;AACA;AACA;AACA;AAEA,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;AAtDF;AAuDE,MAAI,OAAO,WAAW,UAAU;AAC9B,UAAM,IAAI,MAAM;AAAA;AAElB,YACE,OAAO,eAAe,YAAY,KAAK,WAAW,aAClD;AAGF,QAAM,kBAAkB,cAAQ,eAAR,YAAsB;AAC9C,QAAM,QAAQ,KAAK;AACnB,QAAM,MAAM,kBAAkB,QAAQ,gBAAgB;AAGtD,MAAI;AAEJ,MAAI;AAEF,UAAM,WAAW;AAAA,WACV,KAAP;AACA,YAAQ,MAAM,sBAAsB;AACpC,UAAM;AAAA;AAGR,QAAM,SAAS,oBAAI;AACnB,QAAM,iBAAkD;AAExD,MAAI,eAAe;AAEnB,QAAM,MAAM,UAAU,MAAM,KAAK;AAAA,IAC/B;AAAA,IACA;AAAA,OACG;AAAA,IACH,kBAAkB,CAAC,EAAE,UAAU;AAC7B,qBAAe;AACf,aAAO;AAAA;AAAA,IAET,cAAc,CAAC;AAAA,MACb;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,UACI;AACJ,UAAI,kBAAqC;AACzC,UAAI,aAAwD;AAC5D,UAAI,cAA6B;AAEjC,YAAM,aAAa;AACnB,iBAAW,QAAQ,OAAO;AACxB,YAAI,KAAK,SAAS,SAAS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QAAQ,KAAK,QAAQ,EAAE,kBAAkB,IAAI,EAAE,cAAc;AAAA;AAGnE,QAAM,SAAS,SACb,KACA;AAAA,IACE,SAAS;AAAA,IACT,UAAU;AAAA,IACV,aAAa;AAAA,IACb,gBAAgB;AAAA,IAChB,YAAY;AAAA,KAEd;AAGF,MAAI,kBAAkB;AACpB,YAAQ,IACN,wCACA,OAAO,KACJ,MAAM,MACN,OAAO,CAAC,MAAM,CAAC,EAAE,WAAW,OAC5B,KAAK;AAEV,YAAQ,IAAI,0CAA0C;AAAA;AAGxD,MAAI,iBAAiB;AACnB,UAAM,UAAU,MACZ,KAAK,MAAQ,SAAQ,cAAc,WAAW,IAAI,YAAY,OAAO,OAAQ,MAAM,KACnF;AACJ,UAAM,SAAS,GAAG,KAAK,QAAQ,QAAQ,SAAS;AAChD,UAAM,QAAO,SAAS,YAAY,SAAS;AAC3C,UAAM,eAAe,GAAG,IAAI,YAAY,SAAS;AACjD,UAAM,SAAS,UAAU,KAAK,QAAQ,cAAc;AACpD,YAAQ,IACN,eAAQ,SAAQ,uBAAe,+BAA4B,IAAI,uBAAuB;AAAA;AAI1F,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA,IAAI,OAAO;AAAA,IACX,KAAK,OAAO;AAAA;AAAA;AArTA;",
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, 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 { 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 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 }) => {\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 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 (shouldPrintDebug) {\n // prettier-ignore\n console.log('ternary (mediaStyles)', mediaExtraction?.ternaryWithoutMedia?.inlineMediaQuery ?? '', mediaExtraction?.mediaStyles.map((x) => x.identifier).join('.'))\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 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 } 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(30)\n const numOptimized = `${res.optimized}`.padStart(4)\n const memory = memUsed > 10 ? `used ${memUsed}MB` : ''\n console.log(\n `${getPrefixLogs(options)} ${path} ${timing}ms \u05C1\u00B7 ${numOptimized} optimized \u00B7 ${\n res.flattened\n } 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;AACA;AACA;AAEA;AACA;AACA;AACA;AACA;AACA;AAGA;AAEA;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AI,QAAQ,KAAK,QAAQ,EAAE,kBAAkB,IAAI,EAAE,cAAc;AAAA;AAGnE,QAAM,SAAS,SACb,KACA;AAAA,IACE,SAAS;AAAA,IACT,UAAU;AAAA,IACV,aAAa;AAAA,IACb,gBAAgB;AAAA,IAChB,YAAY;AAAA,KAEd;AAGF,MAAI,kBAAkB;AACpB,YAAQ,IACN,wCACA,OAAO,KACJ,MAAM,MACN,OAAO,CAAC,MAAM,CAAC,EAAE,WAAW,OAC5B,KAAK;AAEV,YAAQ,IAAI,0CAA0C;AAAA;AAGxD,MAAI,iBAAiB;AACnB,UAAM,UAAU,MACZ,KAAK,MAAQ,SAAQ,cAAc,WAAW,IAAI,YAAY,OAAO,OAAQ,MAAM,KACnF;AACJ,UAAM,SAAS,GAAG,KAAK,QAAQ,QAAQ,SAAS;AAChD,UAAM,QAAO,SAAS,YAAY,SAAS;AAC3C,UAAM,eAAe,GAAG,IAAI,YAAY,SAAS;AACjD,UAAM,SAAS,UAAU,KAAK,QAAQ,cAAc;AACpD,YAAQ,IACN,GAAG,cAAc,YAAY,SAAQ,uBAAe,+BAClD,IAAI,uBACQ;AAAA;AAIlB,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA,IAAI,OAAO;AAAA,IACX,KAAK,OAAO;AAAA;AAAA;AAjUA;",
6
6
  "names": []
7
7
  }
@@ -0,0 +1,12 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
+ function getPrefixLogs(options) {
4
+ var _a;
5
+ const { TAMAGUI_TARGET } = process.env;
6
+ return (_a = options == null ? void 0 : options.prefixLogs) != null ? _a : `[${TAMAGUI_TARGET}] \xBB `;
7
+ }
8
+ __name(getPrefixLogs, "getPrefixLogs");
9
+ export {
10
+ getPrefixLogs
11
+ };
12
+ //# sourceMappingURL=getPrefixLogs.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/extractor/getPrefixLogs.ts"],
4
+ "sourcesContent": ["import { TamaguiOptions } from '../types'\n\nexport function getPrefixLogs(options?: TamaguiOptions) {\n const { TAMAGUI_TARGET } = process.env\n return options?.prefixLogs ?? `[${TAMAGUI_TARGET}] \u00BB `\n}\n"],
5
+ "mappings": ";;AAEO,uBAAuB,SAA0B;AAFxD;AAGE,QAAM,EAAE,mBAAmB,QAAQ;AACnC,SAAO,yCAAS,eAAT,YAAuB,IAAI;AAAA;AAFpB;",
6
+ "names": []
7
+ }
@@ -28,7 +28,53 @@ function literalToAst(literal) {
28
28
  }
29
29
  }
30
30
  __name(literalToAst, "literalToAst");
31
+ const easyPeasies = ["BooleanLiteral", "StringLiteral", "NumericLiteral"];
32
+ function astToLiteral(node) {
33
+ if (!node) {
34
+ return;
35
+ }
36
+ if (easyPeasies.includes(node.type)) {
37
+ return node.value;
38
+ }
39
+ if (node.name === "undefined" && !node.value) {
40
+ return void 0;
41
+ }
42
+ if (t.isNullLiteral(node)) {
43
+ return null;
44
+ }
45
+ if (t.isObjectExpression(node)) {
46
+ return computeProps(node.properties);
47
+ }
48
+ if (t.isArrayExpression(node)) {
49
+ return node.elements.reduce((acc, element) => [
50
+ ...acc,
51
+ ...(element == null ? void 0 : element.type) === "SpreadElement" ? astToLiteral(element.argument) : [astToLiteral(element)]
52
+ ], []);
53
+ }
54
+ }
55
+ __name(astToLiteral, "astToLiteral");
56
+ function computeProps(props) {
57
+ return props.reduce((acc, prop) => {
58
+ if (prop.type === "SpreadElement") {
59
+ return {
60
+ ...acc,
61
+ ...astToLiteral(prop.argument)
62
+ };
63
+ } else if (prop.type !== "ObjectMethod") {
64
+ const val = astToLiteral(prop.value);
65
+ if (val !== void 0) {
66
+ return {
67
+ ...acc,
68
+ [prop.key.name]: val
69
+ };
70
+ }
71
+ }
72
+ return acc;
73
+ }, {});
74
+ }
75
+ __name(computeProps, "computeProps");
31
76
  export {
77
+ astToLiteral,
32
78
  literalToAst
33
79
  };
34
80
  //# sourceMappingURL=literalToAst.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/extractor/literalToAst.ts"],
4
- "sourcesContent": ["import * as t from '@babel/types'\n\nexport function literalToAst(literal: any): t.Expression {\n if (literal === null) {\n return t.nullLiteral()\n }\n switch (typeof literal) {\n case 'function':\n throw new Error('Unsupported')\n case 'number':\n return t.numericLiteral(literal)\n case 'string':\n return t.stringLiteral(literal)\n case 'boolean':\n return t.booleanLiteral(literal)\n case 'undefined':\n return t.unaryExpression('void', t.numericLiteral(0), true)\n default:\n if (Array.isArray(literal)) {\n return t.arrayExpression(literal.map(literalToAst))\n }\n return t.objectExpression(\n Object.keys(literal)\n .filter((k) => {\n return typeof literal[k] !== 'undefined'\n })\n .map((k) => {\n return t.objectProperty(t.stringLiteral(k), literalToAst(literal[k]))\n })\n )\n }\n}\n"],
5
- "mappings": ";;AAAA;AAEO,sBAAsB,SAA4B;AACvD,MAAI,YAAY,MAAM;AACpB,WAAO,EAAE;AAAA;AAEX,UAAQ,OAAO;AAAA,SACR;AACH,YAAM,IAAI,MAAM;AAAA,SACb;AACH,aAAO,EAAE,eAAe;AAAA,SACrB;AACH,aAAO,EAAE,cAAc;AAAA,SACpB;AACH,aAAO,EAAE,eAAe;AAAA,SACrB;AACH,aAAO,EAAE,gBAAgB,QAAQ,EAAE,eAAe,IAAI;AAAA;AAEtD,UAAI,MAAM,QAAQ,UAAU;AAC1B,eAAO,EAAE,gBAAgB,QAAQ,IAAI;AAAA;AAEvC,aAAO,EAAE,iBACP,OAAO,KAAK,SACT,OAAO,CAAC,MAAM;AACb,eAAO,OAAO,QAAQ,OAAO;AAAA,SAE9B,IAAI,CAAC,MAAM;AACV,eAAO,EAAE,eAAe,EAAE,cAAc,IAAI,aAAa,QAAQ;AAAA;AAAA;AAAA;AAzB7D;",
4
+ "sourcesContent": ["import * as t from '@babel/types'\n\nexport function literalToAst(literal: any): t.Expression {\n if (literal === null) {\n return t.nullLiteral()\n }\n switch (typeof literal) {\n case 'function':\n throw new Error('Unsupported')\n case 'number':\n return t.numericLiteral(literal)\n case 'string':\n return t.stringLiteral(literal)\n case 'boolean':\n return t.booleanLiteral(literal)\n case 'undefined':\n return t.unaryExpression('void', t.numericLiteral(0), true)\n default:\n if (Array.isArray(literal)) {\n return t.arrayExpression(literal.map(literalToAst))\n }\n return t.objectExpression(\n Object.keys(literal)\n .filter((k) => {\n return typeof literal[k] !== 'undefined'\n })\n .map((k) => {\n return t.objectProperty(t.stringLiteral(k), literalToAst(literal[k]))\n })\n )\n }\n}\n\nconst easyPeasies = ['BooleanLiteral', 'StringLiteral', 'NumericLiteral']\n\nexport function astToLiteral(node: any) {\n if (!node) {\n return\n }\n if (easyPeasies.includes(node.type)) {\n return node.value\n }\n if (node.name === 'undefined' && !node.value) {\n return undefined\n }\n if (t.isNullLiteral(node)) {\n return null\n }\n if (t.isObjectExpression(node)) {\n return computeProps(node.properties)\n }\n if (t.isArrayExpression(node)) {\n return node.elements.reduce(\n // @ts-ignore\n (acc, element) => [\n ...acc,\n ...(element?.type === 'SpreadElement'\n ? astToLiteral(element.argument)\n : [astToLiteral(element)]),\n ],\n []\n )\n }\n}\n\nfunction computeProps(props) {\n return props.reduce((acc, prop) => {\n if (prop.type === 'SpreadElement') {\n return {\n ...acc,\n ...astToLiteral(prop.argument),\n }\n } else if (prop.type !== 'ObjectMethod') {\n const val = astToLiteral(prop.value)\n if (val !== undefined) {\n return {\n ...acc,\n [prop.key.name]: val,\n }\n }\n }\n return acc\n }, {})\n}\n"],
5
+ "mappings": ";;AAAA;AAEO,sBAAsB,SAA4B;AACvD,MAAI,YAAY,MAAM;AACpB,WAAO,EAAE;AAAA;AAEX,UAAQ,OAAO;AAAA,SACR;AACH,YAAM,IAAI,MAAM;AAAA,SACb;AACH,aAAO,EAAE,eAAe;AAAA,SACrB;AACH,aAAO,EAAE,cAAc;AAAA,SACpB;AACH,aAAO,EAAE,eAAe;AAAA,SACrB;AACH,aAAO,EAAE,gBAAgB,QAAQ,EAA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patchReactNativeWeb() {
16
16
  return res;
17
17
  })();
18
18
  if (!isEqual) {
19
- console.log("\u{1F95A} Tamagui patching react-native-web to share atomic styling primitives");
19
+ console.log("\xBB Tamagui patching react-native-web to share atomic styling primitives");
20
20
  console.log(" > adding", modulePath);
21
21
  console.log(" > adding", cjsPath);
22
22
  fs.writeFileSync(modulePath, moduleExports);
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/patchReactNativeWeb.ts"],
4
- "sourcesContent": ["import * as fs from 'fs'\nimport path from 'path'\n\n// were patching react-native-web so we can use some internal methods\n// we do it this way because we need to rely on webpack or bundler config to determine cjs vs esm\n// so we can't just require it all directly\n// would be nice in the future to be able to eject from react-native-web entirely optionally\n\n// keep it sync\nexport function patchReactNativeWeb() {\n const rootDir = require.resolve('react-native-web').replace(/\\/dist.*/, '')\n const modulePath = path.join(rootDir, 'dist', 'tamagui-exports.js')\n const cjsPath = path.join(rootDir, 'dist', 'cjs', 'tamagui-exports.js')\n\n const isEqual = (() => {\n let res = false\n try {\n res =\n fs.readFileSync(modulePath, 'utf-8') === moduleExports &&\n fs.readFileSync(cjsPath, 'utf-8') == cjsExports\n } catch {\n res = false\n }\n return res\n })()\n\n if (!isEqual) {\n console.log('\uD83E\uDD5A Tamagui patching react-native-web to share atomic styling primitives')\n console.log(' > adding', modulePath)\n console.log(' > adding', cjsPath)\n fs.writeFileSync(modulePath, moduleExports)\n fs.writeFileSync(cjsPath, cjsExports)\n }\n\n // patch to allow className prop\n const classNamePatch = `if (props.dataSet && props.dataSet['__className']) { domProps.className = className ? className + ' ' + props.dataSet['__className'] : props.dataSet['__className']; delete props.dataSet['__className'] }`\n const domPropsPath = ['modules', 'createDOMProps', 'index.js']\n const domPropsModulePath = path.join(rootDir, 'dist', ...domPropsPath)\n const domPropsCjsPath = path.join(rootDir, 'dist', 'cjs', ...domPropsPath)\n const patchClassName = (file: string) => {\n const contents = fs.readFileSync(file, 'utf-8')\n if (!contents.includes(classNamePatch)) {\n const needle = `domProps.className = className`\n const patchLocation = contents.indexOf(needle) + needle.length + 5\n // its far down the file\n if (patchLocation < 100) {\n console.warn(\n `\u26A0\uFE0F Couldn't apply className patch! Maybe using incompatible react-native-web version.`\n )\n } else {\n const before = contents.slice(0, patchLocation)\n const after = contents.slice(patchLocation)\n const patched = before + '\\n' + classNamePatch + '\\n' + after\n console.log(' > adding className support to react-native-web', file)\n fs.writeFileSync(file, patched)\n }\n }\n }\n patchClassName(domPropsModulePath)\n patchClassName(domPropsCjsPath)\n\n // if (props.className) {\n // domProps.className = className ? className + ' ' + props.className : props.className\n // }\n\n // if entry files not patched, patch them:\n const moduleEntry = path.join(rootDir, 'dist', 'index.js')\n const moduleEntrySrc = fs.readFileSync(moduleEntry, 'utf-8')\n if (!moduleEntrySrc.includes('// tamagui-patch-v4')) {\n fs.writeFileSync(\n moduleEntry,\n `${removePatch(moduleEntrySrc)}\n\n// tamagui-patch-v4\nimport * as TExports from './tamagui-exports'\nexport const TamaguiExports = TExports\n// tamagui-patch-end\n`\n )\n }\n const cjsEntry = path.join(rootDir, 'dist', 'cjs', 'index.js')\n const cjsEntrySrc = fs.readFileSync(cjsEntry, 'utf-8')\n if (!cjsEntrySrc.includes('// tamagui-patch-v4')) {\n fs.writeFileSync(\n cjsEntry,\n `${removePatch(cjsEntrySrc)}\n\n// tamagui-patch-v4\nexports.TamaguiExports = _interopRequireDefault(require(\"./tamagui-exports\"));\n// tamagui-patch-end\n`\n )\n }\n}\n\nfunction removePatch(source: string) {\n return source.replace(/\\/\\/ tamagui-patch([.\\s\\S]*)/g, '')\n}\n\n// view exports/View.ts\nconst forwardedPropsObj = `{\n ...fwdProps.defaultProps,\n ...fwdProps.accessibilityProps,\n ...fwdProps.clickProps,\n ...fwdProps.focusProps,\n ...fwdProps.keyboardProps,\n ...fwdProps.mouseProps,\n ...fwdProps.touchProps,\n ...fwdProps.styleProps,\n href: true,\n lang: true,\n onScroll: true,\n onWheel: true,\n pointerEvents: true\n}\n`\n\nconst moduleExports = `\nexport { atomic } from './exports/StyleSheet/compile'\nexport { default as createCompileableStyle } from './exports/StyleSheet/createCompileableStyle'\nexport { default as createReactDOMStyle } from './exports/StyleSheet/createReactDOMStyle'\nexport { default as i18Style } from './exports/StyleSheet/i18nStyle'\nexport { default as createDOMProps } from './modules/createDOMProps'\nexport { default as AccessibilityUtil } from './modules/AccessibilityUtil'\nexport { default as createElement } from './exports/createElement'\nexport { default as css } from './exports/StyleSheet/css'\nexport { default as TextAncestorContext } from './exports/Text/TextAncestorContext'\nexport { default as pick } from './modules/pick'\nexport { default as useElementLayout } from './modules/useElementLayout'\nexport { default as useMergeRefs } from './modules/useMergeRefs'\nexport { default as usePlatformMethods } from './modules/usePlatformMethods'\nexport { default as useResponderEvents } from './modules/useResponderEvents'\nimport * as fwdProps from './modules/forwardedProps'\nexport const forwardedProps = ${forwardedPropsObj}\n`\n\nconst cjsExports = `\nexports.atomic = require('./exports/StyleSheet/compile').atomic\nexports.createCompileableStyle = require('./exports/StyleSheet/createCompileableStyle')\nexports.createReactDOMStyle = require('./exports/StyleSheet/createReactDOMStyle')\nexports.i18Style = require('./exports/StyleSheet/i18nStyle')\nexports.createDOMProps = require('./modules/createDOMProps')\nexports.AccessibilityUtil = require('./modules/AccessibilityUtil')\nexports.createElement = require('./exports/createElement')\nexports.css = require('./exports/StyleSheet/css')\nexports.TextAncestorContext = require('./exports/Text/TextAncestorContext')\nexports.pick = require('./modules/pick')\nexports.useElementLayout = require('./modules/useElementLayout')\nexports.useMergeRefs = require('./modules/useMergeRefs')\nexports.usePlatformMethods = require('./modules/usePlatformMethods')\nexports.useResponderEvents = require('./modules/useResponderEvents')\nconst fwdProps = require('./modules/forwardedProps')\nexports.forwardedProps = ${forwardedPropsObj}\n`\n"],
4
+ "sourcesContent": ["import * as fs from 'fs'\nimport path from 'path'\n\n// were patching react-native-web so we can use some internal methods\n// we do it this way because we need to rely on webpack or bundler config to determine cjs vs esm\n// so we can't just require it all directly\n// would be nice in the future to be able to eject from react-native-web entirely optionally\n\n// keep it sync\nexport function patchReactNativeWeb() {\n const rootDir = require.resolve('react-native-web').replace(/\\/dist.*/, '')\n const modulePath = path.join(rootDir, 'dist', 'tamagui-exports.js')\n const cjsPath = path.join(rootDir, 'dist', 'cjs', 'tamagui-exports.js')\n\n const isEqual = (() => {\n let res = false\n try {\n res =\n fs.readFileSync(modulePath, 'utf-8') === moduleExports &&\n fs.readFileSync(cjsPath, 'utf-8') == cjsExports\n } catch {\n res = false\n }\n return res\n })()\n\n if (!isEqual) {\n console.log('\u00BB Tamagui patching react-native-web to share atomic styling primitives')\n console.log(' > adding', modulePath)\n console.log(' > adding', cjsPath)\n fs.writeFileSync(modulePath, moduleExports)\n fs.writeFileSync(cjsPath, cjsExports)\n }\n\n // patch to allow className prop\n const classNamePatch = `if (props.dataSet && props.dataSet['__className']) { domProps.className = className ? className + ' ' + props.dataSet['__className'] : props.dataSet['__className']; delete props.dataSet['__className'] }`\n const domPropsPath = ['modules', 'createDOMProps', 'index.js']\n const domPropsModulePath = path.join(rootDir, 'dist', ...domPropsPath)\n const domPropsCjsPath = path.join(rootDir, 'dist', 'cjs', ...domPropsPath)\n const patchClassName = (file: string) => {\n const contents = fs.readFileSync(file, 'utf-8')\n if (!contents.includes(classNamePatch)) {\n const needle = `domProps.className = className`\n const patchLocation = contents.indexOf(needle) + needle.length + 5\n // its far down the file\n if (patchLocation < 100) {\n console.warn(\n `\u26A0\uFE0F Couldn't apply className patch! Maybe using incompatible react-native-web version.`\n )\n } else {\n const before = contents.slice(0, patchLocation)\n const after = contents.slice(patchLocation)\n const patched = before + '\\n' + classNamePatch + '\\n' + after\n console.log(' > adding className support to react-native-web', file)\n fs.writeFileSync(file, patched)\n }\n }\n }\n patchClassName(domPropsModulePath)\n patchClassName(domPropsCjsPath)\n\n // if (props.className) {\n // domProps.className = className ? className + ' ' + props.className : props.className\n // }\n\n // if entry files not patched, patch them:\n const moduleEntry = path.join(rootDir, 'dist', 'index.js')\n const moduleEntrySrc = fs.readFileSync(moduleEntry, 'utf-8')\n if (!moduleEntrySrc.includes('// tamagui-patch-v4')) {\n fs.writeFileSync(\n moduleEntry,\n `${removePatch(moduleEntrySrc)}\n\n// tamagui-patch-v4\nimport * as TExports from './tamagui-exports'\nexport const TamaguiExports = TExports\n// tamagui-patch-end\n`\n )\n }\n const cjsEntry = path.join(rootDir, 'dist', 'cjs', 'index.js')\n const cjsEntrySrc = fs.readFileSync(cjsEntry, 'utf-8')\n if (!cjsEntrySrc.includes('// tamagui-patch-v4')) {\n fs.writeFileSync(\n cjsEntry,\n `${removePatch(cjsEntrySrc)}\n\n// tamagui-patch-v4\nexports.TamaguiExports = _interopRequireDefault(require(\"./tamagui-exports\"));\n// tamagui-patch-end\n`\n )\n }\n}\n\nfunction removePatch(source: string) {\n return source.replace(/\\/\\/ tamagui-patch([.\\s\\S]*)/g, '')\n}\n\n// view exports/View.ts\nconst forwardedPropsObj = `{\n ...fwdProps.defaultProps,\n ...fwdProps.accessibilityProps,\n ...fwdProps.clickProps,\n ...fwdProps.focusProps,\n ...fwdProps.keyboardProps,\n ...fwdProps.mouseProps,\n ...fwdProps.touchProps,\n ...fwdProps.styleProps,\n href: true,\n lang: true,\n onScroll: true,\n onWheel: true,\n pointerEvents: true\n}\n`\n\nconst moduleExports = `\nexport { atomic } from './exports/StyleSheet/compile'\nexport { default as createCompileableStyle } from './exports/StyleSheet/createCompileableStyle'\nexport { default as createReactDOMStyle } from './exports/StyleSheet/createReactDOMStyle'\nexport { default as i18Style } from './exports/StyleSheet/i18nStyle'\nexport { default as createDOMProps } from './modules/createDOMProps'\nexport { default as AccessibilityUtil } from './modules/AccessibilityUtil'\nexport { default as createElement } from './exports/createElement'\nexport { default as css } from './exports/StyleSheet/css'\nexport { default as TextAncestorContext } from './exports/Text/TextAncestorContext'\nexport { default as pick } from './modules/pick'\nexport { default as useElementLayout } from './modules/useElementLayout'\nexport { default as useMergeRefs } from './modules/useMergeRefs'\nexport { default as usePlatformMethods } from './modules/usePlatformMethods'\nexport { default as useResponderEvents } from './modules/useResponderEvents'\nimport * as fwdProps from './modules/forwardedProps'\nexport const forwardedProps = ${forwardedPropsObj}\n`\n\nconst cjsExports = `\nexports.atomic = require('./exports/StyleSheet/compile').atomic\nexports.createCompileableStyle = require('./exports/StyleSheet/createCompileableStyle')\nexports.createReactDOMStyle = require('./exports/StyleSheet/createReactDOMStyle')\nexports.i18Style = require('./exports/StyleSheet/i18nStyle')\nexports.createDOMProps = require('./modules/createDOMProps')\nexports.AccessibilityUtil = require('./modules/AccessibilityUtil')\nexports.createElement = require('./exports/createElement')\nexports.css = require('./exports/StyleSheet/css')\nexports.TextAncestorContext = require('./exports/Text/TextAncestorContext')\nexports.pick = require('./modules/pick')\nexports.useElementLayout = require('./modules/useElementLayout')\nexports.useMergeRefs = require('./modules/useMergeRefs')\nexports.usePlatformMethods = require('./modules/usePlatformMethods')\nexports.useResponderEvents = require('./modules/useResponderEvents')\nconst fwdProps = require('./modules/forwardedProps')\nexports.forwardedProps = ${forwardedPropsObj}\n`\n"],
5
5
  "mappings": ";;AAAA;AACA;AAQO,+BAA+B;AACpC,QAAM,UAAU,AAAgB,oCAAoB,QAAQ,YAAY;AACxE,QAAM,aAAa,KAAK,KAAK,SAAS,QAAQ;AAC9C,QAAM,UAAU,KAAK,KAAK,SAAS,QAAQ,OAAO;AAElD,QAAM,UAAW,OAAM;AACrB,QAAI,MAAM;AACV,QAAI;AACF,YACE,GAAG,aAAa,YAAY,aAAa,iBACzC,GAAG,aAAa,SAAS,YAAY;AAAA,YACvC;AACA,YAAM;AAAA;AAER,WAAO;AAAA;AAGT,MAAI,CAAC,SAAS;AACZ,YAAQ,IAAI;AACZ,YAAQ,IAAI,eAAe;AAC3B,YAAQ,IAAI,eAAe;AAC3B,OAAG,cAAc,YAAY;AAC7B,OAAG,cAAc,SAAS;AAAA;AAI5B,QAAM,iBAAiB;AACvB,QAAM,eAAe,CAAC,WAAW,kBAAkB;AACnD,Q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AAAA;AAAA;AAAA;AAAA;AAAA,gCAgBU;AAAA;AAGhC,MAAM,aAAa;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,2BAgBQ;AAAA;",
6
6
  "names": []
7
7
  }
@@ -51,6 +51,7 @@ function createExtractor() {
51
51
  disableExtractInlineMedia,
52
52
  disableExtractVariables,
53
53
  disableDebugAttr,
54
+ prefixLogs,
54
55
  ...props
55
56
  }) => {
56
57
  if (sourcePath === "") {
@@ -156,7 +157,7 @@ function createExtractor() {
156
157
  }
157
158
  if (disableExtraction) {
158
159
  if (!hasLogged) {
159
- console.log("\u{1F95A} Tamagui disableExtraction set: no CSS or optimizations will be run");
160
+ console.log(prefixLogs, "Tamagui disableExtraction set: no CSS or optimizations will be run");
160
161
  hasLogged = true;
161
162
  }
162
163
  return;
@@ -325,6 +326,29 @@ function createExtractor() {
325
326
  if (!t.isObjectProperty(property)) {
326
327
  throw new Error("expected object property");
327
328
  }
329
+ if (t.isIdentifier(property.key)) {
330
+ const key = property.key.name;
331
+ const mediaQueryKey = key.slice(1);
332
+ const isMediaQuery = key[0] === "$" && mediaQueryConfig[mediaQueryKey];
333
+ if (isMediaQuery) {
334
+ if (t.isExpression(property.value)) {
335
+ const ternaries2 = createTernariesFromObjectProperties(t.stringLiteral(mediaQueryKey), property.value, {
336
+ inlineMediaQuery: mediaQueryKey
337
+ });
338
+ if (ternaries2) {
339
+ return ternaries2.map((value) => ({
340
+ ...ternaryPartial,
341
+ ...value,
342
+ test: t.logicalExpression("&&", value.test, test)
343
+ }));
344
+ } else {
345
+ console.log("\u26A0\uFE0F no ternaries?", property);
346
+ }
347
+ } else {
348
+ console.log("\u26A0\uFE0F not expression", property);
349
+ }
350
+ }
351
+ }
328
352
  if (t.isConditionalExpression(property.value)) {
329
353
  const [truthy, falsy] = [
330
354
  t.objectExpression([t.objectProperty(property.key, property.value.consequent)]),
@@ -769,24 +793,20 @@ function createExtractor() {
769
793
  var _a2;
770
794
  if (!props2)
771
795
  return;
796
+ if (!Object.keys(props2).length)
797
+ return;
772
798
  if (!!excludeProps.size) {
773
799
  for (const key in props2) {
774
800
  if (isExcludedProp(key))
775
801
  delete props2[key];
776
802
  }
777
803
  }
778
- if (shouldPrintDebug) {
779
- props2["debug"] = true;
780
- }
781
804
  const out = postProcessStyles(props2, staticConfig, defaultTheme);
782
- if (shouldPrintDebug) {
783
- delete props2["debug"];
784
- }
785
805
  const next = (_a2 = out == null ? void 0 : out.style) != null ? _a2 : props2;
786
806
  if (shouldPrintDebug) {
787
- console.log(" -- viewProps:\n", logLines(objToStr(out.viewProps)));
788
- console.log(" -- props:\n", logLines(objToStr(props2)));
789
- console.log(" -- next:\n", logLines(objToStr(next)));
807
+ console.log(" -- getStyles (viewProps):\n", logLines(objToStr(out.viewProps)));
808
+ console.log(" -- getStyles (props):\n", logLines(objToStr(props2)));
809
+ console.log(" -- getStyles (next):\n", logLines(objToStr(next)));
790
810
  }
791
811
  for (const key in next) {
792
812
  if (staticConfig.validStyles) {
@@ -815,12 +835,14 @@ function createExtractor() {
815
835
  }
816
836
  }
817
837
  if (shouldPrintDebug) {
818
- console.log(" completeStaticProps\n", completeStaticProps);
819
- console.log(" completeStylesProcessed\n", completeStylesProcessed);
838
+ console.log(" -- completeStaticProps:\n", logLines(objToStr(completeStaticProps)));
839
+ console.log(" -- completeStylesProcessed:\n", logLines(objToStr(completeStylesProcessed)));
820
840
  }
821
841
  let getStyleError = null;
822
842
  for (const attr of attrs) {
823
843
  try {
844
+ if (shouldPrintDebug)
845
+ console.log(" *", attrStr(attr));
824
846
  switch (attr.type) {
825
847
  case "ternary":
826
848
  const a = getStyles(attr.value.alternate);
@@ -869,7 +891,7 @@ function createExtractor() {
869
891
  }
870
892
  }
871
893
  if (shouldPrintDebug) {
872
- console.log(" [\u274A] inline props ", inlinePropCount, shouldDeopt ? " deopted" : "", hasSpread ? " spread" : "", "!flatten", staticConfig.neverFlatten);
894
+ console.log(` \u274A\u274A inline props (${inlinePropCount}):`, shouldDeopt ? " deopted" : "", hasSpread ? " has spread" : "", staticConfig.neverFlatten ? "neverFlatten" : "");
873
895
  console.log(" - attrs (end):\n", logLines(attrs.map(attrStr).join(", ")));
874
896
  }
875
897
  res.optimized++;
@@ -1,6 +1,7 @@
1
1
  var __defProp = Object.defineProperty;
2
2
  var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
3
  import * as t from "@babel/types";
4
+ import { astToLiteral } from "./literalToAst";
4
5
  function isPresent(input) {
5
6
  return input != null;
6
7
  }
@@ -13,7 +14,7 @@ const attrStr = /* @__PURE__ */ __name((attr) => {
13
14
  return attr.type === "attr" ? getNameAttr(attr.value) : attr.type === "ternary" ? `...${ternaryStr(attr.value)}` : `${attr.type}(${objToStr(attr.value)})`;
14
15
  }, "attrStr");
15
16
  const objToStr = /* @__PURE__ */ __name((obj) => {
16
- return Object.entries(obj).map(([k, v]) => `${k}:${Array.isArray(v) ? `[...]` : v && typeof v === "object" ? `{${objToStr(v)}}` : v}`).join(", ");
17
+ return `{${Object.entries(obj).map(([k, v]) => `${k}:${Array.isArray(v) ? `[...]` : v && typeof v === "object" ? `{${objToStr(v)}}` : JSON.stringify(v)}`).join(", ")}}`;
17
18
  }, "objToStr");
18
19
  const getNameAttr = /* @__PURE__ */ __name((attr) => {
19
20
  if (t.isJSXSpreadAttribute(attr)) {
@@ -22,11 +23,21 @@ const getNameAttr = /* @__PURE__ */ __name((attr) => {
22
23
  return "name" in attr ? attr.name.name : `unknown-${attr["type"]}`;
23
24
  }, "getNameAttr");
24
25
  const ternaryStr = /* @__PURE__ */ __name((x) => {
26
+ var _a;
27
+ const conditional = t.isIdentifier(x.test) ? x.test.name : t.isMemberExpression(x.test) ? [x.test.object["name"], x.test.property["name"]] : (_a = astToLiteral(x.test)) != null ? _a : [
28
+ x.test["type"],
29
+ astToLiteral(x.test["left"]),
30
+ x.test["operator"],
31
+ astToLiteral(x.test["right"]),
32
+ x.test["value"],
33
+ x.test["name"]
34
+ ].filter((x2) => typeof x2 !== "undefined").join(" ");
25
35
  return [
26
- "ternary:",
27
- t.isIdentifier(x.test) ? x.test.name : t.isMemberExpression(x.test) ? [x.test.object["name"], x.test.property["name"]] : x.test,
28
- x.consequent ? ` ? ${objToStr(x.consequent)}` : " ? \u26AB\uFE0F",
29
- x.alternate ? ` : ${objToStr(x.alternate)}` : " : \u26AB\uFE0F"
36
+ "ternary(",
37
+ conditional,
38
+ x.consequent ? ` ? ${objToStr(x.consequent)}` : " ? \u{1F6AB}",
39
+ x.alternate ? ` : ${objToStr(x.alternate)}` : " : \u{1F6AB}",
40
+ ")"
30
41
  ].flat().join("");
31
42
  }, "ternaryStr");
32
43
  function findComponentName(scope) {
@@ -15,6 +15,7 @@ import { buildClassName } from "./buildClassName";
15
15
  import { ensureImportingConcat } from "./ensureImportingConcat";
16
16
  import { isSimpleSpread } from "./extractHelpers";
17
17
  import { extractMediaStyle } from "./extractMediaStyle";
18
+ import { getPrefixLogs } from "./getPrefixLogs";
18
19
  import { hoistClassNames } from "./hoistClassNames";
19
20
  import { logLines } from "./logLines";
20
21
  const mergeStyleGroups = {
@@ -69,6 +70,7 @@ function extractToClassNames({
69
70
  lineNumbers,
70
71
  programPath
71
72
  }) => {
73
+ var _a2, _b;
72
74
  let finalClassNames = [];
73
75
  let finalAttrs = [];
74
76
  let finalStyles = [];
@@ -79,14 +81,14 @@ function extractToClassNames({
79
81
  }
80
82
  }
81
83
  const ensureNeededPrevStyle = /* @__PURE__ */ __name((style) => {
82
- var _a2;
84
+ var _a3;
83
85
  const keys = Object.keys(style);
84
86
  if (!keys.some((key) => mergeStyleGroups[key])) {
85
87
  return style;
86
88
  }
87
89
  for (const k in mergeStyleGroups) {
88
90
  if (k in viewStyles) {
89
- style[k] = (_a2 = style[k]) != null ? _a2 : viewStyles[k];
91
+ style[k] = (_a3 = style[k]) != null ? _a3 : viewStyles[k];
90
92
  }
91
93
  }
92
94
  return style;
@@ -96,9 +98,6 @@ function extractToClassNames({
96
98
  return [];
97
99
  const styleWithPrev = ensureNeededPrevStyle(style);
98
100
  const res2 = getStylesAtomic(styleWithPrev);
99
- if (shouldPrintDebug) {
100
- console.log("styleWithPrev", styleWithPrev, res2);
101
- }
102
101
  if (res2.length) {
103
102
  finalStyles = [...finalStyles, ...res2];
104
103
  }
@@ -142,30 +141,38 @@ function extractToClassNames({
142
141
  break;
143
142
  case "ternary":
144
143
  const mediaExtraction = extractMediaStyle(attr.value, jsxPath, extractor.getTamagui(), sourcePath, lastMediaImportance, shouldPrintDebug);
145
- if (mediaExtraction) {
146
- lastMediaImportance++;
144
+ if (shouldPrintDebug) {
145
+ console.log("ternary (mediaStyles)", (_b = (_a2 = mediaExtraction == null ? void 0 : mediaExtraction.ternaryWithoutMedia) == null ? void 0 : _a2.inlineMediaQuery) != null ? _b : "", mediaExtraction == null ? void 0 : mediaExtraction.mediaStyles.map((x) => x.identifier).join("."));
146
+ }
147
+ if (!mediaExtraction) {
148
+ addTernaryStyle(attr.value, addStyles(attr.value.consequent), addStyles(attr.value.alternate));
149
+ continue;
150
+ }
151
+ lastMediaImportance++;
152
+ if (mediaExtraction.mediaStyles) {
147
153
  finalStyles = [...finalStyles, ...mediaExtraction.mediaStyles];
154
+ }
155
+ if (mediaExtraction.ternaryWithoutMedia) {
156
+ addTernaryStyle(mediaExtraction.ternaryWithoutMedia, mediaExtraction.mediaStyles, []);
157
+ } else {
148
158
  finalClassNames = [
149
159
  ...finalClassNames,
150
160
  ...mediaExtraction.mediaStyles.map((x) => t.stringLiteral(x.identifier))
151
161
  ];
152
- if (!mediaExtraction.ternaryWithoutMedia) {
153
- continue;
154
- }
155
- }
156
- const ternary = (mediaExtraction == null ? void 0 : mediaExtraction.ternaryWithoutMedia) || attr.value;
157
- const consInfo = addStyles(ternary.consequent);
158
- const altInfo = addStyles(ternary.alternate);
159
- const cCN = consInfo.map((x) => x.identifier).join(" ");
160
- const aCN = altInfo.map((x) => x.identifier).join(" ");
161
- if (consInfo.length && altInfo.length) {
162
- finalClassNames.push(t.conditionalExpression(ternary.test, t.stringLiteral(cCN), t.stringLiteral(aCN)));
163
- } else {
164
- finalClassNames.push(t.conditionalExpression(ternary.test, t.stringLiteral(" " + cCN), t.stringLiteral(" " + aCN)));
165
162
  }
166
163
  break;
167
164
  }
168
165
  }
166
+ function addTernaryStyle(ternary, a, b) {
167
+ const cCN = a.map((x) => x.identifier).join(" ");
168
+ const aCN = b.map((x) => x.identifier).join(" ");
169
+ if (a.length && b.length) {
170
+ finalClassNames.push(t.conditionalExpression(ternary.test, t.stringLiteral(cCN), t.stringLiteral(aCN)));
171
+ } else {
172
+ finalClassNames.push(t.conditionalExpression(ternary.test, t.stringLiteral(" " + cCN), t.stringLiteral(" " + aCN)));
173
+ }
174
+ }
175
+ __name(addTernaryStyle, "addTernaryStyle");
169
176
  node.attributes = finalAttrs;
170
177
  if (finalClassNames.length) {
171
178
  const names = buildClassName(finalClassNames);
@@ -232,10 +239,10 @@ function extractToClassNames({
232
239
  if (shouldLogTiming) {
233
240
  const memUsed = mem ? Math.round((process.memoryUsage().heapUsed - mem.heapUsed) / 1024 / 1204 * 10) / 10 : 0;
234
241
  const timing = `${Date.now() - start}`.padStart(3);
235
- const path2 = basename(sourcePath).padStart(40);
242
+ const path2 = basename(sourcePath).padStart(30);
236
243
  const numOptimized = `${res.optimized}`.padStart(4);
237
244
  const memory = memUsed > 10 ? `used ${memUsed}MB` : "";
238
- console.log(` \u{1F95A} ${path2} ${timing}ms \u05C1\xB7 ${numOptimized} optimized \xB7 ${res.flattened} flattened ${memory}`);
245
+ console.log(`${getPrefixLogs(options)} ${path2} ${timing}ms \u05C1\xB7 ${numOptimized} optimized \xB7 ${res.flattened} flattened ${memory}`);
239
246
  }
240
247
  return {
241
248
  ast,
@@ -0,0 +1,11 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
+ function getPrefixLogs(options) {
4
+ var _a;
5
+ const { TAMAGUI_TARGET } = process.env;
6
+ return (_a = options == null ? void 0 : options.prefixLogs) != null ? _a : `[${TAMAGUI_TARGET}] \xBB `;
7
+ }
8
+ __name(getPrefixLogs, "getPrefixLogs");
9
+ export {
10
+ getPrefixLogs
11
+ };
@@ -28,6 +28,52 @@ function literalToAst(literal) {
28
28
  }
29
29
  }
30
30
  __name(literalToAst, "literalToAst");
31
+ const easyPeasies = ["BooleanLiteral", "StringLiteral", "NumericLiteral"];
32
+ function astToLiteral(node) {
33
+ if (!node) {
34
+ return;
35
+ }
36
+ if (easyPeasies.includes(node.type)) {
37
+ return node.value;
38
+ }
39
+ if (node.name === "undefined" && !node.value) {
40
+ return void 0;
41
+ }
42
+ if (t.isNullLiteral(node)) {
43
+ return null;
44
+ }
45
+ if (t.isObjectExpression(node)) {
46
+ return computeProps(node.properties);
47
+ }
48
+ if (t.isArrayExpression(node)) {
49
+ return node.elements.reduce((acc, element) => [
50
+ ...acc,
51
+ ...(element == null ? void 0 : element.type) === "SpreadElement" ? astToLiteral(element.argument) : [astToLiteral(element)]
52
+ ], []);
53
+ }
54
+ }
55
+ __name(astToLiteral, "astToLiteral");
56
+ function computeProps(props) {
57
+ return props.reduce((acc, prop) => {
58
+ if (prop.type === "SpreadElement") {
59
+ return {
60
+ ...acc,
61
+ ...astToLiteral(prop.argument)
62
+ };
63
+ } else if (prop.type !== "ObjectMethod") {
64
+ const val = astToLiteral(prop.value);
65
+ if (val !== void 0) {
66
+ return {
67
+ ...acc,
68
+ [prop.key.name]: val
69
+ };
70
+ }
71
+ }
72
+ return acc;
73
+ }, {});
74
+ }
75
+ __name(computeProps, "computeProps");
31
76
  export {
77
+ astToLiteral,
32
78
  literalToAst
33
79
  };
@@ -16,7 +16,7 @@ function patchReactNativeWeb() {
16
16
  return res;
17
17
  })();
18
18
  if (!isEqual) {
19
- console.log("\u{1F95A} Tamagui patching react-native-web to share atomic styling primitives");
19
+ console.log("\xBB Tamagui patching react-native-web to share atomic styling primitives");
20
20
  console.log(" > adding", modulePath);
21
21
  console.log(" > adding", cjsPath);
22
22
  fs.writeFileSync(modulePath, moduleExports);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tamagui/static",
3
- "version": "1.0.0-alpha.62",
3
+ "version": "1.0.0-alpha.66",
4
4
  "source": "src/index.ts",
5
5
  "typings": "types",
6
6
  "main": "dist/cjs",
@@ -59,11 +59,11 @@
59
59
  "@babel/traverse": "^7.15.4",
60
60
  "@dish/babel-preset": "^0.0.6",
61
61
  "@expo/match-media": "^0.1.0",
62
- "@tamagui/build": "^1.0.0-alpha.58",
63
- "@tamagui/core": "^1.0.0-alpha.62",
64
- "@tamagui/core-node": "^1.0.0-alpha.58",
62
+ "@tamagui/build": "^1.0.0-alpha.64",
63
+ "@tamagui/core": "^1.0.0-alpha.66",
64
+ "@tamagui/core-node": "^1.0.0-alpha.64",
65
65
  "@tamagui/fake-react-native": "^1.0.0-alpha.17",
66
- "@tamagui/helpers": "^1.0.0-alpha.58",
66
+ "@tamagui/helpers": "^1.0.0-alpha.64",
67
67
  "babel-literal-to-ast": "^2.1.0",
68
68
  "esbuild": "^0.13.12",
69
69
  "esbuild-register": "^3.1.2",
@@ -72,10 +72,10 @@
72
72
  "invariant": "^2.2.4",
73
73
  "loader-utils": "^2.0.0",
74
74
  "lodash": "^4.17.21",
75
- "tamagui": "^1.0.0-alpha.62"
75
+ "tamagui": "^1.0.0-alpha.66"
76
76
  },
77
77
  "peerDependencies": {
78
78
  "react-native-web": "*"
79
79
  },
80
- "gitHead": "76f3b735226bdb7feffb53e3c8e3fd34392b6a10"
80
+ "gitHead": "c54b9b244b364df7ced148c4e66ce3b66c4127bf"
81
81
  }
@@ -24,7 +24,7 @@ export declare function createExtractor(): {
24
24
  [key: string]: string | number;
25
25
  };
26
26
  }>;
27
- parse: (fileOrPath: NodePath<t.Program> | t.File, { config, importsWhitelist, evaluateVars, shouldPrintDebug, sourcePath, onExtractTag, getFlattenedNode, disableExtraction, disableExtractInlineMedia, disableExtractVariables, disableDebugAttr, ...props }: ExtractorParseProps) => {
27
+ parse: (fileOrPath: NodePath<t.Program> | t.File, { config, importsWhitelist, evaluateVars, shouldPrintDebug, sourcePath, onExtractTag, getFlattenedNode, disableExtraction, disableExtractInlineMedia, disableExtractVariables, disableDebugAttr, prefixLogs, ...props }: ExtractorParseProps) => {
28
28
  flattened: number;
29
29
  optimized: number;
30
30
  modified: number;
@@ -0,0 +1,3 @@
1
+ import { TamaguiOptions } from '../types';
2
+ export declare function getPrefixLogs(options?: TamaguiOptions): string;
3
+ //# sourceMappingURL=getPrefixLogs.d.ts.map
@@ -1,3 +1,4 @@
1
1
  import * as t from '@babel/types';
2
2
  export declare function literalToAst(literal: any): t.Expression;
3
+ export declare function astToLiteral(node: any): any;
3
4
  //# sourceMappingURL=literalToAst.d.ts.map