@tamagui/static 1.0.0-alpha.6 → 1.0.0-alpha.63

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 (212) hide show
  1. package/dist/cjs/constants.js +43 -0
  2. package/dist/cjs/constants.js.map +7 -0
  3. package/dist/cjs/extractor/accessSafe.js +39 -0
  4. package/dist/cjs/extractor/accessSafe.js.map +7 -0
  5. package/dist/cjs/extractor/babelParse.js +58 -0
  6. package/dist/cjs/extractor/babelParse.js.map +7 -0
  7. package/dist/cjs/extractor/buildClassName.js +68 -0
  8. package/dist/cjs/extractor/buildClassName.js.map +7 -0
  9. package/dist/cjs/extractor/createEvaluator.js +79 -0
  10. package/dist/cjs/extractor/createEvaluator.js.map +7 -0
  11. package/dist/cjs/extractor/createExtractor.js +988 -0
  12. package/dist/cjs/extractor/createExtractor.js.map +7 -0
  13. package/dist/cjs/extractor/ensureImportingConcat.js +52 -0
  14. package/dist/cjs/extractor/ensureImportingConcat.js.map +7 -0
  15. package/dist/cjs/extractor/evaluateAstNode.js +122 -0
  16. package/dist/cjs/extractor/evaluateAstNode.js.map +7 -0
  17. package/dist/cjs/extractor/extractHelpers.js +134 -0
  18. package/dist/cjs/extractor/extractHelpers.js.map +7 -0
  19. package/dist/cjs/extractor/extractMediaStyle.js +193 -0
  20. package/dist/cjs/extractor/extractMediaStyle.js.map +7 -0
  21. package/dist/cjs/extractor/extractToClassNames.js +295 -0
  22. package/dist/cjs/extractor/extractToClassNames.js.map +7 -0
  23. package/dist/cjs/extractor/findTopmostFunction.js +46 -0
  24. package/dist/cjs/extractor/findTopmostFunction.js.map +7 -0
  25. package/dist/cjs/extractor/generatedUid.js +56 -0
  26. package/dist/cjs/extractor/generatedUid.js.map +7 -0
  27. package/dist/cjs/extractor/getPropValueFromAttributes.js +77 -0
  28. package/dist/cjs/extractor/getPropValueFromAttributes.js.map +7 -0
  29. package/dist/cjs/extractor/getSourceModule.js +97 -0
  30. package/dist/cjs/extractor/getSourceModule.js.map +7 -0
  31. package/dist/cjs/extractor/getStaticBindingsForScope.js +156 -0
  32. package/dist/cjs/extractor/getStaticBindingsForScope.js.map +7 -0
  33. package/dist/cjs/extractor/hoistClassNames.js +72 -0
  34. package/dist/cjs/extractor/hoistClassNames.js.map +7 -0
  35. package/dist/cjs/extractor/literalToAst.js +121 -0
  36. package/dist/cjs/extractor/literalToAst.js.map +7 -0
  37. package/dist/cjs/extractor/loadTamagui.js +70 -0
  38. package/dist/cjs/extractor/loadTamagui.js.map +7 -0
  39. package/dist/cjs/extractor/logLines.js +40 -0
  40. package/dist/cjs/extractor/logLines.js.map +7 -0
  41. package/dist/cjs/extractor/normalizeTernaries.js +108 -0
  42. package/dist/cjs/extractor/normalizeTernaries.js.map +7 -0
  43. package/dist/cjs/extractor/removeUnusedHooks.js +107 -0
  44. package/dist/cjs/extractor/removeUnusedHooks.js.map +7 -0
  45. package/dist/cjs/index.js +38 -0
  46. package/dist/cjs/index.js.map +7 -0
  47. package/dist/cjs/patchReactNativeWeb.js +157 -0
  48. package/dist/cjs/patchReactNativeWeb.js.map +7 -0
  49. package/dist/cjs/types.js +21 -0
  50. package/dist/cjs/types.js.map +7 -0
  51. package/dist/{constants.js → esm/constants.js} +4 -0
  52. package/dist/{constants.js.map → esm/constants.js.map} +3 -3
  53. package/dist/{extractor → esm/extractor}/accessSafe.js +0 -0
  54. package/dist/{extractor → esm/extractor}/accessSafe.js.map +1 -1
  55. package/dist/{extractor → esm/extractor}/babelParse.js +0 -0
  56. package/dist/{extractor → esm/extractor}/babelParse.js.map +1 -1
  57. package/dist/{extractor → esm/extractor}/buildClassName.js +0 -0
  58. package/dist/{extractor → esm/extractor}/buildClassName.js.map +1 -1
  59. package/dist/{extractor → esm/extractor}/createEvaluator.js +1 -1
  60. package/dist/esm/extractor/createEvaluator.js.map +7 -0
  61. package/dist/{extractor → esm/extractor}/createExtractor.js +189 -79
  62. package/dist/esm/extractor/createExtractor.js.map +7 -0
  63. package/dist/{extractor → esm/extractor}/ensureImportingConcat.js +1 -1
  64. package/dist/esm/extractor/ensureImportingConcat.js.map +7 -0
  65. package/dist/{extractor → esm/extractor}/evaluateAstNode.js +0 -0
  66. package/dist/{extractor → esm/extractor}/evaluateAstNode.js.map +1 -1
  67. package/dist/{extractor → esm/extractor}/extractHelpers.js +25 -9
  68. package/dist/esm/extractor/extractHelpers.js.map +7 -0
  69. package/dist/{extractor → esm/extractor}/extractMediaStyle.js +3 -2
  70. package/dist/{extractor → esm/extractor}/extractMediaStyle.js.map +3 -3
  71. package/dist/{extractor → esm/extractor}/extractToClassNames.js +41 -24
  72. package/dist/esm/extractor/extractToClassNames.js.map +7 -0
  73. package/dist/{extractor → esm/extractor}/findTopmostFunction.js +0 -0
  74. package/dist/{extractor → esm/extractor}/findTopmostFunction.js.map +1 -1
  75. package/dist/{extractor → esm/extractor}/generatedUid.js +0 -0
  76. package/dist/{extractor → esm/extractor}/generatedUid.js.map +1 -1
  77. package/dist/{extractor → esm/extractor}/getPropValueFromAttributes.js +0 -0
  78. package/dist/{extractor → esm/extractor}/getPropValueFromAttributes.js.map +1 -1
  79. package/dist/{extractor → esm/extractor}/getSourceModule.js +0 -0
  80. package/dist/{extractor → esm/extractor}/getSourceModule.js.map +1 -1
  81. package/dist/{extractor → esm/extractor}/getStaticBindingsForScope.js +0 -0
  82. package/dist/{extractor → esm/extractor}/getStaticBindingsForScope.js.map +1 -1
  83. package/dist/{extractor → esm/extractor}/hoistClassNames.js +0 -0
  84. package/dist/{extractor → esm/extractor}/hoistClassNames.js.map +1 -1
  85. package/dist/esm/extractor/literalToAst.js +80 -0
  86. package/dist/esm/extractor/literalToAst.js.map +7 -0
  87. package/dist/{extractor → esm/extractor}/loadTamagui.js +8 -2
  88. package/dist/esm/extractor/loadTamagui.js.map +7 -0
  89. package/dist/esm/extractor/logLines.js +17 -0
  90. package/dist/esm/extractor/logLines.js.map +7 -0
  91. package/dist/{extractor → esm/extractor}/normalizeTernaries.js +3 -2
  92. package/dist/{extractor → esm/extractor}/normalizeTernaries.js.map +2 -2
  93. package/dist/{extractor → esm/extractor}/removeUnusedHooks.js +5 -3
  94. package/dist/{extractor → esm/extractor}/removeUnusedHooks.js.map +2 -2
  95. package/dist/{index.js → esm/index.js} +0 -0
  96. package/dist/{index.js.map → esm/index.js.map} +1 -1
  97. package/dist/{patchReactNativeWeb.js → esm/patchReactNativeWeb.js} +22 -0
  98. package/dist/esm/patchReactNativeWeb.js.map +7 -0
  99. package/dist/{types.js → esm/types.js} +0 -0
  100. package/dist/{types.js.map → esm/types.js.map} +0 -0
  101. package/dist/jsx/constants.js +13 -0
  102. package/dist/jsx/extractor/accessSafe.js +10 -0
  103. package/dist/jsx/extractor/babelParse.js +29 -0
  104. package/dist/jsx/extractor/buildClassName.js +39 -0
  105. package/dist/jsx/extractor/createEvaluator.js +50 -0
  106. package/dist/jsx/extractor/createExtractor.js +928 -0
  107. package/dist/jsx/extractor/ensureImportingConcat.js +23 -0
  108. package/dist/jsx/extractor/evaluateAstNode.js +93 -0
  109. package/dist/jsx/extractor/extractHelpers.js +109 -0
  110. package/dist/jsx/extractor/extractMediaStyle.js +151 -0
  111. package/dist/jsx/extractor/extractToClassNames.js +251 -0
  112. package/dist/jsx/extractor/findTopmostFunction.js +22 -0
  113. package/dist/jsx/extractor/generatedUid.js +27 -0
  114. package/dist/jsx/extractor/getPropValueFromAttributes.js +48 -0
  115. package/dist/jsx/extractor/getSourceModule.js +68 -0
  116. package/dist/jsx/extractor/getStaticBindingsForScope.js +127 -0
  117. package/dist/jsx/extractor/hoistClassNames.js +43 -0
  118. package/dist/jsx/extractor/literalToAst.js +79 -0
  119. package/dist/jsx/extractor/loadTamagui.js +46 -0
  120. package/dist/jsx/extractor/logLines.js +16 -0
  121. package/dist/jsx/extractor/normalizeTernaries.js +52 -0
  122. package/dist/jsx/extractor/removeUnusedHooks.js +79 -0
  123. package/dist/jsx/index.js +13 -0
  124. package/dist/jsx/patchReactNativeWeb.js +128 -0
  125. package/dist/jsx/types.js +0 -0
  126. package/package.json +27 -19
  127. package/types/constants.d.ts +6 -0
  128. package/types/constants.d.ts.map +1 -0
  129. package/types/extractor/accessSafe.d.ts +3 -0
  130. package/types/extractor/accessSafe.d.ts.map +1 -0
  131. package/types/extractor/babelParse.d.ts +5 -0
  132. package/types/extractor/babelParse.d.ts.map +1 -0
  133. package/types/extractor/buildClassName.d.ts +4 -0
  134. package/types/extractor/buildClassName.d.ts.map +1 -0
  135. package/types/extractor/createEvaluator.d.ts +12 -0
  136. package/types/extractor/createEvaluator.d.ts.map +1 -0
  137. package/types/extractor/createExtractor.d.ts +33 -0
  138. package/types/extractor/createExtractor.d.ts.map +1 -0
  139. package/types/extractor/ensureImportingConcat.d.ts +4 -0
  140. package/types/extractor/ensureImportingConcat.d.ts.map +1 -0
  141. package/types/extractor/evaluateAstNode.d.ts +3 -0
  142. package/types/extractor/evaluateAstNode.d.ts.map +1 -0
  143. package/types/extractor/extractHelpers.d.ts +12 -0
  144. package/types/extractor/extractHelpers.d.ts.map +1 -0
  145. package/types/extractor/extractMediaStyle.d.ts +10 -0
  146. package/types/extractor/extractMediaStyle.d.ts.map +1 -0
  147. package/types/extractor/extractToClassNames.d.ts +21 -0
  148. package/types/extractor/extractToClassNames.d.ts.map +1 -0
  149. package/types/extractor/findTopmostFunction.d.ts +4 -0
  150. package/types/extractor/findTopmostFunction.d.ts.map +1 -0
  151. package/types/extractor/generatedUid.d.ts +5 -0
  152. package/types/extractor/generatedUid.d.ts.map +1 -0
  153. package/types/extractor/getPropValueFromAttributes.d.ts +3 -0
  154. package/types/extractor/getPropValueFromAttributes.d.ts.map +1 -0
  155. package/types/extractor/getSourceModule.d.ts +16 -0
  156. package/types/extractor/getSourceModule.d.ts.map +1 -0
  157. package/types/extractor/getStaticBindingsForScope.d.ts +4 -0
  158. package/types/extractor/getStaticBindingsForScope.d.ts.map +1 -0
  159. package/types/extractor/hoistClassNames.d.ts +6 -0
  160. package/types/extractor/hoistClassNames.d.ts.map +1 -0
  161. package/types/extractor/literalToAst.d.ts +4 -0
  162. package/types/extractor/literalToAst.d.ts.map +1 -0
  163. package/types/extractor/loadTamagui.d.ts +9 -0
  164. package/types/extractor/loadTamagui.d.ts.map +1 -0
  165. package/types/extractor/logLines.d.ts +2 -0
  166. package/types/extractor/logLines.d.ts.map +1 -0
  167. package/types/extractor/normalizeTernaries.d.ts +3 -0
  168. package/types/extractor/normalizeTernaries.d.ts.map +1 -0
  169. package/types/extractor/removeUnusedHooks.d.ts +3 -0
  170. package/types/extractor/removeUnusedHooks.d.ts.map +1 -0
  171. package/types/index.d.ts +8 -0
  172. package/types/index.d.ts.map +1 -0
  173. package/types/patchReactNativeWeb.d.ts +2 -0
  174. package/types/patchReactNativeWeb.d.ts.map +1 -0
  175. package/types/types.d.ts +79 -0
  176. package/types/types.d.ts.map +1 -0
  177. package/dist/extractor/createEvaluator.js.map +0 -7
  178. package/dist/extractor/createExtractor.js.map +0 -7
  179. package/dist/extractor/ensureImportingConcat.js.map +0 -7
  180. package/dist/extractor/extractHelpers.js.map +0 -7
  181. package/dist/extractor/extractToClassNames.js.map +0 -7
  182. package/dist/extractor/literalToAst.js +0 -34
  183. package/dist/extractor/literalToAst.js.map +0 -7
  184. package/dist/extractor/loadTamagui.js.map +0 -7
  185. package/dist/index.cjs +0 -2107
  186. package/dist/index.cjs.map +0 -7
  187. package/dist/patchReactNativeWeb.js.map +0 -7
  188. package/src/constants.ts +0 -10
  189. package/src/extractor/accessSafe.ts +0 -18
  190. package/src/extractor/babelParse.ts +0 -27
  191. package/src/extractor/buildClassName.ts +0 -61
  192. package/src/extractor/createEvaluator.ts +0 -68
  193. package/src/extractor/createExtractor.ts +0 -1132
  194. package/src/extractor/ensureImportingConcat.ts +0 -33
  195. package/src/extractor/evaluateAstNode.ts +0 -121
  196. package/src/extractor/extractHelpers.ts +0 -102
  197. package/src/extractor/extractMediaStyle.ts +0 -191
  198. package/src/extractor/extractToClassNames.ts +0 -326
  199. package/src/extractor/findTopmostFunction.ts +0 -22
  200. package/src/extractor/generatedUid.ts +0 -43
  201. package/src/extractor/getPropValueFromAttributes.ts +0 -92
  202. package/src/extractor/getSourceModule.ts +0 -101
  203. package/src/extractor/getStaticBindingsForScope.ts +0 -173
  204. package/src/extractor/hoistClassNames.ts +0 -45
  205. package/src/extractor/literalToAst.ts +0 -32
  206. package/src/extractor/loadTamagui.ts +0 -61
  207. package/src/extractor/normalizeTernaries.ts +0 -60
  208. package/src/extractor/removeUnusedHooks.ts +0 -76
  209. package/src/index.ts +0 -9
  210. package/src/patchReactNativeWeb.ts +0 -123
  211. package/src/types.ts +0 -83
  212. package/types.d.ts +0 -215
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "version": 3,
3
- "sources": ["../../src/extractor/findTopmostFunction.ts"],
3
+ "sources": ["../../../src/extractor/findTopmostFunction.ts"],
4
4
  "sourcesContent": ["import { NodePath } from '@babel/traverse'\nimport * as t from '@babel/types'\n\nexport function findTopmostFunction(jsxPath: NodePath<t.JSXElement>) {\n // get topmost fn\n const isFunction = (path: NodePath<any>) =>\n path.isArrowFunctionExpression() || path.isFunctionDeclaration() || path.isFunctionExpression()\n let compFn: NodePath<any> | null = jsxPath.findParent(isFunction)\n while (compFn) {\n const parent = compFn.findParent(isFunction)\n if (parent) {\n compFn = parent\n } else {\n break\n }\n }\n if (!compFn) {\n // console.error(`Couldn't find a topmost function for media query extraction`)\n return null\n }\n return compFn\n}\n"],
