add lineBreak test to tt.name.updateContext - fixes #2591

This commit is contained in:
Sebastian McKenzie
2015-11-03 11:46:01 +00:00
parent 3b3c1897d0
commit 14ca4d1dc9
5 changed files with 389 additions and 0 deletions

View File

@@ -5,6 +5,7 @@
// See https://github.com/mozilla/sweet.js/wiki/design
import { types as tt } from "./types";
import { lineBreak } from "../util/whitespace";
export class TokContext {
constructor(
@@ -54,6 +55,14 @@ tt.parenR.updateContext = tt.braceR.updateContext = function () {
}
};
tt.name.updateContext = function (prevType) {
if (prevType === tt._let || prevType === tt._const || prevType === tt._var) {
if (lineBreak.test(this.input.slice(this.state.end))) {
this.state.exprAllowed = true;
}
}
};
tt.braceL.updateContext = function (prevType) {
this.state.context.push(this.braceIsBlock(prevType) ? types.b_stat : types.b_expr);
this.state.exprAllowed = true;