rename parser context types

This commit is contained in:
Sebastian McKenzie 2016-06-22 14:06:58 +01:00
parent 3524ad510f
commit cf6e0d365e
5 changed files with 22 additions and 22 deletions

View File

@ -431,9 +431,9 @@ export default function(instance) {
if (this.match(tt.braceL)) {
let curContext = this.curContext();
if (curContext === tc.j_oTag) {
this.state.context.push(tc.b_expr);
this.state.context.push(tc.braceExpression);
} else if (curContext === tc.j_expr) {
this.state.context.push(tc.b_tmpl);
this.state.context.push(tc.templateQuasi);
} else {
inner.call(this, prevType);
}

View File

@ -27,13 +27,13 @@ export class TokContext {
export const types: {
[key: string]: TokContext;
} = {
b_stat: new TokContext("{", false),
b_expr: new TokContext("{", true),
b_tmpl: new TokContext("${", true),
p_stat: new TokContext("(", false),
p_expr: new TokContext("(", true),
q_tmpl: new TokContext("`", true, true, (p) => p.readTmplToken()),
f_expr: new TokContext("function", true)
braceStatement: new TokContext("{", false),
braceExpression: new TokContext("{", true),
templateQuasi: new TokContext("${", true),
parenStatement: new TokContext("(", false),
parenExpression: new TokContext("(", true),
template: new TokContext("`", true, true, (p) => p.readTmplToken()),
functionExpression: new TokContext("function", true)
};
// Token-specific context update code
@ -45,10 +45,10 @@ tt.parenR.updateContext = tt.braceR.updateContext = function () {
}
let out = this.state.context.pop();
if (out === types.b_stat && this.curContext() === types.f_expr) {
if (out === types.braceStatement && this.curContext() === types.functionExpression) {
this.state.context.pop();
this.state.exprAllowed = false;
} else if (out === types.b_tmpl) {
} else if (out === types.templateQuasi) {
this.state.exprAllowed = true;
} else {
this.state.exprAllowed = !out.isExpr;
@ -66,19 +66,19 @@ tt.name.updateContext = function (prevType) {
};
tt.braceL.updateContext = function (prevType) {
this.state.context.push(this.braceIsBlock(prevType) ? types.b_stat : types.b_expr);
this.state.context.push(this.braceIsBlock(prevType) ? types.braceStatement : types.braceExpression);
this.state.exprAllowed = true;
};
tt.dollarBraceL.updateContext = function () {
this.state.context.push(types.b_tmpl);
this.state.context.push(types.templateQuasi);
this.state.exprAllowed = true;
};
tt.parenL.updateContext = function (prevType) {
let statementParens = prevType === tt._if || prevType === tt._for ||
prevType === tt._with || prevType === tt._while;
this.state.context.push(statementParens ? types.p_stat : types.p_expr);
this.state.context.push(statementParens ? types.parenStatement : types.parenExpression);
this.state.exprAllowed = true;
};
@ -87,18 +87,18 @@ tt.incDec.updateContext = function () {
};
tt._function.updateContext = function () {
if (this.curContext() !== types.b_stat) {
this.state.context.push(types.f_expr);
if (this.curContext() !== types.braceStatement) {
this.state.context.push(types.functionExpression);
}
this.state.exprAllowed = false;
};
tt.backQuote.updateContext = function () {
if (this.curContext() === types.q_tmpl) {
if (this.curContext() === types.template) {
this.state.context.pop();
} else {
this.state.context.push(types.q_tmpl);
this.state.context.push(types.template);
}
this.state.exprAllowed = false;
};

View File

@ -767,7 +767,7 @@ export default class Tokenizer {
braceIsBlock(prevType) {
if (prevType === tt.colon) {
let parent = this.curContext();
if (parent === ct.b_stat || parent === ct.b_expr) {
if (parent === ct.braceStatement || parent === ct.braceExpression) {
return !parent.isExpr;
}
}
@ -781,7 +781,7 @@ export default class Tokenizer {
}
if (prevType === tt.braceL) {
return this.curContext() === ct.b_stat;
return this.curContext() === ct.braceStatement;
}
return !this.state.exprAllowed;

View File

@ -37,7 +37,7 @@ export default class State {
this.lastTokEndLoc = this.lastTokStartLoc = null;
this.lastTokStart = this.lastTokEnd = this.pos;
this.context = [ct.b_stat];
this.context = [ct.braceStatement];
this.exprAllowed = true;
this.containsEsc = this.containsOctal = false;

View File

@ -1,3 +1,3 @@
{
"plugins": ["jsx"]
"plugins": ["jsx", "flow"]
}