5
5
  "mappings": ";;AAGO,6BAA6B,SAAiC;AAEnE,QAAM,aAAa,wBAAC,SAClB,KAAK,+BAA+B,KAAK,2BAA2B,KAAK,wBADxD;AAEnB,MAAI,SAA+B,QAAQ,WAAW;AACtD,SAAO,QAAQ;AACb,UAAM,SAAS,OAAO,WAAW;AACjC,QAAI,QAAQ;AACV,eAAS;AAAA,WACJ;AACL;AAAA;AAAA;AAGJ,MAAI,CAAC,QAAQ;AAEX,WAAO;AAAA;AAET,SAAO;AAAA;AAjBO;",
6
6
  "names": []
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "version": 3,
3
- "sources": ["../../src/extractor/generatedUid.ts"],
3
+ "sources": ["../../../src/extractor/generatedUid.ts"],
4
4
  "sourcesContent": ["import * as t from '@babel/types'\nimport invariant from 'invariant'\n\n// TODO: open a PR upstream\ndeclare module '@babel/types' {\n export function toIdentifier(input: string): string\n}\n\n// A clone of path.scope.generateUid that doesn't prepend underscores\nexport function generateUid(scope: any, name: string): string {\n invariant(typeof scope === 'object', 'generateUid expects a scope object as its first parameter')\n invariant(\n typeof name === 'string' && name !== '',\n 'generateUid expects a valid name as its second parameter'\n )\n\n name = t\n .toIdentifier(name)\n .replace(/^_+/, '')\n .replace(/[0-9]+$/g, '')\n\n let uid\n let i = 0\n do {\n if (i > 1) {\n uid = name + i\n } else {\n uid = name\n }\n i++\n } while (\n scope.hasLabel(uid) ||\n scope.hasBinding(uid) ||\n scope.hasGlobal(uid) ||\n scope.hasReference(uid)\n )\n\n const program = scope.getProgramParent()\n program.references[uid] = true\n program.uids[uid] = true\n\n return uid\n}\n"],
