(statements, node, copyOnWrite)
| 99535 | ts.insertStatementAfterCustomPrologue(statements, captureThisStatement); |
| 99536 | } |
| 99537 | function insertCaptureNewTargetIfNeeded(statements, node, copyOnWrite) { |
| 99538 | if (hierarchyFacts & 32768 /* HierarchyFacts.NewTarget */) { |
| 99539 | var newTarget = void 0; |
| 99540 | switch (node.kind) { |
| 99541 | case 214 /* SyntaxKind.ArrowFunction */: |
| 99542 | return statements; |
| 99543 | case 169 /* SyntaxKind.MethodDeclaration */: |
| 99544 | case 172 /* SyntaxKind.GetAccessor */: |
| 99545 | case 173 /* SyntaxKind.SetAccessor */: |
| 99546 | // Methods and accessors cannot be constructors, so 'new.target' will |
| 99547 | // always return 'undefined'. |
| 99548 | newTarget = factory.createVoidZero(); |
| 99549 | break; |
| 99550 | case 171 /* SyntaxKind.Constructor */: |
| 99551 | // Class constructors can only be called with `new`, so `this.constructor` |
| 99552 | // should be relatively safe to use. |
| 99553 | newTarget = factory.createPropertyAccessExpression(ts.setEmitFlags(factory.createThis(), 4 /* EmitFlags.NoSubstitution */), "constructor"); |
| 99554 | break; |
| 99555 | case 256 /* SyntaxKind.FunctionDeclaration */: |
| 99556 | case 213 /* SyntaxKind.FunctionExpression */: |
| 99557 | // Functions can be called or constructed, and may have a `this` due to |
| 99558 | // being a member or when calling an imported function via `other_1.f()`. |
| 99559 | newTarget = factory.createConditionalExpression(factory.createLogicalAnd(ts.setEmitFlags(factory.createThis(), 4 /* EmitFlags.NoSubstitution */), factory.createBinaryExpression(ts.setEmitFlags(factory.createThis(), 4 /* EmitFlags.NoSubstitution */), 102 /* SyntaxKind.InstanceOfKeyword */, factory.getLocalName(node))), |
| 99560 | /*questionToken*/ undefined, factory.createPropertyAccessExpression(ts.setEmitFlags(factory.createThis(), 4 /* EmitFlags.NoSubstitution */), "constructor"), |
| 99561 | /*colonToken*/ undefined, factory.createVoidZero()); |
| 99562 | break; |
| 99563 | default: |
| 99564 | return ts.Debug.failBadSyntaxKind(node); |
| 99565 | } |
| 99566 | var captureNewTargetStatement = factory.createVariableStatement( |
| 99567 | /*modifiers*/ undefined, factory.createVariableDeclarationList([ |
| 99568 | factory.createVariableDeclaration(factory.createUniqueName("_newTarget", 16 /* GeneratedIdentifierFlags.Optimistic */ | 32 /* GeneratedIdentifierFlags.FileLevel */), |
| 99569 | /*exclamationToken*/ undefined, |
| 99570 | /*type*/ undefined, newTarget) |
| 99571 | ])); |
| 99572 | ts.setEmitFlags(captureNewTargetStatement, 1536 /* EmitFlags.NoComments */ | 1048576 /* EmitFlags.CustomPrologue */); |
| 99573 | if (copyOnWrite) { |
| 99574 | statements = statements.slice(); |
| 99575 | } |
| 99576 | ts.insertStatementAfterCustomPrologue(statements, captureNewTargetStatement); |
| 99577 | } |
| 99578 | return statements; |
| 99579 | } |
| 99580 | /** |
| 99581 | * Adds statements to the class body function for a class to define the members of the |
| 99582 | * class. |
no test coverage detected
searching dependent graphs…