-
Notifications
You must be signed in to change notification settings - Fork 138
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Port babel-parser changes from 2020-04-12 to 2020-07-22 #556
Changes from 5 commits
cae92df
4c53842
a72e684
95c2c41
91376a9
6393927
6ba5cba
3cad809
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ import {input, isFlowEnabled, state} from "../traverser/base"; | |
import {unexpected} from "../traverser/util"; | ||
import {charCodes} from "../util/charcodes"; | ||
import {IS_IDENTIFIER_CHAR, IS_IDENTIFIER_START} from "../util/identifier"; | ||
import {IS_WHITESPACE} from "../util/whitespace"; | ||
import {IS_WHITESPACE, skipWhiteSpace} from "../util/whitespace"; | ||
import {ContextualKeyword} from "./keywords"; | ||
import readWord from "./readWord"; | ||
import {TokenType, TokenType as tt} from "./types"; | ||
|
@@ -218,6 +218,20 @@ export function lookaheadTypeAndKeyword(): TypeAndKeyword { | |
return new TypeAndKeyword(type, contextualKeyword); | ||
} | ||
|
||
export function nextTokenStart(): number { | ||
return nextTokenStartSince(state.pos); | ||
} | ||
|
||
export function nextTokenStartSince(pos: number): number { | ||
skipWhiteSpace.lastIndex = pos; | ||
const skip = skipWhiteSpace.exec(input); | ||
return pos + skip![0].length; | ||
} | ||
|
||
export function lookaheadCharCode(): number { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks, this makes sense to me! Both usages do feel a little ugly, but I guess that's to be expected for some parser cases. One thought: it would be nice to avoid the |
||
return input.charCodeAt(nextTokenStart()); | ||
} | ||
|
||
// Read a single token, updating the parser object's token-related | ||
// properties. | ||
export function nextToken(): void { | ||
|
@@ -749,13 +763,17 @@ function readInt(): void { | |
|
||
function readRadixNumber(): void { | ||
let isBigInt = false; | ||
const start = state.pos; | ||
|
||
state.pos += 2; // 0x | ||
readInt(); | ||
|
||
if (input.charCodeAt(state.pos) === charCodes.lowercaseN) { | ||
const nextChar = input.charCodeAt(state.pos); | ||
if (nextChar === charCodes.lowercaseN) { | ||
++state.pos; | ||
isBigInt = true; | ||
} else if (nextChar === charCodes.lowercaseM) { | ||
unexpected("Invalid decimal", start); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think I'd prefer to leave this validation off for the sake of simplicity. |
||
} | ||
|
||
if (isBigInt) { | ||
|
@@ -769,6 +787,7 @@ function readRadixNumber(): void { | |
// Read an integer, octal integer, or floating-point number. | ||
function readNumber(startsWithDot: boolean): void { | ||
let isBigInt = false; | ||
let isDecimal = false; | ||
|
||
if (!startsWithDot) { | ||
readInt(); | ||
|
@@ -793,12 +812,21 @@ function readNumber(startsWithDot: boolean): void { | |
if (nextChar === charCodes.lowercaseN) { | ||
++state.pos; | ||
isBigInt = true; | ||
} else if (nextChar === charCodes.lowercaseM) { | ||
++state.pos; | ||
isDecimal = true; | ||
} | ||
|
||
if (isBigInt) { | ||
finishToken(tt.bigint); | ||
return; | ||
} | ||
|
||
if (isDecimal) { | ||
finishToken(tt.decimal); | ||
return; | ||
} | ||
|
||
finishToken(tt.num); | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FYI this doesn't need to be kept in sync since it's just a benchmark. But either way is fine.