| 1 | import { skipTransparentExprWrappersscip-typescript npm @babel/helper-skip-transparent-expression-wrappers 7.20.0 src/`index.ts`/skipTransparentExprWrappers(). } from "@babel/helper-skip-transparent-expression-wrappers"scip-typescript npm @babel/helper-skip-transparent-expression-wrappers 7.20.0 src/`index.ts`/; |
| 2 | import type { NodePathscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath# } from "@babel/traverse"scip-typescript npm @babel/traverse 7.20.13 src/`index.ts`/; |
| 3 | import { types as tscip-typescript npm @babel/types 7.20.7 src/`index.ts`/ } from "@babel/core"scip-typescript npm @babel/core 7.20.12 src/`index.ts`/; |
| 4 | // https://crbug.com/v8/11558 |
| 5 | |
| 6 | // check if there is a spread element followed by another argument. |
| 7 | // (...[], 0) or (...[], ...[]) |
| 8 | |
| 9 | function matchAffectedArgumentsscip-typescript npm @babel/plugin-bugfix-v8-spread-parameters-in-optional-chaining 7.20.7 src/`util.ts`/matchAffectedArguments().(argumentNodesscip-typescript npm @babel/plugin-bugfix-v8-spread-parameters-in-optional-chaining 7.20.7 src/`util.ts`/matchAffectedArguments().(argumentNodes): tscip-typescript npm @babel/types 7.20.7 src/`index.ts`/.CallExpressionscip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/CallExpression#["arguments"scip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/CallExpression#arguments.]) { |
| 10 | const spreadIndex = argumentNodesscip-typescript npm @babel/plugin-bugfix-v8-spread-parameters-in-optional-chaining 7.20.7 src/`util.ts`/matchAffectedArguments().(argumentNodes).findIndexscip-typescript npm typescript 5.9.3 lib/`lib.es2015.core.d.ts`/Array#findIndex().(node => tscip-typescript npm @babel/types 7.20.7 src/`index.ts`/.isSpreadElementscip-typescript npm @babel/types 7.20.7 src/validators/generated/`index.ts`/isSpreadElement().(node)); |
| 11 | return spreadIndex >= 0 && spreadIndex !== argumentNodesscip-typescript npm @babel/plugin-bugfix-v8-spread-parameters-in-optional-chaining 7.20.7 src/`util.ts`/matchAffectedArguments().(argumentNodes).lengthscip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/Array#length. - 1; |
| 12 | } |
| 13 | |
| 14 | /** |
| 15 | * Check whether the optional chain is affected by https://crbug.com/v8/11558. |
| 16 | * This routine MUST not manipulate NodePath |
| 17 | * |
| 18 | * @export |
| 19 | * @param {(NodePath<t.OptionalMemberExpression | t.OptionalCallExpression>)} path |
| 20 | * @returns {boolean} |
| 21 | */ |
| 22 | export function shouldTransformscip-typescript npm @babel/plugin-bugfix-v8-spread-parameters-in-optional-chaining 7.20.7 src/`util.ts`/shouldTransform().( |
| 23 | pathscip-typescript npm @babel/plugin-bugfix-v8-spread-parameters-in-optional-chaining 7.20.7 src/`util.ts`/shouldTransform().(path): NodePathscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#<tscip-typescript npm @babel/types 7.20.7 src/`index.ts`/.OptionalMemberExpressionscip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/OptionalMemberExpression# | tscip-typescript npm @babel/types 7.20.7 src/`index.ts`/.OptionalCallExpressionscip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/OptionalCallExpression#>, |
| 24 | ): boolean { |
| 25 | let optionalPath: NodePathscip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#<tscip-typescript npm @babel/types 7.20.7 src/`index.ts`/.Expressionscip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/Expression#> = pathscip-typescript npm @babel/plugin-bugfix-v8-spread-parameters-in-optional-chaining 7.20.7 src/`util.ts`/shouldTransform().(path); |
| 26 | const chains: (tscip-typescript npm @babel/types 7.20.7 src/`index.ts`/.OptionalCallExpressionscip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/OptionalCallExpression# | tscip-typescript npm @babel/types 7.20.7 src/`index.ts`/.OptionalMemberExpressionscip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/OptionalMemberExpression#)[] = []; |
| 27 | for (;;) { |
| 28 | if (optionalPath.isOptionalMemberExpressionscip-typescript npm @babel/traverse 7.20.13 src/path/generated/`validators.d.ts`/BaseNodePathValidators#isOptionalMemberExpression().()) { |
| 29 | chains.pushscip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/Array#push().(optionalPath.nodescip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#node.); |
| 30 | optionalPath = skipTransparentExprWrappersscip-typescript npm @babel/helper-skip-transparent-expression-wrappers 7.20.0 src/`index.ts`/skipTransparentExprWrappers().(optionalPath.get("object")); |
| 31 | } else if (optionalPath.isOptionalCallExpressionscip-typescript npm @babel/traverse 7.20.13 src/path/generated/`validators.d.ts`/BaseNodePathValidators#isOptionalCallExpression().()) { |
| 32 | chains.pushscip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/Array#push().(optionalPath.nodescip-typescript npm @babel/traverse 7.20.13 src/path/`index.ts`/NodePath#node.); |
| 33 | optionalPath = skipTransparentExprWrappersscip-typescript npm @babel/helper-skip-transparent-expression-wrappers 7.20.0 src/`index.ts`/skipTransparentExprWrappers().(optionalPath.get("callee")); |
| 34 | } else { |
| 35 | break; |
| 36 | } |
| 37 | } |
| 38 | for (let i = 0; i < chains.lengthscip-typescript npm typescript 5.9.3 lib/`lib.es5.d.ts`/Array#length.; i++) { |
| 39 | const node = chains[i]; |
| 40 | if ( |
| 41 | tscip-typescript npm @babel/types 7.20.7 src/`index.ts`/.isOptionalCallExpressionscip-typescript npm @babel/types 7.20.7 src/validators/generated/`index.ts`/isOptionalCallExpression().(node) && |
| 42 | matchAffectedArgumentsscip-typescript npm @babel/plugin-bugfix-v8-spread-parameters-in-optional-chaining 7.20.7 src/`util.ts`/matchAffectedArguments().(node.argumentsscip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/OptionalCallExpression#arguments.) |
| 43 | ) { |
| 44 | // f?.(...[], 0) |
| 45 | if (node.optionalscip-typescript npm @babel/types 7.20.7 src/ast-types/generated/`index.ts`/OptionalCallExpression#optional.) { |
| 46 | return true; |
| 47 | } |
| 48 | // o?.m(...[], 0) |
| 49 | // when node.optional is false, chains[i + 1] is always well defined |
| 50 | const callee = chains[i + 1]; |
| 51 | if (tscip-typescript npm @babel/types 7.20.7 src/`index.ts`/.isOptionalMemberExpressionscip-typescript npm @babel/types 7.20.7 src/validators/generated/`index.ts`/isOptionalMemberExpression().(callee, { optionalscip-typescript npm @babel/plugin-bugfix-v8-spread-parameters-in-optional-chaining 7.20.7 src/`util.ts`/optional0:: true })) { |
| 52 | return true; |
| 53 | } |
| 54 | } |
| 55 | } |
| 56 | return false; |
| 57 | } |