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

Rephrase parser error message #11208

Merged
merged 6 commits into from Mar 17, 2020
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
16 changes: 6 additions & 10 deletions packages/babel-parser/src/parser/location.js
Expand Up @@ -35,8 +35,7 @@ export const Errors = Object.freeze({
ConstructorClassField: "Classes may not have a field named 'constructor'",
ConstructorClassPrivateField:
"Classes may not have a private field named '#constructor'",
// todo: rephrase to get/set accessor
ConstructorIsAccessor: "Constructor can't have get/set modifier",
ConstructorIsAccessor: "Class constructor may not be an accessor",
ConstructorIsAsync: "Constructor can't be an async function",
ConstructorIsGenerator: "Constructor can't be a generator",
DeclarationMissingInitializer: "%0 require an initialization value",
Expand Down Expand Up @@ -142,13 +141,12 @@ export const Errors = Object.freeze({
StrictEvalArgumentsBinding: "Binding '%0' in strict mode",
StrictFunction:
"In strict mode code, functions can only be declared at top level or inside a block",
StrictOctalLiteral: "Octal literal in strict mode",
StrictOctalLiteral: "Legacy octal literals are not allowed in strict mode",
StrictWith: "'with' in strict mode",
SuperNotAllowed:
"super() is only valid inside a class constructor of a subclass. Maybe a typo in the method name ('constructor') or not extending another class?",
SuperPrivateField: "Private fields can't be accessed on super",
//todo: rephrase this error message as it is too subjective
TrailingDecorator: "You have trailing decorators with no method",
TrailingDecorator: "Decorators must be attached to a class element",
TupleExpressionBarIncorrectEndSyntaxType:
"Tuple expressions ending with '|]' are only allowed when the 'syntaxType' option of the 'recordAndTuple' plugin is set to 'bar'",
TupleExpressionBarIncorrectStartSyntaxType:
Expand Down Expand Up @@ -177,18 +175,16 @@ export const Errors = Object.freeze({
UnexpectedTokenUnaryExponentiation:
"Illegal expression. Wrap left hand side or entire exponentiation in parentheses.",
UnsupportedBind: "Binding should be performed on object property.",
//todo: rephrase this error message as it is too subjective
UnsupportedDecoratorExport:
"You can only use decorators on an export when exporting a class",
"A decorated export must export a class declaration",
UnsupportedDefaultExport:
"Only expressions, functions or classes are allowed as the `default` export.",
UnsupportedImport: "import can only be used in import() or import.meta",
UnsupportedMetaProperty: "The only valid meta property for %0 is %0.%1",
//todo: remove Stage 2 as we are likely to forget updating when it progressed
UnsupportedParameterDecorator:
"Stage 2 decorators cannot be used to decorate parameters",
"Decorators cannot be used to decorate parameters",
Copy link
Member

Choose a reason for hiding this comment

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

Actually, legacy decorators can be used to decorate parameters. (for TS)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think it is okay because this error is not visible to users if they are using legacy decorators. Like we did in "Legacy octal literals are not allowed in strict mode", if an error is thrown on a legacy elements, we should prefix its name. Otherwise we are referring to the latest proposal.

UnsupportedPropertyDecorator:
"Stage 2 decorators disallow object literal property decorators",
"Decorators cannot be used to decorate object literal properties",
UnsupportedSuper:
"super can only be used with function calls (i.e. super()) or in property accesses (i.e. super.prop or super[prop])",
UnterminatedComment: "Unterminated comment",
Expand Down
3 changes: 1 addition & 2 deletions packages/babel-parser/src/plugins/flow.js
Expand Up @@ -104,9 +104,8 @@ const FlowErrors = Object.freeze({
UnexpectedReservedType: "Unexpected reserved type %0",
UnexpectedReservedUnderscore:
"`_` is only allowed as a type argument to call or new",
//todo: replace ´ by `
UnexpectedSpaceBetweenModuloChecks:
"Spaces between ´%´ and ´checks´ are not allowed here.",
"Spaces between `%` and `checks` are not allowed here.",
UnexpectedSpreadType:
"Spread operator cannot appear in class or interface definitions",
UnexpectedSubtractionOperand:
Expand Down
Expand Up @@ -13,15 +13,15 @@
}
},
"errors": [
"SyntaxError: Octal literal in strict mode (2:4)",
"SyntaxError: Octal literal in strict mode (7:4)",
"SyntaxError: Octal literal in strict mode (8:4)",
"SyntaxError: Octal literal in strict mode (14:4)",
"SyntaxError: Octal literal in strict mode (19:4)",
"SyntaxError: Octal literal in strict mode (20:4)",
"SyntaxError: Octal literal in strict mode (25:2)",
"SyntaxError: Octal literal in strict mode (30:2)",
"SyntaxError: Octal literal in strict mode (31:2)"
"SyntaxError: Legacy octal literals are not allowed in strict mode (2:4)",
"SyntaxError: Legacy octal literals are not allowed in strict mode (7:4)",
"SyntaxError: Legacy octal literals are not allowed in strict mode (8:4)",
"SyntaxError: Legacy octal literals are not allowed in strict mode (14:4)",
"SyntaxError: Legacy octal literals are not allowed in strict mode (19:4)",
"SyntaxError: Legacy octal literals are not allowed in strict mode (20:4)",
"SyntaxError: Legacy octal literals are not allowed in strict mode (25:2)",
"SyntaxError: Legacy octal literals are not allowed in strict mode (30:2)",
"SyntaxError: Legacy octal literals are not allowed in strict mode (31:2)"
],
"program": {
"type": "Program",
Expand Down
Expand Up @@ -13,18 +13,18 @@
}
},
"errors": [
"SyntaxError: Octal literal in strict mode (8:2)",
"SyntaxError: Octal literal in strict mode (9:2)",
"SyntaxError: Octal literal in strict mode (11:0)",
"SyntaxError: Octal literal in strict mode (12:0)",
"SyntaxError: Octal literal in strict mode (14:2)",
"SyntaxError: Octal literal in strict mode (14:10)",
"SyntaxError: Octal literal in strict mode (14:18)",
"SyntaxError: Octal literal in strict mode (1:2)",
"SyntaxError: Octal literal in strict mode (1:10)",
"SyntaxError: Octal literal in strict mode (1:18)",
"SyntaxError: Octal literal in strict mode (3:2)",
"SyntaxError: Octal literal in strict mode (4:2)"
"SyntaxError: Legacy octal literals are not allowed in strict mode (8:2)",
"SyntaxError: Legacy octal literals are not allowed in strict mode (9:2)",
"SyntaxError: Legacy octal literals are not allowed in strict mode (11:0)",
"SyntaxError: Legacy octal literals are not allowed in strict mode (12:0)",
"SyntaxError: Legacy octal literals are not allowed in strict mode (14:2)",
"SyntaxError: Legacy octal literals are not allowed in strict mode (14:10)",
"SyntaxError: Legacy octal literals are not allowed in strict mode (14:18)",
"SyntaxError: Legacy octal literals are not allowed in strict mode (1:2)",
"SyntaxError: Legacy octal literals are not allowed in strict mode (1:10)",
"SyntaxError: Legacy octal literals are not allowed in strict mode (1:18)",
"SyntaxError: Legacy octal literals are not allowed in strict mode (3:2)",
"SyntaxError: Legacy octal literals are not allowed in strict mode (4:2)"
],
"program": {
"type": "Program",
Expand Down
Expand Up @@ -13,7 +13,7 @@
}
},
"errors": [
"SyntaxError: Octal literal in strict mode (1:0)"
"SyntaxError: Legacy octal literals are not allowed in strict mode (1:0)"
],
"program": {
"type": "Program",
Expand Down
Expand Up @@ -13,7 +13,7 @@
}
},
"errors": [
"SyntaxError: Octal literal in strict mode (1:35)"
"SyntaxError: Legacy octal literals are not allowed in strict mode (1:35)"
],
"program": {
"type": "Program",
Expand Down Expand Up @@ -158,4 +158,4 @@
],
"directives": []
}
}
}
Expand Up @@ -13,7 +13,7 @@
}
},
"errors": [
"SyntaxError: Octal literal in strict mode (1:33)"
"SyntaxError: Legacy octal literals are not allowed in strict mode (1:33)"
],
"program": {
"type": "Program",
Expand Down Expand Up @@ -159,4 +159,4 @@
],
"directives": []
}
}
}
Expand Up @@ -13,7 +13,7 @@
}
},
"errors": [
"SyntaxError: Octal literal in strict mode (1:38)"
"SyntaxError: Legacy octal literals are not allowed in strict mode (1:38)"
],
"program": {
"type": "Program",
Expand Down
Expand Up @@ -13,7 +13,7 @@
}
},
"errors": [
"SyntaxError: Octal literal in strict mode (1:36)"
"SyntaxError: Legacy octal literals are not allowed in strict mode (1:36)"
],
"program": {
"type": "Program",
Expand Down
Expand Up @@ -13,7 +13,7 @@
}
},
"errors": [
"SyntaxError: Octal literal in strict mode (1:69)"
"SyntaxError: Legacy octal literals are not allowed in strict mode (1:69)"
],
"program": {
"type": "Program",
Expand Down
Expand Up @@ -13,7 +13,7 @@
}
},
"errors": [
"SyntaxError: Octal literal in strict mode (1:65)"
"SyntaxError: Legacy octal literals are not allowed in strict mode (1:65)"
],
"program": {
"type": "Program",
Expand Down
Expand Up @@ -13,7 +13,7 @@
}
},
"errors": [
"SyntaxError: Octal literal in strict mode (2:10)"
"SyntaxError: Legacy octal literals are not allowed in strict mode (2:10)"
],
"program": {
"type": "Program",
Expand Down
Expand Up @@ -13,7 +13,7 @@
}
},
"errors": [
"SyntaxError: Octal literal in strict mode (2:10)"
"SyntaxError: Legacy octal literals are not allowed in strict mode (2:10)"
],
"program": {
"type": "Program",
Expand Down
Expand Up @@ -13,7 +13,7 @@
}
},
"errors": [
"SyntaxError: Constructor can't have get/set modifier (1:14)"
"SyntaxError: Class constructor may not be an accessor (1:14)"
],
"program": {
"type": "Program",
Expand Down
Expand Up @@ -13,7 +13,7 @@
}
},
"errors": [
"SyntaxError: Octal literal in strict mode (1:21)"
"SyntaxError: Legacy octal literals are not allowed in strict mode (1:21)"
],
"program": {
"type": "Program",
Expand Down
Expand Up @@ -13,7 +13,7 @@
}
},
"errors": [
"SyntaxError: Octal literal in strict mode (1:21)"
"SyntaxError: Legacy octal literals are not allowed in strict mode (1:21)"
],
"program": {
"type": "Program",
Expand Down
Expand Up @@ -13,7 +13,7 @@
}
},
"errors": [
"SyntaxError: Octal literal in strict mode (1:2)"
"SyntaxError: Legacy octal literals are not allowed in strict mode (1:2)"
],
"program": {
"type": "Program",
Expand Down
Expand Up @@ -13,7 +13,7 @@
}
},
"errors": [
"SyntaxError: Octal literal in strict mode (1:35)"
"SyntaxError: Legacy octal literals are not allowed in strict mode (1:35)"
],
"program": {
"type": "Program",
Expand Down Expand Up @@ -158,4 +158,4 @@
],
"directives": []
}
}
}
Expand Up @@ -13,7 +13,7 @@
}
},
"errors": [
"SyntaxError: Octal literal in strict mode (1:33)"
"SyntaxError: Legacy octal literals are not allowed in strict mode (1:33)"
],
"program": {
"type": "Program",
Expand Down Expand Up @@ -159,4 +159,4 @@
],
"directives": []
}
}
}
Expand Up @@ -13,7 +13,7 @@
}
},
"errors": [
"SyntaxError: Octal literal in strict mode (1:38)"
"SyntaxError: Legacy octal literals are not allowed in strict mode (1:38)"
],
"program": {
"type": "Program",
Expand Down
Expand Up @@ -13,7 +13,7 @@
}
},
"errors": [
"SyntaxError: Octal literal in strict mode (1:36)"
"SyntaxError: Legacy octal literals are not allowed in strict mode (1:36)"
],
"program": {
"type": "Program",
Expand Down
Expand Up @@ -13,7 +13,7 @@
}
},
"errors": [
"SyntaxError: Octal literal in strict mode (1:36)"
"SyntaxError: Legacy octal literals are not allowed in strict mode (1:36)"
],
"program": {
"type": "Program",
Expand Down
Expand Up @@ -13,8 +13,8 @@
}
},
"errors": [
"SyntaxError: Octal literal in strict mode (1:36)",
"SyntaxError: Octal literal in strict mode (1:57)"
"SyntaxError: Legacy octal literals are not allowed in strict mode (1:36)",
"SyntaxError: Legacy octal literals are not allowed in strict mode (1:57)"
],
"program": {
"type": "Program",
Expand Down
Expand Up @@ -13,7 +13,7 @@
}
},
"errors": [
"SyntaxError: Octal literal in strict mode (1:69)"
"SyntaxError: Legacy octal literals are not allowed in strict mode (1:69)"
],
"program": {
"type": "Program",
Expand Down
Expand Up @@ -13,7 +13,7 @@
}
},
"errors": [
"SyntaxError: Constructor can't have get/set modifier (1:13)"
"SyntaxError: Class constructor may not be an accessor (1:13)"
],
"program": {
"type": "Program",
Expand Down
Expand Up @@ -13,7 +13,7 @@
}
},
"errors": [
"SyntaxError: Constructor can't have get/set modifier (1:13)"
"SyntaxError: Class constructor may not be an accessor (1:13)"
],
"program": {
"type": "Program",
Expand Down
Expand Up @@ -13,7 +13,7 @@
}
},
"errors": [
"SyntaxError: Stage 2 decorators cannot be used to decorate parameters (2:14)"
"SyntaxError: Decorators cannot be used to decorate parameters (2:14)"
],
"program": {
"type": "Program",
Expand Down
Expand Up @@ -13,7 +13,7 @@
}
},
"errors": [
"SyntaxError: Stage 2 decorators cannot be used to decorate parameters (1:14)"
"SyntaxError: Decorators cannot be used to decorate parameters (1:14)"
],
"program": {
"type": "Program",
Expand Down
Expand Up @@ -13,7 +13,7 @@
}
},
"errors": [
"SyntaxError: Stage 2 decorators cannot be used to decorate parameters (2:9)"
"SyntaxError: Decorators cannot be used to decorate parameters (2:9)"
],
"program": {
"type": "Program",
Expand Down
Expand Up @@ -13,7 +13,7 @@
}
},
"errors": [
"SyntaxError: Stage 2 decorators disallow object literal property decorators (2:2)"
"SyntaxError: Decorators cannot be used to decorate object literal properties (2:2)"
],
"program": {
"type": "Program",
Expand Down
@@ -1,4 +1,7 @@
{
"throws": "You can only use decorators on an export when exporting a class (2:0)",
"plugins": [
"decorators-legacy"
],
"throws": "A decorated export must export a class declaration (2:0)",
"sourceType": "module"
}
}