babel-plugin-jsx-dom-expressions 0.40.10 → 0.40.11

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 +28 -4
  2. package/package.json +2 -2
package/index.js CHANGED
@@ -409,6 +409,25 @@ function isComponent(tagName) {
409
409
 
410
410
  }
411
411
 
412
+ // <script> and <style> are only raw text in HTML. Inside SVG the parser decodes
413
+ // entities and treats `<` as markup, so their children still need escaping.
414
+ function isRawTextElement(path) {
415
+ const tagName = getTagName(path.node);
416
+ if (tagName !== "script" && tagName !== "style") return false;
417
+ let parent = path.parentPath,
418
+ rootTag;
419
+ while (t__namespace.isJSXElement(parent.node)) {
420
+ const parentTag = getTagName(parent.node);
421
+ if (isComponent(parentTag)) break;
422
+ if (parentTag === "foreignObject") return true;
423
+ if (parentTag === "svg") return false;
424
+ rootTag = parentTag;
425
+ parent = parent.parentPath;
426
+ }
427
+ // a top-level SVG element is parsed inside an <svg> wrapper
428
+ return !rootTag || !SVGElements.has(rootTag);
429
+ }
430
+
412
431
  function hasStaticMarker(object, path) {
413
432
  if (!object) return false;
414
433
  if (
@@ -1901,6 +1920,7 @@ function findLastElement(children, hydratable) {
1901
1920
  function transformChildren$2(path, results, config) {
1902
1921
  let tempPath = results.id && results.id.name,
1903
1922
  tagName = getTagName(path.node),
1923
+ doNotEscape = isRawTextElement(path),
1904
1924
  nextPlaceholder,
1905
1925
  childPostExprs = [],
1906
1926
  i = 0;
@@ -1913,6 +1933,7 @@ function transformChildren$2(path, results, config) {
1913
1933
 
1914
1934
  }
1915
1935
  const transformed = transformNode(child, {
1936
+ doNotEscape,
1916
1937
  toBeClosed: results.toBeClosed,
1917
1938
  lastElement: index === lastElement,
1918
1939
  skipId: !results.id || !detectExpressions(filteredChildren, index, config)
@@ -2542,7 +2563,7 @@ function transformElement$2(path, info) {
2542
2563
 
2543
2564
  const config = getConfig(path);
2544
2565
  const tagName = getTagName(path.node);
2545
- if (tagName === "script" || tagName === "style") path.doNotEscape = true;
2566
+ if (isRawTextElement(path)) path.doNotEscape = true;
2546
2567
 
2547
2568
  // contains spread attributes
2548
2569
  if (path.node.openingElement.attributes.some((a) => t__namespace.isJSXSpreadAttribute(a)))
@@ -2841,8 +2862,11 @@ function transformAttributes$1(path, results, info) {
2841
2862
  let doEscape = true;
2842
2863
 
2843
2864
  if (key.startsWith("attr:")) key = key.replace("attr:", "");
2844
- if (BooleanAttributes.has(key) || key.startsWith("bool:")) {
2845
- key = key.replace("bool:", "");
2865
+ // preservesPitch is a boolean property, but not an HTML boolean attribute.
2866
+ const isBooleanAttribute =
2867
+ key !== "preservesPitch" && BooleanAttributes.has(toAttribute(key, isSVG));
2868
+ if (isBooleanAttribute || key.startsWith("bool:")) {
2869
+ key = toAttribute(key.replace("bool:", ""), isSVG);
2846
2870
  results.template.push("");
2847
2871
  const fn = t__namespace.callExpression(registerImportMethod(attribute, "ssrAttribute"), [
2848
2872
  t__namespace.stringLiteral(key),
@@ -4068,7 +4092,7 @@ function transformNode(path, info = {}) {
4068
4092
  info.doNotEscape ?
4069
4093
  staticValue.toString() :
4070
4094
  escapeHTML(staticValue.toString()) :
4071
- trimWhitespace(node.extra.raw);
4095
+ trimWhitespace(info.doNotEscape ? node.value : node.extra.raw);
4072
4096
  if (!text.length) return null;
4073
4097
  const results = {
4074
4098
  template: text,
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.40.10",
4
+ "version": "0.40.11",
5
5
  "author": "Ryan Carniato",
6
6
  "license": "MIT",
7
7
  "repository": {
@@ -33,5 +33,5 @@
33
33
  "@rollup/plugin-babel": "6.0.3",
34
34
  "@types/babel__core": "^7.20.5"
35
35
  },
36
- "gitHead": "727298ff79a54ef5299d3649ab7f4105a326e9b3"
36
+ "gitHead": "3eba17b37754abaae2346c0237a4a65de802a316"
37
37
  }