babel-plugin-jsx-dom-expressions 0.35.13 → 0.35.15

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 (2) hide show
  1. package/index.js +120 -51
  2. package/package.json +3 -3
package/index.js CHANGED
@@ -1793,6 +1793,7 @@ function transformElement$2(path, info) {
1793
1793
  wontEscape: path.node.wontEscape,
1794
1794
  renderer: "ssr"
1795
1795
  };
1796
+ if (tagName === "script" || tagName === "style") path.doNotEscape = true;
1796
1797
 
1797
1798
  if (info.topLevel && config.hydratable) {
1798
1799
  if (tagName === "head") {
@@ -1910,7 +1911,7 @@ function escapeExpression(path, expression, attr, escapeLiterals) {
1910
1911
  } else
1911
1912
  expression.callee.body = escapeExpression(path, expression.callee.body, attr, escapeLiterals);
1912
1913
  return expression;
1913
- } else if(t__namespace.isJSXElement(expression) && !isComponent(getTagName(expression))) {
1914
+ } else if (t__namespace.isJSXElement(expression) && !isComponent(getTagName(expression))) {
1914
1915
  expression.wontEscape = true;
1915
1916
  return expression;
1916
1917
  }
@@ -2239,66 +2240,133 @@ function createElement(path, { topLevel, hydratable }) {
2239
2240
  return memo;
2240
2241
  }, []);
2241
2242
 
2242
- let transformed;
2243
+ let props;
2243
2244
  if (attributes.length === 1) {
2244
- transformed = attributes[0].node.argument;
2245
+ props = [attributes[0].node.argument];
2245
2246
  } else {
2246
- transformed = t__namespace.arrowFunctionExpression(
2247
- [],
2248
- t__namespace.objectExpression(
2249
- attributes.reduce((memo, attribute) => {
2250
- const node = attribute.node;
2251
-
2252
- if (t__namespace.isJSXSpreadAttribute(node)) {
2253
- const expr = node.argument;
2254
- memo.push(t__namespace.spreadElement(expr));
2255
- return memo;
2256
- }
2257
- let value = node.value,
2258
- key = t__namespace.isJSXNamespacedName(node.name)
2259
- ? `${node.name.namespace.name}:${node.name.name.name}`
2260
- : node.name.name,
2261
- reservedNameSpace =
2262
- t__namespace.isJSXNamespacedName(node.name) && reservedNameSpaces.has(node.name.namespace.name);
2263
- if (
2264
- ((t__namespace.isJSXNamespacedName(node.name) && reservedNameSpace) || ChildProperties.has(key)) &&
2265
- !t__namespace.isJSXExpressionContainer(value)
2266
- ) {
2267
- node.value = value = t__namespace.JSXExpressionContainer(value || t__namespace.JSXEmptyExpression());
2268
- }
2247
+ props = [];
2248
+ let runningObject = [],
2249
+ dynamicSpread = false,
2250
+ hasChildren = path.node.children.length > 0;
2269
2251
 
2252
+ attributes.forEach(attribute => {
2253
+ const node = attribute.node;
2254
+ if (t__namespace.isJSXSpreadAttribute(node)) {
2255
+ if (runningObject.length) {
2256
+ props.push(t__namespace.objectExpression(runningObject));
2257
+ runningObject = [];
2258
+ }
2259
+ props.push(
2260
+ isDynamic(attribute.get("argument"), {
2261
+ checkMember: true
2262
+ }) && (dynamicSpread = true)
2263
+ ? t__namespace.isCallExpression(node.argument) &&
2264
+ !node.argument.arguments.length &&
2265
+ !t__namespace.isCallExpression(node.argument.callee) &&
2266
+ !t__namespace.isMemberExpression(node.argument.callee)
2267
+ ? node.argument.callee
2268
+ : t__namespace.arrowFunctionExpression([], node.argument)
2269
+ : node.argument
2270
+ );
2271
+ } else {
2272
+ const value = node.value || t__namespace.booleanLiteral(true),
2273
+ id = convertJSXIdentifier(node.name),
2274
+ key = t__namespace.isJSXNamespacedName(node.name)
2275
+ ? `${node.name.namespace.name}:${node.name.name.name}`
2276
+ : node.name.name;
2277
+
2278
+ if (hasChildren && key === "children") return;
2279
+ if (
2280
+ key === "ref" ||
2281
+ key.startsWith("use:") ||
2282
+ key.startsWith("prop:") ||
2283
+ key.startsWith("on")
2284
+ )
2285
+ return;
2286
+ if (t__namespace.isJSXExpressionContainer(value))
2270
2287
  if (
2271
- t__namespace.isJSXExpressionContainer(value) &&
2272
- (reservedNameSpace ||
2273
- ChildProperties.has(key) ||
2274
- !(t__namespace.isStringLiteral(value.expression) || t__namespace.isNumericLiteral(value.expression)))
2288
+ isDynamic(attribute.get("value").get("expression"), {
2289
+ checkMember: true,
2290
+ checkTags: true
2291
+ })
2275
2292
  ) {
2276
- if (
2277
- key === "ref" ||
2278
- key.startsWith("use:") ||
2279
- key.startsWith("prop:") ||
2280
- key.startsWith("on")
2281
- )
2282
- return memo;
2283
-
2284
- memo.push(t__namespace.objectProperty(t__namespace.stringLiteral(key), value.expression));
2285
- } else {
2286
- if (key === "$ServerOnly") return memo;
2287
- if (t__namespace.isJSXExpressionContainer(value)) value = value.expression;
2288
- memo.push(
2289
- t__namespace.objectProperty(t__namespace.stringLiteral(key), value ? value : t__namespace.booleanLiteral(true))
2293
+ let expr = t__namespace.arrowFunctionExpression([], value.expression);
2294
+ runningObject.push(
2295
+ t__namespace.objectMethod(
2296
+ "get",
2297
+ id,
2298
+ [],
2299
+ t__namespace.blockStatement([t__namespace.returnStatement(expr.body)]),
2300
+ !t__namespace.isValidIdentifier(key)
2301
+ )
2290
2302
  );
2291
- }
2292
- return memo;
2293
- }, [])
2294
- )
2295
- );
2303
+ } else runningObject.push(t__namespace.objectProperty(id, value.expression));
2304
+ else runningObject.push(t__namespace.objectProperty(id, value));
2305
+ }
2306
+ });
2307
+
2308
+ if (runningObject.length || !props.length) props.push(t__namespace.objectExpression(runningObject));
2309
+
2310
+ if (props.length > 1 || dynamicSpread) {
2311
+ props = [t__namespace.callExpression(registerImportMethod(path, "mergeProps"), props)];
2312
+ }
2313
+
2314
+ // transformed = t.arrowFunctionExpression(
2315
+ // [],
2316
+ // t.objectExpression(
2317
+ // attributes.reduce((memo, attribute) => {
2318
+ // const node = attribute.node;
2319
+
2320
+ // if (t.isJSXSpreadAttribute(node)) {
2321
+ // const expr = node.argument;
2322
+ // memo.push(t.spreadElement(expr));
2323
+ // return memo;
2324
+ // }
2325
+ // let value = node.value,
2326
+ // key = t.isJSXNamespacedName(node.name)
2327
+ // ? `${node.name.namespace.name}:${node.name.name.name}`
2328
+ // : node.name.name,
2329
+ // reservedNameSpace =
2330
+ // t.isJSXNamespacedName(node.name) && reservedNameSpaces.has(node.name.namespace.name);
2331
+ // if (
2332
+ // ((t.isJSXNamespacedName(node.name) && reservedNameSpace) || ChildProperties.has(key)) &&
2333
+ // !t.isJSXExpressionContainer(value)
2334
+ // ) {
2335
+ // node.value = value = t.JSXExpressionContainer(value || t.JSXEmptyExpression());
2336
+ // }
2337
+
2338
+ // if (
2339
+ // t.isJSXExpressionContainer(value) &&
2340
+ // (reservedNameSpace ||
2341
+ // ChildProperties.has(key) ||
2342
+ // !(t.isStringLiteral(value.expression) || t.isNumericLiteral(value.expression)))
2343
+ // ) {
2344
+ // if (
2345
+ // key === "ref" ||
2346
+ // key.startsWith("use:") ||
2347
+ // key.startsWith("prop:") ||
2348
+ // key.startsWith("on")
2349
+ // )
2350
+ // return memo;
2351
+
2352
+ // memo.push(t.objectProperty(t.stringLiteral(key), value.expression));
2353
+ // } else {
2354
+ // if (key === "$ServerOnly") return memo;
2355
+ // if (t.isJSXExpressionContainer(value)) value = value.expression;
2356
+ // memo.push(
2357
+ // t.objectProperty(t.stringLiteral(key), value ? value : t.booleanLiteral(true))
2358
+ // );
2359
+ // }
2360
+ // return memo;
2361
+ // }, [])
2362
+ // )
2363
+ // );
2296
2364
  }
