babel-plugin-jsx-dom-expressions 0.37.8 → 0.37.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 +206 -97
  2. package/package.json +2 -2
package/index.js CHANGED
@@ -36,6 +36,7 @@ const booleans = [
36
36
  "formnovalidate",
37
37
  "hidden",
38
38
  "indeterminate",
39
+ "inert",
39
40
  "ismap",
40
41
  "loop",
41
42
  "multiple",
@@ -321,16 +322,50 @@ function isDynamic(path, { checkMember, checkTags, checkCallExpressions = true,
321
322
  expr.leadingComments.shift();
322
323
  return false;
323
324
  }
325
+
324
326
  if (
325
- (checkCallExpressions && (t__namespace.isCallExpression(expr) || t__namespace.isOptionalCallExpression(expr))) ||
326
- (checkMember &&
327
- (t__namespace.isMemberExpression(expr) ||
328
- t__namespace.isOptionalMemberExpression(expr) ||
329
- t__namespace.isSpreadElement(expr) ||
330
- (t__namespace.isBinaryExpression(expr) && expr.operator === "in"))) ||
331
- (checkTags && (t__namespace.isJSXElement(expr) || t__namespace.isJSXFragment(expr)))
332
- )
327
+ checkCallExpressions &&
328
+ (t__namespace.isCallExpression(expr) || t__namespace.isOptionalCallExpression(expr))
329
+ ) {
333
330
  return true;
331
+ }
332
+
333
+ if (checkMember && t__namespace.isMemberExpression(expr)) {
334
+ // Do not assume property access on namespaced imports as dynamic.
335
+ const object = path.get("object").node;
336
+
337
+ if (
338
+ t__namespace.isIdentifier(object) &&
339
+ (!expr.computed ||
340
+ !isDynamic(path.get("property"), {
341
+ checkMember,
342
+ checkTags,
343
+ checkCallExpressions,
344
+ native,
345
+ }))
346
+ ) {
347
+ const binding = path.scope.getBinding(object.name);
348
+
349
+ if (binding && binding.path.isImportNamespaceSpecifier()) {
350
+ return false;
351
+ }
352
+ }
353
+
354
+ return true;
355
+ }
356
+
357
+ if (
358
+ checkMember &&
359
+ (t__namespace.isOptionalMemberExpression(expr) ||
360
+ t__namespace.isSpreadElement(expr) ||
361
+ (t__namespace.isBinaryExpression(expr) && expr.operator === "in"))
362
+ ) {
363
+ return true;
364
+ }
365
+
366
+ if (checkTags && (t__namespace.isJSXElement(expr) || t__namespace.isJSXFragment(expr))) {
367
+ return true;
368
+ }
334
369
 
335
370
  let dynamic;
336
371
  path.traverse({
@@ -595,6 +630,22 @@ function canNativeSpread(key, { checkNameSpaces } = {}) {
595
630
  return true;
596
631
  }
597
632
 
633
+ const chars = "etaoinshrdlucwmfygpbTAOISWCBvkxjqzPHFMDRELNGUKVYJQZX_$";
634
+ const base = chars.length;
635
+
636
+ function getNumberedId(num) {
637
+ let out = "";
638
+
639
+ do {
640
+ const digit = num % base;
641
+
642
+ num = Math.floor(num / base);
643
+ out = chars[digit] + out;
644
+ } while (num !== 0);
645
+
646
+ return out;
647
+ }
648
+
598
649
  const InlineElements = [
599
650
  "a",
600
651
  "abbr",
@@ -726,7 +777,8 @@ function transformElement$3(path, info) {
726
777
  isSVG: wrapSVG,
727
778
  hasCustomElement: isCustomElement,
728
779
  tagName,
729
- renderer: "dom"
780
+ renderer: "dom",
781
+ skipTemplate: false
730
782
  };
731
783
  if (config.hydratable && (tagName === "html" || tagName === "head" || tagName === "body")) {
732
784
  results.skipTemplate = true;
@@ -967,12 +1019,12 @@ function transformAttributes$2(path, results) {
967
1019
  .node.attributes.splice(
968
1020
  styleAttribute.key + ++i,
969
1021
  0,
970
- t__namespace.JSXAttribute(
971
- t__namespace.JSXNamespacedName(
972
- t__namespace.JSXIdentifier("style"),
973
- t__namespace.JSXIdentifier(t__namespace.isIdentifier(p.key) ? p.key.name : p.key.value)
1022
+ t__namespace.jsxAttribute(
1023
+ t__namespace.jsxNamespacedName(
1024
+ t__namespace.jsxIdentifier("style"),
1025
+ t__namespace.jsxIdentifier(t__namespace.isIdentifier(p.key) ? p.key.name : p.key.value)
974
1026
  ),
975
- t__namespace.JSXExpressionContainer(p.value)
1027
+ t__namespace.jsxExpressionContainer(p.value)
976
1028
  )
977
1029
  );
978
1030
  styleAttribute.node.value.expression.properties.splice(index - i - 1, 1);
@@ -1011,12 +1063,12 @@ function transformAttributes$2(path, results) {
1011
1063
  .node.attributes.splice(
1012
1064
  classListAttribute.key + ++i,
1013
1065
  0,
1014
- t__namespace.JSXAttribute(
1015
- t__namespace.JSXNamespacedName(
1016
- t__namespace.JSXIdentifier("class"),
1017
- t__namespace.JSXIdentifier(t__namespace.isIdentifier(p.key) ? p.key.name : p.key.value)
1066
+ t__namespace.jsxAttribute(
1067
+ t__namespace.jsxNamespacedName(
1068
+ t__namespace.jsxIdentifier("class"),
1069
+ t__namespace.jsxIdentifier(t__namespace.isIdentifier(p.key) ? p.key.name : p.key.value)
1018
1070
  ),
1019
- t__namespace.JSXExpressionContainer(p.value)
1071
+ t__namespace.jsxExpressionContainer(p.value)
1020
1072
  )
1021
1073
  );
1022
1074
  } else if (computed) {
@@ -1025,8 +1077,8 @@ function transformAttributes$2(path, results) {
1025
1077
  .node.attributes.splice(
1026
1078
  classListAttribute.key + ++i,
1027
1079
  0,
1028
- t__namespace.JSXAttribute(
1029
- t__namespace.JSXIdentifier("class"),
1080
+ t__namespace.jsxAttribute(
1081
+ t__namespace.jsxIdentifier("class"),
1030
1082
  t__namespace.stringLiteral(t__namespace.isIdentifier(p.key) ? p.key.name : p.key.value)
1031
1083
  )
1032
1084
  );
@@ -1045,24 +1097,24 @@ function transformAttributes$2(path, results) {
1045
1097
  if (classAttributes.length > 1) {
1046
1098
  const first = classAttributes[0].node,
1047
1099
  values = [],
1048
- quasis = [t__namespace.TemplateElement({ raw: "" })];
1100
+ quasis = [t__namespace.templateElement({ raw: "" })];
1049
1101
  for (let i = 0; i < classAttributes.length; i++) {
1050
1102
  const attr = classAttributes[i].node,
1051
1103
  isLast = i === classAttributes.length - 1;
1052
1104
  if (!t__namespace.isJSXExpressionContainer(attr.value)) {
1053
1105
  const prev = quasis.pop();
1054
1106
  quasis.push(
1055
- t__namespace.TemplateElement({
1107
+ t__namespace.templateElement({
1056
1108
  raw: (prev ? prev.value.raw : "") + `${attr.value.value}` + (isLast ? "" : " ")
1057
1109
  })
1058
1110
  );
1059
1111
  } else {
1060
1112
  values.push(t__namespace.logicalExpression("||", attr.value.expression, t__namespace.stringLiteral("")));
1061
- quasis.push(t__namespace.TemplateElement({ raw: isLast ? "" : " " }));
1113
+ quasis.push(t__namespace.templateElement({ raw: isLast ? "" : " " }));
1062
1114
  }
1063
1115
  i && attributes.splice(attributes.indexOf(classAttributes[i]), 1);
1064
1116
  }
1065
- if (values.length) first.value = t__namespace.JSXExpressionContainer(t__namespace.TemplateLiteral(quasis, values));
1117
+ if (values.length) first.value = t__namespace.jsxExpressionContainer(t__namespace.templateLiteral(quasis, values));
1066
1118
  else first.value = t__namespace.stringLiteral(quasis[0].value.raw);
1067
1119
  }
1068
1120
  path.get("openingElement").set(
@@ -1098,7 +1150,7 @@ function transformAttributes$2(path, results) {
1098
1150
  reservedNameSpace &&
1099
1151
  !t__namespace.isJSXExpressionContainer(value)
1100
1152
  ) {
1101
- node.value = value = t__namespace.JSXExpressionContainer(value || t__namespace.JSXEmptyExpression());
1153
+ node.value = value = t__namespace.jsxExpressionContainer(value || t__namespace.jsxEmptyExpression());
1102
1154
  }
1103
1155
  if (
1104
1156
  t__namespace.isJSXExpressionContainer(value) &&
@@ -1335,7 +1387,7 @@ function transformAttributes$2(path, results) {
1335
1387
  }
1336
1388
  if (key === "textContent") {
1337
1389
  nextElem = attribute.scope.generateUidIdentifier("el$");
1338
- children = t__namespace.JSXText(" ");
1390
+ children = t__namespace.jsxText(" ");
1339
1391
  children.extra = { raw: " ", rawValue: " " };
1340
1392
  results.declarations.push(
1341
1393
  t__namespace.variableDeclarator(nextElem, t__namespace.memberExpression(elem, t__namespace.identifier("firstChild")))
@@ -1884,50 +1936,65 @@ function wrapDynamics$1(path, dynamics) {
1884
1936
  ])
1885
1937
  );
1886
1938
  }
1887
- const declarations = [],
1888
- statements = [],
1889
- identifiers = [],
1890
- prevId = t__namespace.identifier("_p$");
1891
- dynamics.forEach(({ elem, key, value, isSVG, isCE, tagName }) => {
1892
- const identifier = path.scope.generateUidIdentifier("v$");
1893
- if (key.startsWith("class:") && !t__namespace.isBooleanLiteral(value) && !t__namespace.isUnaryExpression(value)) {
1939
+
1940
+ const prevId = t__namespace.identifier("_p$");
1941
+
1942
+ /** @type {t.VariableDeclarator[]} */
1943
+ const declarations = [];
1944
+ /** @type {t.ExpressionStatement[]} */
1945
+ const statements = [];
1946
+ /** @type {t.Identifier[]} */
1947
+ const properties = [];
1948
+
1949
+ dynamics.forEach(({ elem, key, value, isSVG, isCE, tagName }, index) => {
1950
+ const varIdent = path.scope.generateUidIdentifier("v$");
1951
+
1952
+ const propIdent = t__namespace.identifier(getNumberedId(index));
1953
+ const propMember = t__namespace.memberExpression(prevId, propIdent);
1954
+
1955
+ if (
1956
+ key.startsWith("class:") &&
1957
+ !t__namespace.isBooleanLiteral(value) &&
1958
+ !t__namespace.isUnaryExpression(value)
1959
+ ) {
1894
1960
  value = t__namespace.unaryExpression("!", t__namespace.unaryExpression("!", value));
1895
1961
  }
1896
- identifiers.push(identifier);
1897
- declarations.push(t__namespace.variableDeclarator(identifier, value));
1962
+
1963
+ properties.push(propIdent);
1964
+ declarations.push(t__namespace.variableDeclarator(varIdent, value));
1965
+
1898
1966
  if (key === "classList" || key === "style") {
1899
- const prev = t__namespace.memberExpression(prevId, identifier);
1900
1967
  statements.push(
1901
1968
  t__namespace.expressionStatement(
1902
1969
  t__namespace.assignmentExpression(
1903
1970
  "=",
1904
- prev,
1905
- setAttr$2(path, elem, key, identifier, {
1971
+ propMember,
1972
+ setAttr$2(path, elem, key, varIdent, {
1906
1973
  isSVG,
1907
1974
  isCE,
1908
1975
  tagName,
1909
1976
  dynamic: true,
1910
- prevId: prev
1911
- })
1912
- )
1913
- )
1977
+ prevId: propMember,
1978
+ }),
1979
+ ),
1980
+ ),
1914
1981
  );
1915
1982
  } else {
1916
- const prev = key.startsWith("style:") ? identifier : undefined;
1983
+ const prev = key.startsWith("style:") ? varIdent : undefined;
1917
1984
  statements.push(
1918
1985
  t__namespace.expressionStatement(
1919
1986
  t__namespace.logicalExpression(
1920
1987
  "&&",
1921
- t__namespace.binaryExpression("!==", identifier, t__namespace.memberExpression(prevId, identifier)),
1988
+ t__namespace.binaryExpression("!==", varIdent, propMember),
1922
1989
  setAttr$2(
1923
1990
  path,
1924
1991
  elem,
1925
1992
  key,
1926
- t__namespace.assignmentExpression("=", t__namespace.memberExpression(prevId, identifier), identifier),
1927
- { isSVG, isCE, tagName, dynamic: true, prevId: prev }
1928
- )
1929
- )
1930
- )
1993
+ t__namespace.assignmentExpression("=", propMember, varIdent),
1994
+ { isSVG, isCE, tagName, dynamic: true, prevId: prev },
1995
+ ),
1996
+ ),
1997
+ ),
1931
1998
  );
1932
1999
  }
1933
2000
  });
@@ -1939,11 +2006,13 @@ function wrapDynamics$1(path, dynamics) {
1939
2006
  t__namespace.blockStatement([
1940
2007
  t__namespace.variableDeclaration("const", declarations),
1941
2008
  ...statements,
1942
- t__namespace.returnStatement(prevId)
1943
- ])
2009
+ t__namespace.returnStatement(prevId),
2010
+ ]),
1944
2011
  ),
1945
- t__namespace.objectExpression(identifiers.map(id => t__namespace.objectProperty(id, t__namespace.identifier("undefined"))))
1946
- ])
2012
+ t__namespace.objectExpression(
2013
+ properties.map((id) => t__namespace.objectProperty(id, t__namespace.identifier("undefined"))),
2014
+ ),
2015
+ ]),
1947
2016
  );
1948
2017
  }
1949
2018
 
@@ -2226,17 +2295,16 @@ function normalizeAttributes(path) {
2226
2295
  if (classAttributes.length > 1) {
2227
2296
  const first = classAttributes[0].node,
2228
2297
  values = [],
2229
- quasis = [t__namespace.TemplateElement({ raw: "" })];
2298
+ quasis = [t__namespace.templateElement({ raw: "" })];
2230
2299
  for (let i = 0; i < classAttributes.length; i++) {
2231
2300
  const attr = classAttributes[i].node,
2232
2301
  isLast = i === classAttributes.length - 1;
2233
2302
  if (!t__namespace.isJSXExpressionContainer(attr.value)) {
2234
2303
  const prev = quasis.pop();
2235
2304
  quasis.push(
2236
- t__namespace.TemplateElement({
2305
+ t__namespace.templateElement({
2237
2306
  raw:
2238
2307
  (prev ? prev.value.raw : "") +
2239
- (i ? " " : "") +
2240
2308
  `${attr.value.value}` +
2241
2309
  (isLast ? "" : " ")
2242
2310
  })
@@ -2246,18 +2314,19 @@ function normalizeAttributes(path) {
2246
2314
  if (attr.name.name === "classList") {
2247
2315
  if (t__namespace.isObjectExpression(expr) && !expr.properties.some(p => t__namespace.isSpreadElement(p))) {
2248
2316
  transformClasslistObject(path, expr, values, quasis);
2317
+ if (!isLast) quasis[quasis.length - 1].value.raw += " ";
2249
2318
  i && attributes.splice(attributes.indexOf(classAttributes[i]), 1);
2250
2319
  continue;
2251
2320
  }
2252
2321
  expr = t__namespace.callExpression(registerImportMethod(path, "ssrClassList"), [expr]);
2253
2322
  }
2254
2323
  values.push(t__namespace.logicalExpression("||", expr, t__namespace.stringLiteral("")));
2255
- quasis.push(t__namespace.TemplateElement({ raw: isLast ? "" : " " }));
2324
+ quasis.push(t__namespace.templateElement({ raw: isLast ? "" : " " }));
2256
2325
  }
2257
2326
  i && attributes.splice(attributes.indexOf(classAttributes[i]), 1);
2258
2327
  }
2259
- first.name = t__namespace.JSXIdentifier("class");
2260
- first.value = t__namespace.JSXExpressionContainer(t__namespace.TemplateLiteral(quasis, values));
2328
+ first.name = t__namespace.jsxIdentifier("class");
2329
+ first.value = t__namespace.jsxExpressionContainer(t__namespace.templateLiteral(quasis, values));
2261
2330
  }
2262
2331
  if (styleAttributes.length) transformToObject("style", attributes, styleAttributes);
2263
2332
  return attributes;
@@ -2283,7 +2352,7 @@ function transformAttributes$1(path, results, info) {
2283
2352
  ((t__namespace.isJSXNamespacedName(node.name) && reservedNameSpace) || ChildProperties.has(key)) &&
2284
2353
  !t__namespace.isJSXExpressionContainer(value)
2285
2354
  ) {
2286
- node.value = value = t__namespace.JSXExpressionContainer(value || t__namespace.JSXEmptyExpression());
2355
+ node.value = value = t__namespace.jsxExpressionContainer(value || t__namespace.jsxEmptyExpression());
2287
2356
  }
2288
2357
 
2289
2358
  if (
@@ -2350,7 +2419,7 @@ function transformAttributes$1(path, results, info) {
2350
2419
  !value.expression.properties.some(p => t__namespace.isSpreadElement(p))
2351
2420
  ) {
2352
2421
  const values = [],
2353
- quasis = [t__namespace.TemplateElement({ raw: "" })];
2422
+ quasis = [t__namespace.templateElement({ raw: "" })];
2354
2423
  transformClasslistObject(path, value.expression, values, quasis);
2355
2424
  if (!values.length) value.expression = t__namespace.stringLiteral(quasis[0].value.raw);
2356
2425
  else if (values.length === 1 && !quasis[0].value.raw && !quasis[1].value.raw) {
@@ -2412,19 +2481,19 @@ function transformClasslistObject(path, expr, values, quasis) {
2412
2481
  if (!prop.computed) {
2413
2482
  const prev = quasis.pop();
2414
2483
  quasis.push(
2415
- t__namespace.TemplateElement({
2484
+ t__namespace.templateElement({
2416
2485
  raw:
2417
2486
  (prev ? prev.value.raw : "") + (i ? " " : "") + `${key.value}` + (isLast ? "" : " ")
2418
2487
  })
2419
2488
  );
2420
2489
  } else {
2421
2490
  values.push(key);
2422
- quasis.push(t__namespace.TemplateElement({ raw: isLast ? "" : " " }));
2491
+ quasis.push(t__namespace.templateElement({ raw: isLast ? "" : " " }));
2423
2492
  }
2424
2493
  }
2425
2494
  } else {
2426
2495
  values.push(t__namespace.conditionalExpression(prop.value, key, t__namespace.stringLiteral("")));
2427
- quasis.push(t__namespace.TemplateElement({ raw: isLast ? "" : " " }));
2496
+ quasis.push(t__namespace.templateElement({ raw: isLast ? "" : " " }));
2428
2497
  }
2429
2498
  });
2430
2499
  }
@@ -2662,7 +2731,7 @@ function transformAttributes(path, results) {
2662
2731
  reservedNameSpace &&
2663
2732
  !t__namespace.isJSXExpressionContainer(value)
2664
2733
  ) {
2665
- node.value = value = t__namespace.JSXExpressionContainer(value || t__namespace.JSXEmptyExpression());
2734
+ node.value = value = t__namespace.jsxExpressionContainer(value || t__namespace.jsxEmptyExpression());
2666
2735
  }
2667
2736
  if (t__namespace.isJSXExpressionContainer(value)) {
2668
2737
  if (key === "ref") {
@@ -3011,29 +3080,37 @@ function wrapDynamics(path, dynamics) {
3011
3080
  ])
3012
3081
  );
3013
3082
  }
3014
- const declarations = [],
3015
- statements = [],
3016
- identifiers = [],
3017
- prevId = t__namespace.identifier("_p$");
3018
- dynamics.forEach(({ elem, key, value }) => {
3019
- const identifier = path.scope.generateUidIdentifier("v$");
3020
- identifiers.push(identifier);
3021
- declarations.push(t__namespace.variableDeclarator(identifier, value));
3022
- const prev = t__namespace.memberExpression(prevId, identifier);
3083
+
3084
+ const prevId = t__namespace.identifier("_p$");
3085
+
3086
+ /** @type {t.VariableDeclarator[]} */
3087
+ const declarations = [];
3088
+ /** @type {t.ExpressionStatement[]} */
3089
+ const statements = [];
3090
+ /** @type {t.Identifier[]} */
3091
+ const properties = [];
3092
+
3093
+ dynamics.forEach(({ elem, key, value }, index) => {
3094
+ const varIdent = path.scope.generateUidIdentifier("v$");
3095
+
3096
+ const propIdent = t__namespace.identifier(getNumberedId(index));
3097
+ const propMember = t__namespace.memberExpression(prevId, propIdent);
3098
+
3099
+ properties.push(propIdent);
3100
+ declarations.push(t__namespace.variableDeclarator(varIdent, value));
3101
+
3023
3102
  statements.push(
3024
3103
  t__namespace.expressionStatement(
3025
3104
  t__namespace.logicalExpression(
3026
3105
  "&&",
3027
- t__namespace.binaryExpression("!==", identifier, t__namespace.memberExpression(prevId, identifier)),
3028
- t__namespace.assignmentExpression("=", t__namespace.memberExpression(prevId, identifier), setAttr(
3029
- path,
3030
- elem,
3031
- key,
3032
- identifier,
3033
- { dynamic: true, prevId: prev }
3034
- ))
3035
- )
3036
- )
3106
+ t__namespace.binaryExpression("!==", varIdent, propMember),
3107
+ t__namespace.assignmentExpression(
3108
+ "=",
3109
+ propMember,
3110
+ setAttr(path, elem, key, varIdent, { dynamic: true, prevId: propMember }),
3111
+ ),
3112
+ ),
3113
+ ),
3037
3114
  );
3038
3115
  });
3039
3116
 
@@ -3044,16 +3121,19 @@ function wrapDynamics(path, dynamics) {
3044
3121
  t__namespace.blockStatement([
3045
3122
  t__namespace.variableDeclaration("const", declarations),
3046
3123
  ...statements,
3047
- t__namespace.returnStatement(prevId)
3048
- ])
3124
+ t__namespace.returnStatement(prevId),
3125
+ ]),
3049
3126
  ),
3050
- t__namespace.objectExpression(identifiers.map(id => t__namespace.objectProperty(id, t__namespace.identifier("undefined"))))
3051
- ])
3127
+ t__namespace.objectExpression(
3128
+ properties.map((id) => t__namespace.objectProperty(id, t__namespace.identifier("undefined"))),
3129
+ ),
3130
+ ]),
3052
3131
  );
3053
3132
  }
3054
3133
 
3055
3134
  function convertComponentIdentifier(node) {
3056
3135
  if (t__namespace.isJSXIdentifier(node)) {
3136
+ if (node.name === 'this') return t__namespace.thisExpression();
3057
3137
  if (t__namespace.isValidIdentifier(node.name)) node.type = "Identifier";
3058
3138
  else return t__namespace.stringLiteral(node.name);
3059
3139
  } else if (t__namespace.isJSXMemberExpression(node)) {
@@ -3352,21 +3432,50 @@ function transformJSX(path) {
3352
3432
  path.replaceWith(replace(template(path, result, false)));
3353
3433
  }
3354
3434
 
3435
+ function getTargetFunctionParent(path, parent) {
3436
+ let current = path.scope.getFunctionParent();
3437
+ while (current !== parent && current.path.isArrowFunctionExpression()) {
3438
+ current = current.path.parentPath.scope.getFunctionParent();
3439
+ }
3440
+ return current;
3441
+ }
3442
+
3355
3443
  function transformThis(path) {
3444
+ const parent = path.scope.getFunctionParent();
3356
3445
  let thisId;
3357
3446
  path.traverse({
3358
3447
  ThisExpression(path) {
3359
- thisId || (thisId = path.scope.generateUidIdentifier("self$"));
3360
- path.replaceWith(thisId);
3361
- }
3448
+ const current = getTargetFunctionParent(path, parent);
3449
+ if (current === parent) {
3450
+ thisId || (thisId = path.scope.generateUidIdentifier("self$"));
3451
+ path.replaceWith(thisId);
3452
+ }
3453
+ },
3454
+ JSXElement(path) {
3455
+ let source = path.get('openingElement').get('name');
3456
+ while (source.isJSXMemberExpression()) {
3457
+ source = source.get('object');
3458
+ }
3459
+ if (source.isJSXIdentifier() && source.node.name === 'this') {
3460
+ const current = getTargetFunctionParent(path, parent);
3461
+ if (current === parent) {
3462
+ thisId || (thisId = path.scope.generateUidIdentifier("self$"));
3463
+ source.replaceWith(t__namespace.jsxIdentifier(thisId.name));
3464
+
3465
+ if (path.node.closingElement) {
3466
+ path.node.closingElement.name = path.node.openingElement.name;
3467
+ }
3468
+ }
3469
+ }
3470
+ },
3362
3471
  });
3363
3472
  return node => {
3364
3473
  if (thisId) {
3365
- let parent = path.getStatementParent();
3366
- const decl = t__namespace.variableDeclaration("const", [
3367
- t__namespace.variableDeclarator(thisId, t__namespace.thisExpression())
3368
- ]);
3369
- parent.insertBefore(decl);
3474
+ parent.push({
3475
+ id: thisId,
3476
+ init: t__namespace.thisExpression(),
3477
+ kind: 'const',
3478
+ });
3370
3479
  }
3371
3480
  return node;
3372
3481
  };
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.37.8",
4
+ "version": "0.37.11",
5
5
  "author": "Ryan Carniato",
6
6
  "license": "MIT",
7
7
  "repository": {
@@ -31,5 +31,5 @@
31
31
  "devDependencies": {
32
32
  "@babel/core": "^7.20.12"
33
33
  },
34
- "gitHead": "51b297d6ed45d1a3dbbe7a45f2f58b8b524427ab"
34
+ "gitHead": "74d433381256e4355adc644124026fe0a2ef9875"
35
35
  }