@tamagui/static 2.0.0-rc.31 → 2.0.0-rc.32

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.
@@ -156,7 +156,7 @@ function getBabelParseDefinition(options) {
156
156
  expressions = [],
157
157
  finalAttrs = [],
158
158
  themeKeysUsed = /* @__PURE__ */new Set();
159
- function getStyleExpression(style) {
159
+ function getStyleExpression(style, forTernary = !1) {
160
160
  if (!style) return;
161
161
  const {
162
162
  plain,
@@ -167,8 +167,8 @@ function getBabelParseDefinition(options) {
167
167
  for (const key in themed) themeKeysUsed.add(themed[key].split("$")[1]);
168
168
  themeExpr = getThemedStyleExpression(themed);
169
169
  }
170
- const ident = addSheetStyle(plain, props.node);
171
- return themeExpr ? (addStyleExpression(ident), addStyleExpression(ident, !0), themeExpr) : ident;
170
+ const ident = Object.keys(plain).length > 0 ? addSheetStyle(plain, props.node) : null;
171
+ return themeExpr ? forTernary ? ident ? t.arrayExpression([ident, themeExpr]) : themeExpr : (ident && (addStyleExpression(ident), addStyleExpression(ident, !0)), themeExpr) : ident;
172
172
  }
173
173
  function addStyleExpression(expr, HOC = !1) {
174
174
  Array.isArray(expr) ? (HOC ? hocStylesExpr : stylesExpr).elements.push(...expr) : (HOC ? hocStylesExpr : stylesExpr).elements.push(expr);
@@ -184,7 +184,8 @@ function getBabelParseDefinition(options) {
184
184
  }
185
185
  }), themedStylesAst;
186
186
  }
187
- let hasDynamicStyle = !1;
187
+ let hasDynamicStyle = !1,
188
+ hasMediaKeys = !1;
188
189
  for (const attr of props.attrs) switch (attr.type) {
189
190
  case "style":
190
191
  {
@@ -198,9 +199,9 @@ function getBabelParseDefinition(options) {
198
199
  consequent,
199
200
  alternate
200
201
  } = attr.value,
201
- consExpr = getStyleExpression(consequent),
202
- altExpr = getStyleExpression(alternate);
203
- expressions.push(attr.value.test), addStyleExpression(t.conditionalExpression(t.identifier(`_expressions[${expressions.length - 1}]`), consExpr || t.nullLiteral(), altExpr || t.nullLiteral()), !0);
202
+ consExpr = getStyleExpression(consequent, !0),
203
+ altExpr = getStyleExpression(alternate, !0);
204
+ attr.value.inlineMediaQuery && (hasMediaKeys = !0), expressions.push(attr.value.test), addStyleExpression(t.conditionalExpression(t.identifier(`_expressions[${expressions.length - 1}]`), consExpr || t.nullLiteral(), altExpr || t.nullLiteral()), !0);
204
205
  const styleExpr = t.conditionalExpression(attr.value.test, consExpr || t.nullLiteral(), altExpr || t.nullLiteral());
205
206
  addStyleExpression(styleExpr);
206
207
  break;
@@ -216,10 +217,11 @@ function getBabelParseDefinition(options) {
216
217
  const name = props.flatNodeName || props.node.name.name,
217
218
  wrapperName = `_${name.replace(/^_+/, "")}Styled${wrapperCount++}`,
218
219
  WrapperIdentifier = t.identifier(wrapperName),
219
- WrapperJSXIdentifier = t.jsxIdentifier(wrapperName);
220
+ WrapperJSXIdentifier = t.jsxIdentifier(wrapperName),
221
+ hasThemeKeysFlag = themeKeysUsed.size > 0;
220
222
  root.pushContainer("body", t.variableDeclaration("const", [t.variableDeclarator(WrapperIdentifier, t.callExpression(t.identifier("_withStableStyle"), [t.identifier(name), t.arrowFunctionExpression([t.identifier("theme"), t.identifier("_expressions")],
221
223
  // return styles directly - no useMemo, theme changes must trigger style recalc
222
- t.arrayExpression([...hocStylesExpr.elements]))]))])), props.node.name = WrapperJSXIdentifier, props.jsxPath.node.openingElement.name = WrapperJSXIdentifier, props.jsxPath.node.closingElement && (props.jsxPath.node.closingElement.name = t.jsxIdentifier(wrapperName)), expressions.length && props.node.attributes.push(t.jsxAttribute(t.jsxIdentifier("_expressions"), t.jsxExpressionContainer(t.arrayExpression(expressions))));
224
+ t.arrayExpression([...hocStylesExpr.elements])), t.booleanLiteral(hasThemeKeysFlag), t.booleanLiteral(hasMediaKeys)]))])), props.node.name = WrapperJSXIdentifier, props.jsxPath.node.openingElement.name = WrapperJSXIdentifier, props.jsxPath.node.closingElement && (props.jsxPath.node.closingElement.name = t.jsxIdentifier(wrapperName)), expressions.length && props.node.attributes.push(t.jsxAttribute(t.jsxIdentifier("_expressions"), t.jsxExpressionContainer(t.arrayExpression(expressions))));
223
225
  } else props.node.attributes.push(t.jsxAttribute(t.jsxIdentifier("style"), t.jsxExpressionContainer(stylesExpr.elements.length === 1 ? stylesExpr.elements[0] : stylesExpr)));