5
5
  "mappings": ";;AAAA;AACA;AAQO,qBAAqB,OAAY,MAAsB;AAC5D,YAAU,OAAO,UAAU,UAAU;AACrC,YACE,OAAO,SAAS,YAAY,SAAS,IACrC;AAGF,SAAO,EACJ,aAAa,MACb,QAAQ,OAAO,IACf,QAAQ,YAAY;AAEvB,MAAI;AACJ,MAAI,IAAI;AACR,KAAG;AACD,QAAI,IAAI,GAAG;AACT,YAAM,OAAO;AAAA,WACR;AACL,YAAM;AAAA;AAER;AAAA,WAEA,MAAM,SAAS,QACf,MAAM,WAAW,QACjB,MAAM,UAAU,QAChB,MAAM,aAAa;AAGrB,QAAM,UAAU,MAAM;AACtB,UAAQ,WAAW,OAAO;AAC1B,UAAQ,KAAK,OAAO;AAEpB,SAAO;AAAA;AAhCO;",
6
6
  "names": []
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "version": 3,
3
- "sources": ["../../src/extractor/getPropValueFromAttributes.ts"],
3
+ "sources": ["../../../src/extractor/getPropValueFromAttributes.ts"],
4
4
  "sourcesContent": ["import generate from '@babel/generator'\nimport * as t from '@babel/types'\n\nimport { accessSafe } from './accessSafe'\n\n/**\n * getPropValueFromAttributes gets a prop by name from a list of attributes and accounts for potential spread operators.\n * Here's an example. Given this component:\n * ```\n * <Block coolProp=\"wow\" {...spread1} neatProp=\"ok\" {...spread2} />```\n * getPropValueFromAttributes will return the following:\n * - for propName `coolProp`:\n * ```\n * accessSafe(spread1, 'coolProp') || accessSafe(spread2, 'coolProp') || 'wow'```\n * - for propName `neatProp`:\n * ```\n * accessSafe(spread2, 'neatProp') || 'ok'```\n * - for propName `notPresent`: `null`\n *\n * The returned value should (obviously) be placed after spread operators.\n */\nexport function getPropValueFromAttributes(\n propName: string,\n attrs: (t.JSXAttribute | t.JSXSpreadAttribute)[]\n): t.Expression | null {\n let propIndex: number = -1\n let jsxAttr: t.JSXAttribute | null = null\n for (let idx = -1, len = attrs.length; ++idx < len; ) {\n const attr = attrs[idx]\n if (t.isJSXAttribute(attr) && attr.name && attr.name.name === propName) {\n propIndex = idx\n jsxAttr = attr\n break\n }\n }\n\n if (!jsxAttr || jsxAttr.value == null) {\n return null\n }\n\n let propValue:\n | t.JSXElement\n | t.JSXFragment\n | t.StringLiteral\n | t.JSXExpressionContainer\n | t.JSXEmptyExpression\n | t.Expression = jsxAttr.value\n\n if (t.isJSXExpressionContainer(propValue)) {\n propValue = propValue.expression\n }\n\n // TODO how to handle this??\n if (t.isJSXEmptyExpression(propValue)) {\n console.error('encountered JSXEmptyExpression')\n return null\n }\n\n // filter out spread props that occur before propValue\n const applicableSpreads = attrs\n .filter(\n // 1. idx is greater than propValue prop index\n // 2. attr is a spread operator\n (attr, idx): attr is t.JSXSpreadAttribute => {\n if (t.isJSXSpreadAttribute(attr)) {\n if (t.isIdentifier(attr.argument) || t.isMemberExpression(attr.argument)) {\n return idx > propIndex\n }\n if (t.isLogicalExpression(attr.argument)) {\n return false\n }\n throw new Error(\n `unsupported spread of type \"${attr.argument.type}\": ${generate(attr).code}`\n )\n }\n return false\n }\n )\n .map((attr) => attr.argument)\n\n // if spread operators occur after propValue, create a binary expression for each operator\n // i.e. before1.propValue || before2.propValue || propValue\n // TODO: figure out how to do this without all the extra parens\n if (applicableSpreads.length > 0) {\n propValue = applicableSpreads.reduce<t.Expression>(\n (acc, val) => t.logicalExpression('||', accessSafe(val, propName), acc),\n propValue\n )\n }\n\n return propValue\n}\n"],
5
5
  "mappings": ";;AAAA;AACA;AAEA;AAkBO,oCACL,UACA,OACqB;AACrB,MAAI,YAAoB;AACxB,MAAI,UAAiC;AACrC,WAAS,MAAM,IAAI,MAAM,MAAM,QAAQ,EAAE,MAAM,OAAO;AACpD,UAAM,OAAO,MAAM;AACnB,QAAI,EAAE,eAAe,SAAS,KAAK,QAAQ,KAAK,KAAK,SAAS,UAAU;AACtE,kBAAY;AACZ,gBAAU;AACV;AAAA;AAAA;AAIJ,MAAI,CAAC,WAAW,QAAQ,SAAS,MAAM;AACrC,WAAO;AAAA;AAGT,MAAI,YAMe,QAAQ;AAE3B,MAAI,EAAE,yBAAyB,YAAY;AACzC,gBAAY,UAAU;AAAA;AAIxB,MAAI,EAAE,qBAAqB,YAAY;AACrC,YAAQ,MAAM;AACd,WAAO;AAAA;AAIT,QAAM,oBAAoB,MACvB,OAGC,CAAC,MAAM,QAAsC;AAC3C,QAAI,EAAE,qBAAqB,OAAO;AAChC,UAAI,EAAE,aAAa,KAAK,aAAa,EAAE,mBAAmB,KAAK,WAAW;AACxE,eAAO,MAAM;AAAA;AAEf,UAAI,EAAE,oBAAoB,KAAK,WAAW;AACxC,eAAO;AAAA;AAET,YAAM,IAAI,MACR,+BAA+B,KAAK,SAAS,UAAU,SAAS,MAAM;AAAA;AAG1E,WAAO;AAAA,KAGV,IAAI,CAAC,SAAS,KAAK;AAKtB,MAAI,kBAAkB,SAAS,GAAG;AAChC,gBAAY,kBAAkB,OAC5B,CAAC,KAAK,QAAQ,EAAE,kBAAkB,MAAM,WAAW,KAAK,WAAW,MACnE;AAAA;AAIJ,SAAO;AAAA;AArEO;",
6
6
  "names": []
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "version": 3,
3
- "sources": ["../../src/extractor/getSourceModule.ts"],
3
+ "sources": ["../../../src/extractor/getSourceModule.ts"],
4
4
  "sourcesContent": ["import * as t from '@babel/types'\n\nexport interface SourceModule {\n sourceModule?: string\n imported?: string\n local?: string\n destructured?: boolean\n usesImportSyntax: boolean\n}\n\nexport function getSourceModule(\n itemName: string,\n itemBinding: {\n constant?: boolean\n path: { node: t.Node; parent: any }\n }\n): SourceModule | null {\n // TODO: deal with reassignment\n if (!itemBinding.constant) {\n return null\n }\n\n let sourceModule: string | undefined\n let imported: string | undefined\n let local: string | undefined\n let destructured: boolean | undefined\n let usesImportSyntax = false\n\n const itemNode = itemBinding.path.node\n\n if (\n // import x from 'y';\n t.isImportDefaultSpecifier(itemNode) ||\n // import {x} from 'y';\n t.isImportSpecifier(itemNode)\n ) {\n if (t.isImportDeclaration(itemBinding.path.parent)) {\n sourceModule = itemBinding.path.parent.source.value\n local = itemNode.local.name\n usesImportSyntax = true\n if (t.isImportSpecifier(itemNode)) {\n imported = itemNode.imported['name']\n destructured = true\n } else {\n imported = itemNode.local.name\n destructured = false\n }\n }\n } else if (\n t.isVariableDeclarator(itemNode) &&\n itemNode.init != null &&\n t.isCallExpression(itemNode.init) &&\n t.isIdentifier(itemNode.init.callee) &&\n itemNode.init.callee.name === 'require' &&\n itemNode.init.arguments.length === 1\n ) {\n const firstArg = itemNode.init.arguments[0]\n if (!t.isStringLiteral(firstArg)) {\n return null\n }\n sourceModule = firstArg.value\n\n if (t.isIdentifier(itemNode.id)) {\n local = itemNode.id.name\n imported = itemNode.id.name\n destructured = false\n } else if (t.isObjectPattern(itemNode.id)) {\n for (const objProp of itemNode.id.properties) {\n if (\n t.isObjectProperty(objProp) &&\n t.isIdentifier(objProp.value) &&\n objProp.value.name === itemName\n ) {\n local = objProp.value.name\n // @ts-ignore TODO remove this is only an issue on CI\n imported = objProp.key.name\n destructured = true\n break\n }\n }\n\n if (!local || !imported) {\n console.error('could not find prop with value `%s`', itemName)\n return null\n }\n } else {\n console.error('Unhandled id type: %s', itemNode.id.type)\n return null\n }\n } else {\n return null\n }\n\n return {\n destructured,\n imported,\n local,\n sourceModule,\n usesImportSyntax,\n }\n}\n"],
