Skip to content
This repository has been archived by the owner on May 19, 2018. It is now read-only.

Commit

Permalink
Flow: Allow class properties to be named static (#184)
Browse files Browse the repository at this point in the history
Related: #158
  • Loading branch information
motiz88 authored and hzoo committed Oct 17, 2016
1 parent d14c8bd commit e047a1b
Show file tree
Hide file tree
Showing 3 changed files with 162 additions and 6 deletions.
8 changes: 2 additions & 6 deletions src/plugins/flow.js
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ pp.flowParseObjectType = function (allowStatic, allowExact) {
let optional = false;
let startPos = this.state.start, startLoc = this.state.startLoc;
node = this.startNode();
if (allowStatic && this.isContextual("static")) {
if (allowStatic && this.isContextual("static") && this.lookahead().type !== tt.colon) {
this.next();
isStatic = true;
}
Expand All @@ -376,11 +376,7 @@ pp.flowParseObjectType = function (allowStatic, allowExact) {
}
nodeStart.callProperties.push(this.flowParseObjectTypeCallProperty(node, allowStatic));
} else {
if (isStatic && this.match(tt.colon)) {
propertyKey = this.parseIdentifier();
} else {
propertyKey = this.flowParseObjectPropertyKey();
}
propertyKey = this.flowParseObjectPropertyKey();
if (this.isRelational("<") || this.match(tt.parenL)) {
// This is a method property
if (variance) {
Expand Down
3 changes: 3 additions & 0 deletions test/fixtures/flow/class-properties/named-static/actual.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
declare class A {
static: T;
}
157 changes: 157 additions & 0 deletions test/fixtures/flow/class-properties/named-static/expected.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
{
"type": "File",
"start": 0,
"end": 32,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 3,
"column": 1
}
},
"program": {
"type": "Program",
"start": 0,
"end": 32,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 3,
"column": 1
}
},
"sourceType": "module",
"body": [
{
"type": "DeclareClass",
"start": 0,
"end": 32,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 3,
"column": 1
}
},
"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": [],
"mixins": [],
"body": {
"type": "ObjectTypeAnnotation",
"start": 16,
"end": 32,
"loc": {
"start": {
"line": 1,
"column": 16
},
"end": {
"line": 3,
"column": 1
}
},
"callProperties": [],
"properties": [
{
"type": "ObjectTypeProperty",
"start": 20,
"end": 30,
"loc": {
"start": {
"line": 2,
"column": 2
},
"end": {
"line": 2,
"column": 12
}
},
"key": {
"type": "Identifier",
"start": 20,
"end": 26,
"loc": {
"start": {
"line": 2,
"column": 2
},
"end": {
"line": 2,
"column": 8
},
"identifierName": "static"
},
"name": "static"
},
"value": {
"type": "GenericTypeAnnotation",
"start": 28,
"end": 29,
"loc": {
"start": {
"line": 2,
"column": 10
},
"end": {
"line": 2,
"column": 11
}
},
"typeParameters": null,
"id": {
"type": "Identifier",
"start": 28,
"end": 29,
"loc": {
"start": {
"line": 2,
"column": 10
},
"end": {
"line": 2,
"column": 11
},
"identifierName": "T"
},
"name": "T"
}
},
"optional": false,
"static": false,
"variance": null
}
],
"indexers": [],
"exact": false
}
}
],
"directives": []
}
}

0 comments on commit e047a1b

Please sign in to comment.