Add support for declare export + fixes (#224)
* Add support for declare export * Do not allow declare module inside declare module * Reallow module exports outside module * Add handling of `declare export default` Add check for multiple module.export declarations * Disallow export let/const/type Refactor parsing object properties to share more code and add support for getters and setters * Rename tests * Update test fixtures * Optimize for performance * disallow declare export interface outside of module * Refactor code to be more readable and less lookahead * Add comments * Add test for export star as * Test for number literal getter/setter * Add more tests * Fix tests * Allow union types and correctly eat semi after type * Use non computed keys * Fix tests
This commit is contained in:
1
test/fixtures/flow/declare-export/export-class/actual.js
vendored
Normal file
1
test/fixtures/flow/declare-export/export-class/actual.js
vendored
Normal file
@@ -0,0 +1 @@
|
||||
declare module "foo" { declare export class Foo { meth(p1: number): void; } }
|
||||
275
test/fixtures/flow/declare-export/export-class/expected.json
vendored
Normal file
275
test/fixtures/flow/declare-export/export-class/expected.json
vendored
Normal file
@@ -0,0 +1,275 @@
|
||||
{
|
||||
"type": "File",
|
||||
"start": 0,
|
||||
"end": 77,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 1,
|
||||
"column": 77
|
||||
}
|
||||
},
|
||||
"program": {
|
||||
"type": "Program",
|
||||
"start": 0,
|
||||
"end": 77,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 1,
|
||||
"column": 77
|
||||
}
|
||||
},
|
||||
"sourceType": "module",
|
||||
"body": [
|
||||
{
|
||||
"type": "DeclareModule",
|
||||
"start": 0,
|
||||
"end": 77,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 0
|
||||
},
|
||||
"end": {
|
||||
"line": 1,
|
||||
"column": 77
|
||||
}
|
||||
},
|
||||
"id": {
|
||||
"type": "StringLiteral",
|
||||
"start": 15,
|
||||
"end": 20,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 15
|
||||
},
|
||||
"end": {
|
||||
"line": 1,
|
||||
"column": 20
|
||||
}
|
||||
},
|
||||
"extra": {
|
||||
"rawValue": "foo",
|
||||
"raw": "\"foo\""
|
||||
},
|
||||
"value": "foo"
|
||||
},
|
||||
"body": {
|
||||
"type": "BlockStatement",
|
||||
"start": 21,
|
||||
"end": 77,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 21
|
||||
},
|
||||
"end": {
|
||||
"line": 1,
|
||||
"column": 77
|
||||
}
|
||||
},
|
||||
"body": [
|
||||
{
|
||||
"type": "DeclareExportDeclaration",
|
||||
"start": 23,
|
||||
"end": 75,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 23
|
||||
},
|
||||
"end": {
|
||||
"line": 1,
|
||||
"column": 75
|
||||
}
|
||||
},
|
||||
"declaration": {
|
||||
"type": "DeclareClass",
|
||||
"start": 38,
|
||||
"end": 75,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 38
|
||||
},
|
||||
"end": {
|
||||
"line": 1,
|
||||
"column": 75
|
||||
}
|
||||
},
|
||||
"id": {
|
||||
"type": "Identifier",
|
||||
"start": 44,
|
||||
"end": 47,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 44
|
||||
},
|
||||
"end": {
|
||||
"line": 1,
|
||||
"column": 47
|
||||
},
|
||||
"identifierName": "Foo"
|
||||
},
|
||||
"name": "Foo"
|
||||
},
|
||||
"typeParameters": null,
|
||||
"extends": [],
|
||||
"mixins": [],
|
||||
"body": {
|
||||
"type": "ObjectTypeAnnotation",
|
||||
"start": 48,
|
||||
"end": 75,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 48
|
||||
},
|
||||
"end": {
|
||||
"line": 1,
|
||||
"column": 75
|
||||
}
|
||||
},
|
||||
"callProperties": [],
|
||||
"properties": [
|
||||
{
|
||||
"type": "ObjectTypeProperty",
|
||||
"start": 50,
|
||||
"end": 72,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 50
|
||||
},
|
||||
"end": {
|
||||
"line": 1,
|
||||
"column": 72
|
||||
}
|
||||
},
|
||||
"key": {
|
||||
"type": "Identifier",
|
||||
"start": 50,
|
||||
"end": 54,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 50
|
||||
},
|
||||
"end": {
|
||||
"line": 1,
|
||||
"column": 54
|
||||
},
|
||||
"identifierName": "meth"
|
||||
},
|
||||
"name": "meth"
|
||||
},
|
||||
"static": false,
|
||||
"kind": "init",
|
||||
"value": {
|
||||
"type": "FunctionTypeAnnotation",
|
||||
"start": 50,
|
||||
"end": 72,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 50
|
||||
},
|
||||
"end": {
|
||||
"line": 1,
|
||||
"column": 72
|
||||
}
|
||||
},
|
||||
"params": [
|
||||
{
|
||||
"type": "FunctionTypeParam",
|
||||
"start": 55,
|
||||
"end": 65,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 55
|
||||
},
|
||||
"end": {
|
||||
"line": 1,
|
||||
"column": 65
|
||||
}
|
||||
},
|
||||
"name": {
|
||||
"type": "Identifier",
|
||||
"start": 55,
|
||||
"end": 57,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 55
|
||||
},
|
||||
"end": {
|
||||
"line": 1,
|
||||
"column": 57
|
||||
},
|
||||
"identifierName": "p1"
|
||||
},
|
||||
"name": "p1"
|
||||
},
|
||||
"optional": false,
|
||||
"typeAnnotation": {
|
||||
"type": "NumberTypeAnnotation",
|
||||
"start": 59,
|
||||
"end": 65,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 59
|
||||
},
|
||||
"end": {
|
||||
"line": 1,
|
||||
"column": 65
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"rest": null,
|
||||
"typeParameters": null,
|
||||
"returnType": {
|
||||
"type": "VoidTypeAnnotation",
|
||||
"start": 68,
|
||||
"end": 72,
|
||||
"loc": {
|
||||
"start": {
|
||||
"line": 1,
|
||||
"column": 68
|
||||
},
|
||||
"end": {
|
||||
"line": 1,
|
||||
"column": 72
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"optional": false
|
||||
}
|
||||
],
|
||||
"indexers": [],
|
||||
"exact": false
|
||||
}
|
||||
},
|
||||
"default": false
|
||||
}
|
||||
]
|
||||
},
|
||||
"kind": "ES"
|
||||
}
|
||||
],
|
||||
"directives": []
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user