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

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 (209) 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 +952 -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 +124 -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 +291 -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 +62 -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 +151 -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 +6 -4
  68. package/dist/{extractor → esm/extractor}/extractHelpers.js.map +3 -3
  69. package/dist/{extractor → esm/extractor}/extractMediaStyle.js +3 -2
  70. package/dist/{extractor → esm/extractor}/extractMediaStyle.js.map +2 -2
  71. package/dist/{extractor → esm/extractor}/extractToClassNames.js +35 -22
  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/{extractor → esm/extractor}/literalToAst.js +0 -0
  86. package/dist/{extractor → esm/extractor}/literalToAst.js.map +1 -1
  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 +890 -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 +95 -0
  110. package/dist/jsx/extractor/extractMediaStyle.js +151 -0
  111. package/dist/jsx/extractor/extractToClassNames.js +247 -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 +33 -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 +3 -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/extractToClassNames.js.map +0 -7
  181. package/dist/extractor/loadTamagui.js.map +0 -7
  182. package/dist/index.cjs +0 -2107
  183. package/dist/index.cjs.map +0 -7
  184. package/dist/patchReactNativeWeb.js.map +0 -7
  185. package/src/constants.ts +0 -10
  186. package/src/extractor/accessSafe.ts +0 -18
  187. package/src/extractor/babelParse.ts +0 -27
  188. package/src/extractor/buildClassName.ts +0 -61
  189. package/src/extractor/createEvaluator.ts +0 -68
  190. package/src/extractor/createExtractor.ts +0 -1132
  191. package/src/extractor/ensureImportingConcat.ts +0 -33
  192. package/src/extractor/evaluateAstNode.ts +0 -121
  193. package/src/extractor/extractHelpers.ts +0 -102
  194. package/src/extractor/extractMediaStyle.ts +0 -191
  195. package/src/extractor/extractToClassNames.ts +0 -326
  196. package/src/extractor/findTopmostFunction.ts +0 -22
  197. package/src/extractor/generatedUid.ts +0 -43
  198. package/src/extractor/getPropValueFromAttributes.ts +0 -92
  199. package/src/extractor/getSourceModule.ts +0 -101
  200. package/src/extractor/getStaticBindingsForScope.ts +0 -173
  201. package/src/extractor/hoistClassNames.ts +0 -45
  202. package/src/extractor/literalToAst.ts +0 -32
  203. package/src/extractor/loadTamagui.ts +0 -61
  204. package/src/extractor/normalizeTernaries.ts +0 -60
  205. package/src/extractor/removeUnusedHooks.ts +0 -76
  206. package/src/index.ts +0 -9
  207. package/src/patchReactNativeWeb.ts +0 -123
  208. package/src/types.ts +0 -83
  209. package/types.d.ts +0 -215
