@babel/plugin-transform-optional-chaining 7.28.6 → 7.29.16

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.
package/lib/index.js CHANGED
@@ -55,7 +55,13 @@ function isSimpleMemberExpression(expression) {
55
55
  expression = helperSkipTransparentExpressionWrappers.skipTransparentExprWrapperNodes(expression);
56
56
  return core.types.isIdentifier(expression) || core.types.isSuper(expression) || core.types.isMemberExpression(expression) && !expression.computed && isSimpleMemberExpression(expression.object);
57
57
  }
58
- function needsMemoize(path) {
58
+ function isStaticForNullishCheck(scope, node, pureGetters) {
59
+ if (core.types.isIdentifier(node)) {
60
+ return pureGetters || scope.hasBinding(node.name);
61
+ }
62
+ return scope.isStatic(node);
63
+ }
64
+ function needsMemoize(path, pureGetters) {
59
65
  let optionalPath = path;
60
66
  const {
61
67
  scope
@@ -66,7 +72,7 @@ function needsMemoize(path) {
66
72
  } = optionalPath;
67
73
  const childPath = helperSkipTransparentExpressionWrappers.skipTransparentExprWrappers(optionalPath.isOptionalMemberExpression() ? optionalPath.get("object") : optionalPath.get("callee"));
68
74
  if (node.optional) {
69
- return !scope.isStatic(childPath.node);
75
+ return !isStaticForNullishCheck(scope, childPath.node, pureGetters);
70
76
  }
71
77
  optionalPath = childPath;
72
78
  }
@@ -82,7 +88,7 @@ function transformOptionalChain(path, {
82
88
  const {
83
89
  scope
84
90
  } = path;
85
- if (scope.path.isPattern() && needsMemoize(path)) {
91
+ if (scope.path.isPattern() && needsMemoize(path, pureGetters)) {
86
92
  replacementPath.replaceWith(core.template.expression.ast`(() => ${replacementPath.node})()`);
87
93
  return;
88
94
  }
@@ -122,7 +128,7 @@ function transformOptionalChain(path, {
122
128
  node.callee = core.types.sequenceExpression([core.types.numericLiteral(0), ref]);
123
129
  } else if (pureGetters && isCall && isSimpleMemberExpression(chain)) {
124
130
  check = ref = node.callee;
125
- } else if (scope.isStatic(chain)) {
131
+ } else if (isStaticForNullishCheck(scope, chain, pureGetters)) {
126
132
  check = ref = chainWithTypes;
127
133
  } else {
128
134
  if (!tmpVar || isCall) {
package/lib/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../src/util.ts","../src/transform.ts","../src/index.ts"],"sourcesContent":["import type { NodePath } from \"@babel/core\";\nimport { isTransparentExprWrapper } from \"@babel/helper-skip-transparent-expression-wrappers\";\n/**\n * Test if a NodePath will be cast to boolean when evaluated.\n * It respects transparent expression wrappers defined in\n * \"@babel/helper-skip-transparent-expression-wrappers\"\n *\n * @example\n * // returns true\n * const nodePathADotB = NodePath(\"if (a.b) {}\").get(\"test\"); // a.b\n * willPathCastToBoolean(nodePathADotB)\n * @example\n * // returns false\n * willPathCastToBoolean(NodePath(\"a.b\"))\n * @param {NodePath} path\n * @returns {boolean}\n */\nexport function willPathCastToBoolean(path: NodePath): boolean {\n const maybeWrapped = findOutermostTransparentParent(path);\n const { node, parentPath } = maybeWrapped;\n if (parentPath.isLogicalExpression()) {\n const { operator, right } = parentPath.node;\n if (\n operator === \"&&\" ||\n operator === \"||\" ||\n (operator === \"??\" && node === right)\n ) {\n return willPathCastToBoolean(parentPath);\n }\n }\n if (parentPath.isSequenceExpression()) {\n const { expressions } = parentPath.node;\n if (expressions[expressions.length - 1] === node) {\n return willPathCastToBoolean(parentPath);\n } else {\n // if it is in the middle of a sequence expression, we don't\n // care the return value so just cast to boolean for smaller\n // output\n return true;\n }\n }\n return (\n parentPath.isConditional({ test: node }) ||\n parentPath.isUnaryExpression({ operator: \"!\" }) ||\n parentPath.isForStatement({ test: node }) ||\n parentPath.isWhile({ test: node })\n );\n}\n\n/**\n * Return the outermost transparent expression wrapper of a given path,\n * otherwise returns path itself.\n * @example\n * const nodePathADotB = NodePath(\"(a.b as any)\").get(\"expression\"); // a.b\n * // returns NodePath(\"(a.b as any)\")\n * findOutermostTransparentParent(nodePathADotB);\n * @param {NodePath} path\n * @returns {NodePath}\n */\nexport function findOutermostTransparentParent(path: NodePath): NodePath {\n let maybeWrapped = path;\n path.findParent(p => {\n if (!isTransparentExprWrapper(p.node)) return true;\n maybeWrapped = p;\n });\n return maybeWrapped;\n}\n","import { types as t, template, type NodePath } from \"@babel/core\";\nimport {\n skipTransparentExprWrapperNodes,\n skipTransparentExprWrappers,\n} from \"@babel/helper-skip-transparent-expression-wrappers\";\nimport {\n willPathCastToBoolean,\n findOutermostTransparentParent,\n} from \"./util.ts\";\n\n// TODO(Babel 9): Use .at(-1)\nconst last = <T>(arr: T[]) => arr[arr.length - 1];\n\nfunction isSimpleMemberExpression(\n expression: t.Expression | t.Super,\n): expression is t.Identifier | t.Super | t.MemberExpression {\n expression = skipTransparentExprWrapperNodes(expression);\n return (\n t.isIdentifier(expression) ||\n t.isSuper(expression) ||\n (t.isMemberExpression(expression) &&\n !expression.computed &&\n isSimpleMemberExpression(expression.object))\n );\n}\n\n/**\n * Test if a given optional chain `path` needs to be memoized\n * @param {NodePath} path\n * @returns {boolean}\n */\nfunction needsMemoize(\n path: NodePath<t.OptionalCallExpression | t.OptionalMemberExpression>,\n) {\n let optionalPath: NodePath = path;\n const { scope } = path;\n while (\n optionalPath.isOptionalMemberExpression() ||\n optionalPath.isOptionalCallExpression()\n ) {\n const { node } = optionalPath;\n const childPath = skipTransparentExprWrappers(\n optionalPath.isOptionalMemberExpression()\n ? optionalPath.get(\"object\")\n : optionalPath.get(\"callee\"),\n );\n if (node.optional) {\n return !scope.isStatic(childPath.node);\n }\n\n optionalPath = childPath;\n }\n}\n\nconst NULLISH_CHECK = template.expression(\n `%%check%% === null || %%ref%% === void 0`,\n);\nconst NULLISH_CHECK_NO_DDA = template.expression(`%%check%% == null`);\nconst NULLISH_CHECK_NEG = template.expression(\n `%%check%% !== null && %%ref%% !== void 0`,\n);\nconst NULLISH_CHECK_NO_DDA_NEG = template.expression(`%%check%% != null`);\n\ninterface OptionalChainAssumptions {\n pureGetters: boolean;\n noDocumentAll: boolean;\n}\n\nexport function transformOptionalChain(\n path: NodePath<t.OptionalCallExpression | t.OptionalMemberExpression>,\n { pureGetters, noDocumentAll }: OptionalChainAssumptions,\n replacementPath: NodePath<t.Expression>,\n ifNullish: t.Expression,\n wrapLast?: (value: t.Expression) => t.Expression,\n) {\n const { scope } = path;\n\n // Replace `function (a, x = a.b?.c) {}` to `function (a, x = (() => a.b?.c)() ){}`\n // so the temporary variable can be injected in correct scope\n if (scope.path.isPattern() && needsMemoize(path)) {\n replacementPath.replaceWith(\n template.expression.ast`(() => ${replacementPath.node})()`,\n );\n // The injected optional chain will be queued and eventually transformed when visited\n return;\n }\n\n const optionals = [];\n\n let optionalPath = path;\n while (\n optionalPath.isOptionalMemberExpression() ||\n optionalPath.isOptionalCallExpression()\n ) {\n const { node } = optionalPath;\n if (node.optional) {\n optionals.push(node);\n }\n if (optionalPath.isOptionalMemberExpression()) {\n // @ts-expect-error todo(flow->ts) avoid changing more type\n optionalPath.node.type = \"MemberExpression\";\n // @ts-expect-error todo(flow->ts)\n optionalPath = skipTransparentExprWrappers(optionalPath.get(\"object\"));\n } else if (optionalPath.isOptionalCallExpression()) {\n // @ts-expect-error todo(flow->ts) avoid changing more type\n optionalPath.node.type = \"CallExpression\";\n // @ts-expect-error todo(flow->ts)\n optionalPath = skipTransparentExprWrappers(optionalPath.get(\"callee\"));\n }\n }\n\n if (optionals.length === 0) {\n // Malformed AST: there was an OptionalMemberExpression node\n // with no actual optional elements.\n return;\n }\n\n const checks = [];\n\n let tmpVar;\n\n for (let i = optionals.length - 1; i >= 0; i--) {\n const node = optionals[i] as unknown as\n | t.MemberExpression\n | t.CallExpression;\n\n const isCall = t.isCallExpression(node);\n\n const chainWithTypes = isCall\n ? // V8 intrinsics must not be an optional call\n (node.callee as t.Expression)\n : node.object;\n const chain = skipTransparentExprWrapperNodes(chainWithTypes);\n\n let ref;\n let check;\n if (isCall && t.isIdentifier(chain, { name: \"eval\" })) {\n check = ref = chain;\n // `eval?.()` is an indirect eval call transformed to `(0,eval)()`\n node.callee = t.sequenceExpression([t.numericLiteral(0), ref]);\n } else if (pureGetters && isCall && isSimpleMemberExpression(chain)) {\n // If we assume getters are pure (avoiding a Function#call) and we are at the call,\n // we can avoid a needless memoize. We only do this if the callee is a simple member\n // expression, to avoid multiple calls to nested call expressions.\n check = ref = node.callee;\n } else if (scope.isStatic(chain)) {\n check = ref = chainWithTypes;\n } else {\n // We cannot reuse the tmpVar for calls, because we need to\n // store both the method and the receiver.\n if (!tmpVar || isCall) {\n tmpVar = scope.generateUidIdentifierBasedOnNode(chain);\n scope.push({ id: t.cloneNode(tmpVar) });\n }\n ref = tmpVar;\n check = t.assignmentExpression(\n \"=\",\n t.cloneNode(tmpVar),\n // Here `chainWithTypes` MUST NOT be cloned because it could be\n // updated when generating the memoised context of a call\n // expression. It must be an Expression when `ref` is an identifier\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion\n chainWithTypes as t.Expression,\n );\n\n if (isCall) {\n node.callee = ref;\n } else {\n node.object = ref;\n }\n }\n\n // Ensure call expressions have the proper `this`\n // `foo.bar()` has context `foo`.\n if (isCall && t.isMemberExpression(chain)) {\n if (pureGetters && isSimpleMemberExpression(chain)) {\n // To avoid a Function#call, we can instead re-grab the property from the context object.\n // `a.?b.?()` translates roughly to `_a.b != null && _a.b()`\n node.callee = chainWithTypes;\n } else {\n // Otherwise, we need to memoize the context object, and change the call into a Function#call.\n // `a.?b.?()` translates roughly to `(_b = _a.b) != null && _b.call(_a)`\n const { object } = chain;\n let context: t.Expression;\n if (t.isSuper(object)) {\n context = t.thisExpression();\n } else {\n const memoized = scope.maybeGenerateMemoised(object);\n if (memoized) {\n context = memoized;\n chain.object = t.assignmentExpression(\"=\", memoized, object);\n } else {\n context = object;\n }\n }\n\n node.arguments.unshift(t.cloneNode(context));\n // @ts-expect-error node.callee can not be an V8IntrinsicIdentifier: V8 intrinsic is disallowed in optional chain\n node.callee = t.memberExpression(node.callee, t.identifier(\"call\"));\n }\n }\n\n const data = { check: t.cloneNode(check), ref: t.cloneNode(ref) };\n // We make `ref` non-enumerable, so that @babel/template doesn't throw\n // in the noDocumentAll template if it's not used.\n Object.defineProperty(data, \"ref\", { enumerable: false });\n checks.push(data);\n }\n\n let result = replacementPath.node;\n if (wrapLast) result = wrapLast(result);\n\n const ifNullishBoolean = t.isBooleanLiteral(ifNullish);\n const ifNullishFalse = ifNullishBoolean && ifNullish.value === false;\n const ifNullishVoid =\n !ifNullishBoolean && t.isUnaryExpression(ifNullish, { operator: \"void\" });\n\n const isEvaluationValueIgnored =\n (t.isExpressionStatement(replacementPath.parent) &&\n !replacementPath.isCompletionRecord()) ||\n (t.isSequenceExpression(replacementPath.parent) &&\n last(replacementPath.parent.expressions) !== replacementPath.node);\n\n // prettier-ignore\n const tpl = ifNullishFalse\n ? (noDocumentAll ? NULLISH_CHECK_NO_DDA_NEG : NULLISH_CHECK_NEG)\n : (noDocumentAll ? NULLISH_CHECK_NO_DDA : NULLISH_CHECK);\n const logicalOp = ifNullishFalse ? \"&&\" : \"||\";\n\n const check = checks\n .map(tpl)\n .reduce((expr, check) => t.logicalExpression(logicalOp, expr, check));\n\n replacementPath.replaceWith(\n ifNullishBoolean || (ifNullishVoid && isEvaluationValueIgnored)\n ? t.logicalExpression(logicalOp, check, result)\n : t.conditionalExpression(check, ifNullish, result),\n );\n}\n\nexport function transform(\n path: NodePath<t.OptionalCallExpression | t.OptionalMemberExpression>,\n assumptions: OptionalChainAssumptions,\n) {\n const { scope } = path;\n\n // maybeWrapped points to the outermost transparent expression wrapper\n // or the path itself\n const maybeWrapped = findOutermostTransparentParent(path);\n const { parentPath } = maybeWrapped;\n\n if (parentPath.isUnaryExpression({ operator: \"delete\" })) {\n transformOptionalChain(\n path,\n assumptions,\n parentPath,\n t.booleanLiteral(true),\n );\n } else {\n let wrapLast;\n if (\n parentPath.isCallExpression({ callee: maybeWrapped.node }) &&\n // note that the first condition must implies that `path.optional` is `true`,\n // otherwise the parentPath should be an OptionalCallExpression\n path.isOptionalMemberExpression()\n ) {\n // Ensure (a?.b)() has proper `this`\n wrapLast = (replacement: t.MemberExpression) => {\n // `(a?.b)()` to `(a == null ? undefined : a.b.bind(a))()`\n // object must not be Super as super?.foo is invalid\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion\n const object = skipTransparentExprWrapperNodes(\n replacement.object,\n ) as t.Expression;\n let baseRef: t.Expression;\n if (!assumptions.pureGetters || !isSimpleMemberExpression(object)) {\n // memoize the context object when getters are not always pure\n // or the object is not a simple member expression\n // `(a?.b.c)()` to `(a == null ? undefined : (_a$b = a.b).c.bind(_a$b))()`\n baseRef = scope.maybeGenerateMemoised(object);\n if (baseRef) {\n replacement.object = t.assignmentExpression(\"=\", baseRef, object);\n }\n }\n return t.callExpression(\n t.memberExpression(replacement, t.identifier(\"bind\")),\n [t.cloneNode(baseRef ?? object)],\n );\n };\n }\n\n transformOptionalChain(\n path,\n assumptions,\n path,\n willPathCastToBoolean(maybeWrapped)\n ? t.booleanLiteral(false)\n : scope.buildUndefinedNode(),\n wrapLast,\n );\n }\n}\n","import { declare } from \"@babel/helper-plugin-utils\";\nimport { transform, transformOptionalChain } from \"./transform.ts\";\nimport type { NodePath, types as t } from \"@babel/core\";\n\nexport interface Options {\n loose?: boolean;\n}\nexport default declare((api, options: Options) => {\n api.assertVersion(REQUIRED_VERSION(\"^7.0.0-0 || ^8.0.0-0\"));\n\n const { loose = false } = options;\n const noDocumentAll = api.assumption(\"noDocumentAll\") ?? loose;\n const pureGetters = api.assumption(\"pureGetters\") ?? loose;\n\n return {\n name: \"transform-optional-chaining\",\n manipulateOptions: process.env.BABEL_8_BREAKING\n ? undefined\n : (_, parser) => parser.plugins.push(\"optionalChaining\"),\n\n visitor: {\n \"OptionalCallExpression|OptionalMemberExpression\"(\n path: NodePath<t.OptionalCallExpression | t.OptionalMemberExpression>,\n ) {\n transform(path, { noDocumentAll, pureGetters });\n },\n },\n };\n});\n\nexport { transform, transformOptionalChain };\n"],"names":["willPathCastToBoolean","path","maybeWrapped","findOutermostTransparentParent","node","parentPath","isLogicalExpression","operator","right","isSequenceExpression","expressions","length","isConditional","test","isUnaryExpression","isForStatement","isWhile","findParent","p","isTransparentExprWrapper","last","arr","isSimpleMemberExpression","expression","skipTransparentExprWrapperNodes","t","isIdentifier","isSuper","isMemberExpression","computed","object","needsMemoize","optionalPath","scope","isOptionalMemberExpression","isOptionalCallExpression","childPath","skipTransparentExprWrappers","get","optional","isStatic","NULLISH_CHECK","template","NULLISH_CHECK_NO_DDA","NULLISH_CHECK_NEG","NULLISH_CHECK_NO_DDA_NEG","transformOptionalChain","pureGetters","noDocumentAll","replacementPath","ifNullish","wrapLast","isPattern","replaceWith","ast","optionals","push","type","checks","tmpVar","i","isCall","isCallExpression","chainWithTypes","callee","chain","ref","check","name","sequenceExpression","numericLiteral","generateUidIdentifierBasedOnNode","id","cloneNode","assignmentExpression","context","thisExpression","memoized","maybeGenerateMemoised","arguments","unshift","memberExpression","identifier","data","Object","defineProperty","enumerable","result","ifNullishBoolean","isBooleanLiteral","ifNullishFalse","value","ifNullishVoid","isEvaluationValueIgnored","isExpressionStatement","parent","isCompletionRecord","tpl","logicalOp","map","reduce","expr","logicalExpression","conditionalExpression","transform","assumptions","booleanLiteral","replacement","baseRef","callExpression","buildUndefinedNode","declare","api","options","_api$assumption","_api$assumption2","assertVersion","loose","assumption","manipulateOptions","_","parser","plugins","visitor","OptionalCallExpression|OptionalMemberExpression"],"mappings":";;;;;;;;AAiBO,SAASA,qBAAqBA,CAACC,IAAc,EAAW;AAC7D,EAAA,MAAMC,YAAY,GAAGC,8BAA8B,CAACF,IAAI,CAAC,CAAA;EACzD,MAAM;IAAEG,IAAI;AAAEC,IAAAA,UAAAA;AAAW,GAAC,GAAGH,YAAY,CAAA;AACzC,EAAA,IAAIG,UAAU,CAACC,mBAAmB,EAAE,EAAE;IACpC,MAAM;MAAEC,QAAQ;AAAEC,MAAAA,KAAAA;KAAO,GAAGH,UAAU,CAACD,IAAI,CAAA;AAC3C,IAAA,IACEG,QAAQ,KAAK,I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;"}
1
+ {"version":3,"file":"index.js","sources":["../src/util.ts","../src/transform.ts","../src/index.ts"],"sourcesContent":["import type { NodePath } from \"@babel/core\";\nimport { isTransparentExprWrapper } from \"@babel/helper-skip-transparent-expression-wrappers\";\n/**\n * Test if a NodePath will be cast to boolean when evaluated.\n * It respects transparent expression wrappers defined in\n * \"@babel/helper-skip-transparent-expression-wrappers\"\n *\n * @example\n * // returns true\n * const nodePathADotB = NodePath(\"if (a.b) {}\").get(\"test\"); // a.b\n * willPathCastToBoolean(nodePathADotB)\n * @example\n * // returns false\n * willPathCastToBoolean(NodePath(\"a.b\"))\n * @param {NodePath} path\n * @returns {boolean}\n */\nexport function willPathCastToBoolean(path: NodePath): boolean {\n const maybeWrapped = findOutermostTransparentParent(path);\n const { node, parentPath } = maybeWrapped;\n if (parentPath.isLogicalExpression()) {\n const { operator, right } = parentPath.node;\n if (\n operator === \"&&\" ||\n operator === \"||\" ||\n (operator === \"??\" && node === right)\n ) {\n return willPathCastToBoolean(parentPath);\n }\n }\n if (parentPath.isSequenceExpression()) {\n const { expressions } = parentPath.node;\n if (expressions[expressions.length - 1] === node) {\n return willPathCastToBoolean(parentPath);\n } else {\n // if it is in the middle of a sequence expression, we don't\n // care the return value so just cast to boolean for smaller\n // output\n return true;\n }\n }\n return (\n parentPath.isConditional({ test: node }) ||\n parentPath.isUnaryExpression({ operator: \"!\" }) ||\n parentPath.isForStatement({ test: node }) ||\n parentPath.isWhile({ test: node })\n );\n}\n\n/**\n * Return the outermost transparent expression wrapper of a given path,\n * otherwise returns path itself.\n * @example\n * const nodePathADotB = NodePath(\"(a.b as any)\").get(\"expression\"); // a.b\n * // returns NodePath(\"(a.b as any)\")\n * findOutermostTransparentParent(nodePathADotB);\n * @param {NodePath} path\n * @returns {NodePath}\n */\nexport function findOutermostTransparentParent(path: NodePath): NodePath {\n let maybeWrapped = path;\n path.findParent(p => {\n if (!isTransparentExprWrapper(p.node)) return true;\n maybeWrapped = p;\n });\n return maybeWrapped;\n}\n","import { types as t, template, type NodePath, type Scope } from \"@babel/core\";\nimport {\n skipTransparentExprWrapperNodes,\n skipTransparentExprWrappers,\n} from \"@babel/helper-skip-transparent-expression-wrappers\";\nimport {\n willPathCastToBoolean,\n findOutermostTransparentParent,\n} from \"./util.ts\";\n\n// TODO(Babel 9): Use .at(-1)\nconst last = <T>(arr: T[]) => arr[arr.length - 1];\n\nfunction isSimpleMemberExpression(\n expression: t.Expression | t.Super,\n): expression is t.Identifier | t.Super | t.MemberExpression {\n expression = skipTransparentExprWrapperNodes(expression);\n return (\n t.isIdentifier(expression) ||\n t.isSuper(expression) ||\n (t.isMemberExpression(expression) &&\n !expression.computed &&\n isSimpleMemberExpression(expression.object))\n );\n}\n\n/**\n * Like `scope.isStatic`, but also accepts all the bindings. Reassigned\n * bindings and imports (which the exporting module might reassign) can change\n * value, but no code can run between the nullish check of an optional chain\n * and the following access, so it's safe to read them twice there.\n * Reading an undeclared global might trigger a getter on `globalThis`, so we\n * only read it twice with the `pureGetters` assumption.\n *\n * Do not use this for the `this` context of calls: `a.b?.()` evaluates the `b`\n * getter between the two reads of `a`.\n */\nfunction isStaticForNullishCheck(\n scope: Scope,\n node: t.Node,\n pureGetters: boolean,\n) {\n if (t.isIdentifier(node)) {\n return pureGetters || scope.hasBinding(node.name);\n }\n return scope.isStatic(node);\n}\n\n/**\n * Test if a given optional chain `path` needs to be memoized\n * @param {NodePath} path\n * @returns {boolean}\n */\nfunction needsMemoize(\n path: NodePath<t.OptionalCallExpression | t.OptionalMemberExpression>,\n pureGetters: boolean,\n) {\n let optionalPath: NodePath = path;\n const { scope } = path;\n while (\n optionalPath.isOptionalMemberExpression() ||\n optionalPath.isOptionalCallExpression()\n ) {\n const { node } = optionalPath;\n const childPath = skipTransparentExprWrappers(\n optionalPath.isOptionalMemberExpression()\n ? optionalPath.get(\"object\")\n : optionalPath.get(\"callee\"),\n );\n if (node.optional) {\n return !isStaticForNullishCheck(scope, childPath.node, pureGetters);\n }\n\n optionalPath = childPath;\n }\n}\n\nconst NULLISH_CHECK = template.expression(\n `%%check%% === null || %%ref%% === void 0`,\n);\nconst NULLISH_CHECK_NO_DDA = template.expression(`%%check%% == null`);\nconst NULLISH_CHECK_NEG = template.expression(\n `%%check%% !== null && %%ref%% !== void 0`,\n);\nconst NULLISH_CHECK_NO_DDA_NEG = template.expression(`%%check%% != null`);\n\ninterface OptionalChainAssumptions {\n pureGetters: boolean;\n noDocumentAll: boolean;\n}\n\nexport function transformOptionalChain(\n path: NodePath<t.OptionalCallExpression | t.OptionalMemberExpression>,\n { pureGetters, noDocumentAll }: OptionalChainAssumptions,\n replacementPath: NodePath<t.Expression>,\n ifNullish: t.Expression,\n wrapLast?: (value: t.Expression) => t.Expression,\n) {\n const { scope } = path;\n\n // Replace `function (a, x = a.b?.c) {}` to `function (a, x = (() => a.b?.c)() ){}`\n // so the temporary variable can be injected in correct scope\n if (scope.path.isPattern() && needsMemoize(path, pureGetters)) {\n replacementPath.replaceWith(\n template.expression.ast`(() => ${replacementPath.node})()`,\n );\n // The injected optional chain will be queued and eventually transformed when visited\n return;\n }\n\n const optionals = [];\n\n let optionalPath = path;\n while (\n optionalPath.isOptionalMemberExpression() ||\n optionalPath.isOptionalCallExpression()\n ) {\n const { node } = optionalPath;\n if (node.optional) {\n optionals.push(node);\n }\n if (optionalPath.isOptionalMemberExpression()) {\n // @ts-expect-error todo(flow->ts) avoid changing more type\n optionalPath.node.type = \"MemberExpression\";\n // @ts-expect-error todo(flow->ts)\n optionalPath = skipTransparentExprWrappers(optionalPath.get(\"object\"));\n } else if (optionalPath.isOptionalCallExpression()) {\n // @ts-expect-error todo(flow->ts) avoid changing more type\n optionalPath.node.type = \"CallExpression\";\n // @ts-expect-error todo(flow->ts)\n optionalPath = skipTransparentExprWrappers(optionalPath.get(\"callee\"));\n }\n }\n\n if (optionals.length === 0) {\n // Malformed AST: there was an OptionalMemberExpression node\n // with no actual optional elements.\n return;\n }\n\n const checks = [];\n\n let tmpVar;\n\n for (let i = optionals.length - 1; i >= 0; i--) {\n const node = optionals[i] as unknown as\n | t.MemberExpression\n | t.CallExpression;\n\n const isCall = t.isCallExpression(node);\n\n const chainWithTypes = isCall\n ? // V8 intrinsics must not be an optional call\n (node.callee as t.Expression)\n : node.object;\n const chain = skipTransparentExprWrapperNodes(chainWithTypes);\n\n let ref;\n let check;\n if (isCall && t.isIdentifier(chain, { name: \"eval\" })) {\n check = ref = chain;\n // `eval?.()` is an indirect eval call transformed to `(0,eval)()`\n node.callee = t.sequenceExpression([t.numericLiteral(0), ref]);\n } else if (pureGetters && isCall && isSimpleMemberExpression(chain)) {\n // If we assume getters are pure (avoiding a Function#call) and we are at the call,\n // we can avoid a needless memoize. We only do this if the callee is a simple member\n // expression, to avoid multiple calls to nested call expressions.\n check = ref = node.callee;\n } else if (isStaticForNullishCheck(scope, chain, pureGetters)) {\n check = ref = chainWithTypes;\n } else {\n // We cannot reuse the tmpVar for calls, because we need to\n // store both the method and the receiver.\n if (!tmpVar || isCall) {\n tmpVar = scope.generateUidIdentifierBasedOnNode(chain);\n scope.push({ id: t.cloneNode(tmpVar) });\n }\n ref = tmpVar;\n check = t.assignmentExpression(\n \"=\",\n t.cloneNode(tmpVar),\n // Here `chainWithTypes` MUST NOT be cloned because it could be\n // updated when generating the memoised context of a call\n // expression. It must be an Expression when `ref` is an identifier\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion\n chainWithTypes as t.Expression,\n );\n\n if (isCall) {\n node.callee = ref;\n } else {\n node.object = ref;\n }\n }\n\n // Ensure call expressions have the proper `this`\n // `foo.bar()` has context `foo`.\n if (isCall && t.isMemberExpression(chain)) {\n if (pureGetters && isSimpleMemberExpression(chain)) {\n // To avoid a Function#call, we can instead re-grab the property from the context object.\n // `a.?b.?()` translates roughly to `_a.b != null && _a.b()`\n node.callee = chainWithTypes;\n } else {\n // Otherwise, we need to memoize the context object, and change the call into a Function#call.\n // `a.?b.?()` translates roughly to `(_b = _a.b) != null && _b.call(_a)`\n const { object } = chain;\n let context: t.Expression;\n if (t.isSuper(object)) {\n context = t.thisExpression();\n } else {\n const memoized = scope.maybeGenerateMemoised(object);\n if (memoized) {\n context = memoized;\n chain.object = t.assignmentExpression(\"=\", memoized, object);\n } else {\n context = object;\n }\n }\n\n node.arguments.unshift(t.cloneNode(context));\n // @ts-expect-error node.callee can not be an V8IntrinsicIdentifier: V8 intrinsic is disallowed in optional chain\n node.callee = t.memberExpression(node.callee, t.identifier(\"call\"));\n }\n }\n\n const data = { check: t.cloneNode(check), ref: t.cloneNode(ref) };\n // We make `ref` non-enumerable, so that @babel/template doesn't throw\n // in the noDocumentAll template if it's not used.\n Object.defineProperty(data, \"ref\", { enumerable: false });\n checks.push(data);\n }\n\n let result = replacementPath.node;\n if (wrapLast) result = wrapLast(result);\n\n const ifNullishBoolean = t.isBooleanLiteral(ifNullish);\n const ifNullishFalse = ifNullishBoolean && ifNullish.value === false;\n const ifNullishVoid =\n !ifNullishBoolean && t.isUnaryExpression(ifNullish, { operator: \"void\" });\n\n const isEvaluationValueIgnored =\n (t.isExpressionStatement(replacementPath.parent) &&\n !replacementPath.isCompletionRecord()) ||\n (t.isSequenceExpression(replacementPath.parent) &&\n last(replacementPath.parent.expressions) !== replacementPath.node);\n\n // prettier-ignore\n const tpl = ifNullishFalse\n ? (noDocumentAll ? NULLISH_CHECK_NO_DDA_NEG : NULLISH_CHECK_NEG)\n : (noDocumentAll ? NULLISH_CHECK_NO_DDA : NULLISH_CHECK);\n const logicalOp = ifNullishFalse ? \"&&\" : \"||\";\n\n const check = checks\n .map(tpl)\n .reduce((expr, check) => t.logicalExpression(logicalOp, expr, check));\n\n replacementPath.replaceWith(\n ifNullishBoolean || (ifNullishVoid && isEvaluationValueIgnored)\n ? t.logicalExpression(logicalOp, check, result)\n : t.conditionalExpression(check, ifNullish, result),\n );\n}\n\nexport function transform(\n path: NodePath<t.OptionalCallExpression | t.OptionalMemberExpression>,\n assumptions: OptionalChainAssumptions,\n) {\n const { scope } = path;\n\n // maybeWrapped points to the outermost transparent expression wrapper\n // or the path itself\n const maybeWrapped = findOutermostTransparentParent(path);\n const { parentPath } = maybeWrapped;\n\n if (parentPath.isUnaryExpression({ operator: \"delete\" })) {\n transformOptionalChain(\n path,\n assumptions,\n parentPath,\n t.booleanLiteral(true),\n );\n } else {\n let wrapLast;\n if (\n parentPath.isCallExpression({ callee: maybeWrapped.node }) &&\n // note that the first condition must implies that `path.optional` is `true`,\n // otherwise the parentPath should be an OptionalCallExpression\n path.isOptionalMemberExpression()\n ) {\n // Ensure (a?.b)() has proper `this`\n wrapLast = (replacement: t.MemberExpression) => {\n // `(a?.b)()` to `(a == null ? undefined : a.b.bind(a))()`\n // object must not be Super as super?.foo is invalid\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion\n const object = skipTransparentExprWrapperNodes(\n replacement.object,\n ) as t.Expression;\n let baseRef: t.Expression;\n if (!assumptions.pureGetters || !isSimpleMemberExpression(object)) {\n // memoize the context object when getters are not always pure\n // or the object is not a simple member expression\n // `(a?.b.c)()` to `(a == null ? undefined : (_a$b = a.b).c.bind(_a$b))()`\n baseRef = scope.maybeGenerateMemoised(object);\n if (baseRef) {\n replacement.object = t.assignmentExpression(\"=\", baseRef, object);\n }\n }\n return t.callExpression(\n t.memberExpression(replacement, t.identifier(\"bind\")),\n [t.cloneNode(baseRef ?? object)],\n );\n };\n }\n\n transformOptionalChain(\n path,\n assumptions,\n path,\n willPathCastToBoolean(maybeWrapped)\n ? t.booleanLiteral(false)\n : scope.buildUndefinedNode(),\n wrapLast,\n );\n }\n}\n","import { declare } from \"@babel/helper-plugin-utils\";\nimport { transform, transformOptionalChain } from \"./transform.ts\";\nimport type { NodePath, types as t } from \"@babel/core\";\n\nexport interface Options {\n loose?: boolean;\n}\nexport default declare((api, options: Options) => {\n api.assertVersion(REQUIRED_VERSION(\"^7.0.0-0 || ^8.0.0-0\"));\n\n const { loose = false } = options;\n const noDocumentAll = api.assumption(\"noDocumentAll\") ?? loose;\n const pureGetters = api.assumption(\"pureGetters\") ?? loose;\n\n return {\n name: \"transform-optional-chaining\",\n manipulateOptions: process.env.BABEL_8_BREAKING\n ? undefined\n : (_, parser) => parser.plugins.push(\"optionalChaining\"),\n\n visitor: {\n \"OptionalCallExpression|OptionalMemberExpression\"(\n path: NodePath<t.OptionalCallExpression | t.OptionalMemberExpression>,\n ) {\n transform(path, { noDocumentAll, pureGetters });\n },\n },\n };\n});\n\nexport { transform, transformOptionalChain };\n"],"names":["willPathCastToBoolean","path","maybeWrapped","findOutermostTransparentParent","node","parentPath","isLogicalExpression","operator","right","isSequenceExpression","expressions","length","isConditional","test","isUnaryExpression","isForStatement","isWhile","findParent","p","isTransparentExprWrapper","last","arr","isSimpleMemberExpression","expression","skipTransparentExprWrapperNodes","t","isIdentifier","isSuper","isMemberExpression","computed","object","isStaticForNullishCheck","scope","pureGetters","hasBinding","name","isStatic","needsMemoize","optionalPath","isOptionalMemberExpression","isOptionalCallExpression","childPath","skipTransparentExprWrappers","get","optional","NULLISH_CHECK","template","NULLISH_CHECK_NO_DDA","NULLISH_CHECK_NEG","NULLISH_CHECK_NO_DDA_NEG","transformOptionalChain","noDocumentAll","replacementPath","ifNullish","wrapLast","isPattern","replaceWith","ast","optionals","push","type","checks","tmpVar","i","isCall","isCallExpression","chainWithTypes","callee","chain","ref","check","sequenceExpression","numericLiteral","generateUidIdentifierBasedOnNode","id","cloneNode","assignmentExpression","context","thisExpression","memoized","maybeGenerateMemoised","arguments","unshift","memberExpression","identifier","data","Object","defineProperty","enumerable","result","ifNullishBoolean","isBooleanLiteral","ifNullishFalse","value","ifNullishVoid","isEvaluationValueIgnored","isExpressionStatement","parent","isCompletionRecord","tpl","logicalOp","map","reduce","expr","logicalExpression","conditionalExpression","transform","assumptions","booleanLiteral","replacement","baseRef","callExpression","buildUndefinedNode","declare","api","options","_api$assumption","_api$assumption2","assertVersion","loose","assumption","manipulateOptions","_","parser","plugins","visitor","OptionalCallExpression|OptionalMemberExpression"],"mappings":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AAC,CAAA;EAE3D,MAAM;AAAEC,IAAAA,KAAK,GAAG,KAAA;AAAM,GAAC,GAAGJ,OAAO,CAAA;AACjC,EAAA,MAAMhE,aAAa,GAAA,CAAAiE,eAAA,GAAGF,GAAG,CAACM,UAAU,CAAC,eAAe,CAAC,KAAAJ,IAAAA,GAAAA,eAAA,GAAIG,KAAK,CAAA;AAC9D,EAAA,MAAMtF,WAAW,GAAA,CAAAoF,gBAAA,GAAGH,GAAG,CAACM,UAAU,CAAC,aAAa,CAAC,KAAAH,IAAAA,GAAAA,gBAAA,GAAIE,KAAK,CAAA;EAE1D,OAAO;AACLpF,IAAAA,IAAI,EAAE,6BAA6B;AACnCsF,IAAAA,iBAAiB,EAEbA,CAACC,CAAC,EAAEC,MAAM,KAAKA,MAAM,CAACC,OAAO,CAACjE,IAAI,CAAC,kBAAkB,CAAC;AAE1DkE,IAAAA,OAAO,EAAE;MACP,iDAAiDC,CAC/C7H,IAAqE,EACrE;QACAyG,SAAS,CAACzG,IAAI,EAAE;UAAEkD,aAAa;AAAElB,UAAAA,WAAAA;AAAY,SAAC,CAAC,CAAA;AACjD,OAAA;AACF,KAAA;GACD,CAAA;AACH,CAAC,CAAC;;;;;;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@babel/plugin-transform-optional-chaining",
3
- "version": "7.28.6",
3
+ "version": "7.29.16",
4
4
  "description": "Transform optional chaining operators into a series of nil checks",
5
5
  "repository": {
6
6
  "type": "git",
@@ -17,17 +17,17 @@
17
17
  "babel-plugin"
18
18
  ],
19
19
  "dependencies": {
20
- "@babel/helper-plugin-utils": "^7.28.6",
21
- "@babel/helper-skip-transparent-expression-wrappers": "^7.27.1"
20
+ "@babel/helper-plugin-utils": "^7.29.7",
21
+ "@babel/helper-skip-transparent-expression-wrappers": "^7.29.13"
22
22
  },
23
23
  "peerDependencies": {
24
24
  "@babel/core": "^7.0.0-0"
25
25
  },
26
26
  "devDependencies": {
27
- "@babel/core": "^7.28.6",
28
- "@babel/helper-plugin-test-runner": "^7.27.1",
29
- "@babel/plugin-transform-block-scoping": "^7.28.6",
30
- "@babel/traverse": "^7.28.6"
27
+ "@babel/core": "^7.29.16",
28
+ "@babel/helper-plugin-test-runner": "^7.29.7",
29
+ "@babel/plugin-transform-block-scoping": "^7.29.16",
30
+ "@babel/traverse": "^7.29.16"
31
31
  },
32
32
  "engines": {
33
33
  "node": ">=6.9.0"