[ts] Throw a syntax error for index signature with declare (#12111)
This commit is contained in:
parent
1a074ee7e6
commit
434b65bc2a
@ -80,6 +80,8 @@ const TSErrors = Object.freeze({
|
|||||||
IndexSignatureHasAccessibility:
|
IndexSignatureHasAccessibility:
|
||||||
"Index signatures cannot have an accessibility modifier ('%0')",
|
"Index signatures cannot have an accessibility modifier ('%0')",
|
||||||
IndexSignatureHasStatic: "Index signatures cannot have the 'static' modifier",
|
IndexSignatureHasStatic: "Index signatures cannot have the 'static' modifier",
|
||||||
|
IndexSignatureHasDeclare:
|
||||||
|
"Index signatures cannot have the 'declare' modifier",
|
||||||
InvalidTupleMemberLabel:
|
InvalidTupleMemberLabel:
|
||||||
"Tuple members must be labeled with a simple identifier.",
|
"Tuple members must be labeled with a simple identifier.",
|
||||||
MixedLabeledAndUnlabeledElements:
|
MixedLabeledAndUnlabeledElements:
|
||||||
@ -2108,6 +2110,9 @@ export default (superClass: Class<Parser>): Class<Parser> =>
|
|||||||
(member: any).accessibility,
|
(member: any).accessibility,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
if ((member: any).declare) {
|
||||||
|
this.raise(member.start, TSErrors.IndexSignatureHasDeclare);
|
||||||
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
class C {
|
class C {
|
||||||
abstract [key: string]: string;
|
abstract [key: string]: string;
|
||||||
static [key: string]: string;
|
static [key: string]: string;
|
||||||
|
declare [key: string]: string;
|
||||||
private [key: string]: string;
|
private [key: string]: string;
|
||||||
public [key: string]: string;
|
public [key: string]: string;
|
||||||
protected [key: string]: string;
|
protected [key: string]: string;
|
||||||
|
|||||||
@ -1,22 +1,23 @@
|
|||||||
{
|
{
|
||||||
"type": "File",
|
"type": "File",
|
||||||
"start":0,"end":177,"loc":{"start":{"line":1,"column":0},"end":{"line":7,"column":1}},
|
"start":0,"end":210,"loc":{"start":{"line":1,"column":0},"end":{"line":8,"column":1}},
|
||||||
"errors": [
|
"errors": [
|
||||||
"SyntaxError: Index signatures cannot have the 'abstract' modifier (2:2)",
|
"SyntaxError: Index signatures cannot have the 'abstract' modifier (2:2)",
|
||||||
"SyntaxError: Index signatures cannot have the 'static' modifier (3:2)",
|
"SyntaxError: Index signatures cannot have the 'static' modifier (3:2)",
|
||||||
"SyntaxError: Index signatures cannot have an accessibility modifier ('private') (4:2)",
|
"SyntaxError: Index signatures cannot have the 'declare' modifier (4:2)",
|
||||||
"SyntaxError: Index signatures cannot have an accessibility modifier ('public') (5:2)",
|
"SyntaxError: Index signatures cannot have an accessibility modifier ('private') (5:2)",
|
||||||
"SyntaxError: Index signatures cannot have an accessibility modifier ('protected') (6:2)"
|
"SyntaxError: Index signatures cannot have an accessibility modifier ('public') (6:2)",
|
||||||
|
"SyntaxError: Index signatures cannot have an accessibility modifier ('protected') (7:2)"
|
||||||
],
|
],
|
||||||
"program": {
|
"program": {
|
||||||
"type": "Program",
|
"type": "Program",
|
||||||
"start":0,"end":177,"loc":{"start":{"line":1,"column":0},"end":{"line":7,"column":1}},
|
"start":0,"end":210,"loc":{"start":{"line":1,"column":0},"end":{"line":8,"column":1}},
|
||||||
"sourceType": "module",
|
"sourceType": "module",
|
||||||
"interpreter": null,
|
"interpreter": null,
|
||||||
"body": [
|
"body": [
|
||||||
{
|
{
|
||||||
"type": "ClassDeclaration",
|
"type": "ClassDeclaration",
|
||||||
"start":0,"end":177,"loc":{"start":{"line":1,"column":0},"end":{"line":7,"column":1}},
|
"start":0,"end":210,"loc":{"start":{"line":1,"column":0},"end":{"line":8,"column":1}},
|
||||||
"id": {
|
"id": {
|
||||||
"type": "Identifier",
|
"type": "Identifier",
|
||||||
"start":6,"end":7,"loc":{"start":{"line":1,"column":6},"end":{"line":1,"column":7},"identifierName":"C"},
|
"start":6,"end":7,"loc":{"start":{"line":1,"column":6},"end":{"line":1,"column":7},"identifierName":"C"},
|
||||||
@ -25,7 +26,7 @@
|
|||||||
"superClass": null,
|
"superClass": null,
|
||||||
"body": {
|
"body": {
|
||||||
"type": "ClassBody",
|
"type": "ClassBody",
|
||||||
"start":8,"end":177,"loc":{"start":{"line":1,"column":8},"end":{"line":7,"column":1}},
|
"start":8,"end":210,"loc":{"start":{"line":1,"column":8},"end":{"line":8,"column":1}},
|
||||||
"body": [
|
"body": [
|
||||||
{
|
{
|
||||||
"type": "TSIndexSignature",
|
"type": "TSIndexSignature",
|
||||||
@ -85,7 +86,7 @@
|
|||||||
{
|
{
|
||||||
"type": "TSIndexSignature",
|
"type": "TSIndexSignature",
|
||||||
"start":78,"end":108,"loc":{"start":{"line":4,"column":2},"end":{"line":4,"column":32}},
|
"start":78,"end":108,"loc":{"start":{"line":4,"column":2},"end":{"line":4,"column":32}},
|
||||||
"accessibility": "private",
|
"declare": true,
|
||||||
"parameters": [
|
"parameters": [
|
||||||
{
|
{
|
||||||
"type": "Identifier",
|
"type": "Identifier",
|
||||||
@ -112,57 +113,85 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"type": "TSIndexSignature",
|
"type": "TSIndexSignature",
|
||||||
"start":111,"end":140,"loc":{"start":{"line":5,"column":2},"end":{"line":5,"column":31}},
|
"start":111,"end":141,"loc":{"start":{"line":5,"column":2},"end":{"line":5,"column":32}},
|
||||||
"accessibility": "public",
|
"accessibility": "private",
|
||||||
"parameters": [
|
"parameters": [
|
||||||
{
|
{
|
||||||
"type": "Identifier",
|
"type": "Identifier",
|
||||||
"start":119,"end":130,"loc":{"start":{"line":5,"column":10},"end":{"line":5,"column":21},"identifierName":"key"},
|
"start":120,"end":131,"loc":{"start":{"line":5,"column":11},"end":{"line":5,"column":22},"identifierName":"key"},
|
||||||
"name": "key",
|
"name": "key",
|
||||||
"typeAnnotation": {
|
"typeAnnotation": {
|
||||||
"type": "TSTypeAnnotation",
|
"type": "TSTypeAnnotation",
|
||||||
"start":122,"end":130,"loc":{"start":{"line":5,"column":13},"end":{"line":5,"column":21}},
|
"start":123,"end":131,"loc":{"start":{"line":5,"column":14},"end":{"line":5,"column":22}},
|
||||||
"typeAnnotation": {
|
"typeAnnotation": {
|
||||||
"type": "TSStringKeyword",
|
"type": "TSStringKeyword",
|
||||||
"start":124,"end":130,"loc":{"start":{"line":5,"column":15},"end":{"line":5,"column":21}}
|
"start":125,"end":131,"loc":{"start":{"line":5,"column":16},"end":{"line":5,"column":22}}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"typeAnnotation": {
|
"typeAnnotation": {
|
||||||
"type": "TSTypeAnnotation",
|
"type": "TSTypeAnnotation",
|
||||||
"start":131,"end":139,"loc":{"start":{"line":5,"column":22},"end":{"line":5,"column":30}},
|
"start":132,"end":140,"loc":{"start":{"line":5,"column":23},"end":{"line":5,"column":31}},
|
||||||
"typeAnnotation": {
|
"typeAnnotation": {
|
||||||
"type": "TSStringKeyword",
|
"type": "TSStringKeyword",
|
||||||
"start":133,"end":139,"loc":{"start":{"line":5,"column":24},"end":{"line":5,"column":30}}
|
"start":134,"end":140,"loc":{"start":{"line":5,"column":25},"end":{"line":5,"column":31}}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"type": "TSIndexSignature",
|
"type": "TSIndexSignature",
|
||||||
"start":143,"end":175,"loc":{"start":{"line":6,"column":2},"end":{"line":6,"column":34}},
|
"start":144,"end":173,"loc":{"start":{"line":6,"column":2},"end":{"line":6,"column":31}},
|
||||||
"accessibility": "protected",
|
"accessibility": "public",
|
||||||
"parameters": [
|
"parameters": [
|
||||||
{
|
{
|
||||||
"type": "Identifier",
|
"type": "Identifier",
|
||||||
"start":154,"end":165,"loc":{"start":{"line":6,"column":13},"end":{"line":6,"column":24},"identifierName":"key"},
|
"start":152,"end":163,"loc":{"start":{"line":6,"column":10},"end":{"line":6,"column":21},"identifierName":"key"},
|
||||||
"name": "key",
|
"name": "key",
|
||||||
"typeAnnotation": {
|
"typeAnnotation": {
|
||||||
"type": "TSTypeAnnotation",
|
"type": "TSTypeAnnotation",
|
||||||
"start":157,"end":165,"loc":{"start":{"line":6,"column":16},"end":{"line":6,"column":24}},
|
"start":155,"end":163,"loc":{"start":{"line":6,"column":13},"end":{"line":6,"column":21}},
|
||||||
"typeAnnotation": {
|
"typeAnnotation": {
|
||||||
"type": "TSStringKeyword",
|
"type": "TSStringKeyword",
|
||||||
"start":159,"end":165,"loc":{"start":{"line":6,"column":18},"end":{"line":6,"column":24}}
|
"start":157,"end":163,"loc":{"start":{"line":6,"column":15},"end":{"line":6,"column":21}}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"typeAnnotation": {
|
"typeAnnotation": {
|
||||||
"type": "TSTypeAnnotation",
|
"type": "TSTypeAnnotation",
|
||||||
"start":166,"end":174,"loc":{"start":{"line":6,"column":25},"end":{"line":6,"column":33}},
|
"start":164,"end":172,"loc":{"start":{"line":6,"column":22},"end":{"line":6,"column":30}},
|
||||||
"typeAnnotation": {
|
"typeAnnotation": {
|
||||||
"type": "TSStringKeyword",
|
"type": "TSStringKeyword",
|
||||||
"start":168,"end":174,"loc":{"start":{"line":6,"column":27},"end":{"line":6,"column":33}}
|
"start":166,"end":172,"loc":{"start":{"line":6,"column":24},"end":{"line":6,"column":30}}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "TSIndexSignature",
|
||||||
|
"start":176,"end":208,"loc":{"start":{"line":7,"column":2},"end":{"line":7,"column":34}},
|
||||||
|
"accessibility": "protected",
|
||||||
|
"parameters": [
|
||||||
|
{
|
||||||
|
"type": "Identifier",
|
||||||
|
"start":187,"end":198,"loc":{"start":{"line":7,"column":13},"end":{"line":7,"column":24},"identifierName":"key"},
|
||||||
|
"name": "key",
|
||||||
|
"typeAnnotation": {
|
||||||
|
"type": "TSTypeAnnotation",
|
||||||
|
"start":190,"end":198,"loc":{"start":{"line":7,"column":16},"end":{"line":7,"column":24}},
|
||||||
|
"typeAnnotation": {
|
||||||
|
"type": "TSStringKeyword",
|
||||||
|
"start":192,"end":198,"loc":{"start":{"line":7,"column":18},"end":{"line":7,"column":24}}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"typeAnnotation": {
|
||||||
|
"type": "TSTypeAnnotation",
|
||||||
|
"start":199,"end":207,"loc":{"start":{"line":7,"column":25},"end":{"line":7,"column":33}},
|
||||||
|
"typeAnnotation": {
|
||||||
|
"type": "TSStringKeyword",
|
||||||
|
"start":201,"end":207,"loc":{"start":{"line":7,"column":27},"end":{"line":7,"column":33}}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user