Fix declare class with qualified type identifier (#97)
This makes declare class extends behave the same way as in flow The ast-token after the extends keyword, might be either Identifier or QualifiedTypeIdentifier To do that this commits splits the parseGenericType into two functions, one for parsing genericType and on for qualifiedTypeIdentifier
This commit is contained in:
parent
efab40154e
commit
27ad69d43f
@ -165,7 +165,7 @@ pp.flowParseInterfaceish = function (node, allowStatic) {
|
||||
pp.flowParseInterfaceExtends = function () {
|
||||
let node = this.startNode();
|
||||
|
||||
node.id = this.parseIdentifier();
|
||||
node.id = this.flowParseQualifiedTypeIdentifier();
|
||||
if (this.isRelational("<")) {
|
||||
node.typeParameters = this.flowParseTypeParameterInstantiation();
|
||||
} else {
|
||||
@ -394,18 +394,26 @@ pp.flowObjectTypeSemicolon = function () {
|
||||
}
|
||||
};
|
||||
|
||||
pp.flowParseQualifiedTypeIdentifier = function (startPos, startLoc, id) {
|
||||
startPos = startPos || this.state.start;
|
||||
startLoc = startLoc || this.state.startLoc;
|
||||
let node = id || this.parseIdentifier();
|
||||
|
||||
while (this.eat(tt.dot)) {
|
||||
let node2 = this.startNodeAt(startPos, startLoc);
|
||||
node2.qualification = node;
|
||||
node2.id = this.parseIdentifier();
|
||||
node = this.finishNode(node2, "QualifiedTypeIdentifier");
|
||||
}
|
||||
|
||||
return node;
|
||||
};
|
||||
|
||||
pp.flowParseGenericType = function (startPos, startLoc, id) {
|
||||
let node = this.startNodeAt(startPos, startLoc);
|
||||
|
||||
node.typeParameters = null;
|
||||
node.id = id;
|
||||
|
||||
while (this.eat(tt.dot)) {
|
||||
let node2 = this.startNodeAt(startPos, startLoc);
|
||||
node2.qualification = node.id;
|
||||
node2.id = this.parseIdentifier();
|
||||
node.id = this.finishNode(node2, "QualifiedTypeIdentifier");
|
||||
}
|
||||
node.id = this.flowParseQualifiedTypeIdentifier(startPos, startLoc, id);
|
||||
|
||||
if (this.isRelational("<")) {
|
||||
node.typeParameters = this.flowParseTypeParameterInstantiation();
|
||||
|
||||
1
test/fixtures/flow/declare-statements/16/actual.js
vendored
Normal file
1
test/fixtures/flow/declare-statements/16/actual.js
vendored
Normal file
@ -0,0 +1 @@
|
||||
declare class A extends C.B.D { }
|
||||
185
test/fixtures/flow/declare-statements/16/expected.json
vendored
Normal file
185
test/fixtures/flow/declare-statements/16/expected.json
vendored
Normal file
@ -0,0 +1,185 @@
|
||||
{
|
||||
"type": "File",
|
||||
"start": 0,
|
||||
"end": 33,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 1,
|
||||
"column": 33
|
||||
}
|
||||
},
|
||||
"program": {
|
||||
"type": "Program",
|
||||
"start": 0,
|
||||
"end": 33,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 1,
|
||||
"column": 33
|
||||
}
|
||||
},
|
||||
"sourceType": "module",
|
||||
"body": [
|
||||
{
|
||||
"type": "DeclareClass",
|
||||
"start": 0,
|
||||
"end": 33,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 1,
|
||||
"column": 33
|
||||
}
|
||||
},
|
||||
"id": {
|
||||
"type": "Identifier",
|
||||
"start": 14,
|
||||
"end": 15,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 14
|
||||
},
|
||||
"end": {
|
||||
"line": 1,
|
||||
"column": 15
|
||||
},
|
||||
"identifierName": "A"
|
||||
},
|
||||
"name": "A"
|
||||
},
|
||||
"typeParameters": null,
|
||||
"extends": [
|
||||
{
|
||||
"type": "InterfaceExtends",
|
||||
"start": 24,
|
||||
"end": 29,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 24
|
||||
},
|
||||
"end": {
|
||||
"line": 1,
|
||||
"column": 29
|
||||
}
|
||||
},
|
||||
"id": {
|
||||
"type": "QualifiedTypeIdentifier",
|
||||
"start": 24,
|
||||
"end": 29,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 24
|
||||
},
|
||||
"end": {
|
||||
"line": 1,
|
||||
"column": 29
|
||||
}
|
||||
},
|
||||
"qualification": {
|
||||
"type": "QualifiedTypeIdentifier",
|
||||
"start": 24,
|
||||
"end": 27,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 24
|
||||
},
|
||||
"end": {
|
||||
"line": 1,
|
||||
"column": 27
|
||||
}
|
||||
},
|
||||
"qualification": {
|
||||
"type": "Identifier",
|
||||
"start": 24,
|
||||
"end": 25,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 24
|
||||
},
|
||||
"end": {
|
||||
"line": 1,
|
||||
"column": 25
|
||||
},
|
||||
"identifierName": "C"
|
||||
},
|
||||
"name": "C"
|
||||
},
|
||||
"id": {
|
||||
"type": "Identifier",
|
||||
"start": 26,
|
||||
"end": 27,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 26
|
||||
},
|
||||
"end": {
|
||||
"line": 1,
|
||||
"column": 27
|
||||
},
|
||||
"identifierName": "B"
|
||||
},
|
||||
"name": "B"
|
||||
}
|
||||
},
|
||||
"id": {
|
||||
"type": "Identifier",
|
||||
"start": 28,
|
||||
"end": 29,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 28
|
||||
},
|
||||
"end": {
|
||||
"line": 1,
|
||||
"column": 29
|
||||
},
|
||||
"identifierName": "D"
|
||||
},
|
||||
"name": "D"
|
||||
}
|
||||
},
|
||||
"typeParameters": null
|
||||
}
|
||||
],
|
||||
"mixins": [],
|
||||
"body": {
|
||||
"type": "ObjectTypeAnnotation",
|
||||
"start": 30,
|
||||
"end": 33,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 30
|
||||
},
|
||||
"end": {
|
||||
"line": 1,
|
||||
"column": 33
|
||||
}
|
||||
},
|
||||
"callProperties": [],
|
||||
"properties": [],
|
||||
"indexers": []
|
||||
}
|
||||
}
|
||||
],
|
||||
"directives": []
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user