@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
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/types.ts"],
4
+ "sourcesContent": ["import { NodePath } from '@babel/traverse'\nimport * as t from '@babel/types'\n\nexport type ClassNameObject = t.StringLiteral | t.Expression\n\nexport interface CacheObject {\n [key: string]: any\n}\n\nexport interface TamaguiOptions {\n // module paths you want to compile with tamagui (for example ['tamagui'])\n components: string[]\n // your tamagui.config.ts\n config?: string\n evaluateVars?: boolean\n importsWhitelist?: string[]\n disableExtraction?: boolean\n disableDebugAttr?: boolean\n disableExtractInlineMedia?: boolean\n disableExtractVariables?: boolean\n exclude?: RegExp\n logTimings?: boolean\n\n // probably non user options\n cssPath?: string\n cssData?: any\n deoptProps?: Set<string>\n excludeProps?: string[]\n}\n\nexport type ExtractedAttrAttr = {\n type: 'attr'\n value: t.JSXAttribute | t.JSXSpreadAttribute\n}\n\nexport type ExtractedAttrStyle = {\n type: 'style'\n value: Object\n attr?: t.JSXAttribute | t.JSXSpreadAttribute\n name?: string\n}\n\nexport type ExtractedAttr =\n | ExtractedAttrAttr\n | { type: 'ternary'; value: Ternary }\n | ExtractedAttrStyle\n\nexport type ExtractTagProps = {\n attrs: ExtractedAttr[]\n node: t.JSXOpeningElement\n attemptEval: (exprNode: t.Node, evalFn?: ((node: t.Node) => any) | undefined) => any\n jsxPath: NodePath<t.JSXElement>\n programPath: NodePath<t.Program>\n originalNodeName: string\n lineNumbers: string\n filePath: string\n isFlattened: boolean\n}\n\nexport type ExtractorParseProps = TamaguiOptions & {\n sourcePath?: string\n shouldPrintDebug?: boolean\n onExtractTag: (props: ExtractTagProps) => void\n getFlattenedNode: (props: { isTextView: boolean; tag: string }) => string\n}\n\nexport interface Ternary {\n test: t.Expression\n // shorthand props that don't use hooks\n inlineMediaQuery?: string\n remove: Function\n consequent: Object | null\n alternate: Object | null\n}\n\nexport type StyleObject = {\n property: string\n value: string\n className: string\n identifier: string\n rules: string[]\n}\n\nexport type ClassNameToStyleObj = {\n [key: string]: StyleObject\n}\n\nexport interface PluginContext {\n write: (path: string, rules: { [key: string]: string }) => any\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;AAAA;",
6
+ "names": []
7
+ }
@@ -2,8 +2,12 @@ import findCacheDir from "find-cache-dir";
2
2
  const CSS_FILE_NAME = "__snack.css";
3
3
  const MEDIA_SEP = "_";
4
4
  const cacheDir = findCacheDir({ name: "tamagui", create: true });
5
+ const FAILED_EVAL = Symbol("failed_style_eval");
6
+ const CONCAT_CLASSNAME_IMPORT = "concatClassName";
5
7
  export {
8
+ CONCAT_CLASSNAME_IMPORT,
6
9
  CSS_FILE_NAME,
10
+ FAILED_EVAL,
7
11
  MEDIA_SEP,
8
12
  cacheDir
9
13
  };
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
- "sources": ["../src/constants.ts"],
4
- "sourcesContent": ["import findCacheDir from 'find-cache-dir'\n\nexport const CSS_FILE_NAME = '__snack.css'\n\n// ENSURE THIS ISNT THE SAME AS THE SEPARATOR USED FOR STYLE KEYS\n// SEE matching one in concatClassName\nexport const MEDIA_SEP = '_'\n\n// ensure cache dir\nexport const cacheDir = findCacheDir({ name: 'tamagui', create: true })\n"],
5
- "mappings": "AAAA;AAEO,MAAM,gBAAgB;AAItB,MAAM,YAAY;AAGlB,MAAM,WAAW,aAAa,EAAE,MAAM,WAAW,QAAQ;",
3
+ "sources": ["../../src/constants.ts"],
4
+ "sourcesContent": ["import findCacheDir from 'find-cache-dir'\n\nexport const CSS_FILE_NAME = '__snack.css'\n\n// ENSURE THIS ISNT THE SAME AS THE SEPARATOR USED FOR STYLE KEYS\n// SEE matching one in concatClassName\nexport const MEDIA_SEP = '_'\n\n// ensure cache dir\nexport const cacheDir = findCacheDir({ name: 'tamagui', create: true })\n\nexport const FAILED_EVAL = Symbol('failed_style_eval')\nexport const CONCAT_CLASSNAME_IMPORT = 'concatClassName'\n"],
5
+ "mappings": "AAAA;AAEO,MAAM,gBAAgB;AAItB,MAAM,YAAY;AAGlB,MAAM,WAAW,aAAa,EAAE,MAAM,WAAW,QAAQ;AAEzD,MAAM,cAAc,OAAO;AAC3B,MAAM,0BAA0B;",
6
6
  "names": []
7
7
  }
File without changes
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "version": 3,
3
- "sources": ["../../src/extractor/accessSafe.ts"],
3
+ "sources": ["../../../src/extractor/accessSafe.ts"],
4
4
  "sourcesContent": ["import * as t from '@babel/types'\n\n// accessSafe wraps memberExpressions in object/null checks\n// TODO: inject this as a function? this gets pretty repetitive\nexport function accessSafe(obj: t.Expression, member: string): t.LogicalExpression {\n return t.logicalExpression(\n '&&',\n t.logicalExpression(\n '&&',\n // typeof obj === 'object\n t.binaryExpression('===', t.unaryExpression('typeof', obj), t.stringLiteral('object')),\n // obj !== null\n t.binaryExpression('!==', obj, t.nullLiteral())\n ),\n // obj.member\n t.memberExpression(obj, t.identifier(member), false)\n )\n}\n"],
