perf: run flow code in flow plugin

This commit is contained in:
Daniel Tschinder 2019-01-15 16:22:38 -08:00
parent a1eac37bd2
commit c2e41588aa
2 changed files with 20 additions and 18 deletions

View File

@ -1935,7 +1935,9 @@ export default (superClass: Class<Parser>): Class<Parser> =>
// ensure that inside flow types, we bypass the jsx parser plugin
getTokenFromCode(code: number): void {
const next = this.state.input.charCodeAt(this.state.pos + 1);
if (
if (code === charCodes.leftCurlyBrace && next === charCodes.verticalBar) {
return this.finishOp(tt.braceBarL, 2);
} else if (
this.state.inType &&
(code === charCodes.greaterThan || code === charCodes.lessThan)
) {
@ -2701,6 +2703,20 @@ export default (superClass: Class<Parser>): Class<Parser> =>
super.readToken_mult_modulo(code);
}
readToken_pipe_amp(code: number): void {
const next = this.state.input.charCodeAt(this.state.pos + 1);
if (
code === charCodes.verticalBar &&
next === charCodes.rightCurlyBrace
) {
// '|}'
this.finishOp(tt.braceBarR, 2);
return;
}
super.readToken_pipe_amp(code);
}
parseTopLevel(file: N.File, program: N.Program): N.File {
const fileNode = super.parseTopLevel(file, program);
if (this.state.hasFlowComment) {

View File

@ -482,7 +482,7 @@ export default class Tokenizer extends LocationParser {
}
readToken_pipe_amp(code: number): void {
// '|&'
// '||' '&&' '||=' '&&='
const next = this.state.input.charCodeAt(this.state.pos + 1);
if (next === code) {
@ -504,10 +504,6 @@ export default class Tokenizer extends LocationParser {
if (next === charCodes.greaterThan) {
this.finishOp(tt.pipeline, 2);
return;
} else if (next === charCodes.rightCurlyBrace && this.hasPlugin("flow")) {
// '|}'
this.finishOp(tt.braceBarR, 2);
return;
}
}
@ -688,20 +684,10 @@ export default class Tokenizer extends LocationParser {
++this.state.pos;
this.finishToken(tt.bracketR);
return;
case charCodes.leftCurlyBrace:
if (
this.hasPlugin("flow") &&
this.state.input.charCodeAt(this.state.pos + 1) ===
charCodes.verticalBar
) {
this.finishOp(tt.braceBarL, 2);
} else {
++this.state.pos;
this.finishToken(tt.braceL);
}
++this.state.pos;
this.finishToken(tt.braceL);
return;
case charCodes.rightCurlyBrace:
++this.state.pos;
this.finishToken(tt.braceR);