* Adds a leading VariableStatement for a enum or module declaration.
(statements, node)
| 93608 | * Adds a leading VariableStatement for a enum or module declaration. |
| 93609 | */ |
| 93610 | function addVarForEnumOrModuleDeclaration(statements, node) { |
| 93611 | // Emit a variable statement for the module. We emit top-level enums as a `var` |
| 93612 | // declaration to avoid static errors in global scripts scripts due to redeclaration. |
| 93613 | // enums in any other scope are emitted as a `let` declaration. |
| 93614 | var statement = factory.createVariableStatement(ts.visitNodes(node.modifiers, modifierVisitor, ts.isModifier), factory.createVariableDeclarationList([ |
| 93615 | factory.createVariableDeclaration(factory.getLocalName(node, /*allowComments*/ false, /*allowSourceMaps*/ true)) |
| 93616 | ], currentLexicalScope.kind === 305 /* SyntaxKind.SourceFile */ ? 0 /* NodeFlags.None */ : 1 /* NodeFlags.Let */)); |
| 93617 | ts.setOriginalNode(statement, node); |
| 93618 | recordEmittedDeclarationInScope(node); |
| 93619 | if (isFirstEmittedDeclarationInScope(node)) { |
| 93620 | // Adjust the source map emit to match the old emitter. |
| 93621 | if (node.kind === 260 /* SyntaxKind.EnumDeclaration */) { |
| 93622 | ts.setSourceMapRange(statement.declarationList, node); |
| 93623 | } |
| 93624 | else { |
| 93625 | ts.setSourceMapRange(statement, node); |
| 93626 | } |
| 93627 | // Trailing comments for module declaration should be emitted after the function closure |
| 93628 | // instead of the variable statement: |
| 93629 | // |
| 93630 | // /** Module comment*/ |
| 93631 | // module m1 { |
| 93632 | // function foo4Export() { |
| 93633 | // } |
| 93634 | // } // trailing comment module |
| 93635 | // |
| 93636 | // Should emit: |
| 93637 | // |
| 93638 | // /** Module comment*/ |
| 93639 | // var m1; |
| 93640 | // (function (m1) { |
| 93641 | // function foo4Export() { |
| 93642 | // } |
| 93643 | // })(m1 || (m1 = {})); // trailing comment module |
| 93644 | // |
| 93645 | ts.setCommentRange(statement, node); |
| 93646 | ts.addEmitFlags(statement, 1024 /* EmitFlags.NoTrailingComments */ | 4194304 /* EmitFlags.HasEndOfDeclarationMarker */); |
| 93647 | statements.push(statement); |
| 93648 | return true; |
| 93649 | } |
| 93650 | else { |
| 93651 | // For an EnumDeclaration or ModuleDeclaration that merges with a preceeding |
| 93652 | // declaration we do not emit a leading variable declaration. To preserve the |
| 93653 | // begin/end semantics of the declararation and to properly handle exports |
| 93654 | // we wrap the leading variable declaration in a `MergeDeclarationMarker`. |
| 93655 | var mergeMarker = factory.createMergeDeclarationMarker(statement); |
| 93656 | ts.setEmitFlags(mergeMarker, 1536 /* EmitFlags.NoComments */ | 4194304 /* EmitFlags.HasEndOfDeclarationMarker */); |
| 93657 | statements.push(mergeMarker); |
| 93658 | return false; |
| 93659 | } |
| 93660 | } |
| 93661 | /** |
| 93662 | * Visits a module declaration node. |
| 93663 | * |
no test coverage detected
searching dependent graphs…