babel-plugin-jsx-dom-expressions 0.29.16 → 0.29.17

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 +36 -21
  2. package/package.json +2 -2
package/index.js CHANGED
@@ -46,7 +46,6 @@ var config = {
46
46
 
47
47
  const booleans = [
48
48
  "allowfullscreen",
49
- "allowpaymentrequest",
50
49
  "async",
51
50
  "autofocus",
52
51
  "autoplay",
@@ -56,8 +55,8 @@ const booleans = [
56
55
  "disabled",
57
56
  "formnovalidate",
58
57
  "hidden",
58
+ "indeterminate",
59
59
  "ismap",
60
- "itemscope",
61
60
  "loop",
62
61
  "multiple",
63
62
  "muted",
@@ -69,13 +68,12 @@ const booleans = [
69
68
  "required",
70
69
  "reversed",
71
70
  "seamless",
72
- "selected",
73
- "truespeed"
71
+ "selected"
74
72
  ];
75
73
 
76
74
  const BooleanAttributes = new Set(booleans);
77
75
 
78
- const Properties = new Set(["className", "indeterminate", "value", "readOnly", ...booleans]);
76
+ const Properties = new Set(["className", "value", "readOnly", "formNoValidate", "isMap", "noModule", "playsInline", ...booleans]);
79
77
 
80
78
  const ChildProperties = new Set(["innerHTML", "textContent", "innerText", "children"]);
81
79
 
@@ -87,6 +85,10 @@ const Aliases = {
87
85
 
88
86
  const PropAliases = {
89
87
  class: "className",
88
+ formnovalidate: "formNoValidate",
89
+ ismap: "isMap",
90
+ nomodule: "noModule",
91
+ playsinline: "playsInline",
90
92
  readonly: "readOnly"
91
93
  };
92
94
 
@@ -337,12 +339,11 @@ function getStaticExpression(path) {
337
339
  }
338
340
 
339
341
  // remove unnecessary JSX Text nodes
340
- function filterChildren(children, loose) {
342
+ function filterChildren(children) {
341
343
  return children.filter(
342
344
  ({ node: child }) =>
343
345
  !(t__namespace.isJSXExpressionContainer(child) && t__namespace.isJSXEmptyExpression(child.expression)) &&
344
- (!t__namespace.isJSXText(child) ||
345
- (loose ? !/^[\r\n]\s*$/.test(child.extra.raw) : !/^\s*$/.test(child.extra.raw)))
346
+ (!t__namespace.isJSXText(child) || !/^[\r\n]\s*$/.test(child.extra.raw))
346
347
  );
347
348
  }
348
349
 
@@ -806,6 +807,10 @@ function transformAttributes$1(path, results) {
806
807
  !(t__namespace.isStringLiteral(value.expression) || t__namespace.isNumericLiteral(value.expression)))
807
808
  ) {
808
809
  if (key === "ref") {
810
+ // Normalize expressions for non-null and type-as
811
+ while (t__namespace.isTSNonNullExpression(value.expression) || t__namespace.isTSAsExpression(value.expression)) {
812
+ value.expression = value.expression.expression;
813
+ }
809
814
  if (t__namespace.isLVal(value.expression)) {
810
815
  const refIdentifier = path.scope.generateUidIdentifier("_ref$");
811
816
  results.exprs.unshift(
@@ -1049,7 +1054,7 @@ function transformChildren$1(path, results) {
1049
1054
  tagName = getTagName(path.node),
1050
1055
  nextPlaceholder,
1051
1056
  i = 0;
1052
- const filteredChildren = filterChildren(path.get("children"), true),
1057
+ const filteredChildren = filterChildren(path.get("children")),
1053
1058
  childNodes = filteredChildren
1054
1059
  .map(
1055
1060
  (child, index) =>
@@ -1233,7 +1238,7 @@ function detectExpressions(children, index) {
1233
1238
  )
1234
1239
  )
1235
1240
  return true;
1236
- const nextChildren = filterChildren(children[i].get("children"), true);
1241
+ const nextChildren = filterChildren(children[i].get("children"));
1237
1242
  if (nextChildren.length) if (detectExpressions(nextChildren, 0)) return true;
1238
1243
  }
1239
1244
  }
@@ -1463,7 +1468,6 @@ function setAttr(results, name, value, isSVG) {
1463
1468
  let parts;
1464
1469
  if ((parts = name.split(":")) && parts[1] && reservedNameSpaces.has(parts[0])) {
1465
1470
  name = parts[1];
1466
- parts[0];
1467
1471
  }
1468
1472
 
1469
1473
  name = toAttribute(name, isSVG);
@@ -1781,7 +1785,7 @@ function transformClasslistObject(path, expr, values, quasis) {
1781
1785
  function transformChildren(path, results) {
1782
1786
  const { hydratable } = config,
1783
1787
  doNotEscape = path.doNotEscape;
1784
- const filteredChildren = filterChildren(path.get("children"), true);
1788
+ const filteredChildren = filterChildren(path.get("children"));
1785
1789
  filteredChildren.forEach(node => {
1786
1790
  const child = transformNode(node, { doNotEscape });
1787
1791
  appendToTemplate(results.template, child.template);
@@ -1883,6 +1887,10 @@ function transformComponent(path) {
1883
1887
  if (t__namespace.isJSXExpressionContainer(value))
1884
1888
  if (key === "ref") {
1885
1889
  if (config.generate === "ssr") return;
1890
+ // Normalize expressions for non-null and type-as
1891
+ while (t__namespace.isTSNonNullExpression(value.expression) || t__namespace.isTSAsExpression(value.expression)) {
1892
+ value.expression = value.expression.expression;
1893
+ }
1886
1894
  if (t__namespace.isLVal(value.expression)) {
1887
1895
  const refIdentifier = path.scope.generateUidIdentifier("_ref$");
1888
1896
  runningObject.push(
@@ -2013,18 +2021,20 @@ function transformComponentChildren(children) {
2013
2021
  if (!filteredChildren.length) return;
2014
2022
  let dynamic = false;
2015
2023
 
2016
- let transformedChildren = filteredChildren.map(path => {
2024
+ let transformedChildren = filteredChildren.reduce((memo, path) => {
2017
2025
  if (t__namespace.isJSXText(path.node)) {
2018
- return t__namespace.stringLiteral(trimWhitespace(path.node.extra.rawValue));
2026
+ const v = trimWhitespace(path.node.extra.rawValue);
2027
+ if (v.length) memo.push(t__namespace.stringLiteral(v));
2019
2028
  } else {
2020
2029
  const child = transformNode(path, {
2021
2030
  topLevel: true,
2022
2031
  componentChild: true
2023
2032
  });
2024
2033
  dynamic = dynamic || child.dynamic;
2025
- return createTemplate$2(path, child, filteredChildren.length > 1);
2034
+ memo.push(createTemplate$2(path, child, filteredChildren.length > 1));
2026
2035
  }
2027
- });
2036
+ return memo;
2037
+ }, []);
2028
2038
 
2029
2039
  if (filteredChildren.length === 1) {
2030
2040
  transformedChildren = transformedChildren[0];
@@ -2052,11 +2062,16 @@ function transformFragmentChildren(children, results) {
2052
2062
  const createTemplate$2 = config.generate === "ssr" ? createTemplate : createTemplate$1,
2053
2063
  filteredChildren = filterChildren(children),
2054
2064
  singleChild = filteredChildren.length === 1,
2055
- childNodes = filteredChildren.map(path => {
2056
- if (t__namespace.isJSXText(path.node)) return t__namespace.stringLiteral(trimWhitespace(path.node.extra.raw));
2057
- const child = transformNode(path, { topLevel: true, fragmentChild: true });
2058
- return createTemplate$2(path, child, !singleChild);
2059
- });
2065
+ childNodes = filteredChildren.reduce((memo, path) => {
2066
+ if (t__namespace.isJSXText(path.node)) {
2067
+ const v = trimWhitespace(path.node.extra.raw);
2068
+ if (v.length) memo.push(t__namespace.stringLiteral(v));
2069
+ } else {
2070
+ const child = transformNode(path, { topLevel: true, fragmentChild: true });
2071
+ memo.push(createTemplate$2(path, child, !singleChild));
2072
+ }
2073
+ return memo;
2074
+ }, []);
2060
2075
  results.exprs.push(singleChild ? childNodes[0] : t__namespace.arrayExpression(childNodes));
2061
2076
  }
2062
2077
 
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.29.16",
4
+ "version": "0.29.17",
5
5
  "author": "Ryan Carniato",
6
6
  "license": "MIT",
7
7
  "repository": {
@@ -22,5 +22,5 @@
22
22
  "@babel/plugin-syntax-jsx": "^7.10.4",
23
23
  "@babel/types": "^7.11.5"
24
24
  },
25
- "gitHead": "394e9b0081d5c6221a406ed18b4cd22329a32cc3"
25
+ "gitHead": "bdec422181ff938226a7a21b92ad4862b799f687"
26
26
  }