@tamagui/static 1.0.1-beta.68 → 1.0.1-beta.71

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 (89) hide show
  1. package/dist/cjs/extractor/createEvaluator.js +1 -1
  2. package/dist/cjs/extractor/createEvaluator.js.map +2 -2
  3. package/dist/cjs/extractor/createExtractor.js +227 -115
  4. package/dist/cjs/extractor/createExtractor.js.map +2 -2
  5. package/dist/cjs/extractor/extractToClassNames.js +17 -31
  6. package/dist/cjs/extractor/extractToClassNames.js.map +2 -2
  7. package/dist/cjs/index.js +1 -1
  8. package/dist/cjs/index.js.map +2 -2
  9. package/dist/cjs/types.js.map +1 -1
  10. package/dist/esm/extractor/createEvaluator.js +1 -1
  11. package/dist/esm/extractor/createEvaluator.js.map +2 -2
  12. package/dist/esm/extractor/createExtractor.js +232 -119
  13. package/dist/esm/extractor/createExtractor.js.map +2 -2
  14. package/dist/esm/extractor/extractToClassNames.js +17 -31
  15. package/dist/esm/extractor/extractToClassNames.js.map +2 -2
  16. package/dist/esm/index.js +1 -1
  17. package/dist/esm/index.js.map +1 -1
  18. package/dist/jsx/extractor/createEvaluator.js +1 -1
  19. package/dist/jsx/extractor/createExtractor.js +232 -119
  20. package/dist/jsx/extractor/extractToClassNames.js +17 -31
  21. package/dist/jsx/index.js +1 -1
  22. package/package.json +19 -13
  23. package/src/extractor/createEvaluator.ts +2 -1
  24. package/src/extractor/createExtractor.ts +356 -161
  25. package/src/extractor/extractToClassNames.ts +20 -50
  26. package/src/index.ts +1 -1
  27. package/src/types.ts +6 -8
  28. package/types/constants.d.ts +0 -0
  29. package/types/constants.d.ts.map +0 -0
  30. package/types/extractor/accessSafe.d.ts +0 -0
  31. package/types/extractor/accessSafe.d.ts.map +0 -0
  32. package/types/extractor/babelParse.d.ts +0 -0
  33. package/types/extractor/babelParse.d.ts.map +0 -0
  34. package/types/extractor/buildClassName.d.ts +0 -0
  35. package/types/extractor/buildClassName.d.ts.map +0 -0
  36. package/types/extractor/createEvaluator.d.ts +1 -1
  37. package/types/extractor/createEvaluator.d.ts.map +1 -1
  38. package/types/extractor/createExtractor.d.ts +2 -1
  39. package/types/extractor/createExtractor.d.ts.map +1 -1
  40. package/types/extractor/ensureImportingConcat.d.ts +0 -0
  41. package/types/extractor/ensureImportingConcat.d.ts.map +0 -0
  42. package/types/extractor/evaluateAstNode.d.ts +0 -0
  43. package/types/extractor/evaluateAstNode.d.ts.map +0 -0
  44. package/types/extractor/extractHelpers.d.ts +0 -0
  45. package/types/extractor/extractHelpers.d.ts.map +0 -0
  46. package/types/extractor/extractMediaStyle.d.ts +0 -0
  47. package/types/extractor/extractMediaStyle.d.ts.map +0 -0
  48. package/types/extractor/extractToClassNames.d.ts +1 -6
  49. package/types/extractor/extractToClassNames.d.ts.map +1 -1
  50. package/types/extractor/findTopmostFunction.d.ts +0 -0
  51. package/types/extractor/findTopmostFunction.d.ts.map +0 -0
  52. package/types/extractor/generatedUid.d.ts +0 -0
  53. package/types/extractor/generatedUid.d.ts.map +0 -0
  54. package/types/extractor/getPrefixLogs.d.ts +0 -0
  55. package/types/extractor/getPrefixLogs.d.ts.map +0 -0
  56. package/types/extractor/getPropValueFromAttributes.d.ts +0 -0
  57. package/types/extractor/getPropValueFromAttributes.d.ts.map +0 -0
  58. package/types/extractor/getSourceModule.d.ts +0 -0
  59. package/types/extractor/getSourceModule.d.ts.map +0 -0
  60. package/types/extractor/getStaticBindingsForScope.d.ts +0 -0
  61. package/types/extractor/getStaticBindingsForScope.d.ts.map +0 -0
  62. package/types/extractor/hoistClassNames.d.ts +0 -0
  63. package/types/extractor/hoistClassNames.d.ts.map +0 -0
  64. package/types/extractor/literalToAst.d.ts +0 -0
  65. package/types/extractor/literalToAst.d.ts.map +0 -0
  66. package/types/extractor/loadTamagui.d.ts +0 -0
  67. package/types/extractor/loadTamagui.d.ts.map +0 -0
  68. package/types/extractor/logLines.d.ts +0 -0
  69. package/types/extractor/logLines.d.ts.map +0 -0
  70. package/types/extractor/normalizeTernaries.d.ts +0 -0
  71. package/types/extractor/normalizeTernaries.d.ts.map +0 -0
  72. package/types/extractor/removeUnusedHooks.d.ts +0 -0
  73. package/types/extractor/removeUnusedHooks.d.ts.map +0 -0
  74. package/types/extractor/timer.d.ts +0 -0
  75. package/types/extractor/timer.d.ts.map +0 -0
  76. package/types/extractor/validHTMLAttributes.d.ts +0 -0
  77. package/types/extractor/validHTMLAttributes.d.ts.map +0 -0
  78. package/types/index.d.ts +1 -1
  79. package/types/index.d.ts.map +1 -1
  80. package/types/types.d.ts +4 -7
  81. package/types/types.d.ts.map +1 -1
  82. package/dist/cjs/patchReactNativeWeb.js +0 -167
  83. package/dist/cjs/patchReactNativeWeb.js.map +0 -7
  84. package/dist/esm/patchReactNativeWeb.js +0 -142
  85. package/dist/esm/patchReactNativeWeb.js.map +0 -7
  86. package/dist/jsx/patchReactNativeWeb.js +0 -141
  87. package/src/patchReactNativeWeb.ts +0 -165
  88. package/types/patchReactNativeWeb.d.ts +0 -2
  89. package/types/patchReactNativeWeb.d.ts.map +0 -1