5
5
  "mappings": ";;AAAA;AAUO,yBACL,UACA,aAIqB;AAErB,MAAI,CAAC,YAAY,UAAU;AACzB,WAAO;AAAA;AAGT,MAAI;AACJ,MAAI;AACJ,MAAI;AACJ,MAAI;AACJ,MAAI,mBAAmB;AAEvB,QAAM,WAAW,YAAY,KAAK;AAElC,MAEE,EAAE,yBAAyB,aAE3B,EAAE,kBAAkB,WACpB;AACA,QAAI,EAAE,oBAAoB,YAAY,KAAK,SAAS;AAClD,qBAAe,YAAY,KAAK,OAAO,OAAO;AAC9C,cAAQ,SAAS,MAAM;AACvB,yBAAmB;AACnB,UAAI,EAAE,kBAAkB,WAAW;AACjC,mBAAW,SAAS,SAAS;AAC7B,uBAAe;AAAA,aACV;AACL,mBAAW,SAAS,MAAM;AAC1B,uBAAe;AAAA;AAAA;AAAA,aAInB,EAAE,qBAAqB,aACvB,SAAS,QAAQ,QACjB,EAAE,iBAAiB,SAAS,SAC5B,EAAE,aAAa,SAAS,KAAK,WAC7B,SAAS,KAAK,OAAO,SAAS,aAC9B,SAAS,KAAK,UAAU,WAAW,GACnC;AACA,UAAM,WAAW,SAAS,KAAK,UAAU;AACzC,QAAI,CAAC,EAAE,gBAAgB,WAAW;AAChC,aAAO;AAAA;AAET,mBAAe,SAAS;AAExB,QAAI,EAAE,aAAa,SAAS,KAAK;AAC/B,cAAQ,SAAS,GAAG;AACpB,iBAAW,SAAS,GAAG;AACvB,qBAAe;AAAA,eACN,EAAE,gBAAgB,SAAS,KAAK;AACzC,iBAAW,WAAW,SAAS,GAAG,YAAY;AAC5C,YACE,EAAE,iBAAiB,YACnB,EAAE,aAAa,QAAQ,UACvB,QAAQ,MAAM,SAAS,UACvB;AACA,kBAAQ,QAAQ,MAAM;AAEtB,qBAAW,QAAQ,IAAI;AACvB,yBAAe;AACf;AAAA;AAAA;AAIJ,UAAI,CAAC,SAAS,CAAC,UAAU;AACvB,gBAAQ,MAAM,uCAAuC;AACrD,eAAO;AAAA;AAAA,WAEJ;AACL,cAAQ,MAAM,yBAAyB,SAAS,GAAG;AACnD,aAAO;AAAA;AAAA,SAEJ;AACL,WAAO;AAAA;AAGT,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA;AAAA;AAxFY;",
6
6
  "names": []
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "version": 3,
3
- "sources": ["../../src/extractor/getStaticBindingsForScope.ts"],
3
+ "sources": ["../../../src/extractor/getStaticBindingsForScope.ts"],
4
4
  "sourcesContent": ["import { dirname, extname, resolve } from 'path'\n\nimport { Binding, NodePath } from '@babel/traverse'\nimport * as t from '@babel/types'\nimport { existsSync } from 'fs-extra'\n\nimport { evaluateAstNode } from './evaluateAstNode'\nimport { getSourceModule } from './getSourceModule'\n\nconst isLocalImport = (path: string) => path.startsWith('.') || path.startsWith('/')\n\nfunction resolveImportPath(sourcePath: string, path: string) {\n const sourceDir = dirname(sourcePath)\n if (isLocalImport(path)) {\n if (extname(path) === '') {\n path += '.js'\n }\n return resolve(sourceDir, path)\n }\n return path\n}\n\nfunction importModule(path: string) {\n const filenames = [path.replace('.js', '.tsx'), path.replace('.js', '.ts'), path]\n for (const file of filenames) {\n if (existsSync(file)) {\n // TODO we can clear this when we see updates on it later on\n return require(file)\n }\n }\n return null\n}\n\nexport function getStaticBindingsForScope(\n scope: NodePath<t.JSXElement>['scope'],\n whitelist: string[] = [],\n sourcePath: string,\n bindingCache: Record<string, string | null>,\n shouldPrintDebug: boolean\n): Record<string, any> {\n const bindings: Record<string, Binding> = scope.getAllBindings() as any\n const ret: Record<string, any> = {}\n\n if (shouldPrintDebug) {\n // prettier-ignore\n console.log(' ', Object.keys(bindings).length, 'variables in scope')\n // .map(x => bindings[x].identifier?.name).join(', ')\n }\n\n // on react native at least it doesnt find some bindings? not sure why\n // lets add in whitelisted imports if they exist\n const program = scope.getProgramParent().block as t.Program\n for (const node of program.body) {\n if (t.isImportDeclaration(node)) {\n const importPath = node.source.value\n if (!node.specifiers.length) continue\n if (!isLocalImport(importPath)) {\n continue\n }\n const moduleName = resolveImportPath(sourcePath, importPath)\n const isOnWhitelist = whitelist.some((test) => moduleName.endsWith(test))\n if (!isOnWhitelist) continue\n const src = importModule(moduleName)\n if (!src) continue\n for (const specifier of node.specifiers) {\n if (t.isImportSpecifier(specifier) && t.isIdentifier(specifier.imported)) {\n if (typeof src[specifier.imported.name] !== 'undefined') {\n const val = src[specifier.local.name]\n ret[specifier.local.name] = val\n }\n }\n }\n }\n }\n\n if (!bindingCache) {\n throw new Error('bindingCache is a required param')\n }\n\n for (const k in bindings) {\n const binding = bindings[k]\n\n // check to see if the item is a module\n const sourceModule = getSourceModule(k, binding)\n if (sourceModule) {\n if (!sourceModule.sourceModule) {\n continue\n }\n\n const moduleName = resolveImportPath(sourcePath, sourceModule.sourceModule)\n const isOnWhitelist = whitelist.some((test) => moduleName.endsWith(test))\n\n // TODO we could cache this at the file level.. and check if its been touched since\n\n if (isOnWhitelist) {\n const src = importModule(moduleName)\n if (!src) {\n console.log(\n `\u26A0\uFE0F missing file ${moduleName} via ${sourcePath} import ${sourceModule.sourceModule}?`\n )\n return {}\n }\n if (sourceModule.destructured) {\n if (sourceModule.imported) {\n ret[k] = src[sourceModule.imported]\n }\n } else {\n // crude esmodule check\n // TODO: make sure this actually works\n // if (src && src.__esModule) {\n // ret[k] = src.default\n // } else {\n ret[k] = src\n // }\n }\n }\n continue\n }\n\n const { parent, parentPath } = binding.path\n\n if (!t.isVariableDeclaration(parent) || parent.kind !== 'const') {\n continue\n }\n\n // pick out the right variable declarator\n const dec = parent.declarations.find((d) => t.isIdentifier(d.id) && d.id.name === k)\n\n // if init is not set, there's nothing to evaluate\n // TODO: handle spread syntax\n if (!dec || !dec.init) {\n continue\n }\n\n // missing start/end will break caching\n if (typeof dec.id.start !== 'number' || typeof dec.id.end !== 'number') {\n console.error('dec.id.start/end is not a number')\n continue\n }\n\n if (!t.isIdentifier(dec.id)) {\n console.error('dec is not an identifier')\n continue\n }\n\n const cacheKey = `${dec.id.name}_${dec.id.start}-${dec.id.end}`\n\n // retrieve value from cache\n if (bindingCache.hasOwnProperty(cacheKey)) {\n ret[k] = bindingCache[cacheKey]\n continue\n }\n // retrieve value from cache\n if (bindingCache.hasOwnProperty(cacheKey)) {\n ret[k] = bindingCache[cacheKey]\n continue\n }\n\n // evaluate\n try {\n ret[k] = evaluateAstNode(dec.init, undefined, shouldPrintDebug)\n bindingCache[cacheKey] = ret[k]\n continue\n } catch (e) {\n // skip\n // if (shouldPrintDebug) {\n // console.error('[\uD83D\uDC07] cant eval, skipping', cacheKey) //, e.message)\n // }\n }\n }\n\n return ret\n}\n"],
