Skip to content

Commit

Permalink
check for spaces and tabs before a flow comment
Browse files Browse the repository at this point in the history
  • Loading branch information
vikr01 committed Dec 12, 2018
1 parent 0514a9f commit 6141128
Showing 1 changed file with 20 additions and 6 deletions.
26 changes: 20 additions & 6 deletions packages/babel-parser/src/plugins/flow.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import { types as tc } from "../tokenizer/context";
import * as charCodes from "charcodes";
import { isIteratorStart } from "../util/identifier";

const charCodeTab = 9;

const reservedTypes = [
"any",
"bool",
Expand Down Expand Up @@ -2721,17 +2723,29 @@ export default (superClass: Class<Parser>): Class<Parser> =>
}
skipFlowComment(): number | boolean {
const ch2 = this.input.charCodeAt(this.state.pos + 2);
const ch3 = this.input.charCodeAt(this.state.pos + 3);
let firstNonWhiteSpace = this.state.pos + 2;
while (
[charCodes.space, charCodeTab].includes(
this.input.charCodeAt(firstNonWhiteSpace),
)
) {
firstNonWhiteSpace++;
}
const ch2 = this.input.charCodeAt(firstNonWhiteSpace);
const ch3 = this.input.charCodeAt(firstNonWhiteSpace + 1);
if (ch2 === charCodes.colon && ch3 === charCodes.colon) {
return 4; // check for /*::
return firstNonWhiteSpace + 2; // check for /*::
}
if (this.input.slice(this.state.pos + 2, 14) === "flow-include") {
return 14; // check for /*flow-include
if (
this.input.slice(firstNonWhiteSpace, firstNonWhiteSpace + 12) ===
"flow-include"
) {
return firstNonWhiteSpace + 12; // check for /*flow-include
}
if (ch2 === charCodes.colon && ch3 !== charCodes.colon) {
return 2; // check for /*:, advance only 2 steps
return firstNonWhiteSpace - this.state.pos; // check for /*:, advance up to :
}
return false;
}
Expand Down

0 comments on commit 6141128

Please sign in to comment.