224
226
  }
225
227
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tamagui/static",
3
- "version": "2.0.0-rc.31",
3
+ "version": "2.0.0-rc.32",
4
4
  "gitHead": "a49cc7ea6b93ba384e77a4880ae48ac4a5635c14",
5
5
  "license": "MIT",
6
6
  "source": "src/index.ts",
@@ -50,19 +50,19 @@
50
50
  "@babel/template": "^7.25.0",
51
51
  "@babel/traverse": "^7.25.4",
52
52
  "@babel/types": "^7.25.4",
53
- "@tamagui/cli-color": "2.0.0-rc.31",
54
- "@tamagui/config-default": "2.0.0-rc.31",
55
- "@tamagui/core": "2.0.0-rc.31",
56
- "@tamagui/fake-react-native": "2.0.0-rc.31",
57
- "@tamagui/generate-themes": "2.0.0-rc.31",
58
- "@tamagui/helpers": "2.0.0-rc.31",
59
- "@tamagui/helpers-node": "2.0.0-rc.31",
60
- "@tamagui/proxy-worm": "2.0.0-rc.31",
61
- "@tamagui/react-native-web-internals": "2.0.0-rc.31",
62
- "@tamagui/react-native-web-lite": "2.0.0-rc.31",
63
- "@tamagui/shorthands": "2.0.0-rc.31",
64
- "@tamagui/types": "2.0.0-rc.31",
65
- "@tamagui/web": "2.0.0-rc.31",
53
+ "@tamagui/cli-color": "2.0.0-rc.32",
54
+ "@tamagui/config-default": "2.0.0-rc.32",
55
+ "@tamagui/core": "2.0.0-rc.32",
56
+ "@tamagui/fake-react-native": "2.0.0-rc.32",
57
+ "@tamagui/generate-themes": "2.0.0-rc.32",
58
+ "@tamagui/helpers": "2.0.0-rc.32",
59
+ "@tamagui/helpers-node": "2.0.0-rc.32",
60
+ "@tamagui/proxy-worm": "2.0.0-rc.32",
61
+ "@tamagui/react-native-web-internals": "2.0.0-rc.32",
62
+ "@tamagui/react-native-web-lite": "2.0.0-rc.32",
63
+ "@tamagui/shorthands": "2.0.0-rc.32",
64
+ "@tamagui/types": "2.0.0-rc.32",
65
+ "@tamagui/web": "2.0.0-rc.32",
66
66
  "babel-literal-to-ast": "^2.1.0",
67
67
  "browserslist": "^4.28.1",
68
68
  "check-dependency-version-consistency": "^4.1.0",
@@ -79,7 +79,7 @@
79
79
  },