5
5
  "mappings": ";;AAAA;AAGA;AACA;AAEA;AACA;AAEA,MAAM,gBAAgB,wBAAC,SAAiB,KAAK,WAAW,QAAQ,KAAK,WAAW,MAA1D;AAEtB,2BAA2B,YAAoB,MAAc;AAC3D,QAAM,YAAY,QAAQ;AAC1B,MAAI,cAAc,OAAO;AACvB,QAAI,QAAQ,UAAU,IAAI;AACxB,cAAQ;AAAA;AAEV,WAAO,QAAQ,WAAW;AAAA;AAE5B,SAAO;AAAA;AARA;AAWT,sBAAsB,MAAc;AAClC,QAAM,YAAY,CAAC,KAAK,QAAQ,OAAO,SAAS,KAAK,QAAQ,OAAO,QAAQ;AAC5E,aAAW,QAAQ,WAAW;AAC5B,QAAI,WAAW,OAAO;AAEpB,aAAO,QAAQ;AAAA;AAAA;AAGnB,SAAO;AAAA;AARA;AAWF,mCACL,OACA,YAAsB,IACtB,YACA,cACA,kBACqB;AACrB,QAAM,WAAoC,MAAM;A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AEvB;AAML,cAAI,KAAK;AAAA;AAAA;AAIb;AAAA;AAGF,UAAM,EAAE,QAAQ,eAAe,QAAQ;AAEvC,QAAI,CAAC,EAAE,sBAAsB,WAAW,OAAO,SAAS,SAAS;AAC/D;AAAA;AAIF,UAAM,MAAM,OAAO,aAAa,KAAK,CAAC,MAAM,EAAE,aAAa,EAAE,OAAO,EAAE,GAAG,SAAS;AAIlF,QAAI,CAAC,OAAO,CAAC,IAAI,MAAM;AACrB;AAAA;AAIF,QAAI,OAAO,IAAI,GAAG,UAAU,YAAY,OAAO,IAAI,GAAG,QAAQ,UAAU;AACtE,cAAQ,MAAM;AACd;AAAA;AAGF,QAAI,CAAC,EAAE,aAAa,IAAI,KAAK;AAC3B,cAAQ,MAAM;AACd;AAAA;AAGF,UAAM,WAAW,GAAG,IAAI,GAAG,QAAQ,IAAI,GAAG,SAAS,IAAI,GAAG;AAG1D,QAAI,aAAa,eAAe,WAAW;AACzC,UAAI,KAAK,aAAa;AACtB;AAAA;AAGF,QAAI,aAAa,eAAe,WAAW;AACzC,UAAI,KAAK,aAAa;AACtB;AAAA;AAIF,QAAI;AACF,UAAI,KAAK,gBAAgB,IAAI,MAAM,QAAW;AAC9C,mBAAa,YAAY,IAAI;AAC7B;AAAA,aACO,GAAP;AAAA;AAAA;AAQJ,SAAO;AAAA;AA1IO;",
6
6
  "names": []
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "version": 3,
3
- "sources": ["../../src/extractor/hoistClassNames.ts"],
3
+ "sources": ["../../../src/extractor/hoistClassNames.ts"],
4
4
  "sourcesContent": ["import { NodePath } from '@babel/traverse'\nimport * as t from '@babel/types'\n\nexport function hoistClassNames(\n path: NodePath<t.JSXElement>,\n existing: { [key: string]: t.Identifier },\n expr: t.Expression\n) {\n const hoist = hoistClassNames.bind(null, path, existing)\n if (t.isStringLiteral(expr)) {\n if (expr.value.trim() === '') {\n return expr\n }\n if (existing[expr.value]) {\n return existing[expr.value]\n }\n const identifier = replaceStringWithVariable(expr)\n existing[expr.value] = identifier\n return identifier\n }\n if (t.isBinaryExpression(expr)) {\n return t.binaryExpression(expr.operator, hoist(expr.left), hoist(expr.right))\n }\n if (t.isLogicalExpression(expr)) {\n return t.logicalExpression(expr.operator, hoist(expr.left), hoist(expr.right))\n }\n if (t.isConditionalExpression(expr)) {\n return t.conditionalExpression(expr.test, hoist(expr.consequent), hoist(expr.alternate))\n }\n return expr\n\n function replaceStringWithVariable(str: t.StringLiteral): t.Identifier {\n // hoist outside fn!\n const uid = path.scope.generateUidIdentifier('cn')\n const parent = path.findParent((path) => path.isProgram())\n if (!parent) throw new Error(`no program?`)\n const variable = t.variableDeclaration('const', [\n // adding a space for extra safety\n t.variableDeclarator(uid, t.stringLiteral(` ${str.value}`)),\n ])\n // @ts-ignore\n parent.unshiftContainer('body', variable)\n return uid\n }\n}\n"],
5
5
  "mappings": ";;AACA;AAEO,yBACL,MACA,UACA,MACA;AACA,QAAM,QAAQ,gBAAgB,KAAK,MAAM,MAAM;AAC/C,MAAI,EAAE,gBAAgB,OAAO;AAC3B,QAAI,KAAK,MAAM,WAAW,IAAI;AAC5B,aAAO;AAAA;AAET,QAAI,SAAS,KAAK,QAAQ;AACxB,aAAO,SAAS,KAAK;AAAA;AAEvB,UAAM,aAAa,0BAA0B;AAC7C,aAAS,KAAK,SAAS;AACvB,WAAO;AAAA;AAET,MAAI,EAAE,mBAAmB,OAAO;AAC9B,WAAO,EAAE,iBAAiB,KAAK,UAAU,MAAM,KAAK,OAAO,MAAM,KAAK;AAAA;AAExE,MAAI,EAAE,oBAAoB,OAAO;AAC/B,WAAO,EAAE,kBAAkB,KAAK,UAAU,MAAM,KAAK,OAAO,MAAM,KAAK;AAAA;AAEzE,MAAI,EAAE,wBAAwB,OAAO;AACnC,WAAO,EAAE,sBAAsB,KAAK,MAAM,MAAM,KAAK,aAAa,MAAM,KAAK;AAAA;AAE/E,SAAO;AAEP,qCAAmC,KAAoC;AAErE,UAAM,MAAM,KAAK,MAAM,sBAAsB;AAC7C,UAAM,SAAS,KAAK,WAAW,CAAC,UAAS,MAAK;AAC9C,QAAI,CAAC;AAAQ,YAAM,IAAI,MAAM;AAC7B,UAAM,WAAW,EAAE,oBAAoB,SAAS;AAAA,MAE9C,EAAE,mBAAmB,KAAK,EAAE,cAAc,IAAI,IAAI;AAAA;AAGpD,WAAO,iBAAiB,QAAQ;AAChC,WAAO;AAAA;AAXA;AAAA;AA5BK;",
6
6
  "names": []
@@ -0,0 +1,80 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
+ import * as t from "@babel/types";
4
+ function literalToAst(literal) {
5
+ if (literal === null) {
6
+ return t.nullLiteral();
7
+ }
8
+ switch (typeof literal) {
9
+ case "function":
10
+ throw new Error("Unsupported");
11
+ case "number":
12
+ return t.numericLiteral(literal);
13
+ case "string":
14
+ return t.stringLiteral(literal);
15
+ case "boolean":
16
+ return t.booleanLiteral(literal);
17
+ case "undefined":
18
+ return t.unaryExpression("void", t.numericLiteral(0), true);
19
+ default:
20
+ if (Array.isArray(literal)) {
21
+ return t.arrayExpression(literal.map(literalToAst));
22
+ }
23
+ return t.objectExpression(Object.keys(literal).filter((k) => {
24
+ return typeof literal[k] !== "undefined";
25
+ }).map((k) => {
26
+ return t.objectProperty(t.stringLiteral(k), literalToAst(literal[k]));
27
+ }));
28
+ }
29
+ }
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");
76
+ export {
77
+ astToLiteral,
78
+ literalToAst
79
+ };
80
+ //# sourceMappingURL=literalToAst.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/extractor/literalToAst.ts"],
4
+ "sourcesContent": ["import * as t from '@babel/types'\n\nexport function literalToAst(literal: any): t.Expression {\n if (literal === null) {\n return t.nullLiteral()\n }\n switch (typeof literal) {\n case 'function':\n throw new Error('Unsupported')\n case 'number':\n return t.numericLiteral(literal)\n case 'string':\n return t.stringLiteral(literal)\n case 'boolean':\n return t.booleanLiteral(literal)\n case 'undefined':\n return t.unaryExpression('void', t.numericLiteral(0), true)\n default:\n if (Array.isArray(literal)) {\n return t.arrayExpression(literal.map(literalToAst))\n }\n return t.objectExpression(\n Object.keys(literal)\n .filter((k) => {\n return typeof literal[k] !== 'undefined'\n })\n .map((k) => {\n return t.objectProperty(t.stringLiteral(k), literalToAst(literal[k]))\n })\n )\n }\n}\n\nconst easyPeasies = ['BooleanLiteral', 'StringLiteral', 'NumericLiteral']\n\nexport function astToLiteral(node: any) {\n if (!node) {\n return\n }\n if (easyPeasies.includes(node.type)) {\n return node.value\n }\n if (node.name === 'undefined' && !node.value) {\n return undefined\n }\n if (t.isNullLiteral(node)) {\n return null\n }\n if (t.isObjectExpression(node)) {\n return computeProps(node.properties)\n }\n if (t.isArrayExpression(node)) {\n return node.elements.reduce(\n // @ts-ignore\n (acc, element) => [\n ...acc,\n ...(element?.type === 'SpreadElement'\n ? astToLiteral(element.argument)\n : [astToLiteral(element)]),\n ],\n []\n )\n }\n}\n\nfunction computeProps(props) {\n return props.reduce((acc, prop) => {\n if (prop.type === 'SpreadElement') {\n return {\n ...acc,\n ...astToLiteral(prop.argument),\n }\n } else if (prop.type !== 'ObjectMethod') {\n const val = astToLiteral(prop.value)\n if (val !== undefined) {\n return {\n ...acc,\n [prop.key.name]: val,\n }\n }\n }\n return acc\n }, {})\n}\n"],
5
+ "mappings": ";;AAAA;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;AA+BhB,MAAM,cAAc,CAAC,kBAAkB,iBAAiB;AAEjD,sBAAsB,MAAW;AACtC,MAAI,CAAC,MAAM;AACT;AAAA;AAEF,MAAI,YAAY,SAAS,KAAK,OAAO;AACnC,WAAO,KAAK;AAAA;AAEd,MAAI,KAAK,SAAS,eAAe,CAAC,KAAK,OAAO;AAC5C,WAAO;AAAA;AAET,MAAI,EAAE,cAAc,OAAO;AACzB,WAAO;AAAA;AAET,MAAI,EAAE,mBAAmB,OAAO;AAC9B,WAAO,aAAa,KAAK;AAAA;AAE3B,MAAI,EAAE,kBAAkB,OAAO;AAC7B,WAAO,KAAK,SAAS,OAEnB,CAAC,KAAK,YAAY;AAAA,MAChB,GAAG;AAAA,MACH,GAAI,oCAAS,UAAS,kBAClB,aAAa,QAAQ,YACrB,CAAC,aAAa;AAAA,OAEpB;AAAA;AAAA;AAzBU;AA8BhB,sBAAsB,OAAO;AAC3B,SAAO,MAAM,OAAO,CAAC,KAAK,SAAS;AACjC,QAAI,KAAK,SAAS,iBAAiB;AACjC,aAAO;AAAA,WACF;AAAA,WACA,aAAa,KAAK;AAAA;AAAA,eAEd,KAAK,SAAS,gBAAgB;AACvC,YAAM,MAAM,aAAa,KAAK;AAC9B,UAAI,QAAQ,QAAW;AACrB,eAAO;AAAA,aACF;AAAA,WACF,KAAK,IAAI,OAAO;AAAA;AAAA;AAAA;AAIvB,WAAO;AAAA,KACN;AAAA;AAjBI;",
6
+ "names": []
7
+ }
@@ -8,12 +8,18 @@ function loadTamagui(props) {
8
8
  return loadedTamagui;
9
9
  }
