diff --git a/tools/mujs/lib/compiler/transform.ts b/tools/mujs/lib/compiler/transform.ts index 3ab2dc5fe..493e79227 100644 --- a/tools/mujs/lib/compiler/transform.ts +++ b/tools/mujs/lib/compiler/transform.ts @@ -492,12 +492,20 @@ export class Transformer { // // For every export clause, we will issue a top-level MuIL re-export AST node. for (let exportClause of node.exportClause.elements) { - contract.assert(!exportClause.propertyName); let name: ast.Identifier = this.transformIdentifier(exportClause.name); + let propertyName: ast.Identifier; + if (exportClause.propertyName) { + // The export is being renamed (` as { kind: ast.exportKind, name: name, - token: this.createModuleDefinitionToken(sourceModule, name.ident), + token: this.createModuleDefinitionToken(sourceModule, propertyName.ident), }); } } diff --git a/tools/mujs/tests/output/index.ts b/tools/mujs/tests/output/index.ts index 459eded6b..9e0d3ec75 100644 --- a/tools/mujs/tests/output/index.ts +++ b/tools/mujs/tests/output/index.ts @@ -25,6 +25,7 @@ let testCases: string[] = [ "modules/iface_exp_1", "modules/reexport", "modules/reexport_all", + "modules/reexport_rename", // 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_rename/Mu.json b/tools/mujs/tests/output/modules/reexport_rename/Mu.json new file mode 100644 index 000000000..823321513 --- /dev/null +++ b/tools/mujs/tests/output/modules/reexport_rename/Mu.json @@ -0,0 +1,4 @@ +{ + "name": "reexport_rename" +} + diff --git a/tools/mujs/tests/output/modules/reexport_rename/Mu.out.json b/tools/mujs/tests/output/modules/reexport_rename/Mu.out.json new file mode 100644 index 000000000..ca140a056 --- /dev/null +++ b/tools/mujs/tests/output/modules/reexport_rename/Mu.out.json @@ -0,0 +1,248 @@ +{ + "name": "reexport_rename", + "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": { + "D": { + "kind": "Export", + "name": { + "kind": "Identifier", + "ident": "D", + "loc": { + "file": "index.ts", + "start": { + "line": 1, + "column": 13 + }, + "end": { + "line": 1, + "column": 14 + } + } + }, + "token": "other/C" + }, + "J": { + "kind": "Export", + "name": { + "kind": "Identifier", + "ident": "J", + "loc": { + "file": "index.ts", + "start": { + "line": 1, + "column": 21 + }, + "end": { + "line": 1, + "column": 22 + } + } + }, + "token": "other/I" + }, + "w": { + "kind": "Export", + "name": { + "kind": "Identifier", + "ident": "w", + "loc": { + "file": "index.ts", + "start": { + "line": 1, + "column": 29 + }, + "end": { + "line": 1, + "column": 30 + } + } + }, + "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_rename/index.ts b/tools/mujs/tests/output/modules/reexport_rename/index.ts new file mode 100644 index 000000000..43a266dc5 --- /dev/null +++ b/tools/mujs/tests/output/modules/reexport_rename/index.ts @@ -0,0 +1,2 @@ +export {C as D, I as J, v as w} from "./other"; + diff --git a/tools/mujs/tests/output/modules/reexport_rename/other.ts b/tools/mujs/tests/output/modules/reexport_rename/other.ts new file mode 100644 index 000000000..ba44a127e --- /dev/null +++ b/tools/mujs/tests/output/modules/reexport_rename/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_rename/tsconfig.json b/tools/mujs/tests/output/modules/reexport_rename/tsconfig.json new file mode 100644 index 000000000..8816de4b0 --- /dev/null +++ b/tools/mujs/tests/output/modules/reexport_rename/tsconfig.json @@ -0,0 +1,7 @@ +{ + "files": [ + "index.ts", + "other.ts" + ] +} +