@@ -43,6 +43,11 @@ export function DeclareModule(node: Object) {
|
||||
this.print(node.body, node);
|
||||
}
|
||||
|
||||
export function DeclareTypeAlias(node: Object) {
|
||||
this.push("declare ");
|
||||
this.TypeAlias(node);
|
||||
}
|
||||
|
||||
export function DeclareVariable(node: Object) {
|
||||
this.push("declare var ");
|
||||
this.print(node.id, node);
|
||||
|
||||
@@ -10,3 +10,5 @@ declare class A { static foo(): number; static x : string }
|
||||
declare class A { static [ indexer: number]: string }
|
||||
declare class A { static () : number }
|
||||
declare class A mixins B<T>, C {}
|
||||
declare type A = string
|
||||
declare type T<U> = { [k:string]: U }
|
||||
|
||||
@@ -10,3 +10,5 @@ declare class A { static foo(): number; static x: string; }
|
||||
declare class A { static [indexer: number]: string }
|
||||
declare class A { static (): number }
|
||||
declare class A mixins B<T>, C {}
|
||||
declare type A = string;
|
||||
declare type T<U> = { [k: string]: U };
|
||||
|
||||
@@ -10,3 +10,5 @@ declare class A { static foo(): number; static x : string }
|
||||
declare class A { static [ indexer: number]: string }
|
||||
declare class A { static () : number }
|
||||
declare class A mixins B<T>, C {}
|
||||
declare type A = string
|
||||
declare type T<U> = { [k:string]: U }
|
||||
|
||||
@@ -10,3 +10,5 @@
|
||||
/*:: declare class A { static [ indexer: number]: string }*/
|
||||
/*:: declare class A { static () : number }*/
|
||||
/*:: declare class A mixins B<T>, C {}*/
|
||||
/*:: declare type A = string*/
|
||||
/*:: declare type T<U> = { [k:string]: U }*/
|
||||
|
||||
@@ -10,3 +10,5 @@ declare class A { static foo(): number; static x : string }
|
||||
declare class A { static [ indexer: number]: string }
|
||||
declare class A { static () : number }
|
||||
declare class A mixins B<T>, C {}
|
||||
declare type A = string
|
||||
declare type T<U> = { [k:string]: U }
|
||||
|
||||
@@ -74,6 +74,14 @@ defineType("DeclareModule", {
|
||||
}
|
||||
});
|
||||
|
||||
defineType("DeclareTypeAlias", {
|
||||
visitor: ["id", "typeParameters", "right"],
|
||||
aliases: ["Flow", "FlowDeclaration", "Statement", "Declaration"],
|
||||
fields: {
|
||||
// todo
|
||||
}
|
||||
});
|
||||
|
||||
defineType("DeclareVariable", {
|
||||
visitor: ["id"],
|
||||
aliases: ["Flow", "FlowDeclaration", "Statement", "Declaration"],
|
||||
|
||||
@@ -58,6 +58,8 @@ pp.flowParseDeclare = function (node) {
|
||||
return this.flowParseDeclareVariable(node);
|
||||
} else if (this.isContextual("module")) {
|
||||
return this.flowParseDeclareModule(node);
|
||||
} else if (this.isContextual("type")) {
|
||||
return this.flowParseDeclareTypeAlias(node);
|
||||
} else {
|
||||
this.unexpected();
|
||||
}
|
||||
@@ -96,6 +98,12 @@ pp.flowParseDeclareModule = function (node) {
|
||||
return this.finishNode(node, "DeclareModule");
|
||||
};
|
||||
|
||||
pp.flowParseDeclareTypeAlias = function (node) {
|
||||
this.next();
|
||||
this.flowParseTypeAlias(node);
|
||||
return this.finishNode(node, "DeclareTypeAlias");
|
||||
};
|
||||
|
||||
|
||||
// Interfaces
|
||||
|
||||
|
||||
2
packages/babylon/test/fixtures/flow/declare-statements/14/actual.js
vendored
Normal file
2
packages/babylon/test/fixtures/flow/declare-statements/14/actual.js
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
declare type A = string;
|
||||
declare type T<U> = { [k:string]: U };
|
||||
242
packages/babylon/test/fixtures/flow/declare-statements/14/expected.json
vendored
Normal file
242
packages/babylon/test/fixtures/flow/declare-statements/14/expected.json
vendored
Normal file
@@ -0,0 +1,242 @@
|
||||
{
|
||||
"type": "File",
|
||||
"start": 0,
|
||||
"end": 63,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 2,
|
||||
"column": 38
|
||||
}
|
||||
},
|
||||
"program": {
|
||||
"type": "Program",
|
||||
"start": 0,
|
||||
"end": 63,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 2,
|
||||
"column": 38
|
||||
}
|
||||
},
|
||||
"sourceType": "module",
|
||||
"body": [
|
||||
{
|
||||
"type": "DeclareTypeAlias",
|
||||
"start": 0,
|
||||
"end": 24,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 1,
|
||||
"column": 24
|
||||
}
|
||||
},
|
||||
"id": {
|
||||
"type": "Identifier",
|
||||
"start": 13,
|
||||
"end": 14,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 13
|
||||
},
|
||||
"end": {
|
||||
"line": 1,
|
||||
"column": 14
|
||||
}
|
||||
},
|
||||
"name": "A"
|
||||
},
|
||||
"typeParameters": null,
|
||||
"right": {
|
||||
"type": "StringTypeAnnotation",
|
||||
"start": 17,
|
||||
"end": 23,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 17
|
||||
},
|
||||
"end": {
|
||||
"line": 1,
|
||||
"column": 23
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "DeclareTypeAlias",
|
||||
"start": 25,
|
||||
"end": 63,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 2,
|
||||
"column": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 2,
|
||||
"column": 38
|
||||
}
|
||||
},
|
||||
"id": {
|
||||
"type": "Identifier",
|
||||
"start": 38,
|
||||
"end": 39,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 2,
|
||||
"column": 13
|
||||
},
|
||||
"end": {
|
||||
"line": 2,
|
||||
"column": 14
|
||||
}
|
||||
},
|
||||
"name": "T"
|
||||
},
|
||||
"typeParameters": {
|
||||
"type": "TypeParameterDeclaration",
|
||||
"start": 39,
|
||||
"end": 42,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 2,
|
||||
"column": 14
|
||||
},
|
||||
"end": {
|
||||
"line": 2,
|
||||
"column": 17
|
||||
}
|
||||
},
|
||||
"params": [
|
||||
{
|
||||
"type": "Identifier",
|
||||
"start": 40,
|
||||
"end": 41,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 2,
|
||||
"column": 15
|
||||
},
|
||||
"end": {
|
||||
"line": 2,
|
||||
"column": 16
|
||||
}
|
||||
},
|
||||
"name": "U"
|
||||
}
|
||||
]
|
||||
},
|
||||
"right": {
|
||||
"type": "ObjectTypeAnnotation",
|
||||
"start": 45,
|
||||
"end": 62,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 2,
|
||||
"column": 20
|
||||
},
|
||||
"end": {
|
||||
"line": 2,
|
||||
"column": 37
|
||||
}
|
||||
},
|
||||
"callProperties": [],
|
||||
"properties": [],
|
||||
"indexers": [
|
||||
{
|
||||
"type": "ObjectTypeIndexer",
|
||||
"start": 47,
|
||||
"end": 60,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 2,
|
||||
"column": 22
|
||||
},
|
||||
"end": {
|
||||
"line": 2,
|
||||
"column": 35
|
||||
}
|
||||
},
|
||||
"id": {
|
||||
"type": "Identifier",
|
||||
"start": 48,
|
||||
"end": 49,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 2,
|
||||
"column": 23
|
||||
},
|
||||
"end": {
|
||||
"line": 2,
|
||||
"column": 24
|
||||
}
|
||||
},
|
||||
"name": "k"
|
||||
},
|
||||
"key": {
|
||||
"type": "StringTypeAnnotation",
|
||||
"start": 50,
|
||||
"end": 56,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 2,
|
||||
"column": 25
|
||||
},
|
||||
"end": {
|
||||
"line": 2,
|
||||
"column": 31
|
||||
}
|
||||
}
|
||||
},
|
||||
"value": {
|
||||
"type": "GenericTypeAnnotation",
|
||||
"start": 59,
|
||||
"end": 60,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 2,
|
||||
"column": 34
|
||||
},
|
||||
"end": {
|
||||
"line": 2,
|
||||
"column": 35
|
||||
}
|
||||
},
|
||||
"typeParameters": null,
|
||||
"id": {
|
||||
"type": "Identifier",
|
||||
"start": 59,
|
||||
"end": 60,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 2,
|
||||
"column": 34
|
||||
},
|
||||
"end": {
|
||||
"line": 2,
|
||||
"column": 35
|
||||
}
|
||||
},
|
||||
"name": "U"
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
],
|
||||
"directives": []
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user