5
5
  "mappings": ";;AAAA;AAIO,oBAAoB,KAAmB,QAAqC;AACjF,SAAO,EAAE,kBACP,MACA,EAAE,kBACA,MAEA,EAAE,iBAAiB,OAAO,EAAE,gBAAgB,UAAU,MAAM,EAAE,cAAc,YAE5E,EAAE,iBAAiB,OAAO,KAAK,EAAE,iBAGnC,EAAE,iBAAiB,KAAK,EAAE,WAAW,SAAS;AAAA;AAXlC;",
6
6
  "names": []
File without changes
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "version": 3,
3
- "sources": ["../../src/extractor/babelParse.ts"],
3
+ "sources": ["../../../src/extractor/babelParse.ts"],
4
4
  "sourcesContent": ["import * as babelParser from '@babel/parser'\n\nexport const parserOptions: babelParser.ParserOptions = Object.freeze({\n plugins: [\n 'asyncGenerators',\n 'classProperties',\n 'dynamicImport',\n 'functionBind',\n 'jsx',\n 'numericSeparator',\n 'objectRestSpread',\n 'optionalCatchBinding',\n 'decorators-legacy',\n 'typescript',\n 'optionalChaining',\n 'nullishCoalescingOperator',\n // 'objectRestSpread',\n // 'dynamicImport'\n ],\n sourceType: 'module',\n})\n\nconst parser = babelParser.parse.bind(babelParser)\n\nexport function babelParse(code: string | Buffer): any {\n return parser(code.toString(), parserOptions)\n}\n"],
5
5
  "mappings": ";;AAAA;AAEO,MAAM,gBAA2C,OAAO,OAAO;AAAA,EACpE,SAAS;AAAA,IACP;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA;AAAA,EAIF,YAAY;AAAA;AAGd,MAAM,SAAS,YAAY,MAAM,KAAK;AAE/B,oBAAoB,MAA4B;AACrD,SAAO,OAAO,KAAK,YAAY;AAAA;AADjB;",
6
6
  "names": []
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "version": 3,
3
- "sources": ["../../src/extractor/buildClassName.ts"],
3
+ "sources": ["../../../src/extractor/buildClassName.ts"],
4
4
  "sourcesContent": ["import * as t from '@babel/types'\n\nimport { ClassNameObject } from '../types'\n\nexport function buildClassName(\n classNameObjects: ClassNameObject[]\n): t.Expression | t.StringLiteral | null {\n return classNameObjects.reduce<t.Expression | null>((acc, val) => {\n if (acc == null) {\n if (\n // pass conditional expressions through\n t.isConditionalExpression(val) ||\n // pass non-null literals through\n t.isStringLiteral(val) ||\n t.isNumericLiteral(val)\n ) {\n return val\n }\n return t.logicalExpression('||', val, t.stringLiteral(''))\n }\n\n let inner: t.Expression\n if (t.isStringLiteral(val)) {\n if (t.isStringLiteral(acc)) {\n // join adjacent string literals\n return t.stringLiteral(`${acc.value} ${val.value}`)\n }\n inner = t.stringLiteral(` ${val.value}`)\n } else if (t.isLiteral(val)) {\n inner = t.binaryExpression('+', t.stringLiteral(' '), val)\n } else if (t.isConditionalExpression(val) || t.isBinaryExpression(val)) {\n if (t.isStringLiteral(acc)) {\n return t.binaryExpression('+', t.stringLiteral(`${acc.value} `), val)\n }\n inner = t.binaryExpression('+', t.stringLiteral(' '), val)\n } else if (t.isIdentifier(val) || t.isMemberExpression(val)) {\n // identifiers and member expressions make for reasonable ternaries\n inner = t.conditionalExpression(\n val,\n t.binaryExpression('+', t.stringLiteral(' '), val),\n t.stringLiteral('')\n )\n } else {\n if (t.isStringLiteral(acc)) {\n return t.binaryExpression(\n '+',\n t.stringLiteral(`${acc.value} `),\n t.logicalExpression('||', val, t.stringLiteral(''))\n )\n }\n // use a logical expression for more complex prop values\n inner = t.binaryExpression(\n '+',\n t.stringLiteral(' '),\n t.logicalExpression('||', val, t.stringLiteral(''))\n )\n }\n\n return t.binaryExpression('+', acc, inner)\n }, null)\n}\n"],
