From a32f44f9f4c630c8e644e40bf6c9826b18a420e1 Mon Sep 17 00:00:00 2001 From: Wesley Wigham Date: Mon, 9 Nov 2015 14:24:19 -0800 Subject: [PATCH 1/4] Add command line flag to allow synthetic default exports --- src/compiler/checker.ts | 6 ++- src/compiler/commandLineParser.ts | 5 +++ src/compiler/diagnosticMessages.json | 4 ++ src/compiler/types.ts | 1 + .../allowSyntheticDefaultImports1.js | 22 ++++++++++ .../allowSyntheticDefaultImports1.symbols | 18 ++++++++ .../allowSyntheticDefaultImports1.types | 19 +++++++++ .../allowSyntheticDefaultImports2.js | 40 ++++++++++++++++++ .../allowSyntheticDefaultImports2.symbols | 17 ++++++++ .../allowSyntheticDefaultImports2.types | 18 ++++++++ .../allowSyntheticDefaultImports3.errors.txt | 14 +++++++ .../allowSyntheticDefaultImports3.js | 41 +++++++++++++++++++ .../allowSyntheticDefaultImports4.js | 16 ++++++++ .../allowSyntheticDefaultImports4.symbols | 18 ++++++++ .../allowSyntheticDefaultImports4.types | 19 +++++++++ .../allowSyntheticDefaultImports5.js | 27 ++++++++++++ .../allowSyntheticDefaultImports5.symbols | 18 ++++++++ .../allowSyntheticDefaultImports5.types | 19 +++++++++ .../allowSyntheticDefaultImports6.errors.txt | 15 +++++++ .../allowSyntheticDefaultImports6.js | 27 ++++++++++++ .../compiler/allowSyntheticDefaultImports1.ts | 10 +++++ .../compiler/allowSyntheticDefaultImports2.ts | 9 ++++ .../compiler/allowSyntheticDefaultImports3.ts | 10 +++++ .../compiler/allowSyntheticDefaultImports4.ts | 11 +++++ .../compiler/allowSyntheticDefaultImports5.ts | 10 +++++ .../compiler/allowSyntheticDefaultImports6.ts | 11 +++++ 26 files changed, 424 insertions(+), 1 deletion(-) create mode 100644 tests/baselines/reference/allowSyntheticDefaultImports1.js create mode 100644 tests/baselines/reference/allowSyntheticDefaultImports1.symbols create mode 100644 tests/baselines/reference/allowSyntheticDefaultImports1.types create mode 100644 tests/baselines/reference/allowSyntheticDefaultImports2.js create mode 100644 tests/baselines/reference/allowSyntheticDefaultImports2.symbols create mode 100644 tests/baselines/reference/allowSyntheticDefaultImports2.types create mode 100644 tests/baselines/reference/allowSyntheticDefaultImports3.errors.txt create mode 100644 tests/baselines/reference/allowSyntheticDefaultImports3.js create mode 100644 tests/baselines/reference/allowSyntheticDefaultImports4.js create mode 100644 tests/baselines/reference/allowSyntheticDefaultImports4.symbols create mode 100644 tests/baselines/reference/allowSyntheticDefaultImports4.types create mode 100644 tests/baselines/reference/allowSyntheticDefaultImports5.js create mode 100644 tests/baselines/reference/allowSyntheticDefaultImports5.symbols create mode 100644 tests/baselines/reference/allowSyntheticDefaultImports5.types create mode 100644 tests/baselines/reference/allowSyntheticDefaultImports6.errors.txt create mode 100644 tests/baselines/reference/allowSyntheticDefaultImports6.js create mode 100644 tests/cases/compiler/allowSyntheticDefaultImports1.ts create mode 100644 tests/cases/compiler/allowSyntheticDefaultImports2.ts create mode 100644 tests/cases/compiler/allowSyntheticDefaultImports3.ts create mode 100644 tests/cases/compiler/allowSyntheticDefaultImports4.ts create mode 100644 tests/cases/compiler/allowSyntheticDefaultImports5.ts create mode 100644 tests/cases/compiler/allowSyntheticDefaultImports6.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 706ed1c65a3c9..9dbce88c32b1b 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -46,6 +46,7 @@ namespace ts { const compilerOptions = host.getCompilerOptions(); const languageVersion = compilerOptions.target || ScriptTarget.ES3; const modulekind = compilerOptions.module ? compilerOptions.module : languageVersion === ScriptTarget.ES6 ? ModuleKind.ES6 : ModuleKind.None; + const allowSyntheticDefaultImports = compilerOptions.hasOwnProperty("allowSyntheticDefaultImports") ? compilerOptions.allowSyntheticDefaultImports : modulekind === ModuleKind.System; const emitResolver = createResolver(); @@ -730,9 +731,12 @@ namespace ts { const moduleSymbol = resolveExternalModuleName(node, (node.parent).moduleSpecifier); if (moduleSymbol) { const exportDefaultSymbol = resolveSymbol(moduleSymbol.exports["default"]); - if (!exportDefaultSymbol) { + if (!exportDefaultSymbol && !allowSyntheticDefaultImports) { error(node.name, Diagnostics.Module_0_has_no_default_export, symbolToString(moduleSymbol)); } + else if (!exportDefaultSymbol && allowSyntheticDefaultImports) { + return resolveSymbol(moduleSymbol.exports["export="]) || resolveSymbol(moduleSymbol); + } return exportDefaultSymbol; } } diff --git a/src/compiler/commandLineParser.ts b/src/compiler/commandLineParser.ts index 3fca97c045021..272f5430b8cbc 100644 --- a/src/compiler/commandLineParser.ts +++ b/src/compiler/commandLineParser.ts @@ -279,6 +279,11 @@ namespace ts { name: "forceConsistentCasingInFileNames", type: "boolean", description: Diagnostics.Disallow_inconsistently_cased_references_to_the_same_file + }, + { + name: "allowSyntheticDefaultImports", + type: "boolean", + description: Diagnostics.Allow_default_imports_from_modules_with_no_default_export } ]; diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index e6008ce3c1ebb..cdd20b38a6991 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -2101,6 +2101,10 @@ "category": "Message", "code": 6010 }, + "Allow default imports from modules with no default export": { + "category": "Message", + "code": 6011 + }, "Specify ECMAScript target version: 'ES3' (default), 'ES5', or 'ES2015' (experimental)": { "category": "Message", "code": 6015 diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 679957d1d3878..b846dc88aab7d 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -2109,6 +2109,7 @@ namespace ts { noImplicitReturns?: boolean; noFallthroughCasesInSwitch?: boolean; forceConsistentCasingInFileNames?: boolean; + allowSyntheticDefaultImports?: boolean; /* @internal */ stripInternal?: boolean; // Skip checking lib.d.ts to help speed up tests. diff --git a/tests/baselines/reference/allowSyntheticDefaultImports1.js b/tests/baselines/reference/allowSyntheticDefaultImports1.js new file mode 100644 index 0000000000000..bc78725cb1c5b --- /dev/null +++ b/tests/baselines/reference/allowSyntheticDefaultImports1.js @@ -0,0 +1,22 @@ +//// [tests/cases/compiler/allowSyntheticDefaultImports1.ts] //// + +//// [a.ts] +import Namespace from "./b"; +export var x = new Namespace.Foo(); + +//// [b.ts] +export class Foo { + member: string; +} + + +//// [b.js] +var Foo = (function () { + function Foo() { + } + return Foo; +})(); +exports.Foo = Foo; +//// [a.js] +var b_1 = require("./b"); +exports.x = new b_1["default"].Foo(); diff --git a/tests/baselines/reference/allowSyntheticDefaultImports1.symbols b/tests/baselines/reference/allowSyntheticDefaultImports1.symbols new file mode 100644 index 0000000000000..d88a79e1bf27e --- /dev/null +++ b/tests/baselines/reference/allowSyntheticDefaultImports1.symbols @@ -0,0 +1,18 @@ +=== tests/cases/compiler/a.ts === +import Namespace from "./b"; +>Namespace : Symbol(Namespace, Decl(a.ts, 0, 6)) + +export var x = new Namespace.Foo(); +>x : Symbol(x, Decl(a.ts, 1, 10)) +>Namespace.Foo : Symbol(Namespace.Foo, Decl(b.ts, 0, 0)) +>Namespace : Symbol(Namespace, Decl(a.ts, 0, 6)) +>Foo : Symbol(Namespace.Foo, Decl(b.ts, 0, 0)) + +=== tests/cases/compiler/b.ts === +export class Foo { +>Foo : Symbol(Foo, Decl(b.ts, 0, 0)) + + member: string; +>member : Symbol(member, Decl(b.ts, 0, 18)) +} + diff --git a/tests/baselines/reference/allowSyntheticDefaultImports1.types b/tests/baselines/reference/allowSyntheticDefaultImports1.types new file mode 100644 index 0000000000000..c2265d7611b38 --- /dev/null +++ b/tests/baselines/reference/allowSyntheticDefaultImports1.types @@ -0,0 +1,19 @@ +=== tests/cases/compiler/a.ts === +import Namespace from "./b"; +>Namespace : typeof Namespace + +export var x = new Namespace.Foo(); +>x : Namespace.Foo +>new Namespace.Foo() : Namespace.Foo +>Namespace.Foo : typeof Namespace.Foo +>Namespace : typeof Namespace +>Foo : typeof Namespace.Foo + +=== tests/cases/compiler/b.ts === +export class Foo { +>Foo : Foo + + member: string; +>member : string +} + diff --git a/tests/baselines/reference/allowSyntheticDefaultImports2.js b/tests/baselines/reference/allowSyntheticDefaultImports2.js new file mode 100644 index 0000000000000..3c1981bee9bd0 --- /dev/null +++ b/tests/baselines/reference/allowSyntheticDefaultImports2.js @@ -0,0 +1,40 @@ +//// [tests/cases/compiler/allowSyntheticDefaultImports2.ts] //// + +//// [a.ts] +import Namespace from "./b"; +export var x = new Namespace.Foo(); + +//// [b.ts] +export class Foo { + member: string; +} + +//// [b.js] +System.register([], function(exports_1) { + var Foo; + return { + setters:[], + execute: function() { + Foo = (function () { + function Foo() { + } + return Foo; + })(); + exports_1("Foo", Foo); + } + } +}); +//// [a.js] +System.register(["./b"], function(exports_1) { + var b_1; + var x; + return { + setters:[ + function (b_1_1) { + b_1 = b_1_1; + }], + execute: function() { + exports_1("x", x = new b_1["default"].Foo()); + } + } +}); diff --git a/tests/baselines/reference/allowSyntheticDefaultImports2.symbols b/tests/baselines/reference/allowSyntheticDefaultImports2.symbols new file mode 100644 index 0000000000000..cea6145fbd607 --- /dev/null +++ b/tests/baselines/reference/allowSyntheticDefaultImports2.symbols @@ -0,0 +1,17 @@ +=== tests/cases/compiler/a.ts === +import Namespace from "./b"; +>Namespace : Symbol(Namespace, Decl(a.ts, 0, 6)) + +export var x = new Namespace.Foo(); +>x : Symbol(x, Decl(a.ts, 1, 10)) +>Namespace.Foo : Symbol(Namespace.Foo, Decl(b.ts, 0, 0)) +>Namespace : Symbol(Namespace, Decl(a.ts, 0, 6)) +>Foo : Symbol(Namespace.Foo, Decl(b.ts, 0, 0)) + +=== tests/cases/compiler/b.ts === +export class Foo { +>Foo : Symbol(Foo, Decl(b.ts, 0, 0)) + + member: string; +>member : Symbol(member, Decl(b.ts, 0, 18)) +} diff --git a/tests/baselines/reference/allowSyntheticDefaultImports2.types b/tests/baselines/reference/allowSyntheticDefaultImports2.types new file mode 100644 index 0000000000000..c40fbc7e98859 --- /dev/null +++ b/tests/baselines/reference/allowSyntheticDefaultImports2.types @@ -0,0 +1,18 @@ +=== tests/cases/compiler/a.ts === +import Namespace from "./b"; +>Namespace : typeof Namespace + +export var x = new Namespace.Foo(); +>x : Namespace.Foo +>new Namespace.Foo() : Namespace.Foo +>Namespace.Foo : typeof Namespace.Foo +>Namespace : typeof Namespace +>Foo : typeof Namespace.Foo + +=== tests/cases/compiler/b.ts === +export class Foo { +>Foo : Foo + + member: string; +>member : string +} diff --git a/tests/baselines/reference/allowSyntheticDefaultImports3.errors.txt b/tests/baselines/reference/allowSyntheticDefaultImports3.errors.txt new file mode 100644 index 0000000000000..551355e5cce06 --- /dev/null +++ b/tests/baselines/reference/allowSyntheticDefaultImports3.errors.txt @@ -0,0 +1,14 @@ +tests/cases/compiler/a.ts(1,8): error TS1192: Module '"tests/cases/compiler/b"' has no default export. + + +==== tests/cases/compiler/a.ts (1 errors) ==== + import Namespace from "./b"; + ~~~~~~~~~ +!!! error TS1192: Module '"tests/cases/compiler/b"' has no default export. + export var x = new Namespace.Foo(); + +==== tests/cases/compiler/b.ts (0 errors) ==== + export class Foo { + member: string; + } + \ No newline at end of file diff --git a/tests/baselines/reference/allowSyntheticDefaultImports3.js b/tests/baselines/reference/allowSyntheticDefaultImports3.js new file mode 100644 index 0000000000000..2345ad65d107a --- /dev/null +++ b/tests/baselines/reference/allowSyntheticDefaultImports3.js @@ -0,0 +1,41 @@ +//// [tests/cases/compiler/allowSyntheticDefaultImports3.ts] //// + +//// [a.ts] +import Namespace from "./b"; +export var x = new Namespace.Foo(); + +//// [b.ts] +export class Foo { + member: string; +} + + +//// [b.js] +System.register([], function(exports_1) { + var Foo; + return { + setters:[], + execute: function() { + Foo = (function () { + function Foo() { + } + return Foo; + })(); + exports_1("Foo", Foo); + } + } +}); +//// [a.js] +System.register(["./b"], function(exports_1) { + var b_1; + var x; + return { + setters:[ + function (b_1_1) { + b_1 = b_1_1; + }], + execute: function() { + exports_1("x", x = new b_1["default"].Foo()); + } + } +}); diff --git a/tests/baselines/reference/allowSyntheticDefaultImports4.js b/tests/baselines/reference/allowSyntheticDefaultImports4.js new file mode 100644 index 0000000000000..583d4f0bc9235 --- /dev/null +++ b/tests/baselines/reference/allowSyntheticDefaultImports4.js @@ -0,0 +1,16 @@ +//// [tests/cases/compiler/allowSyntheticDefaultImports4.ts] //// + +//// [b.d.ts] +declare class Foo { + member: string; +} +export = Foo; + +//// [a.ts] +import Foo from "./b"; +export var x = new Foo(); + + +//// [a.js] +var b_1 = require("./b"); +exports.x = new b_1["default"](); diff --git a/tests/baselines/reference/allowSyntheticDefaultImports4.symbols b/tests/baselines/reference/allowSyntheticDefaultImports4.symbols new file mode 100644 index 0000000000000..8edad006c2dd5 --- /dev/null +++ b/tests/baselines/reference/allowSyntheticDefaultImports4.symbols @@ -0,0 +1,18 @@ +=== tests/cases/compiler/b.d.ts === +declare class Foo { +>Foo : Symbol(Foo, Decl(b.d.ts, 0, 0)) + + member: string; +>member : Symbol(member, Decl(b.d.ts, 0, 19)) +} +export = Foo; +>Foo : Symbol(Foo, Decl(b.d.ts, 0, 0)) + +=== tests/cases/compiler/a.ts === +import Foo from "./b"; +>Foo : Symbol(Foo, Decl(a.ts, 0, 6)) + +export var x = new Foo(); +>x : Symbol(x, Decl(a.ts, 1, 10)) +>Foo : Symbol(Foo, Decl(a.ts, 0, 6)) + diff --git a/tests/baselines/reference/allowSyntheticDefaultImports4.types b/tests/baselines/reference/allowSyntheticDefaultImports4.types new file mode 100644 index 0000000000000..5922abeb43f77 --- /dev/null +++ b/tests/baselines/reference/allowSyntheticDefaultImports4.types @@ -0,0 +1,19 @@ +=== tests/cases/compiler/b.d.ts === +declare class Foo { +>Foo : Foo + + member: string; +>member : string +} +export = Foo; +>Foo : Foo + +=== tests/cases/compiler/a.ts === +import Foo from "./b"; +>Foo : typeof Foo + +export var x = new Foo(); +>x : Foo +>new Foo() : Foo +>Foo : typeof Foo + diff --git a/tests/baselines/reference/allowSyntheticDefaultImports5.js b/tests/baselines/reference/allowSyntheticDefaultImports5.js new file mode 100644 index 0000000000000..e1528e2791521 --- /dev/null +++ b/tests/baselines/reference/allowSyntheticDefaultImports5.js @@ -0,0 +1,27 @@ +//// [tests/cases/compiler/allowSyntheticDefaultImports5.ts] //// + +//// [b.d.ts] +declare class Foo { + member: string; +} +export = Foo; + +//// [a.ts] +import Foo from "./b"; +export var x = new Foo(); + + +//// [a.js] +System.register(["./b"], function(exports_1) { + var b_1; + var x; + return { + setters:[ + function (b_1_1) { + b_1 = b_1_1; + }], + execute: function() { + exports_1("x", x = new b_1["default"]()); + } + } +}); diff --git a/tests/baselines/reference/allowSyntheticDefaultImports5.symbols b/tests/baselines/reference/allowSyntheticDefaultImports5.symbols new file mode 100644 index 0000000000000..8edad006c2dd5 --- /dev/null +++ b/tests/baselines/reference/allowSyntheticDefaultImports5.symbols @@ -0,0 +1,18 @@ +=== tests/cases/compiler/b.d.ts === +declare class Foo { +>Foo : Symbol(Foo, Decl(b.d.ts, 0, 0)) + + member: string; +>member : Symbol(member, Decl(b.d.ts, 0, 19)) +} +export = Foo; +>Foo : Symbol(Foo, Decl(b.d.ts, 0, 0)) + +=== tests/cases/compiler/a.ts === +import Foo from "./b"; +>Foo : Symbol(Foo, Decl(a.ts, 0, 6)) + +export var x = new Foo(); +>x : Symbol(x, Decl(a.ts, 1, 10)) +>Foo : Symbol(Foo, Decl(a.ts, 0, 6)) + diff --git a/tests/baselines/reference/allowSyntheticDefaultImports5.types b/tests/baselines/reference/allowSyntheticDefaultImports5.types new file mode 100644 index 0000000000000..5922abeb43f77 --- /dev/null +++ b/tests/baselines/reference/allowSyntheticDefaultImports5.types @@ -0,0 +1,19 @@ +=== tests/cases/compiler/b.d.ts === +declare class Foo { +>Foo : Foo + + member: string; +>member : string +} +export = Foo; +>Foo : Foo + +=== tests/cases/compiler/a.ts === +import Foo from "./b"; +>Foo : typeof Foo + +export var x = new Foo(); +>x : Foo +>new Foo() : Foo +>Foo : typeof Foo + diff --git a/tests/baselines/reference/allowSyntheticDefaultImports6.errors.txt b/tests/baselines/reference/allowSyntheticDefaultImports6.errors.txt new file mode 100644 index 0000000000000..80b9cf8d074ab --- /dev/null +++ b/tests/baselines/reference/allowSyntheticDefaultImports6.errors.txt @@ -0,0 +1,15 @@ +tests/cases/compiler/a.ts(1,8): error TS1192: Module '"tests/cases/compiler/b"' has no default export. + + +==== tests/cases/compiler/b.d.ts (0 errors) ==== + declare class Foo { + member: string; + } + export = Foo; + +==== tests/cases/compiler/a.ts (1 errors) ==== + import Foo from "./b"; + ~~~ +!!! error TS1192: Module '"tests/cases/compiler/b"' has no default export. + export var x = new Foo(); + \ No newline at end of file diff --git a/tests/baselines/reference/allowSyntheticDefaultImports6.js b/tests/baselines/reference/allowSyntheticDefaultImports6.js new file mode 100644 index 0000000000000..0e27ce127d82e --- /dev/null +++ b/tests/baselines/reference/allowSyntheticDefaultImports6.js @@ -0,0 +1,27 @@ +//// [tests/cases/compiler/allowSyntheticDefaultImports6.ts] //// + +//// [b.d.ts] +declare class Foo { + member: string; +} +export = Foo; + +//// [a.ts] +import Foo from "./b"; +export var x = new Foo(); + + +//// [a.js] +System.register(["./b"], function(exports_1) { + var b_1; + var x; + return { + setters:[ + function (b_1_1) { + b_1 = b_1_1; + }], + execute: function() { + exports_1("x", x = new b_1["default"]()); + } + } +}); diff --git a/tests/cases/compiler/allowSyntheticDefaultImports1.ts b/tests/cases/compiler/allowSyntheticDefaultImports1.ts new file mode 100644 index 0000000000000..4793da791361c --- /dev/null +++ b/tests/cases/compiler/allowSyntheticDefaultImports1.ts @@ -0,0 +1,10 @@ +// @allowSyntheticDefaultImports: true +// @module: commonjs +// @Filename: a.ts +import Namespace from "./b"; +export var x = new Namespace.Foo(); + +// @Filename: b.ts +export class Foo { + member: string; +} diff --git a/tests/cases/compiler/allowSyntheticDefaultImports2.ts b/tests/cases/compiler/allowSyntheticDefaultImports2.ts new file mode 100644 index 0000000000000..8fa004be38720 --- /dev/null +++ b/tests/cases/compiler/allowSyntheticDefaultImports2.ts @@ -0,0 +1,9 @@ +// @module: system +// @Filename: a.ts +import Namespace from "./b"; +export var x = new Namespace.Foo(); + +// @Filename: b.ts +export class Foo { + member: string; +} \ No newline at end of file diff --git a/tests/cases/compiler/allowSyntheticDefaultImports3.ts b/tests/cases/compiler/allowSyntheticDefaultImports3.ts new file mode 100644 index 0000000000000..65d11c892c97c --- /dev/null +++ b/tests/cases/compiler/allowSyntheticDefaultImports3.ts @@ -0,0 +1,10 @@ +// @allowSyntheticDefaultImports: false +// @module: system +// @Filename: a.ts +import Namespace from "./b"; +export var x = new Namespace.Foo(); + +// @Filename: b.ts +export class Foo { + member: string; +} diff --git a/tests/cases/compiler/allowSyntheticDefaultImports4.ts b/tests/cases/compiler/allowSyntheticDefaultImports4.ts new file mode 100644 index 0000000000000..1d26c6277c1c6 --- /dev/null +++ b/tests/cases/compiler/allowSyntheticDefaultImports4.ts @@ -0,0 +1,11 @@ +// @allowSyntheticDefaultImports: true +// @module: commonjs +// @Filename: b.d.ts +declare class Foo { + member: string; +} +export = Foo; + +// @Filename: a.ts +import Foo from "./b"; +export var x = new Foo(); diff --git a/tests/cases/compiler/allowSyntheticDefaultImports5.ts b/tests/cases/compiler/allowSyntheticDefaultImports5.ts new file mode 100644 index 0000000000000..30ebba67144a8 --- /dev/null +++ b/tests/cases/compiler/allowSyntheticDefaultImports5.ts @@ -0,0 +1,10 @@ +// @module: system +// @Filename: b.d.ts +declare class Foo { + member: string; +} +export = Foo; + +// @Filename: a.ts +import Foo from "./b"; +export var x = new Foo(); diff --git a/tests/cases/compiler/allowSyntheticDefaultImports6.ts b/tests/cases/compiler/allowSyntheticDefaultImports6.ts new file mode 100644 index 0000000000000..ff0300e30b472 --- /dev/null +++ b/tests/cases/compiler/allowSyntheticDefaultImports6.ts @@ -0,0 +1,11 @@ +// @allowSyntheticDefaultImports: false +// @module: system +// @Filename: b.d.ts +declare class Foo { + member: string; +} +export = Foo; + +// @Filename: a.ts +import Foo from "./b"; +export var x = new Foo(); From 9024032571316f17ccdc80a3392b9d173621babe Mon Sep 17 00:00:00 2001 From: Wesley Wigham Date: Mon, 9 Nov 2015 15:13:55 -0800 Subject: [PATCH 2/4] use typeof --- src/compiler/checker.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 9dbce88c32b1b..102b6b0c67015 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -46,7 +46,7 @@ namespace ts { const compilerOptions = host.getCompilerOptions(); const languageVersion = compilerOptions.target || ScriptTarget.ES3; const modulekind = compilerOptions.module ? compilerOptions.module : languageVersion === ScriptTarget.ES6 ? ModuleKind.ES6 : ModuleKind.None; - const allowSyntheticDefaultImports = compilerOptions.hasOwnProperty("allowSyntheticDefaultImports") ? compilerOptions.allowSyntheticDefaultImports : modulekind === ModuleKind.System; + const allowSyntheticDefaultImports = typeof compilerOptions.allowSyntheticDefaultImports !== "undefined" ? compilerOptions.allowSyntheticDefaultImports : modulekind === ModuleKind.System; const emitResolver = createResolver(); From adc3f2bd199c5441c7922164bba005ba26eb5a9d Mon Sep 17 00:00:00 2001 From: Wesley Wigham Date: Wed, 25 Nov 2015 17:27:07 -0800 Subject: [PATCH 3/4] update description --- src/compiler/commandLineParser.ts | 2 +- src/compiler/diagnosticMessages.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/compiler/commandLineParser.ts b/src/compiler/commandLineParser.ts index 8ec47fcffef7b..034b7022e8232 100644 --- a/src/compiler/commandLineParser.ts +++ b/src/compiler/commandLineParser.ts @@ -283,7 +283,7 @@ namespace ts { { name: "allowSyntheticDefaultImports", type: "boolean", - description: Diagnostics.Allow_default_imports_from_modules_with_no_default_export + description: Diagnostics.Allow_default_imports_from_modules_with_no_default_export_This_does_not_affect_code_emit_just_typechecking }, { name: "allowJs", diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 9646353d8f8b9..882fd41d6d493 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -2109,7 +2109,7 @@ "category": "Message", "code": 6010 }, - "Allow default imports from modules with no default export": { + "Allow default imports from modules with no default export. This does not affect code emit, just typechecking.": { "category": "Message", "code": 6011 }, From fd5f4404cb4bed07c234ec468d7ab9815cc59a73 Mon Sep 17 00:00:00 2001 From: Wesley Wigham Date: Wed, 25 Nov 2015 18:22:44 -0800 Subject: [PATCH 4/4] accept new baselines --- tests/baselines/reference/allowSyntheticDefaultImports1.js | 2 ++ tests/baselines/reference/allowSyntheticDefaultImports2.js | 2 ++ tests/baselines/reference/allowSyntheticDefaultImports3.js | 2 ++ tests/baselines/reference/allowSyntheticDefaultImports4.js | 1 + tests/baselines/reference/allowSyntheticDefaultImports5.js | 1 + tests/baselines/reference/allowSyntheticDefaultImports6.js | 1 + 6 files changed, 9 insertions(+) diff --git a/tests/baselines/reference/allowSyntheticDefaultImports1.js b/tests/baselines/reference/allowSyntheticDefaultImports1.js index bc78725cb1c5b..699880f930ccb 100644 --- a/tests/baselines/reference/allowSyntheticDefaultImports1.js +++ b/tests/baselines/reference/allowSyntheticDefaultImports1.js @@ -11,6 +11,7 @@ export class Foo { //// [b.js] +"use strict"; var Foo = (function () { function Foo() { } @@ -18,5 +19,6 @@ var Foo = (function () { })(); exports.Foo = Foo; //// [a.js] +"use strict"; var b_1 = require("./b"); exports.x = new b_1["default"].Foo(); diff --git a/tests/baselines/reference/allowSyntheticDefaultImports2.js b/tests/baselines/reference/allowSyntheticDefaultImports2.js index 3c1981bee9bd0..d21750c65fc31 100644 --- a/tests/baselines/reference/allowSyntheticDefaultImports2.js +++ b/tests/baselines/reference/allowSyntheticDefaultImports2.js @@ -11,6 +11,7 @@ export class Foo { //// [b.js] System.register([], function(exports_1) { + "use strict"; var Foo; return { setters:[], @@ -26,6 +27,7 @@ System.register([], function(exports_1) { }); //// [a.js] System.register(["./b"], function(exports_1) { + "use strict"; var b_1; var x; return { diff --git a/tests/baselines/reference/allowSyntheticDefaultImports3.js b/tests/baselines/reference/allowSyntheticDefaultImports3.js index 2345ad65d107a..8864a28e7960d 100644 --- a/tests/baselines/reference/allowSyntheticDefaultImports3.js +++ b/tests/baselines/reference/allowSyntheticDefaultImports3.js @@ -12,6 +12,7 @@ export class Foo { //// [b.js] System.register([], function(exports_1) { + "use strict"; var Foo; return { setters:[], @@ -27,6 +28,7 @@ System.register([], function(exports_1) { }); //// [a.js] System.register(["./b"], function(exports_1) { + "use strict"; var b_1; var x; return { diff --git a/tests/baselines/reference/allowSyntheticDefaultImports4.js b/tests/baselines/reference/allowSyntheticDefaultImports4.js index 583d4f0bc9235..747f59dc904fd 100644 --- a/tests/baselines/reference/allowSyntheticDefaultImports4.js +++ b/tests/baselines/reference/allowSyntheticDefaultImports4.js @@ -12,5 +12,6 @@ export var x = new Foo(); //// [a.js] +"use strict"; var b_1 = require("./b"); exports.x = new b_1["default"](); diff --git a/tests/baselines/reference/allowSyntheticDefaultImports5.js b/tests/baselines/reference/allowSyntheticDefaultImports5.js index e1528e2791521..c9121512b610c 100644 --- a/tests/baselines/reference/allowSyntheticDefaultImports5.js +++ b/tests/baselines/reference/allowSyntheticDefaultImports5.js @@ -13,6 +13,7 @@ export var x = new Foo(); //// [a.js] System.register(["./b"], function(exports_1) { + "use strict"; var b_1; var x; return { diff --git a/tests/baselines/reference/allowSyntheticDefaultImports6.js b/tests/baselines/reference/allowSyntheticDefaultImports6.js index 0e27ce127d82e..64d52e70af9d7 100644 --- a/tests/baselines/reference/allowSyntheticDefaultImports6.js +++ b/tests/baselines/reference/allowSyntheticDefaultImports6.js @@ -13,6 +13,7 @@ export var x = new Foo(); //// [a.js] System.register(["./b"], function(exports_1) { + "use strict"; var b_1; var x; return {