@@ -16,7 +16,6 @@ import { isSimpleSpread } from "./extractHelpers";
16
16
  import { extractMediaStyle } from "./extractMediaStyle";
17
17
  import { getPrefixLogs } from "./getPrefixLogs";
18
18
  import { hoistClassNames } from "./hoistClassNames";
19
- import { literalToAst } from "./literalToAst";
20
19
  import { logLines } from "./logLines";
21
20
  import { timer } from "./timer";
22
21
  const mergeStyleGroups = {
@@ -26,15 +25,11 @@ const mergeStyleGroups = {
26
25
  shadowOffset: true
27
26
  };
28
27
  function extractToClassNames({
29
- loader,
30
28
  extractor,
31
29
  source,
32
30
  sourcePath,
33
31
  options,
34
- shouldPrintDebug,
35
- cssLoaderPath,
36
- threaded,
37
- cssPath
32
+ shouldPrintDebug
38
33
  }) {
39
34
  var _a;
40
35
  const tm = timer();
@@ -61,6 +56,10 @@ function extractToClassNames({
61
56
  shouldPrintDebug,
62
57
  ...options,
63
58
  target: "html",
59
+ extractStyledDefinitions: true,
60
+ onStyleRule(identifier, rules) {
61
+ cssMap.set(`.${identifier}`, { css: rules.join(";"), commentTexts: [] });
62
+ },
64
63
  getFlattenedNode: ({ tag }) => {
65
64
  hasFlattened = true;
66
65
  return tag;
@@ -77,6 +76,8 @@ function extractToClassNames({
77
76
  isFlattened
78
77
  }) => {
79
78
  var _a2, _b;
79
+ const didFlattenThisTag = hasFlattened;
80
+ hasFlattened = false;
80
81
  let finalClassNames = [];
81
82
  let finalAttrs = [];
82
83
  let finalStyles = [];
@@ -117,26 +118,13 @@ function extractToClassNames({
117
118
  switch (attr.type) {
118
119
  case "style":
119
120
  if (!isFlattened) {
120
- const { hoverStyle, pressStyle, focusStyle } = attr.value;
121
- const pseudos = [
122
- ["hoverStyle", hoverStyle],
123
- ["pressStyle", pressStyle],
124
- ["focusStyle", focusStyle]
125
- ];
126
121
  const styles2 = getStylesAtomic(attr.value, {
127
122
  splitTransforms: true
128
123
  });
129
124
  finalStyles = [...finalStyles, ...styles2];
130
- for (const [key, value] of pseudos) {
131
- if (value && Object.keys(value).length) {
132
- finalAttrs.push(t.jsxAttribute(t.jsxIdentifier(key), t.jsxExpressionContainer(literalToAst(value))));
133
- }
134
- }
135
125
  for (const style of styles2) {
136
- if (style.pseudo) {
137
- continue;
138
- }
139
- finalAttrs.push(t.jsxAttribute(t.jsxIdentifier(style.property), t.stringLiteral(style.identifier)));
126
+ const prop = style.pseudo ? `${style.property}-${style.pseudo}` : style.property;
127
+ finalAttrs.push(t.jsxAttribute(t.jsxIdentifier(prop), t.stringLiteral(style.identifier)));
140
128
  }
141
129
  } else {
142
130
  const styles2 = addStyles(attr.value);
@@ -217,7 +205,7 @@ function extractToClassNames({
217
205
  const nameExpr = names ? hoistClassNames(jsxPath, existingHoists, names) : null;
218
206
  let expr = nameExpr;
219
207
  if (nameExpr && !t.isIdentifier(nameExpr)) {
220
- if (!hasFlattened) {
208
+ if (!didFlattenThisTag) {
221
209
  } else {
222
210
  ensureImportingConcat(programPath);
223
211
  const simpleSpreads = attrs.filter((x) => t.isJSXSpreadAttribute(x.value) && isSimpleSpread(x.value));
@@ -230,7 +218,8 @@ function extractToClassNames({
230
218
  node.attributes.push(t.jsxAttribute(t.jsxIdentifier("className"), t.jsxExpressionContainer(expr)));
231
219
  }
232
220
  const comment = util.format("/* %s:%s (%s) */", filePath, lineNumbers, originalNodeName);
233
- for (const { className, rules } of finalStyles) {
221
+ for (const { identifier, rules } of finalStyles) {
222
+ const className = `.${identifier}`;
234
223
  if (cssMap.has(className)) {
235
224
  if (comment) {
236
225
  const val = cssMap.get(className);
@@ -250,19 +239,13 @@ function extractToClassNames({
250
239
  }
251
240
  }
252
241
  });
253
- if (!res || !res.modified && !res.optimized && !res.flattened) {
242
+ if (!res || !res.modified && !res.optimized && !res.flattened && !res.styled) {
254
243
  if (shouldPrintDebug) {
255
244
  console.log("no res or none modified", res);
256
245
  }
257
246
  return null;
258
247
  }
259
248
  const styles = Array.from(cssMap.values()).map((x) => x.css).join("\n").trim();
260
- if (styles) {
261
- const cssQuery = threaded ? `cssData=${Buffer.from(styles).toString("base64")}` : `cssPath=${cssPath}`;
262
- const remReq = loader.remainingRequest;
263
- const importPath = `${cssPath}!=!${cssLoaderPath}?${cssQuery}!${remReq}`;
264
- ast.program.body.unshift(t.importDeclaration([], t.stringLiteral(importPath)));
265
- }
266
249
  const result = generate(ast, {
267
250
  concise: false,
268
251
  filename: sourcePath,
@@ -277,6 +260,7 @@ function extractToClassNames({
277
260
  if (shouldLogTiming) {
278
261
  const memUsed = mem ? Math.round((process.memoryUsage().heapUsed - mem.heapUsed) / 1024 / 1204 * 10) / 10 : 0;
279
262
  const path2 = basename(sourcePath).replace(/\.[jt]sx?$/, "").slice(0, 22).trim().padStart(24);
263
+ const numStyled = `${res.styled}`.padStart(3);
280
264
  const numOptimized = `${res.optimized}`.padStart(3);
281
265
  const numFound = `${res.found}`.padStart(3);
282
266
  const numFlattened = `${res.flattened}`.padStart(3);
@@ -284,7 +268,9 @@ function extractToClassNames({
284
268
  const timing = Date.now() - start;
285
269
  const timingWarning = timing > 50 ? "\u26A0\uFE0F" : timing > 150 ? "\u2622\uFE0F" : "";
286
270
  const timingStr = `${timing}ms${timingWarning}`.padStart(6);
287
- console.log(`${getPrefixLogs(options)} ${path2} ${numFound} \xB7 ${numOptimized} \xB7 ${numFlattened} ${timingStr} ${memory ? `(${memory})` : ""}`);
271
+ const pre = getPrefixLogs(options);
272
+ const memStr = memory ? `(${memory})` : "";
273
+ console.log(`${pre} ${path2} ${numFound} \xB7 ${numOptimized} \xB7 ${numFlattened} \xB7 ${numStyled} ${timingStr} ${memStr}`);
288
274
  }
289
275
  return {
290
276
  ast,
package/dist/jsx/index.js CHANGED
@@ -5,7 +5,7 @@ import { literalToAst } from "./extractor/literalToAst";
5
5
  export * from "./constants";
6
6
  export * from "./extractor/extractToClassNames";
7
7
  export * from "./extractor/extractHelpers";
8
- export * from "./patchReactNativeWeb";
8
+ export * from "@tamagui/patch-rnw";
9
9
  export {
10
10
  TamaguiOptions,
11
11
  createExtractor,
package/package.json CHANGED
@@ -1,12 +1,13 @@
1
1
  {
2
2
  "name": "@tamagui/static",
3
- "version": "1.0.1-beta.68",
3
+ "version": "1.0.1-beta.71",
4
4
  "source": "src/index.ts",
5
5
  "types": "./types/index.d.ts",
6
6
  "main": "dist/cjs",
7
7
  "module": "dist/esm",
8
8
  "module:jsx": "dist/jsx",
9
9
  "files": [
10
+ "patches",
10
11
  "src",
11
12
  "types",
12
13
  "dist"
@@ -17,7 +18,8 @@
17
18
  "clean": "tamagui-build clean",
18
19
  "clean:build": "tamagui-build clean:build",
19
20
  "test": "NODE_ENV=test TAMAGUI_COMPILE_PROCESS=1 jest --forceExit",
20
- "test:babel": "yarn test tests/babel-test.tsx",
21
+ "test:output": "TAMAGUI_TARGET=web node -r esbuild-register test-output.tsx",
22
+ "test:babel": "DISABLE_PRE_TEST=true yarn test tests/babel-test.tsx",
21
23
  "test:debug": "NODE_ENV=test TAMAGUI_COMPILE_PROCESS=1 DEBUG_FILE=extract-specs.tsx DEBUG=1 yarn test",
22
24
  "test:watch": "NODE_ENV=test TAMAGUI_COMPILE_PROCESS=1 yarn test --watch",
23
25
  "test:update-snapshots": "NODE_ENV=test jest --updateSnapshot"
@@ -36,11 +38,11 @@
36
38
  "@babel/parser": "^7.15.7",
37
39
  "@babel/traverse": "^7.15.4",
38
40
  "@expo/match-media": "^0.3.0",
39
- "@tamagui/build": "^1.0.1-beta.68",
40
- "@tamagui/core-node": "^1.0.1-beta.68",
41
- "@tamagui/fake-react-native": "^1.0.1-beta.68",
42
- "@tamagui/helpers": "^1.0.1-beta.68",
43
- "@tamagui/proxy-worm": "^1.0.1-beta.68",
41
+ "@tamagui/build": "^1.0.1-beta.71",
42
+ "@tamagui/core-node": "^1.0.1-beta.71",
43
+ "@tamagui/fake-react-native": "^1.0.1-beta.71",
44
+ "@tamagui/helpers": "^1.0.1-beta.71",
45
+ "@tamagui/proxy-worm": "^1.0.1-beta.71",
44
46
  "babel-literal-to-ast": "^2.1.0",
45
47
  "esbuild": "^0.14.36",
46
48
  "esbuild-register": "^3.3.2",
@@ -48,13 +50,15 @@
48
50
  "fs-extra": "^9.1.0",
49
51
  "invariant": "^2.2.4",
50
52
  "lodash": "^4.17.21",
51
- "tamagui": "^1.0.1-beta.68"
53
+ "tamagui": "^1.0.1-beta.71"
52
54
  },
53
55
  "devDependencies": {
54
56
  "@babel/plugin-syntax-typescript": "^7.14.5",
55
57
  "@babel/types": "^7.15.6",
56
58
  "@dish/babel-preset": "^0.0.6",
57
- "@testing-library/react": "13.0.0-alpha.4",
59
+ "@tamagui/config-base": "^1.0.1-beta.71",
60
+ "@testing-library/jest-dom": "^5.16.4",
61
+ "@testing-library/react": "^13.3.0",
58
62
  "@types/jest": "*",
59
63
  "@types/node": "^16.11.9",
60
64
  "@types/react-native": "^0.67.3",
@@ -62,15 +66,17 @@
62
66
  "babel-loader": "^8.2.5",
63
67
  "css-loader": "^5.2.4",
64
68
  "esbuild-loader": "^2.18.0",
65
- "jest": "^27.3.1",
69
+ "jest": "^28.1.1",
70
+ "jest-dom": "^4.0.0",
71
+ "jest-environment-jsdom": "^28.1.1",
66
72
  "null-loader": "^4.0.1",
67
73
  "react": "*",
68
74
  "react-dom": "*",
69
75
  "react-native-web": "^0.17.5",
70
- "react-test-renderer": "^18.1.0",
71
- "style-loader": "^3.3.0",
76
+ "react-test-renderer": "^18.2.0",
77
+ "style-loader": "^3.3.1",
72
78
  "typescript": "^4.7.2",
73
- "webpack": "^5.72.0"
79
+ "webpack": "^5.73.0"
74
80
  },
75
81
  "peerDependencies": {
76
82
  "react-native-web": "*"
@@ -21,7 +21,7 @@ export function createEvaluator({
21
21
  tamaguiConfig: TamaguiConfig
22
22
  staticNamespace: Record<string, any>
23
23
  sourcePath: string
24
- traversePath: NodePath<t.JSXElement>
24
+ traversePath?: NodePath<t.JSXElement>
25
25
  shouldPrintDebug: boolean | 'verbose'
26
26
  }) {
27
27
  // called when evaluateAstNode encounters a dynamic-looking prop
@@ -30,6 +30,7 @@ export function createEvaluator({
30
30
  if (
31
31
  t.isMemberExpression(n) &&
32
32
  t.isIdentifier(n.property) &&
33
+ traversePath &&
33
34
  isValidThemeHook(traversePath, n, sourcePath)
34
35
  ) {
35
36
  const key = n.property.name