10
10
  process.env.IS_STATIC = "is_static";
11
- const proxyWorm = require("@tamagui/fake-react-native");
11
+ const rnw = require("react-native-web");
12
12
  const Mod = require("module");
13
13
  const og = Mod.prototype.require;
14
14
  Mod.prototype.require = function(path) {
15
+ if (path.endsWith(".css")) {
16
+ return {};
17
+ }
18
+ if (path === "@gorhom/bottom-sheet") {
19
+ return {};
20
+ }
15
21
  if (path.startsWith("react-native") && !path.startsWith("react-native-web/dist/cjs/exports")) {
16
- return proxyWorm;
22
+ return rnw;
17
23
  }
18
24
  return og.apply(this, arguments);
19
25
  };
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/extractor/loadTamagui.ts"],
4
+ "sourcesContent": ["import { join } from 'path'\n\nimport type { StaticComponent, 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, StaticComponent>\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 // we just need to read the config around them\n process.env.IS_STATIC = 'is_static'\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') {\n return {}\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 return og.apply(this, arguments)\n }\n\n // import config\n const configPath = join(process.cwd(), props.config)\n const tamaguiConfigExport = require(configPath)\n const tamaguiConfig = (tamaguiConfigExport['default'] ||\n tamaguiConfigExport) as TamaguiInternalConfig\n\n // import components\n const components = {}\n for (const module of props.components) {\n const exported = require(module)\n Object.assign(components, exported)\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)\n\n loadedTamagui = {\n components,\n tamaguiConfig,\n }\n\n return loadedTamagui\n}\n"],
5
+ "mappings": ";;AAAA;AAGA;AAEA,IAAI,gBAAqB;AAElB,qBAAqB,OAG1B;AACA,MAAI,eAAe;AACjB,WAAO;AAAA;AAKT,UAAQ,IAAI,YAAY;AACxB,QAAM,MAAM,QAAQ;AACpB,QAAM,MAAM,QAAQ;AACpB,QAAM,KAAK,IAAI,UAAU;AACzB,MAAI,UAAU,UAAU,SAAU,MAAc;AAC9C,QAAI,KAAK,SAAS,SAAS;AACzB,aAAO;AAAA;AAET,QAAI,SAAS,wBAAwB;AACnC,aAAO;AAAA;AAET,QACE,KAAK,WAAW,mBAEhB,CAAC,KAAK,WAAW,sCACjB;AACA,aAAO;AAAA;AAET,WAAO,GAAG,MAAM,MAAM;AAAA;AAIxB,QAAM,aAAa,KAAK,QAAQ,OAAO,MAAM;AAC7C,QAAM,sBAAsB,QAAQ;AACpC,QAAM,gBAAiB,oBAAoB,cACzC;AAGF,QAAM,aAAa;AACnB,aAAW,UAAU,MAAM,YAAY;AACrC,UAAM,WAAW,QAAQ;AACzB,WAAO,OAAO,YAAY;AAAA;AAI5B,UAAQ,IAAI,YAAY;AACxB,MAAI,UAAU,UAAU;AAGxB,gBAAc;AAEd,kBAAgB;AAAA,IACd;AAAA,IACA;AAAA;AAGF,SAAO;AAAA;AAxDO;",
6
+ "names": []
7
+ }
@@ -0,0 +1,17 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
+ const logLines = /* @__PURE__ */ __name((str) => {
4
+ let lines = [""];
5
+ const items = str.split(" ");
6
+ for (const item of items) {
7
+ if (item.length + lines[lines.length - 1].length > 85) {
8
+ lines.push("");
9
+ }
10
+ lines[lines.length - 1] += item + " ";
11
+ }
12
+ return lines.map((line, i) => " " + (i == 0 ? "" : " ") + line.trim()).join("\n");
13
+ }, "logLines");
14
+ export {
15
+ logLines
16
+ };
17
+ //# sourceMappingURL=logLines.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/extractor/logLines.ts"],
4
+ "sourcesContent": ["export const logLines = (str: string) => {\n let lines: string[] = ['']\n const items = str.split(' ')\n for (const item of items) {\n if (item.length + lines[lines.length - 1].length > 85) {\n lines.push('')\n }\n lines[lines.length - 1] += item + ' '\n }\n return lines.map((line, i) => ' ' + (i == 0 ? '' : ' ') + line.trim()).join('\\n')\n}\n"],
5
+ "mappings": ";;AAAO,MAAM,WAAW,wBAAC,QAAgB;AACvC,MAAI,QAAkB,CAAC;AACvB,QAAM,QAAQ,IAAI,MAAM;AACxB,aAAW,QAAQ,OAAO;AACxB,QAAI,KAAK,SAAS,MAAM,MAAM,SAAS,GAAG,SAAS,IAAI;AACrD,YAAM,KAAK;AAAA;AAEb,UAAM,MAAM,SAAS,MAAM,OAAO;AAAA;AAEpC,SAAO,MAAM,IAAI,CAAC,MAAM,MAAM,gBAAiB,MAAK,IAAI,KAAK,OAAO,KAAK,QAAQ,KAAK;AAAA,GAThE;",
6
+ "names": []
7
+ }
@@ -4,6 +4,7 @@ import generate from "@babel/generator";
4
4
  import * as t from "@babel/types";
5
5
  import invariant from "invariant";
6
6
  function normalizeTernaries(ternaries) {
7
+ var _a, _b;
7
8
  invariant(Array.isArray(ternaries), "extractStaticTernaries expects param 1 to be an array of ternaries");
8
9
  if (ternaries.length === 0) {
9
10
  return [];
@@ -35,8 +36,8 @@ function normalizeTernaries(ternaries) {
35
36
  remove
36
37
  };
37
38
  }
38
- const altStyle = (shouldSwap ? consequent : alternate) ?? {};
39
- const consStyle = (shouldSwap ? alternate : consequent) ?? {};
39
+ const altStyle = (_a = shouldSwap ? consequent : alternate) != null ? _a : {};
40
+ const consStyle = (_b = shouldSwap ? alternate : consequent) != null ? _b : {};
40
41
  Object.assign(ternariesByKey[key].alternate, altStyle);
41
42
  Object.assign(ternariesByKey[key].consequent, consStyle);
42
43
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
- "sources": ["../../src/extractor/normalizeTernaries.ts"],
3
+ "sources": ["../../../src/extractor/normalizeTernaries.ts"],
4
4
  "sourcesContent": ["import generate from '@babel/generator'\nimport * as t from '@babel/types'\nimport invariant from 'invariant'\n\nimport { Ternary } from '../types'\n\nexport function normalizeTernaries(ternaries: Ternary[]) {\n invariant(Array.isArray(ternaries), 'extractStaticTernaries expects param 1 to be an array of ternaries')\n\n if (ternaries.length === 0) {\n return []\n }\n\n const ternariesByKey: { [key: string]: Ternary } = {}\n\n for (let idx = -1, len = ternaries.length; ++idx < len; ) {\n const { test, consequent, alternate, remove, ...rest } = ternaries[idx]\n\n let ternaryTest = test\n\n // strip parens\n if (t.isExpressionStatement(test)) {\n ternaryTest = (test as any).expression\n }\n\n // convert `!thing` to `thing` with swapped consequent and alternate\n let shouldSwap = false\n if (t.isUnaryExpression(test) && test.operator === '!') {\n ternaryTest = test.argument\n shouldSwap = true\n } else if (t.isBinaryExpression(test)) {\n if (test.operator === '!==' || test.operator === '!=') {\n ternaryTest = t.binaryExpression(test.operator, test.left, test.right)\n shouldSwap = true\n }\n }\n\n const key = generate(ternaryTest).code\n\n if (!ternariesByKey[key]) {\n ternariesByKey[key] = {\n ...rest,\n alternate: {},\n consequent: {},\n test: ternaryTest,\n remove,\n }\n }\n const altStyle = (shouldSwap ? consequent : alternate) ?? {}\n const consStyle = (shouldSwap ? alternate : consequent) ?? {}\n Object.assign(ternariesByKey[key].alternate, altStyle)\n Object.assign(ternariesByKey[key].consequent, consStyle)\n }\n\n const ternaryExpression = Object.keys(ternariesByKey).map((key) => {\n return ternariesByKey[key]\n })\n\n return ternaryExpression\n}\n"],
5
- "mappings": ";;AAAA;AACA;AACA;AAIO,4BAA4B,WAAsB;AACvD,YAAU,MAAM,QAAQ,YAAY;AAEpC,MAAI,UAAU,WAAW,GAAG;AAC1B,WAAO;AAAA;AAGT,QAAM,iBAA6C;AAEnD,WAAS,MAAM,IAAI,MAAM,UAAU,QAAQ,EAAE,MAAM,OAAO;AACxD,UAAM,EAAE,MAAM,YAAY,WAAW,WAAW,SAAS,UAAU;AAEnE,QAAI,cAAc;AAGlB,QAAI,EAAE,sBAAsB,OAAO;AACjC,oBAAe,KAAa;AAAA;AAI9B,QAAI,aAAa;AACjB,QAAI,EAAE,kBAAkB,SAAS,KAAK,aAAa,KAAK;AACtD,oBAAc,KAAK;AACnB,mBAAa;AAAA,eACJ,EAAE,mBAAmB,OAAO;AACrC,UAAI,KAAK,aAAa,SAAS,KAAK,aAAa,MAAM;AACrD,sBAAc,EAAE,iBAAiB,KAAK,UAAU,KAAK,MAAM,KAAK;AAChE,qBAAa;AAAA;AAAA;AAIjB,UAAM,MAAM,SAAS,aAAa;AAElC,QAAI,CAAC,eAAe,MAAM;AACxB,q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Y,eAAzB,YAAwC;AAC3D,WAAO,OAAO,eAAe,KAAK,WAAW;AAC7C,WAAO,OAAO,eAAe,KAAK,YAAY;AAAA;AAGhD,QAAM,oBAAoB,OAAO,KAAK,gBAAgB,IAAI,CAAC,QAAQ;AACjE,WAAO,eAAe;AAAA;AAGxB,SAAO;AAAA;AApDO;",
6
6
  "names": []
7
7
  }