@@ -0,0 +1,48 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
+ import generate from "@babel/generator";
4
+ import * as t from "@babel/types";
5
+ import { accessSafe } from "./accessSafe";
6
+ function getPropValueFromAttributes(propName, attrs) {
7
+ let propIndex = -1;
8
+ let jsxAttr = null;
9
+ for (let idx = -1, len = attrs.length; ++idx < len; ) {
10
+ const attr = attrs[idx];
11
+ if (t.isJSXAttribute(attr) && attr.name && attr.name.name === propName) {
12
+ propIndex = idx;
13
+ jsxAttr = attr;
14
+ break;
15
+ }
16
+ }
17
+ if (!jsxAttr || jsxAttr.value == null) {
18
+ return null;
19
+ }
20
+ let propValue = jsxAttr.value;
21
+ if (t.isJSXExpressionContainer(propValue)) {
22
+ propValue = propValue.expression;
23
+ }
24
+ if (t.isJSXEmptyExpression(propValue)) {
25
+ console.error("encountered JSXEmptyExpression");
26
+ return null;
27
+ }
28
+ const applicableSpreads = attrs.filter((attr, idx) => {
29
+ if (t.isJSXSpreadAttribute(attr)) {
30
+ if (t.isIdentifier(attr.argument) || t.isMemberExpression(attr.argument)) {
31
+ return idx > propIndex;
32
+ }
33
+ if (t.isLogicalExpression(attr.argument)) {
34
+ return false;
35
+ }
36
+ throw new Error(`unsupported spread of type "${attr.argument.type}": ${generate(attr).code}`);
37
+ }
38
+ return false;
39
+ }).map((attr) => attr.argument);
40
+ if (applicableSpreads.length > 0) {
41
+ propValue = applicableSpreads.reduce((acc, val) => t.logicalExpression("||", accessSafe(val, propName), acc), propValue);
42
+ }
43
+ return propValue;
44
+ }
45
+ __name(getPropValueFromAttributes, "getPropValueFromAttributes");
46
+ export {
47
+ getPropValueFromAttributes
48
+ };
@@ -0,0 +1,68 @@
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 getSourceModule(itemName, itemBinding) {
5
+ if (!itemBinding.constant) {
6
+ return null;
7
+ }
8
+ let sourceModule;
9
+ let imported;
10
+ let local;
11
+ let destructured;
12
+ let usesImportSyntax = false;
13
+ const itemNode = itemBinding.path.node;
14
+ if (t.isImportDefaultSpecifier(itemNode) || t.isImportSpecifier(itemNode)) {
15
+ if (t.isImportDeclaration(itemBinding.path.parent)) {
16
+ sourceModule = itemBinding.path.parent.source.value;
17
+ local = itemNode.local.name;
18
+ usesImportSyntax = true;
19
+ if (t.isImportSpecifier(itemNode)) {
20
+ imported = itemNode.imported["name"];
21
+ destructured = true;
22
+ } else {
23
+ imported = itemNode.local.name;
24
+ destructured = false;
25
+ }
26
+ }
27
+ } else if (t.isVariableDeclarator(itemNode) && itemNode.init != null && t.isCallExpression(itemNode.init) && t.isIdentifier(itemNode.init.callee) && itemNode.init.callee.name === "require" && itemNode.init.arguments.length === 1) {
28
+ const firstArg = itemNode.init.arguments[0];
29
+ if (!t.isStringLiteral(firstArg)) {
30
+ return null;
31
+ }
32
+ sourceModule = firstArg.value;
33
+ if (t.isIdentifier(itemNode.id)) {
34
+ local = itemNode.id.name;
35
+ imported = itemNode.id.name;
36
+ destructured = false;
37
+ } else if (t.isObjectPattern(itemNode.id)) {
38
+ for (const objProp of itemNode.id.properties) {
39
+ if (t.isObjectProperty(objProp) && t.isIdentifier(objProp.value) && objProp.value.name === itemName) {
40
+ local = objProp.value.name;
41
+ imported = objProp.key.name;
42
+ destructured = true;
43
+ break;
44
+ }
45
+ }
46
+ if (!local || !imported) {
47
+ console.error("could not find prop with value `%s`", itemName);
48
+ return null;
49
+ }
50
+ } else {
51
+ console.error("Unhandled id type: %s", itemNode.id.type);
52
+ return null;
53
+ }
54
+ } else {
55
+ return null;
56
+ }
57
+ return {
58
+ destructured,
59
+ imported,
60
+ local,
61
+ sourceModule,
62
+ usesImportSyntax
63
+ };
64
+ }
65
+ __name(getSourceModule, "getSourceModule");
66
+ export {
67
+ getSourceModule
68
+ };
@@ -0,0 +1,127 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
+ import { dirname, extname, resolve } from "path";
4
+ import * as t from "@babel/types";
5
+ import { existsSync } from "fs-extra";
6
+ import { evaluateAstNode } from "./evaluateAstNode";
7
+ import { getSourceModule } from "./getSourceModule";
8
+ const isLocalImport = /* @__PURE__ */ __name((path) => path.startsWith(".") || path.startsWith("/"), "isLocalImport");
9
+ function resolveImportPath(sourcePath, path) {
10
+ const sourceDir = dirname(sourcePath);
11
+ if (isLocalImport(path)) {
12
+ if (extname(path) === "") {
13
+ path += ".js";
14
+ }
15
+ return resolve(sourceDir, path);
16
+ }
17
+ return path;
18
+ }
19
+ __name(resolveImportPath, "resolveImportPath");
20
+ function importModule(path) {
21
+ const filenames = [path.replace(".js", ".tsx"), path.replace(".js", ".ts"), path];
22
+ for (const file of filenames) {
23
+ if (existsSync(file)) {
24
+ return require(file);
25
+ }
26
+ }
27
+ return null;
28
+ }
29
+ __name(importModule, "importModule");
30
+ function getStaticBindingsForScope(scope, whitelist = [], sourcePath, bindingCache, shouldPrintDebug) {
31
+ const bindings = scope.getAllBindings();
32
+ const ret = {};
33
+ if (shouldPrintDebug) {
34
+ console.log(" ", Object.keys(bindings).length, "variables in scope");
35
+ }
36
+ const program = scope.getProgramParent().block;
37
+ for (const node of program.body) {
38
+ if (t.isImportDeclaration(node)) {
39
+ const importPath = node.source.value;
40
+ if (!node.specifiers.length)
41
+ continue;
42
+ if (!isLocalImport(importPath)) {
43
+ continue;
44
+ }
45
+ const moduleName = resolveImportPath(sourcePath, importPath);
46
+ const isOnWhitelist = whitelist.some((test) => moduleName.endsWith(test));
47
+ if (!isOnWhitelist)
48
+ continue;
49
+ const src = importModule(moduleName);
50
+ if (!src)
51
+ continue;
52
+ for (const specifier of node.specifiers) {
53
+ if (t.isImportSpecifier(specifier) && t.isIdentifier(specifier.imported)) {
54
+ if (typeof src[specifier.imported.name] !== "undefined") {
55
+ const val = src[specifier.local.name];
56
+ ret[specifier.local.name] = val;
57
+ }
58
+ }
59
+ }
60
+ }
61
+ }
62
+ if (!bindingCache) {
63
+ throw new Error("bindingCache is a required param");
64
+ }
65
+ for (const k in bindings) {
66
+ const binding = bindings[k];
67
+ const sourceModule = getSourceModule(k, binding);
68
+ if (sourceModule) {
69
+ if (!sourceModule.sourceModule) {
70
+ continue;
71
+ }
72
+ const moduleName = resolveImportPath(sourcePath, sourceModule.sourceModule);
73
+ const isOnWhitelist = whitelist.some((test) => moduleName.endsWith(test));
74
+ if (isOnWhitelist) {
75
+ const src = importModule(moduleName);
76
+ if (!src) {
77
+ console.log(`\u26A0\uFE0F missing file ${moduleName} via ${sourcePath} import ${sourceModule.sourceModule}?`);
78
+ return {};
79
+ }
80
+ if (sourceModule.destructured) {
81
+ if (sourceModule.imported) {
82
+ ret[k] = src[sourceModule.imported];
83
+ }
84
+ } else {
85
+ ret[k] = src;
86
+ }
87
+ }
88
+ continue;
89
+ }
90
+ const { parent, parentPath } = binding.path;
91
+ if (!t.isVariableDeclaration(parent) || parent.kind !== "const") {
92
+ continue;
93
+ }
94
+ const dec = parent.declarations.find((d) => t.isIdentifier(d.id) && d.id.name === k);
95
+ if (!dec || !dec.init) {
96
+ continue;
97
+ }
98
+ if (typeof dec.id.start !== "number" || typeof dec.id.end !== "number") {
99
+ console.error("dec.id.start/end is not a number");
100
+ continue;
101
+ }
102
+ if (!t.isIdentifier(dec.id)) {
103
+ console.error("dec is not an identifier");
104
+ continue;
105
+ }
106
+ const cacheKey = `${dec.id.name}_${dec.id.start}-${dec.id.end}`;
107
+ if (bindingCache.hasOwnProperty(cacheKey)) {
108
+ ret[k] = bindingCache[cacheKey];
109
+ continue;
110
+ }
111
+ if (bindingCache.hasOwnProperty(cacheKey)) {
112
+ ret[k] = bindingCache[cacheKey];
113
+ continue;
114
+ }
115
+ try {
116
+ ret[k] = evaluateAstNode(dec.init, void 0, shouldPrintDebug);
117
+ bindingCache[cacheKey] = ret[k];
118
+ continue;
119
+ } catch (e) {
120
+ }
121
+ }
122
+ return ret;
123
+ }
124
+ __name(getStaticBindingsForScope, "getStaticBindingsForScope");
125
+ export {
126
+ getStaticBindingsForScope
127
+ };
@@ -0,0 +1,43 @@
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 hoistClassNames(path, existing, expr) {
5
+ const hoist = hoistClassNames.bind(null, path, existing);
6
+ if (t.isStringLiteral(expr)) {
7
+ if (expr.value.trim() === "") {
8
+ return expr;
9
+ }
10
+ if (existing[expr.value]) {
11
+ return existing[expr.value];
12
+ }
13
+ const identifier = replaceStringWithVariable(expr);
14
+ existing[expr.value] = identifier;
15
+ return identifier;
16
+ }
17
+ if (t.isBinaryExpression(expr)) {
18
+ return t.binaryExpression(expr.operator, hoist(expr.left), hoist(expr.right));
19
+ }
20
+ if (t.isLogicalExpression(expr)) {
21
+ return t.logicalExpression(expr.operator, hoist(expr.left), hoist(expr.right));
22
+ }
23
+ if (t.isConditionalExpression(expr)) {
24
+ return t.conditionalExpression(expr.test, hoist(expr.consequent), hoist(expr.alternate));
25
+ }
26
+ return expr;
27
+ function replaceStringWithVariable(str) {
28
+ const uid = path.scope.generateUidIdentifier("cn");
29
+ const parent = path.findParent((path2) => path2.isProgram());
30
+ if (!parent)
31
+ throw new Error(`no program?`);
32
+ const variable = t.variableDeclaration("const", [
33
+ t.variableDeclarator(uid, t.stringLiteral(` ${str.value}`))
34
+ ]);
35
+ parent.unshiftContainer("body", variable);
36
+ return uid;
37
+ }
38
+ __name(replaceStringWithVariable, "replaceStringWithVariable");
39
+ }
40
+ __name(hoistClassNames, "hoistClassNames");
41
+ export {
42
+ hoistClassNames
43
+ };
@@ -0,0 +1,33 @@
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
+ export {
32
+ literalToAst
33
+ };
@@ -0,0 +1,46 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
+ import { join } from "path";
4
+ import { createTamagui } from "@tamagui/core-node";
5
+ let loadedTamagui = null;
6
+ function loadTamagui(props) {
7
+ if (loadedTamagui) {
8
+ return loadedTamagui;
9
+ }
10
+ process.env.IS_STATIC = "is_static";
11
+ const rnw = require("react-native-web");
12
+ const Mod = require("module");
13
+ const og = Mod.prototype.require;
14
+ Mod.prototype.require = function(path) {
15
+ if (path.endsWith(".css")) {
16
+ return {};
17
+ }
18
+ if (path === "@gorhom/bottom-sheet") {
19
+ return {};
20
+ }
21
+ if (path.startsWith("react-native") && !path.startsWith("react-native-web/dist/cjs/exports")) {
22
+ return rnw;
23
+ }
24
+ return og.apply(this, arguments);
25
+ };
26
+ const configPath = join(process.cwd(), props.config);
27
+ const tamaguiConfigExport = require(configPath);
28
+ const tamaguiConfig = tamaguiConfigExport["default"] || tamaguiConfigExport;
29
+ const components = {};
30
+ for (const module of props.components) {
31
+ const exported = require(module);
32
+ Object.assign(components, exported);
33
+ }
34
+ process.env.IS_STATIC = void 0;
35
+ Mod.prototype.require = og;
36
+ createTamagui(tamaguiConfig);
37
+ loadedTamagui = {
38
+ components,
39
+ tamaguiConfig
40
+ };
41
+ return loadedTamagui;
42
+ }
43
+ __name(loadTamagui, "loadTamagui");
44
+ export {
45
+ loadTamagui
46
+ };
@@ -0,0 +1,16 @@
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
+ };
@@ -0,0 +1,52 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
+ import generate from "@babel/generator";
4
+ import * as t from "@babel/types";
5
+ import invariant from "invariant";
6
+ function normalizeTernaries(ternaries) {
7
+ var _a, _b;
8
+ invariant(Array.isArray(ternaries), "extractStaticTernaries expects param 1 to be an array of ternaries");
9
+ if (ternaries.length === 0) {
10
+ return [];
11
+ }
12
+ const ternariesByKey = {};
13
+ for (let idx = -1, len = ternaries.length; ++idx < len; ) {
14
+ const { test, consequent, alternate, remove, ...rest } = ternaries[idx];
15
+ let ternaryTest = test;
16
+ if (t.isExpressionStatement(test)) {
17
+ ternaryTest = test.expression;
18
+ }
19
+ let shouldSwap = false;
20
+ if (t.isUnaryExpression(test) && test.operator === "!") {
21
+ ternaryTest = test.argument;
22
+ shouldSwap = true;
23
+ } else if (t.isBinaryExpression(test)) {
24
+ if (test.operator === "!==" || test.operator === "!=") {
25
+ ternaryTest = t.binaryExpression(test.operator, test.left, test.right);
26
+ shouldSwap = true;
27
+ }
28
+ }
29
+ const key = generate(ternaryTest).code;
30
+ if (!ternariesByKey[key]) {
31
+ ternariesByKey[key] = {
32
+ ...rest,
33
+ alternate: {},
34
+ consequent: {},
35
+ test: ternaryTest,
36
+ remove
37
+ };
38
+ }
39
+ const altStyle = (_a = shouldSwap ? consequent : alternate) != null ? _a : {};
40
+ const consStyle = (_b = shouldSwap ? alternate : consequent) != null ? _b : {};
41
+ Object.assign(ternariesByKey[key].alternate, altStyle);
42
+ Object.assign(ternariesByKey[key].consequent, consStyle);
43
+ }
44
+ const ternaryExpression = Object.keys(ternariesByKey).map((key) => {
45
+ return ternariesByKey[key];
46
+ });
47
+ return ternaryExpression;
48
+ }
49
+ __name(normalizeTernaries, "normalizeTernaries");
50
+ export {
51
+ normalizeTernaries
52
+ };
@@ -0,0 +1,79 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
+ import * as t from "@babel/types";
4
+ const hooks = {
5
+ useMedia: true,
6
+ useTheme: true
7
+ };
8
+ function removeUnusedHooks(compFn, shouldPrintDebug) {
9
+ var _a;
10
+ compFn.scope.crawl();
11
+ let bodyStatements = compFn == null ? void 0 : compFn.get("body");
12
+ if (!bodyStatements) {
13
+ console.log("no body statemnts?", compFn);
14
+ return;
15
+ }
16
+ if (!Array.isArray(bodyStatements)) {
17
+ if (bodyStatements.isFunctionExpression()) {
18
+ bodyStatements = bodyStatements.scope.path.get("body");
19
+ } else {
20
+ bodyStatements = bodyStatements.get("body");
21
+ }
22
+ }
23
+ if (!bodyStatements || !Array.isArray(bodyStatements)) {
24
+ return;
25
+ }
26
+ const statements = bodyStatements;
27
+ for (const statement of statements) {
28
+ if (!statement.isVariableDeclaration()) {
29
+ continue;
30
+ }
31
+ const declarations = statement.get("declarations");
32
+ if (!Array.isArray(declarations)) {
33
+ continue;
34
+ }
35
+ const isBindingReferenced = /* @__PURE__ */ __name((name) => {
36
+ var _a2;
37
+ return !!((_a2 = statement.scope.getBinding(name)) == null ? void 0 : _a2.referenced);
38
+ }, "isBindingReferenced");
39
+ for (const declarator of declarations) {
40
+ const id = declarator.get("id");
41
+ const init = declarator.node.init;
42
+ if (Array.isArray(id) || Array.isArray(init)) {
43
+ continue;
44
+ }
45
+ const shouldRemove = (() => {
46
+ const isHook = t.isCallExpression(init) && t.isIdentifier(init.callee) && hooks[init.callee.name];
47
+ if (!isHook) {
48
+ return false;
49
+ }
50
+ if (t.isIdentifier(id.node)) {
51
+ const name = id.node.name;
52
+ return !isBindingReferenced(name);
53
+ } else if (t.isObjectPattern(id.node)) {
54
+ const propPaths = id.get("properties");
55
+ return propPaths.every((prop) => {
56
+ if (!prop.isObjectProperty())
57
+ return false;
58
+ const value = prop.get("value");
59
+ if (Array.isArray(value) || !value.isIdentifier())
60
+ return false;
61
+ const name = value.node.name;
62
+ return !isBindingReferenced(name);
63
+ });
64
+ }
65
+ return false;
66
+ })();
67
+ if (shouldRemove) {
68
+ declarator.remove();
69
+ if (shouldPrintDebug) {
70
+ console.log(` [\u{1FA9D}] removed ${(_a = id.node["name"]) != null ? _a : ""}`);
71
+ }
72
+ }
73
+ }
74
+ }
75
+ }
76
+ __name(removeUnusedHooks, "removeUnusedHooks");
77
+ export {
78
+ removeUnusedHooks
79
+ };
@@ -0,0 +1,13 @@
1
+ process.env.TAMAGUI_COMPILE_PROCESS = "1";
2
+ import { TamaguiOptions } from "./types";
3
+ import { createExtractor } from "./extractor/createExtractor";
4
+ import { literalToAst } from "./extractor/literalToAst";
5
+ export * from "./constants";
6
+ export * from "./extractor/extractToClassNames";
7
+ export * from "./extractor/extractHelpers";
8
+ export * from "./patchReactNativeWeb";
9
+ export {
10
+ TamaguiOptions,
11
+ createExtractor,
12
+ literalToAst
13
+ };
@@ -0,0 +1,128 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
+ import * as fs from "fs";
4
+ import path from "path";
5
+ function patchReactNativeWeb() {
6
+ const rootDir = require.resolve("react-native-web").replace(/\/dist.*/, "");
7
+ const modulePath = path.join(rootDir, "dist", "tamagui-exports.js");
8
+ const cjsPath = path.join(rootDir, "dist", "cjs", "tamagui-exports.js");
9
+ const isEqual = (() => {
10
+ let res = false;
11
+ try {
12
+ res = fs.readFileSync(modulePath, "utf-8") === moduleExports && fs.readFileSync(cjsPath, "utf-8") == cjsExports;
13
+ } catch {
14
+ res = false;
15
+ }
16
+ return res;
17
+ })();
18
+ if (!isEqual) {
19
+ console.log("\u{1F95A} Tamagui patching react-native-web to share atomic styling primitives");
20
+ console.log(" > adding", modulePath);
21
+ console.log(" > adding", cjsPath);
22
+ fs.writeFileSync(modulePath, moduleExports);
23
+ fs.writeFileSync(cjsPath, cjsExports);
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);
47
+ const moduleEntry = path.join(rootDir, "dist", "index.js");
48
+ const moduleEntrySrc = fs.readFileSync(moduleEntry, "utf-8");
49
+ if (!moduleEntrySrc.includes("// tamagui-patch-v4")) {
50
+ fs.writeFileSync(moduleEntry, `${removePatch(moduleEntrySrc)}
51
+
52
+ // tamagui-patch-v4
53
+ import * as TExports from './tamagui-exports'
54
+ export const TamaguiExports = TExports
55
+ // tamagui-patch-end
56
+ `);
57
+ }
58
+ const cjsEntry = path.join(rootDir, "dist", "cjs", "index.js");
59
+ const cjsEntrySrc = fs.readFileSync(cjsEntry, "utf-8");
60
+ if (!cjsEntrySrc.includes("// tamagui-patch-v4")) {
61
+ fs.writeFileSync(cjsEntry, `${removePatch(cjsEntrySrc)}
62
+
63
+ // tamagui-patch-v4
64
+ exports.TamaguiExports = _interopRequireDefault(require("./tamagui-exports"));
65
+ // tamagui-patch-end
66
+ `);
67
+ }
68
+ }
69
+ __name(patchReactNativeWeb, "patchReactNativeWeb");
70
+ function removePatch(source) {
71
+ return source.replace(/\/\/ tamagui-patch([.\s\S]*)/g, "");
72
+ }
73
+ __name(removePatch, "removePatch");
74
+ const forwardedPropsObj = `{
75
+ ...fwdProps.defaultProps,
76
+ ...fwdProps.accessibilityProps,
77
+ ...fwdProps.clickProps,
78
+ ...fwdProps.focusProps,
79
+ ...fwdProps.keyboardProps,
80
+ ...fwdProps.mouseProps,
81
+ ...fwdProps.touchProps,
82
+ ...fwdProps.styleProps,
83
+ href: true,
84
+ lang: true,
85
+ onScroll: true,
86
+ onWheel: true,
87
+ pointerEvents: true
88
+ }
89
+ `;
90
+ const moduleExports = `
91
+ export { atomic } from './exports/StyleSheet/compile'
92
+ export { default as createCompileableStyle } from './exports/StyleSheet/createCompileableStyle'
93
+ export { default as createReactDOMStyle } from './exports/StyleSheet/createReactDOMStyle'
94
+ export { default as i18Style } from './exports/StyleSheet/i18nStyle'
95
+ export { default as createDOMProps } from './modules/createDOMProps'
96
+ export { default as AccessibilityUtil } from './modules/AccessibilityUtil'
97
+ export { default as createElement } from './exports/createElement'
98
+ export { default as css } from './exports/StyleSheet/css'
99
+ export { default as TextAncestorContext } from './exports/Text/TextAncestorContext'
100
+ export { default as pick } from './modules/pick'
101
+ export { default as useElementLayout } from './modules/useElementLayout'
102
+ export { default as useMergeRefs } from './modules/useMergeRefs'
103
+ export { default as usePlatformMethods } from './modules/usePlatformMethods'
104
+ export { default as useResponderEvents } from './modules/useResponderEvents'
105
+ import * as fwdProps from './modules/forwardedProps'
106
+ export const forwardedProps = ${forwardedPropsObj}
107
+ `;
108
+ const cjsExports = `
109
+ exports.atomic = require('./exports/StyleSheet/compile').atomic
110
+ exports.createCompileableStyle = require('./exports/StyleSheet/createCompileableStyle')
111
+ exports.createReactDOMStyle = require('./exports/StyleSheet/createReactDOMStyle')
112
+ exports.i18Style = require('./exports/StyleSheet/i18nStyle')
113
+ exports.createDOMProps = require('./modules/createDOMProps')
114
+ exports.AccessibilityUtil = require('./modules/AccessibilityUtil')
115
+ exports.createElement = require('./exports/createElement')
116
+ exports.css = require('./exports/StyleSheet/css')
117
+ exports.TextAncestorContext = require('./exports/Text/TextAncestorContext')
118
+ exports.pick = require('./modules/pick')
119
+ exports.useElementLayout = require('./modules/useElementLayout')
120
+ exports.useMergeRefs = require('./modules/useMergeRefs')
121
+ exports.usePlatformMethods = require('./modules/usePlatformMethods')
122
+ exports.useResponderEvents = require('./modules/useResponderEvents')
123
+ const fwdProps = require('./modules/forwardedProps')
124
+ exports.forwardedProps = ${forwardedPropsObj}
125
+ `;
126
+ export {
127
+ patchReactNativeWeb
128
+ };
File without changes