Make let a contextual keyword

This commit is contained in:
Daniel Tschinder
2019-01-21 19:46:40 -08:00
parent 65febdd13a
commit 178f2d7949
24 changed files with 636 additions and 42 deletions

View File

@@ -344,7 +344,7 @@ export default (superClass: Class<Parser>): Class<Parser> =>
} else {
if (
this.match(tt._const) ||
this.match(tt._let) ||
this.isLet() ||
((this.isContextual("type") || this.isContextual("interface")) &&
!insideModule)
) {

View File

@@ -1190,8 +1190,15 @@ export default (superClass: Class<Parser>): Class<Parser> =>
if (this.isLineTerminator()) {
return;
}
let starttype = this.state.type;
let kind;
switch (this.state.type) {
if (this.isContextual("let")) {
starttype = tt._var;
kind = "let";
}
switch (starttype) {
case tt._function:
this.next();
return this.parseFunction(nany, /* isStatement */ true);
@@ -1210,8 +1217,8 @@ export default (superClass: Class<Parser>): Class<Parser> =>
}
// falls through
case tt._var:
case tt._let:
return this.parseVarStatement(nany, this.state.type);
kind = kind || this.state.value;
return this.parseVarStatement(nany, kind);
case tt.name: {
const value = this.state.value;
if (value === "global") {