@@ -6,8 +6,9 @@ const hooks = {
6
6
  useTheme: true
7
7
  };
8
8
  function removeUnusedHooks(compFn, shouldPrintDebug) {
9
+ var _a;
9
10
  compFn.scope.crawl();
10
- let bodyStatements = compFn?.get("body");
11
+ let bodyStatements = compFn == null ? void 0 : compFn.get("body");
11
12
  if (!bodyStatements) {
12
13
  console.log("no body statemnts?", compFn);
13
14
  return;
@@ -32,7 +33,8 @@ function removeUnusedHooks(compFn, shouldPrintDebug) {
32
33
  continue;
33
34
  }
34
35
  const isBindingReferenced = /* @__PURE__ */ __name((name) => {
35
- return !!statement.scope.getBinding(name)?.referenced;
36
+ var _a2;
37
+ return !!((_a2 = statement.scope.getBinding(name)) == null ? void 0 : _a2.referenced);
36
38
  }, "isBindingReferenced");
37
39
  for (const declarator of declarations) {
38
40
  const id = declarator.get("id");
@@ -65,7 +67,7 @@ function removeUnusedHooks(compFn, shouldPrintDebug) {
65
67
  if (shouldRemove) {
66
68
  declarator.remove();
67
69
  if (shouldPrintDebug) {
68
- console.log(` [\u{1FA9D}] removed ${id.node["name"] ?? ""}`);
70
+ console.log(` [\u{1FA9D}] removed ${(_a = id.node["name"]) != null ? _a : ""}`);
69
71
  }
70
72
  }
71
73
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
- "sources": ["../../src/extractor/removeUnusedHooks.ts"],
3
+ "sources": ["../../../src/extractor/removeUnusedHooks.ts"],
4
4
  "sourcesContent": ["import { NodePath } from '@babel/traverse'\nimport * as t from '@babel/types'\n\nconst hooks = {\n useMedia: true,\n useTheme: true,\n}\n\nexport function removeUnusedHooks(compFn: NodePath<any>, shouldPrintDebug: boolean) {\n compFn.scope.crawl()\n // check the top level statements\n let bodyStatements = compFn?.get('body')\n if (!bodyStatements) {\n console.log('no body statemnts?', compFn)\n return\n }\n if (!Array.isArray(bodyStatements)) {\n if (bodyStatements.isFunctionExpression()) {\n bodyStatements = bodyStatements.scope.path.get('body')\n } else {\n bodyStatements = bodyStatements.get('body')\n }\n }\n if (!bodyStatements || !Array.isArray(bodyStatements)) {\n return\n }\n const statements = bodyStatements as NodePath<any>[]\n for (const statement of statements) {\n if (!statement.isVariableDeclaration()) {\n continue\n }\n const declarations = statement.get('declarations')\n if (!Array.isArray(declarations)) {\n continue\n }\n const isBindingReferenced = (name: string) => {\n return !!statement.scope.getBinding(name)?.referenced\n }\n for (const declarator of declarations) {\n const id = declarator.get('id')\n const init = declarator.node.init\n if (Array.isArray(id) || Array.isArray(init)) {\n continue\n }\n const shouldRemove = (() => {\n const isHook =\n t.isCallExpression(init) && t.isIdentifier(init.callee) && hooks[init.callee.name]\n if (!isHook) {\n return false\n }\n if (t.isIdentifier(id.node)) {\n // remove \"const media = useMedia()\"\n const name = id.node.name\n return !isBindingReferenced(name)\n } else if (t.isObjectPattern(id.node)) {\n // remove \"const { sm } = useMedia()\"\n const propPaths = id.get('properties') as NodePath<any>[]\n return propPaths.every((prop) => {\n if (!prop.isObjectProperty()) return false\n const value = prop.get('value')\n if (Array.isArray(value) || !value.isIdentifier()) return false\n const name = value.node.name\n return !isBindingReferenced(name)\n })\n }\n return false\n })()\n if (shouldRemove) {\n declarator.remove()\n if (shouldPrintDebug) {\n console.log(` [\uD83E\uDE9D] removed ${id.node['name'] ?? ''}`)\n }\n }\n }\n }\n}\n"],
5
- "mappings": ";;AACA;AAEA,MAAM,QAAQ;AAAA,EACZ,UAAU;AAAA,EACV,UAAU;AAAA;AAGL,2BAA2B,QAAuB,kBAA2B;AAClF,SAAO,MAAM;AAEb,MAAI,iBAAiB,QAAQ,IAAI;AACjC,MAAI,CAAC,gBAAgB;AACnB,Y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B,gBAAM,OAAO,GAAG,KAAK;AACrB,iBAAO,CAAC,oBAAoB;AAAA,mBACnB,EAAE,gBAAgB,GAAG,OAAO;AAErC,gBAAM,YAAY,GAAG,IAAI;AACzB,iBAAO,UAAU,MAAM,CAAC,SAAS;AAC/B,gBAAI,CAAC,KAAK;AAAoB,qBAAO;AACrC,kBAAM,QAAQ,KAAK,IAAI;AACvB,gBAAI,MAAM,QAAQ,UAAU,CAAC,MAAM;AAAgB,qBAAO;AAC1D,kBAAM,OAAO,MAAM,KAAK;AACxB,mBAAO,CAAC,oBAAoB;AAAA;AAAA;AAGhC,eAAO;AAAA;AAET,UAAI,cAAc;AAChB,mBAAW;AACX,YAAI,kBAAkB;AACpB,kBAAQ,IAAI,yBAAkB,SAAG,KAAK,YAAR,YAAmB;AAAA;AAAA;AAAA;AAAA;AAAA;AA9D3C;",
6
6
  "names": []
7
7
  }
File without changes
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "version": 3,
3
- "sources": ["../src/index.ts"],
3
+ "sources": ["../../src/index.ts"],
4
4
  "sourcesContent": ["process.env.TAMAGUI_COMPILE_PROCESS = '1'\n\nexport { TamaguiOptions } from './types'\nexport { createExtractor } from './extractor/createExtractor'\nexport { literalToAst } from './extractor/literalToAst'\nexport * from './constants'\nexport * from './extractor/extractToClassNames'\nexport * from './extractor/extractHelpers'\nexport * from './patchReactNativeWeb'\n"],
5
5
  "mappings": "AAAA,QAAQ,IAAI,0BAA0B;AAEtC;AACA;AACA;AACA;AACA;AACA;AACA;",
6
6
  "names": []
@@ -22,6 +22,28 @@ function patchReactNativeWeb() {
22
22
  fs.writeFileSync(modulePath, moduleExports);
23
23
  fs.writeFileSync(cjsPath, cjsExports);
24
24
  }
25
+ const classNamePatch = `if (props.dataSet && props.dataSet['__className']) { domProps.className = className ? className + ' ' + props.dataSet['__className'] : props.dataSet['__className']; delete props.dataSet['__className'] }`;
26
+ const domPropsPath = ["modules", "createDOMProps", "index.js"];
27
+ const domPropsModulePath = path.join(rootDir, "dist", ...domPropsPath);
28
+ const domPropsCjsPath = path.join(rootDir, "dist", "cjs", ...domPropsPath);
29
+ const patchClassName = /* @__PURE__ */ __name((file) => {
30
+ const contents = fs.readFileSync(file, "utf-8");
31
+ if (!contents.includes(classNamePatch)) {
32
+ const needle = `domProps.className = className`;
33
+ const patchLocation = contents.indexOf(needle) + needle.length + 5;
34
+ if (patchLocation < 100) {
35
+ console.warn(`\u26A0\uFE0F Couldn't apply className patch! Maybe using incompatible react-native-web version.`);
36
+ } else {
37
+ const before = contents.slice(0, patchLocation);
38
+ const after = contents.slice(patchLocation);
39
+ const patched = before + "\n" + classNamePatch + "\n" + after;
40
+ console.log(" > adding className support to react-native-web", file);
41
+ fs.writeFileSync(file, patched);
42
+ }
43
+ }
44
+ }, "patchClassName");
45
+ patchClassName(domPropsModulePath);
46
+ patchClassName(domPropsCjsPath);
25
47
  const moduleEntry = path.join(rootDir, "dist", "index.js");
26
48
  const moduleEntrySrc = fs.readFileSync(moduleEntry, "utf-8");
27
49
  if (!moduleEntrySrc.includes("// tamagui-patch-v4")) {
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 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"],
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,QAAM,qBAAqB,KAAK,KAAK,SAAS,QAAQ,GAAG;AACzD,QAAM,kBAAkB,KAAK,KAAK,SAAS,QAAQ,OAAO,GAAG;AAC7D,QAAM,iBAAiB,wBAAC,SAAiB;AACvC,UAAM,WAAW,GAAG,aAAa,MAAM;AACvC,QAAI,CAAC,SAAS,SAAS,iBAAiB;AACtC,YAAM,SAAS;AACf,YAAM,gBAAgB,SAAS,QAAQ,UAAU,OAAO,SAAS;AAEjE,UAAI,gBAAgB,KAAK;AACvB,gBAAQ,KACN;AAAA,aAEG;AACL,cAAM,SAAS,SAAS,MAAM,GAAG;AACjC,cAAM,QAAQ,SAAS,MAAM;AAC7B,cAAM,UAAU,SAAS,OAAO,iBAAiB,OAAO;AACxD,gBAAQ,IAAI,qDAAqD;AACjE,WAAG,cAAc,MAAM;AAAA;AAAA;AAAA,KAfN;AAmBvB,iBAAe;AACf,iBAAe;AAOf,QAAM,cAAc,KAAK,KAAK,SAAS,QAAQ;AAC/C,QAAM,iBAAiB,GAAG,aAAa,aAAa;AACpD,MAAI,CAAC,eAAe,SAAS,wBAAwB;AACnD,OAAG,cACD,aACA,GAAG,YAAY;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AASnB,QAAM,WAAW,KAAK,KAAK,SAAS,QAAQ,OAAO;AACnD,QAAM,cAAc,GAAG,aAAa,UAAU;AAC9C,MAAI,CAAC,YAAY,SAAS,wBAAwB;AAChD,OAAG,cACD,UACA,GAAG,YAAY;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AA5EL;AAsFhB,qBAAqB,QAAgB;AACnC,SAAO,OAAO,QAAQ,iCAAiC;AAAA;AADhD;AAKT,MAAM,oBAAoB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAiB1B,MAAM,gBAAgB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;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
+ "names": []
7
+ }
File without changes
File without changes
@@ -0,0 +1,13 @@
1
+ import findCacheDir from "find-cache-dir";
2
+ const CSS_FILE_NAME = "__snack.css";
3
+ const MEDIA_SEP = "_";
4
+ const cacheDir = findCacheDir({ name: "tamagui", create: true });
5
+ const FAILED_EVAL = Symbol("failed_style_eval");
6
+ const CONCAT_CLASSNAME_IMPORT = "concatClassName";
7
+ export {
8
+ CONCAT_CLASSNAME_IMPORT,
9
+ CSS_FILE_NAME,
10
+ FAILED_EVAL,
11
+ MEDIA_SEP,
12
+ cacheDir
13
+ };
@@ -0,0 +1,10 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
+ import * as t from "@babel/types";
4
+ function accessSafe(obj, member) {
5
+ return t.logicalExpression("&&", t.logicalExpression("&&", t.binaryExpression("===", t.unaryExpression("typeof", obj), t.stringLiteral("object")), t.binaryExpression("!==", obj, t.nullLiteral())), t.memberExpression(obj, t.identifier(member), false));
6
+ }
7
+ __name(accessSafe, "accessSafe");
8
+ export {
9
+ accessSafe
10
+ };
@@ -0,0 +1,29 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
+ import * as babelParser from "@babel/parser";
4
+ const parserOptions = Object.freeze({
5
+ plugins: [
6
+ "asyncGenerators",
7
+ "classProperties",
8
+ "dynamicImport",
9
+ "functionBind",
10
+ "jsx",
11
+ "numericSeparator",
12
+ "objectRestSpread",
13
+ "optionalCatchBinding",
14
+ "decorators-legacy",
15
+ "typescript",
16
+ "optionalChaining",
17
+ "nullishCoalescingOperator"
18
+ ],
19
+ sourceType: "module"
20
+ });
21
+ const parser = babelParser.parse.bind(babelParser);
22
+ function babelParse(code) {
23
+ return parser(code.toString(), parserOptions);
24
+ }
25
+ __name(babelParse, "babelParse");
26
+ export {
27
+ babelParse,
28
+ parserOptions
29
+ };
@@ -0,0 +1,39 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
+ import * as t from "@babel/types";
4
+ function buildClassName(classNameObjects) {
5
+ return classNameObjects.reduce((acc, val) => {
6
+ if (acc == null) {
7
+ if (t.isConditionalExpression(val) || t.isStringLiteral(val) || t.isNumericLiteral(val)) {
8
+ return val;
9
+ }
10
+ return t.logicalExpression("||", val, t.stringLiteral(""));
11
+ }
12
+ let inner;
13
+ if (t.isStringLiteral(val)) {
14
+ if (t.isStringLiteral(acc)) {
15
+ return t.stringLiteral(`${acc.value} ${val.value}`);
16
+ }
17
+ inner = t.stringLiteral(` ${val.value}`);
18
+ } else if (t.isLiteral(val)) {
19
+ inner = t.binaryExpression("+", t.stringLiteral(" "), val);
20
+ } else if (t.isConditionalExpression(val) || t.isBinaryExpression(val)) {
21
+ if (t.isStringLiteral(acc)) {
22
+ return t.binaryExpression("+", t.stringLiteral(`${acc.value} `), val);
23
+ }
24
+ inner = t.binaryExpression("+", t.stringLiteral(" "), val);
25
+ } else if (t.isIdentifier(val) || t.isMemberExpression(val)) {
26
+ inner = t.conditionalExpression(val, t.binaryExpression("+", t.stringLiteral(" "), val), t.stringLiteral(""));
27
+ } else {
28
+ if (t.isStringLiteral(acc)) {
29
+ return t.binaryExpression("+", t.stringLiteral(`${acc.value} `), t.logicalExpression("||", val, t.stringLiteral("")));
30
+ }
31
+ inner = t.binaryExpression("+", t.stringLiteral(" "), t.logicalExpression("||", val, t.stringLiteral("")));
32
+ }
33
+ return t.binaryExpression("+", acc, inner);
34
+ }, null);
35
+ }
36
+ __name(buildClassName, "buildClassName");
37
+ export {
38
+ buildClassName
39
+ };
@@ -0,0 +1,50 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
+ import vm from "vm";
4
+ import generate from "@babel/generator";
5
+ import * as t from "@babel/types";
6
+ import { FAILED_EVAL } from "../constants";
7
+ import { evaluateAstNode } from "./evaluateAstNode";
8
+ import { isValidThemeHook } from "./extractHelpers";
9
+ function createEvaluator({
10
+ tamaguiConfig,
11
+ staticNamespace,
12
+ sourcePath,
13
+ traversePath,
14
+ shouldPrintDebug
15
+ }) {
16
+ const evalFn = /* @__PURE__ */ __name((n) => {
17
+ if (t.isMemberExpression(n) && t.isIdentifier(n.property) && isValidThemeHook(traversePath, n, sourcePath)) {
18
+ const key = n.property.name;
19
+ if (shouldPrintDebug) {
20
+ console.log(" > found theme prop", key);
21
+ }
22
+ console.log("SHOULD FIND THEME (NESTED NOW)", key);
23
+ return `var(--${key})`;
24
+ }
25
+ if (t.isIdentifier(n) && staticNamespace.hasOwnProperty(n.name)) {
26
+ return staticNamespace[n.name];
27
+ }
28
+ const evalContext = vm.createContext(staticNamespace);
29
+ const code = `(${generate(n).code})`;
30
+ return vm.runInContext(code, evalContext);
31
+ }, "evalFn");
32
+ return (n) => {
33
+ return evaluateAstNode(n, evalFn);
34
+ };
35
+ }
36
+ __name(createEvaluator, "createEvaluator");
37
+ function createSafeEvaluator(attemptEval) {
38
+ return (n) => {
39
+ try {
40
+ return attemptEval(n);
41
+ } catch (err) {
42
+ return FAILED_EVAL;
43
+ }
44
+ };
45
+ }
46
+ __name(createSafeEvaluator, "createSafeEvaluator");
47
+ export {
48
+ createEvaluator,
49
+ createSafeEvaluator
50
+ };