Implement reexport renames
This implements renaming exports during reexporting, by recognizing the propertyName Identifier and using it accordingly in the member map and corresponding ast.Export object. There is also a new test for this.
This commit is contained in:
parent
6804681940
commit
b13ad61d89
7 changed files with 276 additions and 2 deletions
|
@ -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 (`<propertyName> as <name`). Bind the rename.
|
||||
propertyName = this.transformIdentifier(exportClause.propertyName);
|
||||
}
|
||||
else {
|
||||
propertyName = name;
|
||||
}
|
||||
|
||||
exports.push(<ast.Export>{
|
||||
kind: ast.exportKind,
|
||||
name: name,
|
||||
token: this.createModuleDefinitionToken(sourceModule, name.ident),
|
||||
token: this.createModuleDefinitionToken(sourceModule, propertyName.ident),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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",
|
||||
|
|
4
tools/mujs/tests/output/modules/reexport_rename/Mu.json
Normal file
4
tools/mujs/tests/output/modules/reexport_rename/Mu.json
Normal file
|
@ -0,0 +1,4 @@
|
|||
{
|
||||
"name": "reexport_rename"
|
||||
}
|
||||
|
248
tools/mujs/tests/output/modules/reexport_rename/Mu.out.json
Normal file
248
tools/mujs/tests/output/modules/reexport_rename/Mu.out.json
Normal file
|
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
2
tools/mujs/tests/output/modules/reexport_rename/index.ts
Normal file
2
tools/mujs/tests/output/modules/reexport_rename/index.ts
Normal file
|
@ -0,0 +1,2 @@
|
|||
export {C as D, I as J, v as w} from "./other";
|
||||
|
4
tools/mujs/tests/output/modules/reexport_rename/other.ts
Normal file
4
tools/mujs/tests/output/modules/reexport_rename/other.ts
Normal file
|
@ -0,0 +1,4 @@
|
|||
export class C {}
|
||||
export interface I {}
|
||||
export let v = 42;
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
{
|
||||
"files": [
|
||||
"index.ts",
|
||||
"other.ts"
|
||||
]
|
||||
}
|
||||
|
Loading…
Reference in a new issue