Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions src/compiler/emitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1515,8 +1515,15 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
else if (declaration.kind === SyntaxKind.ImportSpecifier) {
// Identifier references named import
write(getGeneratedNameForNode(<ImportDeclaration>declaration.parent.parent.parent));
write(".");
writeTextOfNode(currentSourceFile, (<ImportSpecifier>declaration).propertyName || (<ImportSpecifier>declaration).name);
var name = (<ImportSpecifier>declaration).propertyName || (<ImportSpecifier>declaration).name;
var identifier = getSourceTextOfNodeFromSourceFile(currentSourceFile, name);
if (languageVersion === ScriptTarget.ES3 && identifier === "default") {
write(`["default"]`);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just use single quotes.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But that would fail the linter.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On that note, we should consider merging #4458 at some point.

}
else {
write(".");
write(identifier);
}
return;
}
}
Expand Down
33 changes: 33 additions & 0 deletions tests/baselines/reference/es3defaultAliasIsQuoted.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
//// [tests/cases/compiler/es3defaultAliasIsQuoted.ts] ////

//// [es3defaultAliasQuoted_file0.ts]

export class Foo {
static CONSTANT = "Foo";
}

export default function assert(value: boolean) {
if (!value) throw new Error("Assertion failed!");
}

//// [es3defaultAliasQuoted_file1.ts]
import {Foo, default as assert} from "./es3defaultAliasQuoted_file0";
assert(Foo.CONSTANT === "Foo");

//// [es3defaultAliasQuoted_file0.js]
var Foo = (function () {
function Foo() {
}
Foo.CONSTANT = "Foo";
return Foo;
})();
exports.Foo = Foo;
function assert(value) {
if (!value)
throw new Error("Assertion failed!");
}
exports.__esModule = true;
exports["default"] = assert;
//// [es3defaultAliasQuoted_file1.js]
var es3defaultAliasQuoted_file0_1 = require("./es3defaultAliasQuoted_file0");
es3defaultAliasQuoted_file0_1["default"](es3defaultAliasQuoted_file0_1.Foo.CONSTANT === "Foo");
30 changes: 30 additions & 0 deletions tests/baselines/reference/es3defaultAliasIsQuoted.symbols
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
=== tests/cases/compiler/es3defaultAliasQuoted_file0.ts ===

export class Foo {
>Foo : Symbol(Foo, Decl(es3defaultAliasQuoted_file0.ts, 0, 0))

static CONSTANT = "Foo";
>CONSTANT : Symbol(Foo.CONSTANT, Decl(es3defaultAliasQuoted_file0.ts, 1, 18))
}

export default function assert(value: boolean) {
>assert : Symbol(assert, Decl(es3defaultAliasQuoted_file0.ts, 3, 1))
>value : Symbol(value, Decl(es3defaultAliasQuoted_file0.ts, 5, 31))

if (!value) throw new Error("Assertion failed!");
>value : Symbol(value, Decl(es3defaultAliasQuoted_file0.ts, 5, 31))
>Error : Symbol(Error, Decl(lib.d.ts, 876, 38), Decl(lib.d.ts, 889, 11))
}

=== tests/cases/compiler/es3defaultAliasQuoted_file1.ts ===
import {Foo, default as assert} from "./es3defaultAliasQuoted_file0";
>Foo : Symbol(Foo, Decl(es3defaultAliasQuoted_file1.ts, 0, 8))
>default : Symbol(assert, Decl(es3defaultAliasQuoted_file1.ts, 0, 12))
>assert : Symbol(assert, Decl(es3defaultAliasQuoted_file1.ts, 0, 12))

assert(Foo.CONSTANT === "Foo");
>assert : Symbol(assert, Decl(es3defaultAliasQuoted_file1.ts, 0, 12))
>Foo.CONSTANT : Symbol(Foo.CONSTANT, Decl(es3defaultAliasQuoted_file0.ts, 1, 18))
>Foo : Symbol(Foo, Decl(es3defaultAliasQuoted_file1.ts, 0, 8))
>CONSTANT : Symbol(Foo.CONSTANT, Decl(es3defaultAliasQuoted_file0.ts, 1, 18))

37 changes: 37 additions & 0 deletions tests/baselines/reference/es3defaultAliasIsQuoted.types
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
=== tests/cases/compiler/es3defaultAliasQuoted_file0.ts ===

export class Foo {
>Foo : Foo

static CONSTANT = "Foo";
>CONSTANT : string
>"Foo" : string
}

export default function assert(value: boolean) {
>assert : (value: boolean) => void
>value : boolean

if (!value) throw new Error("Assertion failed!");
>!value : boolean
>value : boolean
>new Error("Assertion failed!") : Error
>Error : ErrorConstructor
>"Assertion failed!" : string
}

=== tests/cases/compiler/es3defaultAliasQuoted_file1.ts ===
import {Foo, default as assert} from "./es3defaultAliasQuoted_file0";
>Foo : typeof Foo
>default : (value: boolean) => void
>assert : (value: boolean) => void

assert(Foo.CONSTANT === "Foo");
>assert(Foo.CONSTANT === "Foo") : void
>assert : (value: boolean) => void
>Foo.CONSTANT === "Foo" : boolean
>Foo.CONSTANT : string
>Foo : typeof Foo
>CONSTANT : string
>"Foo" : string

15 changes: 15 additions & 0 deletions tests/cases/compiler/es3defaultAliasIsQuoted.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// @module: commonjs
// @target: es3

// @Filename: es3defaultAliasQuoted_file0.ts
export class Foo {
static CONSTANT = "Foo";
}

export default function assert(value: boolean) {
if (!value) throw new Error("Assertion failed!");
}

// @Filename: es3defaultAliasQuoted_file1.ts
import {Foo, default as assert} from "./es3defaultAliasQuoted_file0";
assert(Foo.CONSTANT === "Foo");