mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-11-18 20:11:14 +00:00
Fix block-scoped enum declarations
This commit is contained in:
1 parent
441d762065
commit
324c9bb349
9 files changed
+24
-22
No files matched your search
@@ -2601,14 +2601,16 @@ namespace ts {
|
||||
* Adds a leading VariableStatement for a enum or module declaration.
|
||||
*/
|
||||
function addVarForEnumOrModuleDeclaration(statements: Statement[], node: ModuleDeclaration | EnumDeclaration) {
|
||||
// Emit a variable statement for the module.
|
||||
// Emit a variable statement for the module. We emit top-level enums as a `var`
|
||||
// declaration to avoid static errors in global scripts scripts due to redeclaration.
|
||||
// enums in any other scope are emitted as a `let` declaration.
|
||||
const statement = createVariableStatement(
|
||||
visitNodes(node.modifiers, modifierVisitor, isModifier),
|
||||
[
|
||||
createVariableDeclarationList([
|
||||
createVariableDeclaration(
|
||||
getLocalName(node, /*allowComments*/ false, /*allowSourceMaps*/ true)
|
||||
)
|
||||
]
|
||||
], currentScope.kind === SyntaxKind.SourceFile ? NodeFlags.None : NodeFlags.Let)
|
||||
);
|
||||
|
||||
setOriginalNode(statement, node);
|
||||
|
||||
Reference in new issue
Block a user