Skip to content

Commit

Permalink
fix(lexer): improved line counting
Browse files Browse the repository at this point in the history
  • Loading branch information
KFlash committed Aug 23, 2019
1 parent 6c28caf commit c29be84
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/lexer/comments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export function skipMultiLineComment(parser: ParserState, state: LexerState): Le
state |= LexerState.NewLine | LexerState.LastIsCR;
scanNewLine(parser);
} else if (parser.currentChar === Chars.LineFeed) {
consumeLineFeed(parser, (state & LexerState.LastIsCR) !== 0);
consumeLineFeed(parser, state);
state = (state | LexerState.LastIsCR | LexerState.NewLine) ^ LexerState.LastIsCR;
} else if ((parser.currentChar ^ Chars.LineSeparator) <= 1) {
state = (state | LexerState.LastIsCR | LexerState.NewLine) ^ LexerState.LastIsCR;
Expand Down
4 changes: 2 additions & 2 deletions src/lexer/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,10 @@ export function consumeMultiUnitCodePoint(parser: ParserState, hi: number): 0 |
/**
* Use to consume a line feed instead of `scanNewLine`.
*/
export function consumeLineFeed(parser: ParserState, lastIsCR: boolean): void {
export function consumeLineFeed(parser: ParserState, state: LexerState): void {
parser.currentChar = parser.source.charCodeAt(++parser.index);
parser.flags |= Flags.NewLine;
if (!lastIsCR) {
if ((state & LexerState.LastIsCR) === 0) {
parser.column = 0;
parser.line++;
}
Expand Down
2 changes: 1 addition & 1 deletion src/lexer/scan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,7 @@ export function scanSingleToken(parser: ParserState, context: Context, state: Le
break;

case Token.LineFeed:
consumeLineFeed(parser, (state & LexerState.LastIsCR) !== 0);
consumeLineFeed(parser, state);
state = (state | LexerState.LastIsCR | LexerState.NewLine) ^ LexerState.LastIsCR;
break;

Expand Down

0 comments on commit c29be84

Please sign in to comment.