Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit e200dad

Browse filesBrowse files
committed
Merge pull request microsoft#4829 from weswigham/default-aliasing-bug
Default aliasing bug fix
2 parents c9170b8 + f3062c5 commit e200dad
Copy full SHA for e200dad

5 files changed

+124-2Lines changed: 124 additions & 2 deletions

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎src/compiler/emitter.ts‎

Copy file name to clipboardExpand all lines: src/compiler/emitter.ts
+9-2Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1515,8 +1515,15 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
15151515
else if (declaration.kind === SyntaxKind.ImportSpecifier) {
15161516
// Identifier references named import
15171517
write(getGeneratedNameForNode(<ImportDeclaration>declaration.parent.parent.parent));
1518-
write(".");
1519-
writeTextOfNode(currentSourceFile, (<ImportSpecifier>declaration).propertyName || (<ImportSpecifier>declaration).name);
1518+
var name = (<ImportSpecifier>declaration).propertyName || (<ImportSpecifier>declaration).name;
1519+
var identifier = getSourceTextOfNodeFromSourceFile(currentSourceFile, name);
1520+
if (languageVersion === ScriptTarget.ES3 && identifier === "default") {
1521+
write(`["default"]`);
1522+
}
1523+
else {
1524+
write(".");
1525+
write(identifier);
1526+
}
15201527
return;
15211528
}
15221529
}
Collapse file
+33Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
//// [tests/cases/compiler/es3defaultAliasIsQuoted.ts] ////
2+
3+
//// [es3defaultAliasQuoted_file0.ts]
4+
5+
export class Foo {
6+
static CONSTANT = "Foo";
7+
}
8+
9+
export default function assert(value: boolean) {
10+
if (!value) throw new Error("Assertion failed!");
11+
}
12+
13+
//// [es3defaultAliasQuoted_file1.ts]
14+
import {Foo, default as assert} from "./es3defaultAliasQuoted_file0";
15+
assert(Foo.CONSTANT === "Foo");
16+
17+
//// [es3defaultAliasQuoted_file0.js]
18+
var Foo = (function () {
19+
function Foo() {
20+
}
21+
Foo.CONSTANT = "Foo";
22+
return Foo;
23+
})();
24+
exports.Foo = Foo;
25+
function assert(value) {
26+
if (!value)
27+
throw new Error("Assertion failed!");
28+
}
29+
exports.__esModule = true;
30+
exports["default"] = assert;
31+
//// [es3defaultAliasQuoted_file1.js]
32+
var es3defaultAliasQuoted_file0_1 = require("./es3defaultAliasQuoted_file0");
33+
es3defaultAliasQuoted_file0_1["default"](es3defaultAliasQuoted_file0_1.Foo.CONSTANT === "Foo");
Collapse file
+30Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
=== tests/cases/compiler/es3defaultAliasQuoted_file0.ts ===
2+
3+
export class Foo {
4+
>Foo : Symbol(Foo, Decl(es3defaultAliasQuoted_file0.ts, 0, 0))
5+
6+
static CONSTANT = "Foo";
7+
>CONSTANT : Symbol(Foo.CONSTANT, Decl(es3defaultAliasQuoted_file0.ts, 1, 18))
8+
}
9+
10+
export default function assert(value: boolean) {
11+
>assert : Symbol(assert, Decl(es3defaultAliasQuoted_file0.ts, 3, 1))
12+
>value : Symbol(value, Decl(es3defaultAliasQuoted_file0.ts, 5, 31))
13+
14+
if (!value) throw new Error("Assertion failed!");
15+
>value : Symbol(value, Decl(es3defaultAliasQuoted_file0.ts, 5, 31))
16+
>Error : Symbol(Error, Decl(lib.d.ts, 876, 38), Decl(lib.d.ts, 889, 11))
17+
}
18+
19+
=== tests/cases/compiler/es3defaultAliasQuoted_file1.ts ===
20+
import {Foo, default as assert} from "./es3defaultAliasQuoted_file0";
21+
>Foo : Symbol(Foo, Decl(es3defaultAliasQuoted_file1.ts, 0, 8))
22+
>default : Symbol(assert, Decl(es3defaultAliasQuoted_file1.ts, 0, 12))
23+
>assert : Symbol(assert, Decl(es3defaultAliasQuoted_file1.ts, 0, 12))
24+
25+
assert(Foo.CONSTANT === "Foo");
26+
>assert : Symbol(assert, Decl(es3defaultAliasQuoted_file1.ts, 0, 12))
27+
>Foo.CONSTANT : Symbol(Foo.CONSTANT, Decl(es3defaultAliasQuoted_file0.ts, 1, 18))
28+
>Foo : Symbol(Foo, Decl(es3defaultAliasQuoted_file1.ts, 0, 8))
29+
>CONSTANT : Symbol(Foo.CONSTANT, Decl(es3defaultAliasQuoted_file0.ts, 1, 18))
30+
Collapse file
+37Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
=== tests/cases/compiler/es3defaultAliasQuoted_file0.ts ===
2+
3+
export class Foo {
4+
>Foo : Foo
5+
6+
static CONSTANT = "Foo";
7+
>CONSTANT : string
8+
>"Foo" : string
9+
}
10+
11+
export default function assert(value: boolean) {
12+
>assert : (value: boolean) => void
13+
>value : boolean
14+
15+
if (!value) throw new Error("Assertion failed!");
16+
>!value : boolean
17+
>value : boolean
18+
>new Error("Assertion failed!") : Error
19+
>Error : ErrorConstructor
20+
>"Assertion failed!" : string
21+
}
22+
23+
=== tests/cases/compiler/es3defaultAliasQuoted_file1.ts ===
24+
import {Foo, default as assert} from "./es3defaultAliasQuoted_file0";
25+
>Foo : typeof Foo
26+
>default : (value: boolean) => void
27+
>assert : (value: boolean) => void
28+
29+
assert(Foo.CONSTANT === "Foo");
30+
>assert(Foo.CONSTANT === "Foo") : void
31+
>assert : (value: boolean) => void
32+
>Foo.CONSTANT === "Foo" : boolean
33+
>Foo.CONSTANT : string
34+
>Foo : typeof Foo
35+
>CONSTANT : string
36+
>"Foo" : string
37+
Collapse file
+15Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// @module: commonjs
2+
// @target: es3
3+
4+
// @Filename: es3defaultAliasQuoted_file0.ts
5+
export class Foo {
6+
static CONSTANT = "Foo";
7+
}
8+
9+
export default function assert(value: boolean) {
10+
if (!value) throw new Error("Assertion failed!");
11+
}
12+
13+
// @Filename: es3defaultAliasQuoted_file1.ts
14+
import {Foo, default as assert} from "./es3defaultAliasQuoted_file0";
15+
assert(Foo.CONSTANT === "Foo");

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.