2297
2365
 
2298
2366
  const exprs = [
2299
2367
  t__namespace.callExpression(registerImportMethod(path, "ssrElement"), [
2300
2368
  t__namespace.stringLiteral(tagName),
2301
- transformed,
2369
+ props[0],
2302
2370
  childNodes.length
2303
2371
  ? hydratable
2304
2372
  ? t__namespace.arrowFunctionExpression(
@@ -2832,7 +2900,8 @@ function transformComponent(path) {
2832
2900
  // Normalize expressions for non-null and type-as
2833
2901
  while (
2834
2902
  t__namespace.isTSNonNullExpression(value.expression) ||
2835
- t__namespace.isTSAsExpression(value.expression)
2903
+ t__namespace.isTSAsExpression(value.expression) ||
2904
+ t__namespace.isTSSatisfiesExpression(value.expression)
2836
2905
  ) {
2837
2906
  value.expression = value.expression.expression;
2838
2907
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "babel-plugin-jsx-dom-expressions",
3
3
  "description": "A JSX to DOM plugin that wraps expressions for fine grained change detection",
4
- "version": "0.35.13",
4
+ "version": "0.35.15",
5
5
  "author": "Ryan Carniato",
6
6
  "license": "MIT",
7
7
  "repository": {
@@ -23,7 +23,7 @@
23
23
  "@babel/plugin-syntax-jsx": "^7.18.6",
24
24
  "@babel/types": "^7.20.7",
25
25
  "html-entities": "2.3.3",
26
- "validate-html-nesting": "^1.1.0"
26
+ "validate-html-nesting": "^1.2.0"
27
27
  },
28
28
  "peerDependencies": {
29
29
  "@babel/core": "^7.20.12"
@@ -31,5 +31,5 @@
31
31
  "devDependencies": {
32
32
  "@babel/core": "^7.20.12"
33
33
  },
34
- "gitHead": "a7a444cd18147a73ae1c514f8defcc0efadf18d2"
34
+ "gitHead": "817109e55d6f04f8567fa70f4deeddb81e15f1ee"
35
35
  }