add scope to TSModuleDeclaration (#10119)
This commit is contained in:
committed by
Nicolò Ribaudo
parent
599d2ff324
commit
b0acfb24dd
@@ -9,6 +9,7 @@ import type Parser from "../../parser";
|
||||
import {
|
||||
type BindingTypes,
|
||||
BIND_NONE,
|
||||
SCOPE_TS_MODULE,
|
||||
SCOPE_OTHER,
|
||||
BIND_TS_ENUM,
|
||||
BIND_TS_CONST_ENUM,
|
||||
@@ -1167,7 +1168,9 @@ export default (superClass: Class<Parser>): Class<Parser> =>
|
||||
this.tsParseModuleOrNamespaceDeclaration(inner, true);
|
||||
node.body = inner;
|
||||
} else {
|
||||
this.scope.enter(SCOPE_TS_MODULE);
|
||||
node.body = this.tsParseModuleBlock();
|
||||
this.scope.exit();
|
||||
}
|
||||
return this.finishNode(node, "TSModuleDeclaration");
|
||||
}
|
||||
@@ -1183,9 +1186,10 @@ export default (superClass: Class<Parser>): Class<Parser> =>
|
||||
} else {
|
||||
this.unexpected();
|
||||
}
|
||||
|
||||
if (this.match(tt.braceL)) {
|
||||
this.scope.enter(SCOPE_TS_MODULE);
|
||||
node.body = this.tsParseModuleBlock();
|
||||
this.scope.exit();
|
||||
} else {
|
||||
this.semicolon();
|
||||
}
|
||||
@@ -1337,10 +1341,12 @@ export default (superClass: Class<Parser>): Class<Parser> =>
|
||||
// `global { }` (with no `declare`) may appear inside an ambient module declaration.
|
||||
// Would like to use tsParseAmbientExternalModuleDeclaration here, but already ran past "global".
|
||||
if (this.match(tt.braceL)) {
|
||||
this.scope.enter(SCOPE_TS_MODULE);
|
||||
const mod: N.TsModuleDeclaration = node;
|
||||
mod.global = true;
|
||||
mod.id = expr;
|
||||
mod.body = this.tsParseModuleBlock();
|
||||
this.scope.exit();
|
||||
return this.finishNode(mod, "TSModuleDeclaration");
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -2,17 +2,18 @@
|
||||
|
||||
// Each scope gets a bitset that may contain these flags
|
||||
// prettier-ignore
|
||||
export const SCOPE_OTHER = 0b000000000,
|
||||
SCOPE_PROGRAM = 0b000000001,
|
||||
SCOPE_FUNCTION = 0b000000010,
|
||||
SCOPE_ASYNC = 0b000000100,
|
||||
SCOPE_GENERATOR = 0b000001000,
|
||||
SCOPE_ARROW = 0b000010000,
|
||||
SCOPE_SIMPLE_CATCH = 0b000100000,
|
||||
SCOPE_SUPER = 0b001000000,
|
||||
SCOPE_DIRECT_SUPER = 0b010000000,
|
||||
SCOPE_CLASS = 0b100000000,
|
||||
SCOPE_VAR = SCOPE_PROGRAM | SCOPE_FUNCTION;
|
||||
export const SCOPE_OTHER = 0b0000000000,
|
||||
SCOPE_PROGRAM = 0b0000000001,
|
||||
SCOPE_FUNCTION = 0b0000000010,
|
||||
SCOPE_ASYNC = 0b0000000100,
|
||||
SCOPE_GENERATOR = 0b0000001000,
|
||||
SCOPE_ARROW = 0b0000010000,
|
||||
SCOPE_SIMPLE_CATCH = 0b0000100000,
|
||||
SCOPE_SUPER = 0b0001000000,
|
||||
SCOPE_DIRECT_SUPER = 0b0010000000,
|
||||
SCOPE_CLASS = 0b0100000000,
|
||||
SCOPE_TS_MODULE = 0b1000000000,
|
||||
SCOPE_VAR = SCOPE_PROGRAM | SCOPE_FUNCTION | SCOPE_TS_MODULE;
|
||||
|
||||
export type ScopeFlags =
|
||||
| typeof SCOPE_OTHER
|
||||
|
||||
Reference in New Issue
Block a user