8000 Merge pull request #5881 from weswigham/rootdir-module-names · nycdotnet/TypeScript@90391fe · GitHub
[go: up one dir, main page]

Skip to content

Commit 90391fe

Browse files
committed
Merge pull request microsoft#5881 from weswigham/rootdir-module-names
Respect root dir/common src dir when generating module names
2 parents 19d7e62 + 81e012f commit 90391fe

File tree

55 files changed

+243
-72
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+243
-72
lines changed

src/compiler/utilities.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1889,8 +1889,10 @@ namespace ts {
18891889
* Resolves a local path to a path which is absolute to the base of the emit
18901890
*/
18911891
export function getExternalModuleNameFromPath(host: EmitHost, fileName: string): string {
1892-
const dir = toPath(host.getCommonSourceDirectory(), host.getCurrentDirectory(), f => host.getCanonicalFileName(f));
1893-
const relativePath = getRelativePathToDirectoryOrUrl(dir, fileName, dir, f => host.getCanonicalFileName(f), /*isAbsolutePathAnUrl*/ false);
1892+
const getCanonicalFileName = (f: string) => host.getCanonicalFileName(f);
1893+
const dir = toPath(host.getCommonSourceDirectory(), host.getCurrentDirectory(), getCanonicalFileName);
1894+
const filePath = getNormalizedAbsolutePath(fileName, host.getCurrentDirectory());
1895+
const relativePath = getRelativePathToDirectoryOrUrl(dir, filePath, dir, getCanonicalFileName, /*isAbsolutePathAnUrl*/ false);
18941896
return removeFileExtension(relativePath);
18951897
}
18961898

tests/baselines/reference/commonSourceDir6.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,17 @@ export var pi = Math.PI;
1616
export var y = x * i;
1717

1818
//// [concat.js]
19-
define("tests/cases/compiler/baz", ["require", "exports", "tests/cases/compiler/a/bar", "tests/cases/compiler/a/foo"], function (require, exports, bar_1, foo_1) {
19+
define("baz", ["require", "exports", "a/bar", "a/foo"], function (require, exports, bar_1, foo_1) {
2020
"use strict";
2121
exports.pi = Math.PI;
2222
exports.y = bar_1.x * foo_1.i;
2323
});
24-
define("tests/cases/compiler/a/foo", ["require", "exports", "tests/cases/compiler/baz"], function (require, exports, baz_1) {
24+
define("a/foo", ["require", "exports", "baz"], function (require, exports, baz_1) {
2525
"use strict";
2626
exports.i = Math.sqrt(-1);
2727
exports.z = baz_1.pi * baz_1.pi;
2828
});
29-
define("tests/cases/compiler/a/bar", ["require", "exports", "tests/cases/compiler/a/foo"], function (require, exports, foo_2) {
29+
define("a/bar", ["require", "exports", "a/foo"], function (require, exports, foo_2) {
3030
"use strict";
3131
exports.x = foo_2.z + foo_2.z;
3232
});

tests/baselines/reference/filesEmittingIntoSameOutputWithOutOption.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ function foo() {
1010

1111

1212
//// [a.js]
13-
define("tests/cases/compiler/a", ["require", "exports"], function (require, exports) {
13+
define("a", ["require", "exports"], function (require, exports) {
1414
"use strict";
1515
var c = (function () {
1616
function c() {
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
//// [tests/cases/conformance/es6/moduleExportsAmd/outFilerootDirModuleNamesAmd.ts] ////
2+
3+
//// [a.ts]
4+
import foo from "./b";
5+
export default class Foo {}
6+
foo();
7+
8+
//// [b.ts]
9+
import Foo from "./a";
10+
export default function foo() { new Foo(); }
11+
12+
13+
//// [output.js]
14+
define("b", ["require", "exports", "a"], function (require, exports, a_1) {
15+
"use strict";
16+
function foo() { new a_1.default(); }
17+
exports.default = foo;
18+
});
19+
define("a", ["require", "exports", "b"], function (require, exports, b_1) {
20+
"use strict";
21+
class Foo {
22+
}
23+
exports.default = Foo;
24+
b_1.default();
25+
});
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
=== tests/cases/conformance/es6/moduleExportsAmd/src/a.ts ===
2+
import foo from "./b";
3+
>foo : Symbol(foo, Decl(a.ts, 0, 6))
4+
5+
export default class Foo {}
6+
>Foo : Symbol(Foo, Decl(a.ts, 0, 22))
7+
8+
foo();
9+
>foo : Symbol(foo, Decl(a.ts, 0, 6))
10+
11+
=== tests/cases/conformance/es6/moduleExportsAmd/src/b.ts ===
12+
import Foo from "./a";
13+
>Foo : Symbol(Foo, Decl(b.ts, 0, 6))
14+
15+
export default function foo() { new Foo(); }
16+
>foo : Symbol(foo, Decl(b.ts, 0, 22))
17+
>Foo : Symbol(Foo, Decl(b.ts, 0, 6))
18+
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
=== tests/cases/conformance/es6/moduleExportsAmd/src/a.ts ===
2+
import foo from "./b";
3+
>foo : () => void
4+
5+
export default class Foo {}
6+
>Foo : Foo
7+
8+
foo();
9+
>foo() : void
10+
>foo : () => void
11+
12+
=== tests/cases/conformance/es6/moduleExportsAmd/src/b.ts ===
13+
import Foo from "./a";
14+
>Foo : typeof Foo
15+
16+
export default function foo() { new Foo(); }
17+
>foo : () => void
18+
>new Foo() : Foo
19+
>Foo : typeof Foo
20+
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
//// [tests/cases/conformance/es6/moduleExportsSystem/outFilerootDirModuleNamesSystem.ts] ////
2+
3+
//// [a.ts]
4+
import foo from "./b";
5+
export default class Foo {}
6+
foo();
7+
8+
//// [b.ts]
9+
import Foo from "./a";
10+
export default function foo() { new Foo(); }
11+
12+
13+
//// [output.js]
14+
System.register("b", ["a"], function(exports_1) {
15+
"use strict";
16+
var a_1;
17+
function foo() { new a_1.default(); }
18+
exports_1("default", foo);
19+
return {
20+
setters:[
21+
function (a_1_1) {
22+
a_1 = a_1_1;
23+
}],
24+
execute: function() {
25+
}
26+
}
27+
});
28+
System.register("a", ["b"], function(exports_2) {
29+
"use strict";
30+
var b_1;
31+
var Foo;
32+
return {
33+
setters:[
34+
function (b_1_1) {
35+
b_1 = b_1_1;
36+
}],
37+
execute: function() {
38+
class Foo {
39+
}
40+
exports_2("default", Foo);
41+
b_1.default();
42+
}
43+
}
44+
});
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
=== tests/cases/conformance/es6/moduleExportsSystem/src/a.ts ===
2+
import foo from "./b";
3+
>foo : Symbol(foo, Decl(a.ts, 0, 6))
4+
5+
export default class Foo {}
6+
>Foo : Symbol(Foo, Decl(a.ts, 0, 22))
7+
8+
foo();
9+
>foo : Symbol(foo, Decl(a.ts, 0, 6))
10+
11+
=== tests/cases/conformance/es6/moduleExportsSystem/src/b.ts ===
12+
import Foo from "./a";
13+
>Foo : Symbol(Foo, Decl(b.ts, 0, 6))
14+
15+
export default function foo() { new Foo(); }
16+
>foo : Symbol(foo, Decl(b.ts, 0, 22))
17+
>Foo : Symbol(Foo, Decl(b.ts, 0, 6))
18+
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
=== tests/cases/conformance/es6/moduleExportsSystem/src/a.ts ===
2+
import foo from "./b";
3+
>foo : () => void
4+
5+
export default class Foo {}
6+
>Foo : Foo
7+
8+
foo();
9+
>foo() : void
10+
>foo : () => void
11+
12+
=== tests/cases/conformance/es6/moduleExportsSystem/src/b.ts ===
13+
import Foo from "./a";
14+
>Foo : typeof Foo
15+
16+
export default function foo() { new Foo(); }
17+
>foo : () => void
18+
>new Foo() : Foo
19+
>Foo : typeof Foo
20+

tests/baselines/reference/outModuleConcatAmd.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ var __extends = (this && this.__extends) || function (d, b) {
1414
function __() { this.constructor = d; }
1515
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
1616
};
17-
define("tests/cases/compiler/ref/a", ["require", "exports"], function (require, exports) {
17+
define("ref/a", ["require", "exports"], function (require, exports) {
1818
"use strict";
1919
var A = (function () {
2020
function A() {
@@ -23,7 +23,7 @@ define("tests/cases/compiler/ref/a", ["require", "exports"], function (require,
2323
})();
2424
exports.A = A;
2525
});
26-
define("tests/cases/compiler/b", ["require", "exports", "tests/cases/compiler/ref/a"], function (require, exports, a_1) {
26+
define("b", ["require", "exports", "ref/a"], function (require, exports, a_1) {
2727
"use strict";
2828
var B = (function (_super) {
2929
__extends(B, _super);
@@ -37,12 +37,12 @@ define("tests/cases/compiler/b", ["require", "exports", "tests/cases/compiler/re
3737
//# sourceMappingURL=all.js.map
3838

3939
//// [all.d.ts]
40-
declare module "tests/cases/compiler/ref/a" {
40+
declare module "ref/a" {
4141
export class A {
4242
}
4343
}
44-
declare module "tests/cases/compiler/b" {
45-
import { A } from "tests/cases/compiler/ref/a";
44+
declare module "b" {
45+
import { A } from "ref/a";
4646
export class B extends A {
4747
}
4848
}

0 commit comments

Comments
 (0)
0