Skip to content

Commit

Permalink
Correctly parse interface methods named 'static' (#8374)
Browse files Browse the repository at this point in the history
  • Loading branch information
bakkot authored and nicolo-ribaudo committed Jul 24, 2018
1 parent c70a32a commit a811cf7
Show file tree
Hide file tree
Showing 7 changed files with 390 additions and 85 deletions.
4 changes: 2 additions & 2 deletions packages/babel-parser/src/plugins/flow.js
Expand Up @@ -463,7 +463,7 @@ export default (superClass: Class<Parser>): Class<Parser> =>
} while (this.eat(tt.comma));
}

node.body = this.flowParseObjectType(true, false, false, isClass);
node.body = this.flowParseObjectType(isClass, false, false, isClass);
}

flowParseInterfaceExtends(): N.FlowInterfaceExtends {
Expand Down Expand Up @@ -656,7 +656,7 @@ export default (superClass: Class<Parser>): Class<Parser> =>
} while (this.eat(tt.comma));
}

node.body = this.flowParseObjectType(true, false, false, false);
node.body = this.flowParseObjectType(false, false, false, false);

return this.finishNode(node, "InterfaceTypeAnnotation");
}
Expand Down
@@ -0,0 +1 @@
type T = interface { static(): number }
@@ -0,0 +1,175 @@
{
"type": "File",
"start": 0,
"end": 39,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 39
}
},
"program": {
"type": "Program",
"start": 0,
"end": 39,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 39
}
},
"sourceType": "module",
"interpreter": null,
"body": [
{
"type": "TypeAlias",
"start": 0,
"end": 39,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 39
}
},
"id": {
"type": "Identifier",
"start": 5,
"end": 6,
"loc": {
"start": {
"line": 1,
"column": 5
},
"end": {
"line": 1,
"column": 6
},
"identifierName": "T"
},
"name": "T"
},
"typeParameters": null,
"right": {
"type": "InterfaceTypeAnnotation",
"start": 9,
"end": 39,
"loc": {
"start": {
"line": 1,
"column": 9
},
"end": {
"line": 1,
"column": 39
}
},
"extends": [],
"body": {
"type": "ObjectTypeAnnotation",
"start": 19,
"end": 39,
"loc": {
"start": {
"line": 1,
"column": 19
},
"end": {
"line": 1,
"column": 39
}
},
"callProperties": [],
"properties": [
{
"type": "ObjectTypeProperty",
"start": 21,
"end": 37,
"loc": {
"start": {
"line": 1,
"column": 21
},
"end": {
"line": 1,
"column": 37
}
},
"key": {
"type": "Identifier",
"start": 21,
"end": 27,
"loc": {
"start": {
"line": 1,
"column": 21
},
"end": {
"line": 1,
"column": 27
},
"identifierName": "static"
},
"name": "static"
},
"static": false,
"proto": false,
"kind": "init",
"method": true,
"value": {
"type": "FunctionTypeAnnotation",
"start": 21,
"end": 37,
"loc": {
"start": {
"line": 1,
"column": 21
},
"end": {
"line": 1,
"column": 37
}
},
"params": [],
"rest": null,
"typeParameters": null,
"returnType": {
"type": "NumberTypeAnnotation",
"start": 31,
"end": 37,
"loc": {
"start": {
"line": 1,
"column": 31
},
"end": {
"line": 1,
"column": 37
}
}
}
},
"optional": false
}
],
"indexers": [],
"internalSlots": [],
"exact": false
}
}
}
],
"directives": []
}
}
@@ -1,5 +1,4 @@
interface IFoo {
x: boolean;
static (): void;
static y: boolean;
}

0 comments on commit a811cf7

Please sign in to comment.