Skip to content
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

Add some parser missing plugins errors #11478

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
30 changes: 19 additions & 11 deletions packages/babel-parser/src/tokenizer/index.js
Expand Up @@ -113,6 +113,7 @@ export default class Tokenizer extends LocationParser {
// parser/util.js
/*::
+unexpected: (pos?: ?number, messageOrType?: string | TokenType) => empty;
+expectPlugin: (name: string, pos?: ?number) => true;
*/

isLookahead: boolean;
Expand Down Expand Up @@ -405,10 +406,14 @@ export default class Tokenizer extends LocationParser {
}

if (
this.hasPlugin("recordAndTuple") &&
(next === charCodes.leftCurlyBrace ||
next === charCodes.leftSquareBracket)
next === charCodes.leftCurlyBrace ||
(next === charCodes.leftSquareBracket && this.hasPlugin("recordAndTuple"))
) {
// 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") {
throw this.raise(
this.state.pos,
Expand All @@ -426,14 +431,8 @@ export default class Tokenizer extends LocationParser {
this.finishToken(tt.bracketHashL);
}
this.state.pos += 2;
} else if (
this.hasPlugin("classPrivateProperties") ||
this.hasPlugin("classPrivateMethods") ||
this.getPluginOption("pipelineOperator", "proposal") === "smart"
) {
this.finishOp(tt.hash, 1);
} else {
throw this.raise(this.state.pos, Errors.InvalidOrUnexpectedToken, "#");
this.finishOp(tt.hash, 1);
}
}

Expand Down Expand Up @@ -1080,8 +1079,13 @@ export default class Tokenizer extends LocationParser {
if (val == null) {
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;
isBigInt = true;
}
Expand Down Expand Up @@ -1154,6 +1158,10 @@ export default class Tokenizer extends LocationParser {
}
}

if (next === charCodes.underscore) {
this.expectPlugin("numericSeparator", this.state.pos);
}

if (next === charCodes.lowercaseN) {
// disallow floats, legacy octal syntax and non octal decimals
// new style octal ("0o") is handled in this.readRadixNumber
Expand Down
@@ -1,3 +1,3 @@
{
"throws": "Unexpected character '#' (1:2)"
}
"throws": "Unexpected token, expected \";\" (1:2)"
}

This file was deleted.

This file was deleted.

@@ -0,0 +1,3 @@
{
"throws": "This experimental syntax requires enabling one of the following parser plugin(s): 'classPrivateProperties, classPrivateMethods' (2:2)"
}
@@ -0,0 +1 @@
0b1_0
@@ -1,4 +1,3 @@
{
"throws": "This experimental syntax requires enabling the parser plugin: 'bigInt' (1:1)",
"plugins": []
}
"throws": "This experimental syntax requires enabling the parser plugin: 'numericSeparator' (1:3)"
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The diff here may be a bit confusing as I also remove the unused bigint missing plugin errors.

@@ -1,4 +1,3 @@
{
"throws": "This experimental syntax requires enabling the parser plugin: 'numericSeparator' (1:17)",
"plugins": []
}
"throws": "This experimental syntax requires enabling the parser plugin: 'numericSeparator' (1:1)"
}
@@ -1,4 +1,3 @@
{
"plugins": [],
"throws": "Unexpected character '#' (1:0)"
}
"throws": "This experimental syntax requires enabling the parser plugin: 'recordAndTuple' (1:0)"
}