Mark reexports as definitions

This fixes a bug where we didn't consider reexports (ast.Export nodes)
definitions, and thus stuck them into the statements section of a module
initializer rather than the definitions section.

It also adds test cases for reexporting, both `export {a,b,c} from "module"`
and `export * from "module"` kinds.
This commit is contained in:
joeduffy 2017-01-13 05:38:52 -08:00
parent 7247fcbb56
commit 6804681940
12 changed files with 501 additions and 0 deletions

View file

@ -123,6 +123,7 @@ export type ClassMethodKind = "ClassMethod";
export function isDefinition(node: Node): boolean {
switch (node.kind) {
case moduleKind:
case exportKind:
case classKind:
case localVariableKind:
case modulePropertyKind:

View file

@ -13,6 +13,7 @@ import {asyncTest} from "../util";
let testCases: string[] = [
"empty",
// Module members and exports.
"modules/var_1",
"modules/var_exp_1",
"modules/func_1",
@ -22,6 +23,8 @@ let testCases: string[] = [
"modules/class_exp_1",
"modules/iface_1",
"modules/iface_exp_1",
"modules/reexport",
"modules/reexport_all",
// These are not quite real-world-code, but they are more complex "integration" style tests.
"scenarios/point",

View file

@ -0,0 +1,4 @@
{
"name": "reexport"
}

View file

@ -0,0 +1,248 @@
{
"name": "reexport",
"modules": {
"other": {
"kind": "Module",
"name": {
"kind": "Identifier",
"ident": "other"
},
"members": {
"C": {
"kind": "Class",
"name": {
"kind": "Identifier",
"ident": "C",
"loc": {
"file": "other.ts",
"start": {
"line": 1,
"column": 13
},
"end": {
"line": 1,
"column": 14
}
}
},
"access": "public",
"members": {},
"abstract": false,
"loc": {
"file": "other.ts",
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 17
}
}
},
"I": {
"kind": "Class",
"name": {
"kind": "Identifier",
"ident": "I",
"loc": {
"file": "other.ts",
"start": {
"line": 2,
"column": 17
},
"end": {
"line": 2,
"column": 18
}
}
},
"access": "public",
"members": {},
"interface": true,
"loc": {
"file": "other.ts",
"start": {
"line": 2,
"column": 0
},
"end": {
"line": 2,
"column": 21
}
}
},
"v": {
"kind": "ModuleProperty",
"name": {
"kind": "Identifier",
"ident": "v",
"loc": {
"file": "other.ts",
"start": {
"line": 3,
"column": 11
},
"end": {
"line": 3,
"column": 12
}
}
},
"access": "public",
"type": "any"
},
".init": {
"kind": "ModuleMethod",
"name": {
"kind": "Identifier",
"ident": ".init"
},
"access": "public",
"body": {
"kind": "Block",
"statements": [
{
"kind": "BinaryOperatorExpression",
"left": {
"kind": "LoadLocationExpression",
"name": {
"kind": "Identifier",
"ident": "v",
"loc": {
"file": "other.ts",
"start": {
"line": 3,
"column": 11
},
"end": {
"line": 3,
"column": 12
}
}
}
},
"operator": "=",
"right": {
"kind": "NumberLiteral",
"raw": "42",
"value": 42,
"loc": {
"file": "other.ts",
"start": {
"line": 3,
"column": 15
},
"end": {
"line": 3,
"column": 17
}
}
},
"loc": {
"file": "other.ts",
"start": {
"line": 3,
"column": 0
},
"end": {
"line": 3,
"column": 18
}
}
}
]
}
}
},
"loc": {
"file": "other.ts",
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 5,
"column": 0
}
}
},
"index": {
"kind": "Module",
"name": {
"kind": "Identifier",
"ident": "index"
},
"members": {
"C": {
"kind": "Export",
"name": {
"kind": "Identifier",
"ident": "C",
"loc": {
"file": "index.ts",
"start": {
"line": 1,
"column": 8
},
"end": {
"line": 1,
"column": 9
}
}
},
"token": "other/C"
},
"I": {
"kind": "Export",
"name": {
"kind": "Identifier",
"ident": "I",
"loc": {
"file": "index.ts",
"start": {
"line": 1,
"column": 11
},
"end": {
"line": 1,
"column": 12
}
}
},
"token": "other/I"
},
"v": {
"kind": "Export",
"name": {
"kind": "Identifier",
"ident": "v",
"loc": {
"file": "index.ts",
"start": {
"line": 1,
"column": 14
},
"end": {
"line": 1,
"column": 15
}
}
},
"token": "other/v"
}
},
"loc": {
"file": "index.ts",
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 3,
"column": 0
}
}
}
}
}

View file

@ -0,0 +1,2 @@
export {C, I, v} from "./other";

View file

@ -0,0 +1,4 @@
export class C {}
export interface I {}
export let v = 42;

View file

@ -0,0 +1,7 @@
{
"files": [
"index.ts",
"other.ts"
]
}

View file

@ -0,0 +1,4 @@
{
"name": "reexport_all"
}

View file

@ -0,0 +1,215 @@
{
"name": "reexport_all",
"modules": {
"other": {
"kind": "Module",
"name": {
"kind": "Identifier",
"ident": "other"
},
"members": {
"C": {
"kind": "Class",
"name": {
"kind": "Identifier",
"ident": "C",
"loc": {
"file": "other.ts",
"start": {
"line": 1,
"column": 13
},
"end": {
"line": 1,
"column": 14
}
}
},
"access": "public",
"members": {},
"abstract": false,
"loc": {
"file": "other.ts",
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 17
}
}
},
"I": {
"kind": "Class",
"name": {
"kind": "Identifier",
"ident": "I",
"loc": {
"file": "other.ts",
"start": {
"line": 2,
"column": 17
},
"end": {
"line": 2,
"column": 18
}
}
},
"access": "public",
"members": {},
"interface": true,
"loc": {
"file": "other.ts",
"start": {
"line": 2,
"column": 0
},
"end": {
"line": 2,
"column": 21
}
}
},
"v": {
"kind": "ModuleProperty",
"name": {
"kind": "Identifier",
"ident": "v",
"loc": {
"file": "other.ts",
"start": {
"line": 3,
"column": 11
},
"end": {
"line": 3,
"column": 12
}
}
},
"access": "public",
"type": "any"
},
".init": {
"kind": "ModuleMethod",
"name": {
"kind": "Identifier",
"ident": ".init"
},
"access": "public",
"body": {
"kind": "Block",
"statements": [
{
"kind": "BinaryOperatorExpression",
"left": {
"kind": "LoadLocationExpression",
"name": {
"kind": "Identifier",
"ident": "v",
"loc": {
"file": "other.ts",
"start": {
"line": 3,
"column": 11
},
"end": {
"line": 3,
"column": 12
}
}
}
},
"operator": "=",
"right": {
"kind": "NumberLiteral",
"raw": "42",
"value": 42,
"loc": {
"file": "other.ts",
"start": {
"line": 3,
"column": 15
},
"end": {
"line": 3,
"column": 17
}
}
},
"loc": {
"file": "other.ts",
"start": {
"line": 3,
"column": 0
},
"end": {
"line": 3,
"column": 18
}
}
}
]
}
}
},
"loc": {
"file": "other.ts",
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 5,
"column": 0
}
}
},
"index": {
"kind": "Module",
"name": {
"kind": "Identifier",
"ident": "index"
},
"members": {
"other/C": {
"kind": "Export",
"name": {
"kind": "Identifier",
"ident": "other/C"
},
"token": "other/C"
},
"other/I": {
"kind": "Export",
"name": {
"kind": "Identifier",
"ident": "other/I"
},
"token": "other/I"
},
"other/v": {
"kind": "Export",
"name": {
"kind": "Identifier",
"ident": "other/v"
},
"token": "other/v"
}
},
"loc": {
"file": "index.ts",
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 3,
"column": 0
}
}
}
}
}

View file

@ -0,0 +1,2 @@
export * from "./other";

View file

@ -0,0 +1,4 @@
export class C {}
export interface I {}
export let v = 42;

View file

@ -0,0 +1,7 @@
{
"files": [
"index.ts",
"other.ts"
]
}