Rephrase parser error message (#11208)

* 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>
This commit is contained in:
Huáng Jùnliàng 2020-03-16 21:48:32 -04:00 committed by GitHub
parent 8e7ca22ed7
commit 841f4428e8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
35 changed files with 76 additions and 73 deletions

View File

@ -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",
@ -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:
@ -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",

View File

@ -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:

View File

@ -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",

View File

@ -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",

View File

@ -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",

View File

@ -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",
@ -158,4 +158,4 @@
],
"directives": []
}
}
}

View File

@ -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",
@ -159,4 +159,4 @@
],
"directives": []
}
}
}

View File

@ -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",

View File

@ -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",

View File

@ -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",

View File

@ -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",

View File

@ -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",

View File

@ -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",

View File

@ -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",

View File

@ -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",

View File

@ -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",

View File

@ -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",

View File

@ -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",
@ -158,4 +158,4 @@
],
"directives": []
}
}
}

View File

@ -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",
@ -159,4 +159,4 @@
],
"directives": []
}
}
}

View File

@ -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",

View File

@ -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",

View File

@ -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",

View File

@ -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",

View File

@ -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",

View File

@ -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",

View File

@ -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",

View File

@ -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",

View File

@ -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",

View File

@ -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",

View File

@ -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",

View File

@ -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"
}
}

View File

@ -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"
}
}

View File

@ -1,4 +1,6 @@
{
"plugins": ["decorators-legacy"],
"throws": "You have trailing decorators with no method (1:18)"
}
"plugins": [
"decorators-legacy"
],
"throws": "Decorators must be attached to a class element (1:18)"
}

View File

@ -13,7 +13,7 @@
}
},
"errors": [
"SyntaxError: Spaces between ´%´ and ´checks´ are not allowed here. (1:20)"
"SyntaxError: Spaces between `%` and `checks` are not allowed here. (1:20)"
],
"program": {
"type": "Program",

View File

@ -13,7 +13,7 @@
}
},
"errors": [
"SyntaxError: Spaces between ´%´ and ´checks´ are not allowed here. (1:17)"
"SyntaxError: Spaces between `%` and `checks` are not allowed here. (1:17)"
],
"program": {
"type": "Program",