5
5
  "mappings": ";;AAAA;AAIO,wBACL,kBACuC;AACvC,SAAO,iBAAiB,OAA4B,CAAC,KAAK,QAAQ;AAChE,QAAI,OAAO,MAAM;AACf,UAEE,EAAE,wBAAwB,QAE1B,EAAE,gBAAgB,QAClB,EAAE,iBAAiB,MACnB;AACA,eAAO;AAAA;AAET,aAAO,EAAE,kBAAkB,MAAM,KAAK,EAAE,cAAc;AAAA;AAGxD,QAAI;AACJ,QAAI,EAAE,gBAAgB,MAAM;AAC1B,UAAI,EAAE,gBAAgB,MAAM;AAE1B,eAAO,EAAE,cAAc,GAAG,IAAI,SAAS,IAAI;AAAA;AAE7C,cAAQ,EAAE,cAAc,IAAI,IAAI;AAAA,eACvB,EAAE,UAAU,MAAM;AAC3B,cAAQ,EAAE,iBAAiB,KAAK,EAAE,cAAc,MAAM;AAAA,eAC7C,EAAE,wBAAwB,QAAQ,EAAE,mBAAmB,MAAM;AACtE,UAAI,EAAE,gBAAgB,MAAM;AAC1B,eAAO,EAAE,iBAAiB,KAAK,EAAE,cAAc,GAAG,IAAI,WAAW;AAAA;AAEnE,cAAQ,EAAE,iBAAiB,KAAK,EAAE,cAAc,MAAM;AAAA,eAC7C,EAAE,aAAa,QAAQ,EAAE,mBAAmB,MAAM;AAE3D,cAAQ,EAAE,sBACR,KACA,EAAE,iBAAiB,KAAK,EAAE,cAAc,MAAM,MAC9C,EAAE,cAAc;AAAA,WAEb;AACL,UAAI,EAAE,gBAAgB,MAAM;AAC1B,eAAO,EAAE,iBACP,KACA,EAAE,cAAc,GAAG,IAAI,WACvB,EAAE,kBAAkB,MAAM,KAAK,EAAE,cAAc;AAAA;AAInD,cAAQ,EAAE,iBACR,KACA,EAAE,cAAc,MAChB,EAAE,kBAAkB,MAAM,KAAK,EAAE,cAAc;AAAA;AAInD,WAAO,EAAE,iBAAiB,KAAK,KAAK;AAAA,KACnC;AAAA;AAvDW;",
6
6
  "names": []
