diff --git a/tools/mujs/lib/ast/definitions.ts b/tools/mujs/lib/ast/definitions.ts index 037f510dc..5144ffad1 100644 --- a/tools/mujs/lib/ast/definitions.ts +++ b/tools/mujs/lib/ast/definitions.ts @@ -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: diff --git a/tools/mujs/tests/output/index.ts b/tools/mujs/tests/output/index.ts index 2369473a8..459eded6b 100644 --- a/tools/mujs/tests/output/index.ts +++ b/tools/mujs/tests/output/index.ts @@ -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", diff --git a/tools/mujs/tests/output/modules/reexport/Mu.json b/tools/mujs/tests/output/modules/reexport/Mu.json new file mode 100644 index 000000000..4d4e6db93 --- /dev/null +++ b/tools/mujs/tests/output/modules/reexport/Mu.json @@ -0,0 +1,4 @@ +{ + "name": "reexport" +} + diff --git a/tools/mujs/tests/output/modules/reexport/Mu.out.json b/tools/mujs/tests/output/modules/reexport/Mu.out.json new file mode 100644 index 000000000..b8f3a8eec --- /dev/null +++ b/tools/mujs/tests/output/modules/reexport/Mu.out.json @@ -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 + } + } + } + } +} diff --git a/tools/mujs/tests/output/modules/reexport/index.ts b/tools/mujs/tests/output/modules/reexport/index.ts new file mode 100644 index 000000000..0ba2ab537 --- /dev/null +++ b/tools/mujs/tests/output/modules/reexport/index.ts @@ -0,0 +1,2 @@ +export {C, I, v} from "./other"; + diff --git a/tools/mujs/tests/output/modules/reexport/other.ts b/tools/mujs/tests/output/modules/reexport/other.ts new file mode 100644 index 000000000..ba44a127e --- /dev/null +++ b/tools/mujs/tests/output/modules/reexport/other.ts @@ -0,0 +1,4 @@ +export class C {} +export interface I {} +export let v = 42; + diff --git a/tools/mujs/tests/output/modules/reexport/tsconfig.json b/tools/mujs/tests/output/modules/reexport/tsconfig.json new file mode 100644 index 000000000..8816de4b0 --- /dev/null +++ b/tools/mujs/tests/output/modules/reexport/tsconfig.json @@ -0,0 +1,7 @@ +{ + "files": [ + "index.ts", + "other.ts" + ] +} + diff --git a/tools/mujs/tests/output/modules/reexport_all/Mu.json b/tools/mujs/tests/output/modules/reexport_all/Mu.json new file mode 100644 index 000000000..6477839a2 --- /dev/null +++ b/tools/mujs/tests/output/modules/reexport_all/Mu.json @@ -0,0 +1,4 @@ +{ + "name": "reexport_all" +} + diff --git a/tools/mujs/tests/output/modules/reexport_all/Mu.out.json b/tools/mujs/tests/output/modules/reexport_all/Mu.out.json new file mode 100644 index 000000000..2c8941761 --- /dev/null +++ b/tools/mujs/tests/output/modules/reexport_all/Mu.out.json @@ -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 + } + } + } + } +} diff --git a/tools/mujs/tests/output/modules/reexport_all/index.ts b/tools/mujs/tests/output/modules/reexport_all/index.ts new file mode 100644 index 000000000..7a844a851 --- /dev/null +++ b/tools/mujs/tests/output/modules/reexport_all/index.ts @@ -0,0 +1,2 @@ +export * from "./other"; + diff --git a/tools/mujs/tests/output/modules/reexport_all/other.ts b/tools/mujs/tests/output/modules/reexport_all/other.ts new file mode 100644 index 000000000..ba44a127e --- /dev/null +++ b/tools/mujs/tests/output/modules/reexport_all/other.ts @@ -0,0 +1,4 @@ +export class C {} +export interface I {} +export let v = 42; + diff --git a/tools/mujs/tests/output/modules/reexport_all/tsconfig.json b/tools/mujs/tests/output/modules/reexport_all/tsconfig.json new file mode 100644 index 000000000..8816de4b0 --- /dev/null +++ b/tools/mujs/tests/output/modules/reexport_all/tsconfig.json @@ -0,0 +1,7 @@ +{ + "files": [ + "index.ts", + "other.ts" + ] +} +