Add some parser missing plugins errors (#11478)
* fix: do not throw invalid hash in tokenizer * refactor: bigint has been enabled by default * polish: add numeric separator missing plugin error * fix: forward expectPlugin declaration
This commit is contained in:
parent
d05334bde2
commit
2e4f18ac92
@ -113,6 +113,7 @@ export default class Tokenizer extends LocationParser {
|
|||||||
// parser/util.js
|
// parser/util.js
|
||||||
/*::
|
/*::
|
||||||
+unexpected: (pos?: ?number, messageOrType?: string | TokenType) => empty;
|
+unexpected: (pos?: ?number, messageOrType?: string | TokenType) => empty;
|
||||||
|
+expectPlugin: (name: string, pos?: ?number) => true;
|
||||||
*/
|
*/
|
||||||
|
|
||||||
isLookahead: boolean;
|
isLookahead: boolean;
|
||||||
@ -405,10 +406,14 @@ export default class Tokenizer extends LocationParser {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (
|
if (
|
||||||
this.hasPlugin("recordAndTuple") &&
|
next === charCodes.leftCurlyBrace ||
|
||||||
(next === charCodes.leftCurlyBrace ||
|
(next === charCodes.leftSquareBracket && this.hasPlugin("recordAndTuple"))
|
||||||
next === charCodes.leftSquareBracket)
|
|
||||||
) {
|
) {
|
||||||
|
// When we see `#{`, it is likely to be a hash record.
|
||||||
|
// However we don't yell at `#[` since users may intend to use "computed private fields",
|
||||||
|
// which is not allowed in the spec. Throwing expecting recordAndTuple is
|
||||||
|
// misleading
|
||||||
|
this.expectPlugin("recordAndTuple");
|
||||||
if (this.getPluginOption("recordAndTuple", "syntaxType") !== "hash") {
|
if (this.getPluginOption("recordAndTuple", "syntaxType") !== "hash") {
|
||||||
throw this.raise(
|
throw this.raise(
|
||||||
this.state.pos,
|
this.state.pos,
|
||||||
@ -426,14 +431,8 @@ export default class Tokenizer extends LocationParser {
|
|||||||
this.finishToken(tt.bracketHashL);
|
this.finishToken(tt.bracketHashL);
|
||||||
}
|
}
|
||||||
this.state.pos += 2;
|
this.state.pos += 2;
|
||||||
} else if (
|
|
||||||
this.hasPlugin("classPrivateProperties") ||
|
|
||||||
this.hasPlugin("classPrivateMethods") ||
|
|
||||||
this.getPluginOption("pipelineOperator", "proposal") === "smart"
|
|
||||||
) {
|
|
||||||
this.finishOp(tt.hash, 1);
|
|
||||||
} else {
|
} else {
|
||||||
throw this.raise(this.state.pos, Errors.InvalidOrUnexpectedToken, "#");
|
this.finishOp(tt.hash, 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1080,8 +1079,13 @@ export default class Tokenizer extends LocationParser {
|
|||||||
if (val == null) {
|
if (val == null) {
|
||||||
this.raise(this.state.start + 2, Errors.InvalidDigit, radix);
|
this.raise(this.state.start + 2, Errors.InvalidDigit, radix);
|
||||||
}
|
}
|
||||||
|
const next = this.input.charCodeAt(this.state.pos);
|
||||||
|
|
||||||
if (this.input.charCodeAt(this.state.pos) === charCodes.lowercaseN) {
|
if (next === charCodes.underscore) {
|
||||||
|
this.expectPlugin("numericSeparator", this.state.pos);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (next === charCodes.lowercaseN) {
|
||||||
++this.state.pos;
|
++this.state.pos;
|
||||||
isBigInt = true;
|
isBigInt = true;
|
||||||
}
|
}
|
||||||
@ -1154,6 +1158,10 @@ export default class Tokenizer extends LocationParser {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (next === charCodes.underscore) {
|
||||||
|
this.expectPlugin("numericSeparator", this.state.pos);
|
||||||
|
}
|
||||||
|
|
||||||
if (next === charCodes.lowercaseN) {
|
if (next === charCodes.lowercaseN) {
|
||||||
// disallow floats, legacy octal syntax and non octal decimals
|
// disallow floats, legacy octal syntax and non octal decimals
|
||||||
// new style octal ("0o") is handled in this.readRadixNumber
|
// new style octal ("0o") is handled in this.readRadixNumber
|
||||||
|
|||||||
@ -1,3 +1,3 @@
|
|||||||
{
|
{
|
||||||
"throws": "Unexpected character '#' (1:2)"
|
"throws": "Unexpected token, expected \";\" (1:2)"
|
||||||
}
|
}
|
||||||
@ -1 +0,0 @@
|
|||||||
1n
|
|
||||||
@ -1,4 +0,0 @@
|
|||||||
{
|
|
||||||
"throws": "This experimental syntax requires enabling the parser plugin: 'classPrivateProperties' (2:3)",
|
|
||||||
"plugins": []
|
|
||||||
}
|
|
||||||
@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"throws": "This experimental syntax requires enabling one of the following parser plugin(s): 'classPrivateProperties, classPrivateMethods' (2:2)"
|
||||||
|
}
|
||||||
1
packages/babel-parser/test/fixtures/experimental/_no-plugin/numeric-separator-radix/input.js
vendored
Normal file
1
packages/babel-parser/test/fixtures/experimental/_no-plugin/numeric-separator-radix/input.js
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
0b1_0
|
||||||
@ -1,4 +1,3 @@
|
|||||||
{
|
{
|
||||||
"throws": "This experimental syntax requires enabling the parser plugin: 'bigInt' (1:1)",
|
"throws": "This experimental syntax requires enabling the parser plugin: 'numericSeparator' (1:3)"
|
||||||
"plugins": []
|
|
||||||
}
|
}
|
||||||
@ -1,4 +1,3 @@
|
|||||||
{
|
{
|
||||||
"throws": "This experimental syntax requires enabling the parser plugin: 'numericSeparator' (1:17)",
|
"throws": "This experimental syntax requires enabling the parser plugin: 'numericSeparator' (1:1)"
|
||||||
"plugins": []
|
|
||||||
}
|
}
|
||||||
@ -1,4 +1,3 @@
|
|||||||
{
|
{
|
||||||
"plugins": [],
|
"throws": "This experimental syntax requires enabling the parser plugin: 'recordAndTuple' (1:0)"
|
||||||
"throws": "Unexpected character '#' (1:0)"
|
|
||||||
}
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user