@@ -3,7 +3,7 @@ var __name = (target, value) => __defProp(target, "name", { value, configurable:
3
3
  import vm from "vm";
4
4
  import generate from "@babel/generator";
5
5
  import * as t from "@babel/types";
6
- import { FAILED_EVAL } from "./createExtractor";
6
+ import { FAILED_EVAL } from "../constants";
7
7
  import { evaluateAstNode } from "./evaluateAstNode";
8
8
  import { isValidThemeHook } from "./extractHelpers";
9
9
  function createEvaluator({
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/extractor/createEvaluator.ts"],
4
+ "sourcesContent": ["import vm from 'vm'\n\nimport generate from '@babel/generator'\nimport { NodePath } from '@babel/traverse'\nimport * as t from '@babel/types'\nimport type { TamaguiConfig } from '@tamagui/core'\n\nimport { FAILED_EVAL } from '../constants'\nimport { evaluateAstNode } from './evaluateAstNode'\nimport { isValidThemeHook } from './extractHelpers'\n\nexport function createEvaluator({\n tamaguiConfig,\n staticNamespace,\n sourcePath,\n traversePath,\n shouldPrintDebug,\n}: {\n tamaguiConfig: TamaguiConfig\n staticNamespace: Record<string, any>\n sourcePath: string\n traversePath: NodePath<t.JSXElement>\n shouldPrintDebug: boolean\n}) {\n // called when evaluateAstNode encounters a dynamic-looking prop\n const evalFn = (n: t.Node) => {\n // themes\n if (\n t.isMemberExpression(n) &&\n t.isIdentifier(n.property) &&\n isValidThemeHook(traversePath, n, sourcePath)\n ) {\n const key = n.property.name\n if (shouldPrintDebug) {\n console.log(' > found theme prop', key)\n }\n console.log('SHOULD FIND THEME (NESTED NOW)', key) // tamaguiConfig.themes)\n // if (!themeKeys.has(key)) {\n // throw new Error(` > accessing non-existent theme key: ${key}`)\n // }\n return `var(--${key})`\n }\n // variable\n if (t.isIdentifier(n) && staticNamespace.hasOwnProperty(n.name)) {\n return staticNamespace[n.name]\n }\n const evalContext = vm.createContext(staticNamespace)\n const code = `(${generate(n as any).code})`\n // if (shouldPrintDebug) {\n // console.log('evaluating', { n, code, evalContext })\n // }\n return vm.runInContext(code, evalContext)\n }\n\n return (n: t.Node) => {\n return evaluateAstNode(n, evalFn)\n }\n}\n\nexport function createSafeEvaluator(attemptEval: (n: t.Node) => any) {\n return (n: t.Node) => {\n try {\n return attemptEval(n)\n } catch (err) {\n return FAILED_EVAL\n }\n }\n}\n"],
5
+ "mappings": ";;AAAA;AAEA;AAEA;AAGA;AACA;AACA;AAEO,yBAAyB;AAAA,EAC9B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,GAOC;AAED,QAAM,SAAS,wBAAC,MAAc;AAE5B,QACE,EAAE,mBAAmB,MACrB,EAAE,aAAa,EAAE,aACjB,iBAAiB,cAAc,GAAG,aAClC;AACA,YAAM,MAAM,EAAE,SAAS;AACvB,UAAI,kBAAkB;AACpB,gBAAQ,IAAI,0BAA0B;AAAA;AAExC,cAAQ,IAAI,kCAAkC;AAI9C,aAAO,SAAS;AAAA;AAGlB,QAAI,EAAE,aAAa,MAAM,gBAAgB,eAAe,EAAE,OAAO;AAC/D,aAAO,gBAAgB,EAAE;AAAA;AAE3B,UAAM,cAAc,GAAG,cAAc;AACrC,UAAM,OAAO,IAAI,SAAS,GAAU;AAIpC,WAAO,GAAG,aAAa,MAAM;AAAA,KA1BhB;AA6Bf,SAAO,CAAC,MAAc;AACpB,WAAO,gBAAgB,GAAG;AAAA;AAAA;AA5Cd;AAgDT,6BAA6B,aAAiC;AACnE,SAAO,CAAC,MAAc;AACpB,QAAI;AACF,aAAO,YAAY;AAAA,aACZ,KAAP;AACA,aAAO;AAAA;AAAA;AAAA;AALG;",
6
+ "names": []
7
+ }
@@ -2,9 +2,10 @@ var __defProp = Object.defineProperty;
2
2
  var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
3
  import traverse from "@babel/traverse";
4
4
  import * as t from "@babel/types";
5
- import * as CoreNode from "@tamagui/core-node";
5
+ import { mediaQueryConfig, postProcessStyles, pseudos } from "@tamagui/core-node";
6
6
  import { stylePropsTransform } from "@tamagui/helpers";
7
7
  import { difference, pick } from "lodash";
8
+ import { FAILED_EVAL } from "../constants";
8
9
  import { createEvaluator, createSafeEvaluator } from "./createEvaluator";
9
10
  import { evaluateAstNode } from "./evaluateAstNode";
10
11
  import { attrStr, findComponentName, isInsideTamagui, isPresent, objToStr } from "./extractHelpers";
@@ -12,10 +13,9 @@ import { findTopmostFunction } from "./findTopmostFunction";
12
13
  import { getStaticBindingsForScope } from "./getStaticBindingsForScope";
13
14
  import { literalToAst } from "./literalToAst";
14
15
  import { loadTamagui } from "./loadTamagui";
16
+ import { logLines } from "./logLines";
15
17
  import { normalizeTernaries } from "./normalizeTernaries";
16
18
  import { removeUnusedHooks } from "./removeUnusedHooks";
17
- const { mediaQueryConfig, postProcessStyles, pseudos } = CoreNode;
18
- const FAILED_EVAL = Symbol("failed_style_eval");
19
19
  const UNTOUCHED_PROPS = {
20
20
  key: true,
21
21
  style: true,
@@ -36,7 +36,7 @@ function createExtractor() {
36
36
  let loadedTamaguiConfig;
37
37
  let hasLogged = false;
38
38
  return {
39
- getTamaguiConfig() {
39
+ getTamagui() {
40
40
  return loadedTamaguiConfig;
41
41
  },
42
42
  parse: (fileOrPath, {
@@ -48,6 +48,8 @@ function createExtractor() {
48
48
  onExtractTag,
49
49
  getFlattenedNode,
50
50
  disableExtraction,
51
+ disableExtractInlineMedia,
52
+ disableExtractVariables,
51
53
  disableDebugAttr,
52
54
  ...props
53
55
  }) => {
@@ -64,8 +66,13 @@ function createExtractor() {
64
66
  loadedTamaguiConfig = tamaguiConfig;
65
67
  const defaultTheme = tamaguiConfig.themes[Object.keys(tamaguiConfig.themes)[0]];
66
68
  const body = fileOrPath.type === "Program" ? fileOrPath.get("body") : fileOrPath.program.body;
67
- const isInternalImport = /* @__PURE__ */ __name((importStr) => isInsideTamagui(sourcePath) && importStr[0] === ".", "isInternalImport");
68
- const validComponents = Object.keys(components).filter((key) => !!components[key]?.staticConfig).reduce((obj, name) => {
69
+ const isInternalImport = /* @__PURE__ */ __name((importStr) => {
70
+ return isInsideTamagui(sourcePath) && importStr[0] === ".";
71
+ }, "isInternalImport");
72
+ const validComponents = Object.keys(components).filter((key) => {
73
+ var _a;
74
+ return key[0].toUpperCase() === key[0] && !!((_a = components[key]) == null ? void 0 : _a.staticConfig);
75
+ }).reduce((obj, name) => {
69
76
  obj[name] = components[name];
70
77
  return obj;
71
78
  }, {});
@@ -92,7 +99,7 @@ function createExtractor() {
92
99
  return null;
93
100
  }
94
101
  let couldntParse = false;
95
- const modifiedComponents = new Set();
102
+ const modifiedComponents = /* @__PURE__ */ new Set();
96
103
  const bindingCache = {};
97
104
  const callTraverse = /* @__PURE__ */ __name((a) => {
98
105
  return fileOrPath.type === "File" ? traverse(fileOrPath, a) : fileOrPath.traverse(a);
@@ -110,11 +117,12 @@ function createExtractor() {
110
117
  }
111
118
  },
112
119
  JSXElement(traversePath) {
120
+ var _a, _b, _c, _d, _e, _f;
113
121
  const node = traversePath.node.openingElement;
114
122
  const ogAttributes = node.attributes;
115
123
  const componentName = findComponentName(traversePath.scope);
116
124
  const closingElement = traversePath.node.closingElement;
117
- if (t.isJSXMemberExpression(closingElement?.name) || !t.isJSXIdentifier(node.name)) {
125
+ if (t.isJSXMemberExpression(closingElement == null ? void 0 : closingElement.name) || !t.isJSXIdentifier(node.name)) {
118
126
  return;
119
127
  }
120
128
  const binding = traversePath.scope.getBinding(node.name.name);
@@ -155,8 +163,8 @@ function createExtractor() {
155
163
  }
156
164
  const { staticConfig } = component;
157
165
  const isTextView = staticConfig.isText || false;
158
- const validStyles = staticConfig?.validStyles ?? {};
159
- let tagName = staticConfig.defaultProps?.tag ?? (isTextView ? "span" : "div");
166
+ const validStyles = (_a = staticConfig == null ? void 0 : staticConfig.validStyles) != null ? _a : {};
167
+ let tagName = (_c = (_b = staticConfig.defaultProps) == null ? void 0 : _b.tag) != null ? _c : isTextView ? "span" : "div";
160
168
  traversePath.get("openingElement").get("attributes").forEach((path) => {
161
169
  const attr = path.node;
162
170
  if (t.isJSXSpreadAttribute(attr))
@@ -169,11 +177,11 @@ function createExtractor() {
169
177
  tagName = val.value;
170
178
  });
171
179
  const flatNode = getFlattenedNode({ isTextView, tag: tagName });
172
- const deoptProps = new Set([
173
- ...props.deoptProps ?? [],
174
- ...staticConfig.deoptProps ?? []
180
+ const deoptProps = /* @__PURE__ */ new Set([
181
+ ...(_d = props.deoptProps) != null ? _d : [],
182
+ ...(_e = staticConfig.deoptProps) != null ? _e : []
175
183
  ]);
176
- const excludeProps = new Set(props.excludeProps ?? []);
184
+ const excludeProps = new Set((_f = props.excludeProps) != null ? _f : []);
177
185
  const isExcludedProp = /* @__PURE__ */ __name((name) => {
178
186
  const res2 = excludeProps.has(name);
179
187
  if (res2 && shouldPrintDebug)
@@ -198,9 +206,6 @@ function createExtractor() {
198
206
  if (shouldPrintDebug) {
199
207
  console.log(" staticNamespace", Object.keys(staticNamespace).join(", "));
200
208
  }
201
- const hasDeopt = /* @__PURE__ */ __name((obj) => {
202
- return Object.keys(obj).some(isDeoptedProp);
203
- }, "hasDeopt");
204
209
  const flattenedAttrs = [];
205
210
  traversePath.get("openingElement").get("attributes").forEach((path) => {
206
211
  const attr = path.node;
@@ -247,9 +252,19 @@ function createExtractor() {
247
252
  node.attributes = flattenedAttrs;
248
253
  if (staticConfig.defaultProps) {
249
254
  for (const key in staticConfig.defaultProps) {
255
+ if (key === "StyleSheet") {
256
+ continue;
257
+ }
250
258
  const serialize = require("babel-literal-to-ast");
251
259
  const val = staticConfig.defaultProps[key];
252
- node.attributes.unshift(t.jsxAttribute(t.jsxIdentifier(key), typeof val === "string" ? t.stringLiteral(val) : t.jsxExpressionContainer(serialize(val))));
260
+ try {
261
+ const serializedDefaultProp = serialize(val);
262
+ node.attributes.unshift(t.jsxAttribute(t.jsxIdentifier(key), typeof val === "string" ? t.stringLiteral(val) : t.jsxExpressionContainer(serializedDefaultProp)));
263
+ } catch (err) {
264
+ console.warn(`\u26A0\uFE0F Error evaluating default prop for component ${node.name.name}, prop ${key}
265
+ error: ${err}
266
+ value:`, val, "\n defaultProps:", staticConfig.defaultProps);
267
+ }
253
268
  }
254
269
  }
255
270
  let attrs = [];
@@ -264,16 +279,22 @@ function createExtractor() {
264
279
  }
265
280
  return res2;
266
281
  } catch (err) {
267
- console.log("Error extracting attribute", err.message, err.stack);
268
- console.log("node", path.node);
282
+ if (shouldPrintDebug) {
283
+ console.log("Error extracting attribute", err.message, err.stack);
284
+ console.log("node", path.node);
285
+ }
269
286
  return {
270
287
  type: "attr",
271
288
  value: path.node
272
289
  };
273
290
  }
274
291
  }).flat(4).filter(isPresent);
292
+ if (shouldPrintDebug) {
293
+ console.log(" - attrs (before):\n", logLines(attrs.map(attrStr).join(", ")));
294
+ }
275
295
  function isStaticAttributeName(name) {
276
- return !!(!!validStyles[name] || staticConfig.validPropsExtra?.[name] || !!pseudos[name] || staticConfig.variants?.[name] || tamaguiConfig.shorthands[name] || (name[0] === "$" ? !!mediaQueryConfig[name.slice(1)] : false));
296
+ var _a2, _b2;
297
+ return !!(!!validStyles[name] || ((_a2 = staticConfig.validPropsExtra) == null ? void 0 : _a2[name]) || !!pseudos[name] || ((_b2 = staticConfig.variants) == null ? void 0 : _b2[name]) || tamaguiConfig.shorthands[name] || (name[0] === "$" ? !!mediaQueryConfig[name.slice(1)] : false));
277
298
  }
278
299
  __name(isStaticAttributeName, "isStaticAttributeName");
279
300
  function isExtractable(obj) {
@@ -304,6 +325,29 @@ function createExtractor() {
304
325
  if (!t.isObjectProperty(property)) {
305
326
  throw new Error("expected object property");
306
327
  }
328
+ if (t.isIdentifier(property.key)) {
329
+ const key = property.key.name;
330
+ const mediaQueryKey = key.slice(1);
331
+ const isMediaQuery = key[0] === "$" && mediaQueryConfig[mediaQueryKey];
332
+ if (isMediaQuery) {
333
+ if (t.isExpression(property.value)) {
334
+ const ternaries2 = createTernariesFromObjectProperties(t.stringLiteral(mediaQueryKey), property.value, {
335
+ inlineMediaQuery: mediaQueryKey
336
+ });
337
+ if (ternaries2) {
338
+ return ternaries2.map((value) => ({
339
+ ...ternaryPartial,
340
+ ...value,
341
+ test: t.logicalExpression("&&", value.test, test)
342
+ }));
343
+ } else {
344
+ console.log("\u26A0\uFE0F no ternaries?", property);
345
+ }
346
+ } else {
347
+ console.log("\u26A0\uFE0F not expression", property);
348
+ }
349
+ }
350
+ }
307
351
  if (t.isConditionalExpression(property.value)) {
308
352
  const [truthy, falsy] = [
309
353
  t.objectExpression([t.objectProperty(property.key, property.value.consequent)]),
@@ -367,10 +411,16 @@ function createExtractor() {
367
411
  }
368
412
  }
369
413
  if (t.isJSXSpreadAttribute(attribute) || !attribute.name || typeof attribute.name.name !== "string") {
414
+ if (shouldPrintDebug) {
415
+ console.log(" ! inlining, spread attr");
416
+ }
370
417
  inlinePropCount++;
371
418
  return attr;
372
419
  }
373
420
  const name = attribute.name.name;
421
+ if (name.startsWith("data-")) {
422
+ return attr;
423
+ }
374
424
  if (isExcludedProp(name)) {
375
425
  return null;
376
426
  }
@@ -384,7 +434,10 @@ function createExtractor() {
384
434
  if (UNTOUCHED_PROPS[name]) {
385
435
  return attr;
386
436
  }
387
- if (name[0] === "$" && t.isJSXExpressionContainer(attribute?.value)) {
437
+ if (name[0] === "$" && t.isJSXExpressionContainer(attribute == null ? void 0 : attribute.value)) {
438
+ if (disableExtractInlineMedia) {
439
+ return attr;
440
+ }
388
441
  const shortname = name.slice(1);
389
442
  if (mediaQueryConfig[shortname]) {
390
443
  const expression = attribute.value.expression;
@@ -402,7 +455,7 @@ function createExtractor() {
402
455
  }
403
456
  }
404
457
  const [value, valuePath] = (() => {
405
- if (t.isJSXExpressionContainer(attribute?.value)) {
458
+ if (t.isJSXExpressionContainer(attribute == null ? void 0 : attribute.value)) {
406
459
  return [attribute.value.expression, path.get("value")];
407
460
  } else {
408
461
  return [attribute.value, path.get("value")];
@@ -424,6 +477,17 @@ function createExtractor() {
424
477
  value: path.node
425
478
  };
426
479
  }
480
+ if (disableExtractVariables) {
481
+ if (value) {
482
+ if (value.type === "StringLiteral" && value.value[0] === "$") {
483
+ if (shouldPrintDebug) {
484
+ console.log(` ! inlining, native disable extract: ${name} =`, value.value);
485
+ }
486
+ inlinePropCount++;
487
+ return attr;
488
+ }
489
+ }
490
+ }
427
491
  const styleValue = attemptEvalSafe(value);
428
492
  if (!isStaticAttributeName(name)) {
429
493
  let keys = [name];
@@ -433,21 +497,33 @@ function createExtractor() {
433
497
  keys = Object.keys(out);
434
498
  }
435
499
  }
436
- if (keys.some((k) => !isStaticAttributeName(k) && k !== "tag")) {
437
- if (shouldPrintDebug) {
438
- console.log(" ! inlining, not static attribute name", name);
500
+ for (const key of keys) {
501
+ if (!isStaticAttributeName(key)) {
502
+ if (shouldPrintDebug) {
503
+ console.log(" ! inlining, non-static", key);
504
+ }
505
+ inlinePropCount++;
439
506
  }
440
- inlinePropCount++;
507
+ }
508
+ if (inlinePropCount) {
441
509
  return attr;
442
510
  }
443
511
  }
444
512
  if (styleValue !== FAILED_EVAL) {
513
+ if (shouldPrintDebug) {
514
+ console.log(` style: ${name} =`, styleValue);
515
+ }
445
516
  return {
446
517
  type: "style",
447
- value: { [name]: styleValue }
518
+ value: { [name]: styleValue },
519
+ name,
520
+ attr: path.node
448
521
  };
449
522
  }
450
523
  if (t.isBinaryExpression(value)) {
524
+ if (shouldPrintDebug) {
525
+ console.log(` binary expression ${name} = `, value);
526
+ }
451
527
  const { operator, left, right } = value;
452
528
  const lVal = attemptEvalSafe(left);
453
529
  const rVal = attemptEvalSafe(right);
@@ -472,16 +548,25 @@ function createExtractor() {
472
548
  }
473
549
  const staticConditional = getStaticConditional(value);
474
550
  if (staticConditional) {
551
+ if (shouldPrintDebug) {
552
+ console.log(` static conditional ${name} = `, value);
553
+ }
475
554
  return { type: "ternary", value: staticConditional };
476
555
  }
477
556
  const staticLogical = getStaticLogical(value);
478
557
  if (staticLogical) {
558
+ if (shouldPrintDebug) {
559
+ console.log(` static ternary ${name} = `, value);
560
+ }
479
561
  return { type: "ternary", value: staticLogical };
480
562
  }
481
563
  if (shouldPrintDebug) {
482
564
  console.log(" ! inline prop via no match", name, value.type);
483
565
  }
484
566
  inlinePropCount++;
567
+ if (shouldPrintDebug) {
568
+ console.log(` inlining ${name} = `, value);
569
+ }
485
570
  return attr;
486
571
  function addBinaryConditional(operator, staticExpr, cond) {
487
572
  if (getStaticConditional(cond)) {
@@ -556,9 +641,6 @@ function createExtractor() {
556
641
  __name(getStaticLogical, "getStaticLogical");
557
642
  }
558
643
  __name(evaluateAttribute, "evaluateAttribute");
559
- if (shouldPrintDebug) {
560
- console.log(" - attrs (before): ", attrs.map(attrStr).join(", "));
561
- }
562
644
  node.attributes = attrs.filter(isAttr).map((x) => x.value);
563
645
  if (couldntParse) {
564
646
  if (shouldPrintDebug) {
@@ -631,16 +713,19 @@ function createExtractor() {
631
713
  const shouldFlatten = !shouldDeopt && inlinePropCount === 0 && !hasSpread && staticConfig.neverFlatten !== true && (staticConfig.neverFlatten === "jsx" ? hasOnlyStringChildren : true);
632
714
  if (!shouldFlatten) {
633
715
  attrs = attrs.reduce((acc, cur) => {
716
+ var _a2, _b2;
634
717
  if (cur.type === "style") {
635
718
  for (const key in cur.value) {
636
- const shouldInsertNull = !!staticConfig.ensureOverriddenProp?.[key];
719
+ const shouldEnsureOverridden = !!((_a2 = staticConfig.ensureOverriddenProp) == null ? void 0 : _a2[key]);
637
720
  const isSetInAttrsAlready = attrs.some((x) => x.type === "attr" && x.value.type === "JSXAttribute" && x.value.name.name === key);
638
- const shouldInsertNullOverride = shouldInsertNull && !isSetInAttrsAlready;
639
- if (shouldInsertNullOverride) {
640
- acc.push({
641
- type: "attr",
642
- value: t.jsxAttribute(t.jsxIdentifier(key), t.jsxExpressionContainer(t.nullLiteral()))
643
- });
721
+ if (!isSetInAttrsAlready) {
722
+ const isVariant = !!((_b2 = staticConfig.variants) == null ? void 0 : _b2[cur.name || ""]);
723
+ if (isVariant || shouldEnsureOverridden) {
724
+ acc.push({
725
+ type: "attr",
726
+ value: cur.attr || t.jsxAttribute(t.jsxIdentifier(key), t.jsxExpressionContainer(t.nullLiteral()))
727
+ });
728
+ }
644
729
  }
645
730
  }
646
731
  }
@@ -649,16 +734,35 @@ function createExtractor() {
649
734
  }, []);
650
735
  }
651
736
  if (shouldPrintDebug) {
652
- console.log(" - attrs (flattened): ", attrs.map(attrStr).join(", "));
737
+ console.log(" - attrs (flattened): \n", logLines(attrs.map(attrStr).join(", ")));
653
738
  }
654
739
  attrs = attrs.reduce((acc, cur) => {
655
- if (cur.type !== "attr" || !t.isJSXAttribute(cur.value) || typeof cur.value.name.name !== "string") {
656
- if (cur.type === "style") {
657
- const key = Object.keys(cur.value)[0];
658
- if (!validStyles[key] && !pseudos[key]) {
740
+ if (cur.type === "style") {
741
+ let key = Object.keys(cur.value)[0];
742
+ let value = cur.value[key];
743
+ const nonShortKey = tamaguiConfig.shorthands[key];
744
+ if (nonShortKey) {
745
+ cur.value = { [nonShortKey]: value };
746
+ key = nonShortKey;
747
+ }
748
+ if (!shouldFlatten) {
749
+ if (stylePropsTransform[key] || !validStyles[key] && !pseudos[key] && !key.startsWith("data-")) {
750
+ acc.push({
751
+ type: "attr",
752
+ value: t.jsxAttribute(t.jsxIdentifier(key), t.jsxExpressionContainer(typeof value === "string" ? t.stringLiteral(value) : literalToAst(value)))
753
+ });
754
+ return acc;
755
+ }
756
+ }
757
+ if (disableExtractVariables) {
758
+ if (value[0] === "$") {
659
759
  if (shouldPrintDebug) {
660
- console.log(" \u274C excluding", key);
760
+ console.log(` keeping variable inline: ${key} =`, value);
661
761
  }
762
+ acc.push({
763
+ type: "attr",
764
+ value: t.jsxAttribute(t.jsxIdentifier(key), t.jsxExpressionContainer(t.stringLiteral(value)))
765
+ });
662
766
  return acc;
663
767
  }
664
768
  }
@@ -667,12 +771,12 @@ function createExtractor() {
667
771
  return acc;
668
772
  }, []);
669
773
  if (shouldPrintDebug) {
670
- console.log(" - attrs (evaluated styles): ", attrs.map(attrStr).join(", "));
774
+ console.log(" - attrs (evaluated): \n", logLines(attrs.map(attrStr).join(", ")));
671
775
  }
672
776
  let prev = null;
673
777
  attrs = attrs.reduce((acc, cur) => {
674
778
  if (cur.type === "style") {
675
- if (prev?.type === "style") {
779
+ if ((prev == null ? void 0 : prev.type) === "style") {
676
780
  Object.assign(prev.value, cur.value);
677
781
  return acc;
678
782
  }
@@ -682,9 +786,10 @@ function createExtractor() {
682
786
  return acc;
683
787
  }, []);
684
788
  if (shouldPrintDebug) {
685
- console.log(" - attrs (combined \u{1F500}): ", attrs.map(attrStr).join(", "));
789
+ console.log(" - attrs (combined \u{1F500}): \n", logLines(attrs.map(attrStr).join(", ")));
686
790
  }
687
791
  const getStyles = /* @__PURE__ */ __name((props2) => {
792
+ var _a2;
688
793
  if (!props2)
689
794
  return;
690
795
  if (!!excludeProps.size) {
@@ -693,15 +798,21 @@ function createExtractor() {
693
798
  delete props2[key];
694
799
  }
695
800
  }
801
+ if (shouldPrintDebug) {
802
+ props2["debug"] = true;
803
+ }
696
804
  const out = postProcessStyles(props2, staticConfig, defaultTheme);
697
- const next = out?.style ?? props2;
698
805
  if (shouldPrintDebug) {
699
- console.log(" >> getStyles: ", objToStr(props2), "==>>", objToStr(next));
700
- console.log(" >> style: ", objToStr(out.style));
701
- console.log(" >> viewp: ", objToStr(out.viewProps));
806
+ delete props2["debug"];
702
807
  }
703
- if (staticConfig.validStyles) {
704
- for (const key in next) {
808
+ const next = (_a2 = out == null ? void 0 : out.style) != null ? _a2 : props2;
809
+ if (shouldPrintDebug) {
810
+ console.log(" -- viewProps:\n", logLines(objToStr(out.viewProps)));
811
+ console.log(" -- props:\n", logLines(objToStr(props2)));
812
+ console.log(" -- next:\n", logLines(objToStr(next)));
813
+ }
814
+ for (const key in next) {
815
+ if (staticConfig.validStyles) {
705
816
  if (!staticConfig.validStyles[key] && !pseudos[key]) {
706
817
  delete next[key];
707
818
  }
@@ -709,9 +820,6 @@ function createExtractor() {
709
820
  }
710
821
  return next;
711
822
  }, "getStyles");
712
- if (shouldPrintDebug) {
713
- console.log(" staticConfig.defaultProps", staticConfig.defaultProps);
714
- }
715
823
  const completeStylesProcessed = getStyles({
716
824
  ...staticConfig.defaultProps,
717
825
  ...completeStaticProps
@@ -721,7 +829,6 @@ function createExtractor() {
721
829
  const toAdd = pick(completeStylesProcessed, ...stylesToAddToInitialGroup);
722
830
  const firstGroup = attrs.find((x) => x.type === "style");
723
831
  if (shouldPrintDebug) {
724
- console.log(" stylesToAddToInitialGroup", stylesToAddToInitialGroup.join(", "));
725
832
  console.log(" toAdd", objToStr(toAdd));
726
833
  }
727
834
  if (!firstGroup) {
@@ -731,9 +838,10 @@ function createExtractor() {
731
838
  }
732
839
  }
733
840
  if (shouldPrintDebug) {
734
- console.log(" completeStaticProps", objToStr(completeStaticProps));
735
- console.log(" completeStylesProcessed", objToStr(completeStylesProcessed));
841
+ console.log(" completeStaticProps:", completeStaticProps);
842
+ console.log(" completeStylesProcessed:", completeStylesProcessed);
736
843
  }
844
+ let getStyleError = null;
737
845
  for (const attr of attrs) {
738
846
  try {
739
847
  switch (attr.type) {
@@ -742,32 +850,35 @@ function createExtractor() {
742
850
  const c = getStyles(attr.value.consequent);
743
851
  attr.value.alternate = a;
744
852
  attr.value.consequent = c;
745
- if (shouldPrintDebug) {
853
+ if (shouldPrintDebug)
746
854
  console.log(" => tern ", attrStr(attr));
747
- }
748
- break;
855
+ continue;
749
856
  case "style":
750
- const next = {};
751
- for (const key in attr.value) {
752
- if (key in stylePropsTransform) {
753
- next["transform"] = completeStylesProcessed["transform"];
754
- } else {
755
- next[key] = completeStylesProcessed[key] ?? attr.value[key];
756
- }
857
+ for (const keyIn in attr.value) {
858
+ const [key, value] = (() => {
859
+ var _a2;
860
+ if (keyIn in stylePropsTransform) {
861
+ return ["transform", completeStylesProcessed["transform"]];
862
+ } else {
863
+ return [keyIn, (_a2 = completeStylesProcessed[keyIn]) != null ? _a2 : attr.value[keyIn]];
864
+ }
865
+ })();
866
+ delete attr.value[keyIn];
867
+ attr.value[key] = value;
757
868
  }
758
- attr.value = next;
759
- break;
869
+ continue;
760
870
  }
761
871
  } catch (err) {
762
- if (shouldPrintDebug) {
763
- console.log(" postprocessing error, deopt", err);
764
- node.attributes = ogAttributes;
765
- return node;
766
- }
872
+ getStyleError = err;
767
873
  }
768
874
  }
875
+ if (getStyleError) {
876
+ console.log(" \u26A0\uFE0F postprocessing error, deopt", getStyleError);
877
+ node.attributes = ogAttributes;
878
+ return node;
879
+ }
769
880
  if (shouldPrintDebug) {
770
- console.log(" - attrs (after): ", attrs.map(attrStr).join(", "));
881
+ console.log(" - attrs (after):\n", logLines(attrs.map(attrStr).join(", ")));
771
882
  }
772
883
  if (shouldFlatten) {
773
884
  if (shouldPrintDebug) {
@@ -782,7 +893,7 @@ function createExtractor() {
782
893
  }
783
894
  if (shouldPrintDebug) {
784
895
  console.log(" [\u274A] inline props ", inlinePropCount, shouldDeopt ? " deopted" : "", hasSpread ? " spread" : "", "!flatten", staticConfig.neverFlatten);
785
- console.log(" - attrs (end): ", attrs.map(attrStr).join(", "));
896
+ console.log(" - attrs (end):\n", logLines(attrs.map(attrStr).join(", ")));
786
897
  }
787
898
  res.optimized++;
788
899
  onExtractTag({
@@ -813,7 +924,6 @@ function createExtractor() {
813
924
  }
814
925
  __name(createExtractor, "createExtractor");
815
926
  export {
816
- FAILED_EVAL,
817
927
  createExtractor
818
928
  };
819
929
  //# sourceMappingURL=createExtractor.js.map