rename parser context types
This commit is contained in:
parent
3524ad510f
commit
cf6e0d365e
@ -431,9 +431,9 @@ export default function(instance) {
|
|||||||
if (this.match(tt.braceL)) {
|
if (this.match(tt.braceL)) {
|
||||||
let curContext = this.curContext();
|
let curContext = this.curContext();
|
||||||
if (curContext === tc.j_oTag) {
|
if (curContext === tc.j_oTag) {
|
||||||
this.state.context.push(tc.b_expr);
|
this.state.context.push(tc.braceExpression);
|
||||||
} else if (curContext === tc.j_expr) {
|
} else if (curContext === tc.j_expr) {
|
||||||
this.state.context.push(tc.b_tmpl);
|
this.state.context.push(tc.templateQuasi);
|
||||||
} else {
|
} else {
|
||||||
inner.call(this, prevType);
|
inner.call(this, prevType);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -27,13 +27,13 @@ export class TokContext {
|
|||||||
export const types: {
|
export const types: {
|
||||||
[key: string]: TokContext;
|
[key: string]: TokContext;
|
||||||
} = {
|
} = {
|
||||||
b_stat: new TokContext("{", false),
|
braceStatement: new TokContext("{", false),
|
||||||
b_expr: new TokContext("{", true),
|
braceExpression: new TokContext("{", true),
|
||||||
b_tmpl: new TokContext("${", true),
|
templateQuasi: new TokContext("${", true),
|
||||||
p_stat: new TokContext("(", false),
|
parenStatement: new TokContext("(", false),
|
||||||
p_expr: new TokContext("(", true),
|
parenExpression: new TokContext("(", true),
|
||||||
q_tmpl: new TokContext("`", true, true, (p) => p.readTmplToken()),
|
template: new TokContext("`", true, true, (p) => p.readTmplToken()),
|
||||||
f_expr: new TokContext("function", true)
|
functionExpression: new TokContext("function", true)
|
||||||
};
|
};
|
||||||
|
|
||||||
// Token-specific context update code
|
// Token-specific context update code
|
||||||
@ -45,10 +45,10 @@ tt.parenR.updateContext = tt.braceR.updateContext = function () {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let out = this.state.context.pop();
|
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.context.pop();
|
||||||
this.state.exprAllowed = false;
|
this.state.exprAllowed = false;
|
||||||
} else if (out === types.b_tmpl) {
|
} else if (out === types.templateQuasi) {
|
||||||
this.state.exprAllowed = true;
|
this.state.exprAllowed = true;
|
||||||
} else {
|
} else {
|
||||||
this.state.exprAllowed = !out.isExpr;
|
this.state.exprAllowed = !out.isExpr;
|
||||||
@ -66,19 +66,19 @@ tt.name.updateContext = function (prevType) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
tt.braceL.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;
|
this.state.exprAllowed = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
tt.dollarBraceL.updateContext = function () {
|
tt.dollarBraceL.updateContext = function () {
|
||||||
this.state.context.push(types.b_tmpl);
|
this.state.context.push(types.templateQuasi);
|
||||||
this.state.exprAllowed = true;
|
this.state.exprAllowed = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
tt.parenL.updateContext = function (prevType) {
|
tt.parenL.updateContext = function (prevType) {
|
||||||
let statementParens = prevType === tt._if || prevType === tt._for ||
|
let statementParens = prevType === tt._if || prevType === tt._for ||
|
||||||
prevType === tt._with || prevType === tt._while;
|
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;
|
this.state.exprAllowed = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -87,18 +87,18 @@ tt.incDec.updateContext = function () {
|
|||||||
};
|
};
|
||||||
|
|
||||||
tt._function.updateContext = function () {
|
tt._function.updateContext = function () {
|
||||||
if (this.curContext() !== types.b_stat) {
|
if (this.curContext() !== types.braceStatement) {
|
||||||
this.state.context.push(types.f_expr);
|
this.state.context.push(types.functionExpression);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.state.exprAllowed = false;
|
this.state.exprAllowed = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
tt.backQuote.updateContext = function () {
|
tt.backQuote.updateContext = function () {
|
||||||
if (this.curContext() === types.q_tmpl) {
|
if (this.curContext() === types.template) {
|
||||||
this.state.context.pop();
|
this.state.context.pop();
|
||||||
} else {
|
} else {
|
||||||
this.state.context.push(types.q_tmpl);
|
this.state.context.push(types.template);
|
||||||
}
|
}
|
||||||
this.state.exprAllowed = false;
|
this.state.exprAllowed = false;
|
||||||
};
|
};
|
||||||
|
|||||||
@ -767,7 +767,7 @@ export default class Tokenizer {
|
|||||||
braceIsBlock(prevType) {
|
braceIsBlock(prevType) {
|
||||||
if (prevType === tt.colon) {
|
if (prevType === tt.colon) {
|
||||||
let parent = this.curContext();
|
let parent = this.curContext();
|
||||||
if (parent === ct.b_stat || parent === ct.b_expr) {
|
if (parent === ct.braceStatement || parent === ct.braceExpression) {
|
||||||
return !parent.isExpr;
|
return !parent.isExpr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -781,7 +781,7 @@ export default class Tokenizer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (prevType === tt.braceL) {
|
if (prevType === tt.braceL) {
|
||||||
return this.curContext() === ct.b_stat;
|
return this.curContext() === ct.braceStatement;
|
||||||
}
|
}
|
||||||
|
|
||||||
return !this.state.exprAllowed;
|
return !this.state.exprAllowed;
|
||||||
|
|||||||
@ -37,7 +37,7 @@ export default class State {
|
|||||||
this.lastTokEndLoc = this.lastTokStartLoc = null;
|
this.lastTokEndLoc = this.lastTokStartLoc = null;
|
||||||
this.lastTokStart = this.lastTokEnd = this.pos;
|
this.lastTokStart = this.lastTokEnd = this.pos;
|
||||||
|
|
||||||
this.context = [ct.b_stat];
|
this.context = [ct.braceStatement];
|
||||||
this.exprAllowed = true;
|
this.exprAllowed = true;
|
||||||
|
|
||||||
this.containsEsc = this.containsOctal = false;
|
this.containsEsc = this.containsOctal = false;
|
||||||
|
|||||||
2
test/fixtures/jsx/options.json
vendored
2
test/fixtures/jsx/options.json
vendored
@ -1,3 +1,3 @@
|
|||||||
{
|
{
|
||||||
"plugins": ["jsx"]
|
"plugins": ["jsx", "flow"]
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user