- The visitor keys for `ObjectTypeAnnotation`s were incorrect so those nodes weren't being traversed so comments weren't attached for them.
 - The type parser wasn't eating the semicolons for the nodes so the `end` location of each of the type properties wasn't accurate which threw off the code generation newline algorithm.
 - Type properties hadn't been given the `UserWhitespacable` alias.
This commit is contained in:
Sebastian McKenzie 2015-03-29 16:44:36 +11:00
parent bbba374783
commit c9243e8e97
5 changed files with 26 additions and 10 deletions

View File

@ -215,6 +215,7 @@ pp.flow_parseObjectTypeIndexer = function (node, isStatic) {
this.expect(tt.colon)
node.value = this.flow_parseType()
this.flow_objectTypeSemicolon()
return this.finishNode(node, "ObjectTypeIndexer")
}
@ -251,6 +252,7 @@ pp.flow_parseObjectTypeMethod = function (start, isStatic, key) {
node.static = isStatic
node.key = key
node.optional = false
this.flow_objectTypeSemicolon()
return this.finishNode(node, "ObjectTypeProperty")
}
@ -258,6 +260,7 @@ pp.flow_parseObjectTypeCallProperty = function (node, isStatic) {
var valueNode = this.startNode()
node.static = isStatic
node.value = this.flow_parseObjectTypeMethodish(valueNode)
this.flow_objectTypeSemicolon()
return this.finishNode(node, "ObjectTypeCallProperty")
}
@ -307,13 +310,10 @@ pp.flow_parseObjectType = function (allowStatic) {
node.value = this.flow_parseType()
node.optional = optional
node.static = isStatic
this.flow_objectTypeSemicolon()
nodeStart.properties.push(this.finishNode(node, "ObjectTypeProperty"))
}
}
if (!this.eat(tt.semi) && this.type !== tt.braceR) {
this.unexpected()
}
}
this.expect(tt.braceR)
@ -321,6 +321,12 @@ pp.flow_parseObjectType = function (allowStatic) {
return this.finishNode(nodeStart, "ObjectTypeAnnotation")
}
pp.flow_objectTypeSemicolon = function () {
if (!this.eat(tt.semi) && this.type !== tt.braceR) {
this.unexpected()
}
}
pp.flow_parseGenericType = function (start, id) {
var node = this.startNodeAt(start)

View File

@ -167,17 +167,25 @@ export { TypeParameterInstantiation as TypeParameterDeclaration };
export function ObjectTypeAnnotation(node, print) {
this.push("{");
var props = node.properties.concat(node.callProperties, node.indexers);
if (props.length) {
this.space();
print.list(props, { indent: true, separator: "; " });
print.list(props, {
separator: false,
indent: true
});
this.space();
}
this.push("}");
}
export function ObjectTypeCallProperty(node, print) {
if (node.static) this.push("static ");
print(node.value);
this.semicolon();
}
export function ObjectTypeIndexer(node, print) {
@ -191,6 +199,7 @@ export function ObjectTypeIndexer(node, print) {
this.push(":");
this.space();
print(node.value);
this.semicolon();
}
export function ObjectTypeProperty(node, print) {
@ -202,6 +211,7 @@ export function ObjectTypeProperty(node, print) {
this.space();
}
print(node.value);
this.semicolon();
}
export function QualifiedTypeIdentifier(node, print) {

View File

@ -100,7 +100,7 @@ class CodeGenerator {
};
print.list = function (items, opts = {}) {
opts.separator ||= ", ";
if (opts.separator == null) opts.separator = ", ";
print.join(items, opts);
};

View File

@ -98,9 +98,9 @@
"TypeParameterDeclaration": ["Flow"],
"TypeParameterInstantiation": ["Flow"],
"ObjectTypeAnnotation": ["Flow"],
"ObjectTypeCallProperty": ["Flow"],
"ObjectTypeIndexer": ["Flow"],
"ObjectTypeProperty": ["Flow"],
"ObjectTypeCallProperty": ["Flow", "UserWhitespacable"],
"ObjectTypeIndexer": ["Flow", "UserWhitespacable"],
"ObjectTypeProperty": ["Flow", "UserWhitespacable"],
"QualifiedTypeIdentifier": ["Flow"],
"UnionTypeAnnotation": ["Flow"],
"VoidTypeAnnotation": ["Flow"],

View File

@ -98,7 +98,7 @@
"TypeCastExpression": ["expression", "typeAnnotation"],
"TypeParameterDeclaration": ["params"],
"TypeParameterInstantiation": ["params"],
"ObjectTypeAnnotation": ["key", "value"],
"ObjectTypeAnnotation": ["properties", "indexers", "callProperties"],
"ObjectTypeCallProperty": ["value"],
"ObjectTypeIndexer": ["id", "key", "value"],
"ObjectTypeProperty": ["key", "value"],