80
80
  "devDependencies": {
81
81
  "@babel/plugin-syntax-typescript": "^7.25.4",
82
- "@tamagui/build": "2.0.0-rc.31",
82
+ "@tamagui/build": "2.0.0-rc.32",
83
83
  "@types/babel__core": "^7.20.5",
84
84
  "@types/find-root": "^1.1.2",
85
85
  "@types/node": "^22.1.0",
@@ -210,7 +210,7 @@ export function getBabelParseDefinition(options: TamaguiOptions) {
210
210
  const finalAttrs: (t.JSXAttribute | t.JSXSpreadAttribute)[] = []
211
211
  const themeKeysUsed = new Set<string>()
212
212
 
213
- function getStyleExpression(style: object | null) {
213
+ function getStyleExpression(style: object | null, forTernary = false) {
214
214
  if (!style) return
215
215
 
216
216
  // split theme properties and leave them as props since RN has no concept of theme
@@ -226,13 +226,24 @@ export function getBabelParseDefinition(options: TamaguiOptions) {
226
226
  // make a sub-array
227
227
  themeExpr = getThemedStyleExpression(themed)
228
228
  }
229
- const ident = addSheetStyle(plain, props.node)
229
+ const hasPlainKeys = Object.keys(plain).length > 0
230
+ const ident = hasPlainKeys ? addSheetStyle(plain, props.node) : null
230
231
  if (themeExpr) {
231
- addStyleExpression(ident)
232
- addStyleExpression(ident, true)
232
+ if (forTernary) {
233
+ // for ternary branches, return combined expression
234
+ // without adding plain styles unconditionally
235
+ if (ident) {
236
+ return t.arrayExpression([ident, themeExpr])
237
+ }
238
+ return themeExpr
239
+ }
240
+ // for base styles, add unconditionally
241
+ if (ident) {
242
+ addStyleExpression(ident)
243
+ addStyleExpression(ident, true)
244
+ }
233
245
  return themeExpr
234
246
  }
235
- // since we only do flattened disabling this path
236
247
  return ident
237
248
  }
238
249
 
@@ -268,6 +279,7 @@ export function getBabelParseDefinition(options: TamaguiOptions) {
268
279
  }
269
280
 
270
281
  let hasDynamicStyle = false
282
+ let hasMediaKeys = false
271
283
 
272
284
  for (const attr of props.attrs) {
273
285
  switch (attr.type) {
@@ -280,8 +292,12 @@ export function getBabelParseDefinition(options: TamaguiOptions) {
280
292
 
281
293
  case 'ternary': {
282
294
  const { consequent, alternate } = attr.value
283
- const consExpr = getStyleExpression(consequent)
284
- const altExpr = getStyleExpression(alternate)
295
+ const consExpr = getStyleExpression(consequent, true)
296
+ const altExpr = getStyleExpression(alternate, true)
297
+
298
+ if (attr.value.inlineMediaQuery) {
299
+ hasMediaKeys = true
300
+ }
285
301
 
286
302
  expressions.push(attr.value.test)
287
303
  addStyleExpression(
@@ -338,6 +354,7 @@ export function getBabelParseDefinition(options: TamaguiOptions) {
338
354
  const WrapperIdentifier = t.identifier(wrapperName)
339
355
  const WrapperJSXIdentifier = t.jsxIdentifier(wrapperName)
340
356
 
357
+ const hasThemeKeysFlag = themeKeysUsed.size > 0
341
358
  root.pushContainer(
342
359
  'body',
343
360
  t.variableDeclaration('const', [
@@ -350,6 +367,8 @@ export function getBabelParseDefinition(options: TamaguiOptions) {
350
367
  // return styles directly - no useMemo, theme changes must trigger style recalc
351
368
  t.arrayExpression([...hocStylesExpr.elements])
352
369
  ),
370
+ t.booleanLiteral(hasThemeKeysFlag),
371
+ t.booleanLiteral(hasMediaKeys),
353
372
  ])
354
373
  ),
355
374
  ])
@@ -1 +1 @@
1
- {"version":3,"file":"extractToNative.d.ts","sourceRoot":"","sources":["../../src/extractor/extractToNative.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,eAAe,EAAwB,MAAM,aAAa,CAAA;AAQxE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,UAAU,CAAA;AAsB9C,wBAAgB,eAAe,CAC7B,cAAc,EAAE,MAAM,EACtB,UAAU,EAAE,MAAM,EAClB,OAAO,EAAE,cAAc,GACtB,eAAe,CAoBjB;AAED,wBAAgB,cAAc,QAK7B;AAED,wBAAgB,uBAAuB,CAAC,OAAO,EAAE,cAAc;;;;wBAM3C,GAAG;;;EA+WtB"}
1
+ {"version":3,"file":"extractToNative.d.ts","sourceRoot":"","sources":["../../src/extractor/extractToNative.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,eAAe,EAAwB,MAAM,aAAa,CAAA;AAQxE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,UAAU,CAAA;AAsB9C,wBAAgB,eAAe,CAC7B,cAAc,EAAE,MAAM,EACtB,UAAU,EAAE,MAAM,EAClB,OAAO,EAAE,cAAc,GACtB,eAAe,CAoBjB;AAED,wBAAgB,cAAc,QAK7B;AAED,wBAAgB,uBAAuB,CAAC,OAAO,EAAE,cAAc;;;;wBAM3C,GAAG;;;EAkYtB"}