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

Polish parser errors #12258

Merged
merged 4 commits into from
Oct 27, 2020
Merged
Show file tree
Hide file tree
Changes from 2 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
7 changes: 4 additions & 3 deletions packages/babel-parser/src/parser/error-message.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ export const ErrorMessages = Object.freeze({
"Can not use 'await' as identifier inside an async function",
AwaitExpressionFormalParameter:
"await is not allowed in async function parameters",
AwaitNotInAsyncFunction:
"Can not use keyword 'await' outside an async function",
AwaitNotInAsyncContext:
"'await' is only valid in async functions and the top level bodies of modules",
JLHwung marked this conversation as resolved.
Show resolved Hide resolved
AwaitNotInAsyncFunction: "'await' is only valid in async function",
JLHwung marked this conversation as resolved.
Show resolved Hide resolved
BadGetterArity: "getter must not have any formal parameters",
BadSetterArity: "setter must have exactly one formal parameter",
BadSetterRestParameter:
Expand Down Expand Up @@ -210,7 +211,7 @@ export const ErrorMessages = Object.freeze({
VarRedeclaration: "Identifier '%0' has already been declared",
YieldBindingIdentifier:
"Can not use 'yield' as identifier inside a generator",
YieldInParameter: "yield is not allowed in generator parameters",
YieldInParameter: "Yield expression is not allowed in formal parameters",
ZeroDigitNumericSeparator:
"Numeric separator can not be used after leading 0",
});
7 changes: 6 additions & 1 deletion packages/babel-parser/src/parser/expression.js
Original file line number Diff line number Diff line change
Expand Up @@ -2343,7 +2343,12 @@ export default class ExpressionParser extends LValParser {

if (reservedTest(word, this.inModule)) {
if (!this.prodParam.hasAwait && word === "await") {
this.raise(startLoc, Errors.AwaitNotInAsyncFunction);
this.raise(
startLoc,
this.hasPlugin("topLevelAwait")
? Errors.AwaitNotInAsyncContext
: Errors.AwaitNotInAsyncFunction,
);
} else {
this.raise(startLoc, Errors.UnexpectedReservedWord, word);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"type": "File",
"start":0,"end":14,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":14}},
"errors": [
"SyntaxError: Can not use keyword 'await' outside an async function (1:0)"
"SyntaxError: 'await' is only valid in async function (1:0)"
],
"program": {
"type": "Program",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"type": "File",
"start":0,"end":20,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":20}},
"errors": [
"SyntaxError: Can not use keyword 'await' outside an async function (1:6)"
"SyntaxError: 'await' is only valid in async function (1:6)"
],
"program": {
"type": "Program",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"type": "File",
"start":0,"end":24,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":24}},
"errors": [
"SyntaxError: Can not use keyword 'await' outside an async function (1:8)"
"SyntaxError: 'await' is only valid in async function (1:8)"
],
"program": {
"type": "Program",
Expand All @@ -24,6 +24,9 @@
{
"type": "ObjectProperty",
"start":8,"end":13,"loc":{"start":{"line":1,"column":8},"end":{"line":1,"column":13}},
"extra": {
"shorthand": true
},
"method": false,
"key": {
"type": "Identifier",
Expand All @@ -36,9 +39,6 @@
"type": "Identifier",
"start":8,"end":13,"loc":{"start":{"line":1,"column":8},"end":{"line":1,"column":13},"identifierName":"await"},
"name": "await"
},
"extra": {
"shorthand": true
}
}
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"type": "File",
"start":0,"end":26,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":26}},
"errors": [
"SyntaxError: Can not use keyword 'await' outside an async function (1:15)"
"SyntaxError: 'await' is only valid in async function (1:15)"
],
"program": {
"type": "Program",
Expand All @@ -28,6 +28,9 @@
{
"type": "ObjectProperty",
"start":15,"end":20,"loc":{"start":{"line":1,"column":15},"end":{"line":1,"column":20}},
"extra": {
"shorthand": true
},
"method": false,
"key": {
"type": "Identifier",
Expand All @@ -40,9 +43,6 @@
"type": "Identifier",
"start":15,"end":20,"loc":{"start":{"line":1,"column":15},"end":{"line":1,"column":20},"identifierName":"await"},
"name": "await"
},
"extra": {
"shorthand": true
}
}
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"type": "File",
"start":0,"end":19,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":19}},
"errors": [
"SyntaxError: Can not use keyword 'await' outside an async function (1:9)"
"SyntaxError: 'await' is only valid in async function (1:9)"
],
"program": {
"type": "Program",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"type": "File",
"start":0,"end":14,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":14}},
"errors": [
"SyntaxError: Can not use keyword 'await' outside an async function (1:6)"
"SyntaxError: 'await' is only valid in async function (1:6)"
],
"program": {
"type": "Program",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"type": "File",
"start":0,"end":39,"loc":{"start":{"line":1,"column":0},"end":{"line":3,"column":1}},
"errors": [
"SyntaxError: yield is not allowed in generator parameters (2:7)"
"SyntaxError: Yield expression is not allowed in formal parameters (2:7)"
],
"program": {
"type": "Program",
Expand Down Expand Up @@ -66,4 +66,4 @@
],
"directives": []
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"type": "File",
"start":0,"end":53,"loc":{"start":{"line":1,"column":0},"end":{"line":3,"column":1}},
"errors": [
"SyntaxError: yield is not allowed in generator parameters (2:15)"
"SyntaxError: Yield expression is not allowed in formal parameters (2:15)"
],
"program": {
"type": "Program",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"type": "File",
"start":0,"end":42,"loc":{"start":{"line":1,"column":0},"end":{"line":3,"column":1}},
"errors": [
"SyntaxError: yield is not allowed in generator parameters (2:7)"
"SyntaxError: Yield expression is not allowed in formal parameters (2:7)"
],
"program": {
"type": "Program",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"type": "File",
"start":0,"end":49,"loc":{"start":{"line":1,"column":0},"end":{"line":3,"column":1}},
"errors": [
"SyntaxError: yield is not allowed in generator parameters (2:17)"
"SyntaxError: Yield expression is not allowed in formal parameters (2:17)"
],
"program": {
"type": "Program",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"type": "File",
"start":0,"end":47,"loc":{"start":{"line":1,"column":0},"end":{"line":3,"column":1}},
"errors": [
"SyntaxError: yield is not allowed in generator parameters (2:8)",
"SyntaxError: Yield expression is not allowed in formal parameters (2:8)",
"SyntaxError: Binding invalid left-hand side in function parameter list (2:8)"
],
"program": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"type": "File",
"start":0,"end":41,"loc":{"start":{"line":1,"column":0},"end":{"line":3,"column":1}},
"errors": [
"SyntaxError: yield is not allowed in generator parameters (2:8)"
"SyntaxError: Yield expression is not allowed in formal parameters (2:8)"
],
"program": {
"type": "Program",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"type": "File",
"start":0,"end":27,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":27}},
"errors": [
"SyntaxError: yield is not allowed in generator parameters (1:15)"
"SyntaxError: Yield expression is not allowed in formal parameters (1:15)"
],
"program": {
"type": "Program",
Expand All @@ -16,6 +16,10 @@
"expression": {
"type": "ObjectExpression",
"start":1,"end":26,"loc":{"start":{"line":1,"column":1},"end":{"line":1,"column":26}},
"extra": {
"parenthesized": true,
"parenStart": 0
},
"properties": [
{
"type": "ObjectMethod",
Expand Down Expand Up @@ -55,11 +59,7 @@
"directives": []
}
}
],
"extra": {
"parenthesized": true,
"parenStart": 0
}
]
}
}
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"type": "File",
"start":0,"end":26,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":26}},
"errors": [
"SyntaxError: yield is not allowed in generator parameters (1:17)"
"SyntaxError: Yield expression is not allowed in formal parameters (1:17)"
],
"program": {
"type": "Program",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"type": "File",
"start":0,"end":35,"loc":{"start":{"line":1,"column":0},"end":{"line":3,"column":1}},
"errors": [
"SyntaxError: yield is not allowed in generator parameters (2:3)",
"SyntaxError: Yield expression is not allowed in formal parameters (2:3)",
"SyntaxError: Binding invalid left-hand side in function parameter list (2:3)"
],
"program": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"type": "File",
"start":0,"end":38,"loc":{"start":{"line":1,"column":0},"end":{"line":3,"column":1}},
"errors": [
"SyntaxError: yield is not allowed in generator parameters (2:3)",
"SyntaxError: Yield expression is not allowed in formal parameters (2:3)",
"SyntaxError: Binding invalid left-hand side in function parameter list (2:3)"
],
"program": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"type": "File",
"start":0,"end":41,"loc":{"start":{"line":1,"column":0},"end":{"line":3,"column":1}},
"errors": [
"SyntaxError: yield is not allowed in generator parameters (2:9)",
"SyntaxError: Yield expression is not allowed in formal parameters (2:9)",
"SyntaxError: Binding invalid left-hand side in function parameter list (2:9)"
],
"program": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
"type": "File",
"start":0,"end":33,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":33}},
"errors": [
"SyntaxError: yield is not allowed in generator parameters (1:17)",
"SyntaxError: yield is not allowed in generator parameters (1:24)"
"SyntaxError: Yield expression is not allowed in formal parameters (1:17)",
"SyntaxError: Yield expression is not allowed in formal parameters (1:24)"
],
"program": {
"type": "Program",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"type": "File",
"start":0,"end":38,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":38}},
"errors": [
"SyntaxError: yield is not allowed in generator parameters (1:21)"
"SyntaxError: Yield expression is not allowed in formal parameters (1:21)"
],
"program": {
"type": "Program",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"type": "File",
"start":0,"end":30,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":30}},
"errors": [
"SyntaxError: yield is not allowed in generator parameters (1:16)",
"SyntaxError: Yield expression is not allowed in formal parameters (1:16)",
"SyntaxError: Binding invalid left-hand side in function parameter list (1:16)"
],
"program": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"type": "File",
"start":0,"end":39,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":39}},
"errors": [
"SyntaxError: yield is not allowed in generator parameters (1:25)",
"SyntaxError: Yield expression is not allowed in formal parameters (1:25)",
"SyntaxError: Binding invalid left-hand side in function parameter list (1:25)"
],
"program": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"type": "File",
"start":0,"end":35,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":35}},
"errors": [
"SyntaxError: yield is not allowed in generator parameters (1:21)"
"SyntaxError: Yield expression is not allowed in formal parameters (1:21)"
],
"program": {
"type": "Program",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
{
"plugins": ["topLevelAwait"],
"plugins": [
"topLevelAwait"
],
"sourceType": "module",
"errorRecovery": false,
"throws": "Can not use keyword 'await' outside an async function (1:6)"
}
"throws": "'await' is only valid in async functions and the top level bodies of modules (1:6)"
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
{
"plugins": ["topLevelAwait"],
"plugins": [
"topLevelAwait"
],
"sourceType": "module",
"errorRecovery": false,
"throws": "Can not use keyword 'await' outside an async function (2:2)"
}
"throws": "'await' is only valid in async functions and the top level bodies of modules (2:2)"
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@
"supportsTopLevelAwait": false
},
"presets": ["env"],
"throws": "Can not use keyword 'await' outside an async function (1:0)"
"throws": "'await' is only valid in async function (1:0)"
}