Skip to content

Commit

Permalink
fix issue with using string index and shift interchangably
Browse files Browse the repository at this point in the history
  • Loading branch information
vikr01 committed Dec 13, 2018
1 parent 6141128 commit cdd876d
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions packages/babel-parser/src/plugins/flow.js
Expand Up @@ -2723,29 +2723,32 @@ export default (superClass: Class<Parser>): Class<Parser> =>
}
skipFlowComment(): number | boolean {
let firstNonWhiteSpace = this.state.pos + 2;
const { pos } = this.state;
let shiftToFirstNonWhiteSpace = 2;
while (
[charCodes.space, charCodeTab].includes(
this.input.charCodeAt(firstNonWhiteSpace),
this.input.charCodeAt(pos + shiftToFirstNonWhiteSpace),
)
) {
firstNonWhiteSpace++;
shiftToFirstNonWhiteSpace++;
}
const ch2 = this.input.charCodeAt(firstNonWhiteSpace);
const ch3 = this.input.charCodeAt(firstNonWhiteSpace + 1);
const ch2 = this.input.charCodeAt(shiftToFirstNonWhiteSpace + pos);
const ch3 = this.input.charCodeAt(shiftToFirstNonWhiteSpace + pos + 1);
if (ch2 === charCodes.colon && ch3 === charCodes.colon) {
return firstNonWhiteSpace + 2; // check for /*::
return shiftToFirstNonWhiteSpace + 2; // check for /*::
}
if (
this.input.slice(firstNonWhiteSpace, firstNonWhiteSpace + 12) ===
"flow-include"
this.input.slice(
shiftToFirstNonWhiteSpace + pos,
shiftToFirstNonWhiteSpace + pos + 12,
) === "flow-include"
) {
return firstNonWhiteSpace + 12; // check for /*flow-include
return shiftToFirstNonWhiteSpace + 12; // check for /*flow-include
}
if (ch2 === charCodes.colon && ch3 !== charCodes.colon) {
return firstNonWhiteSpace - this.state.pos; // check for /*:, advance up to :
return shiftToFirstNonWhiteSpace; // check for /*:, advance up to :
}
return false;
}
Expand Down

0 comments on commit cdd876d

Please sign in to comment.