Skip to content

Commit

Permalink
Rephrase parser error message (#11208)
Browse files Browse the repository at this point in the history
* refactor: rephrase some parser error messages

* update test fixtures

* Update packages/babel-parser/src/parser/location.js

Co-Authored-By: Nicol貌 Ribaudo <nicolo.ribaudo@gmail.com>

* address review comments

* Update packages/babel-parser/src/parser/location.js

Co-Authored-By: Brian Ng <bng412@gmail.com>

* update test fixtures

Co-authored-by: Nicol貌 Ribaudo <nicolo.ribaudo@gmail.com>
Co-authored-by: Brian Ng <bng412@gmail.com>
  • Loading branch information
3 people committed Mar 17, 2020
1 parent 8e7ca22 commit 841f442
Show file tree
Hide file tree
Showing 35 changed files with 76 additions and 73 deletions.
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",
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"
}
}

0 comments on commit 841f442

Please sign in to comment.