mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-09 16:39:46 -05:00
This commit is contained in:
@@ -1135,6 +1135,10 @@ namespace ts {
|
||||
else {
|
||||
symbolFromVariable = getPropertyOfVariable(targetSymbol, name.text);
|
||||
}
|
||||
// If the export member we're looking for is default, and there is no real default but allowSyntheticDefaultImports is on, return the entire module as the default
|
||||
if (!symbolFromVariable && allowSyntheticDefaultImports && name.text === "default") {
|
||||
symbolFromVariable = resolveExternalModuleSymbol(moduleSymbol) || resolveSymbol(moduleSymbol);
|
||||
}
|
||||
// if symbolFromVariable is export - get its final target
|
||||
symbolFromVariable = resolveSymbol(symbolFromVariable);
|
||||
const symbolFromModule = getExportOfModule(targetSymbol, name.text);
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
tests/cases/compiler/a.ts(2,5): error TS2339: Property 'default' does not exist on type 'typeof "tests/cases/compiler/b"'.
|
||||
tests/cases/compiler/a.ts(3,5): error TS2339: Property 'default' does not exist on type 'typeof "tests/cases/compiler/b"'.
|
||||
|
||||
|
||||
==== tests/cases/compiler/a.ts (2 errors) ====
|
||||
import Foo = require("./b");
|
||||
Foo.default.bar();
|
||||
~~~~~~~
|
||||
!!! error TS2339: Property 'default' does not exist on type 'typeof "tests/cases/compiler/b"'.
|
||||
Foo.default.default.foo();
|
||||
~~~~~~~
|
||||
!!! error TS2339: Property 'default' does not exist on type 'typeof "tests/cases/compiler/b"'.
|
||||
==== tests/cases/compiler/b.d.ts (0 errors) ====
|
||||
export function foo();
|
||||
|
||||
export function bar();
|
||||
|
||||
17
tests/baselines/reference/allowSyntheticDefaultImports10.js
Normal file
17
tests/baselines/reference/allowSyntheticDefaultImports10.js
Normal file
@@ -0,0 +1,17 @@
|
||||
//// [tests/cases/compiler/allowSyntheticDefaultImports10.ts] ////
|
||||
|
||||
//// [b.d.ts]
|
||||
export function foo();
|
||||
|
||||
export function bar();
|
||||
|
||||
//// [a.ts]
|
||||
import Foo = require("./b");
|
||||
Foo.default.bar();
|
||||
Foo.default.default.foo();
|
||||
|
||||
//// [a.js]
|
||||
"use strict";
|
||||
var Foo = require("./b");
|
||||
Foo.default.bar();
|
||||
Foo.default.default.foo();
|
||||
28
tests/baselines/reference/allowSyntheticDefaultImports7.js
Normal file
28
tests/baselines/reference/allowSyntheticDefaultImports7.js
Normal file
@@ -0,0 +1,28 @@
|
||||
//// [tests/cases/compiler/allowSyntheticDefaultImports7.ts] ////
|
||||
|
||||
//// [b.d.ts]
|
||||
export function foo();
|
||||
|
||||
export function bar();
|
||||
|
||||
//// [a.ts]
|
||||
import { default as Foo } from "./b";
|
||||
Foo.bar();
|
||||
Foo.foo();
|
||||
|
||||
//// [a.js]
|
||||
System.register(["./b"], function(exports_1, context_1) {
|
||||
"use strict";
|
||||
var __moduleName = context_1 && context_1.id;
|
||||
var b_1;
|
||||
return {
|
||||
setters:[
|
||||
function (b_1_1) {
|
||||
b_1 = b_1_1;
|
||||
}],
|
||||
execute: function() {
|
||||
b_1["default"].bar();
|
||||
b_1["default"].foo();
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -0,0 +1,22 @@
|
||||
=== tests/cases/compiler/b.d.ts ===
|
||||
export function foo();
|
||||
>foo : Symbol(foo, Decl(b.d.ts, 0, 0))
|
||||
|
||||
export function bar();
|
||||
>bar : Symbol(bar, Decl(b.d.ts, 0, 22))
|
||||
|
||||
=== tests/cases/compiler/a.ts ===
|
||||
import { default as Foo } from "./b";
|
||||
>default : Symbol(Foo, Decl(a.ts, 0, 8))
|
||||
>Foo : Symbol(Foo, Decl(a.ts, 0, 8))
|
||||
|
||||
Foo.bar();
|
||||
>Foo.bar : Symbol(Foo.bar, Decl(b.d.ts, 0, 22))
|
||||
>Foo : Symbol(Foo, Decl(a.ts, 0, 8))
|
||||
>bar : Symbol(Foo.bar, Decl(b.d.ts, 0, 22))
|
||||
|
||||
Foo.foo();
|
||||
>Foo.foo : Symbol(Foo.foo, Decl(b.d.ts, 0, 0))
|
||||
>Foo : Symbol(Foo, Decl(a.ts, 0, 8))
|
||||
>foo : Symbol(Foo.foo, Decl(b.d.ts, 0, 0))
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
=== tests/cases/compiler/b.d.ts ===
|
||||
export function foo();
|
||||
>foo : () => any
|
||||
|
||||
export function bar();
|
||||
>bar : () => any
|
||||
|
||||
=== tests/cases/compiler/a.ts ===
|
||||
import { default as Foo } from "./b";
|
||||
>default : typeof Foo
|
||||
>Foo : typeof Foo
|
||||
|
||||
Foo.bar();
|
||||
>Foo.bar() : any
|
||||
>Foo.bar : () => any
|
||||
>Foo : typeof Foo
|
||||
>bar : () => any
|
||||
|
||||
Foo.foo();
|
||||
>Foo.foo() : any
|
||||
>Foo.foo : () => any
|
||||
>Foo : typeof Foo
|
||||
>foo : () => any
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
tests/cases/compiler/a.ts(1,10): error TS2305: Module '"tests/cases/compiler/b"' has no exported member 'default'.
|
||||
|
||||
|
||||
==== tests/cases/compiler/b.d.ts (0 errors) ====
|
||||
export function foo();
|
||||
|
||||
export function bar();
|
||||
|
||||
==== tests/cases/compiler/a.ts (1 errors) ====
|
||||
import { default as Foo } from "./b";
|
||||
~~~~~~~
|
||||
!!! error TS2305: Module '"tests/cases/compiler/b"' has no exported member 'default'.
|
||||
Foo.bar();
|
||||
Foo.foo();
|
||||
28
tests/baselines/reference/allowSyntheticDefaultImports8.js
Normal file
28
tests/baselines/reference/allowSyntheticDefaultImports8.js
Normal file
@@ -0,0 +1,28 @@
|
||||
//// [tests/cases/compiler/allowSyntheticDefaultImports8.ts] ////
|
||||
|
||||
//// [b.d.ts]
|
||||
export function foo();
|
||||
|
||||
export function bar();
|
||||
|
||||
//// [a.ts]
|
||||
import { default as Foo } from "./b";
|
||||
Foo.bar();
|
||||
Foo.foo();
|
||||
|
||||
//// [a.js]
|
||||
System.register(["./b"], function(exports_1, context_1) {
|
||||
"use strict";
|
||||
var __moduleName = context_1 && context_1.id;
|
||||
var b_1;
|
||||
return {
|
||||
setters:[
|
||||
function (b_1_1) {
|
||||
b_1 = b_1_1;
|
||||
}],
|
||||
execute: function() {
|
||||
b_1["default"].bar();
|
||||
b_1["default"].foo();
|
||||
}
|
||||
}
|
||||
});
|
||||
17
tests/baselines/reference/allowSyntheticDefaultImports9.js
Normal file
17
tests/baselines/reference/allowSyntheticDefaultImports9.js
Normal file
@@ -0,0 +1,17 @@
|
||||
//// [tests/cases/compiler/allowSyntheticDefaultImports9.ts] ////
|
||||
|
||||
//// [b.d.ts]
|
||||
export function foo();
|
||||
|
||||
export function bar();
|
||||
|
||||
//// [a.ts]
|
||||
import { default as Foo } from "./b";
|
||||
Foo.bar();
|
||||
Foo.foo();
|
||||
|
||||
//// [a.js]
|
||||
"use strict";
|
||||
var b_1 = require("./b");
|
||||
b_1["default"].bar();
|
||||
b_1["default"].foo();
|
||||
@@ -0,0 +1,22 @@
|
||||
=== tests/cases/compiler/b.d.ts ===
|
||||
export function foo();
|
||||
>foo : Symbol(foo, Decl(b.d.ts, 0, 0))
|
||||
|
||||
export function bar();
|
||||
>bar : Symbol(bar, Decl(b.d.ts, 0, 22))
|
||||
|
||||
=== tests/cases/compiler/a.ts ===
|
||||
import { default as Foo } from "./b";
|
||||
>default : Symbol(Foo, Decl(a.ts, 0, 8))
|
||||
>Foo : Symbol(Foo, Decl(a.ts, 0, 8))
|
||||
|
||||
Foo.bar();
|
||||
>Foo.bar : Symbol(Foo.bar, Decl(b.d.ts, 0, 22))
|
||||
>Foo : Symbol(Foo, Decl(a.ts, 0, 8))
|
||||
>bar : Symbol(Foo.bar, Decl(b.d.ts, 0, 22))
|
||||
|
||||
Foo.foo();
|
||||
>Foo.foo : Symbol(Foo.foo, Decl(b.d.ts, 0, 0))
|
||||
>Foo : Symbol(Foo, Decl(a.ts, 0, 8))
|
||||
>foo : Symbol(Foo.foo, Decl(b.d.ts, 0, 0))
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
=== tests/cases/compiler/b.d.ts ===
|
||||
export function foo();
|
||||
>foo : () => any
|
||||
|
||||
export function bar();
|
||||
>bar : () => any
|
||||
|
||||
=== tests/cases/compiler/a.ts ===
|
||||
import { default as Foo } from "./b";
|
||||
>default : typeof Foo
|
||||
>Foo : typeof Foo
|
||||
|
||||
Foo.bar();
|
||||
>Foo.bar() : any
|
||||
>Foo.bar : () => any
|
||||
>Foo : typeof Foo
|
||||
>bar : () => any
|
||||
|
||||
Foo.foo();
|
||||
>Foo.foo() : any
|
||||
>Foo.foo : () => any
|
||||
>Foo : typeof Foo
|
||||
>foo : () => any
|
||||
|
||||
11
tests/cases/compiler/allowSyntheticDefaultImports10.ts
Normal file
11
tests/cases/compiler/allowSyntheticDefaultImports10.ts
Normal file
@@ -0,0 +1,11 @@
|
||||
// @allowSyntheticDefaultImports: true
|
||||
// @module: commonjs
|
||||
// @Filename: b.d.ts
|
||||
export function foo();
|
||||
|
||||
export function bar();
|
||||
|
||||
// @Filename: a.ts
|
||||
import Foo = require("./b");
|
||||
Foo.default.bar();
|
||||
Foo.default.default.foo();
|
||||
10
tests/cases/compiler/allowSyntheticDefaultImports7.ts
Normal file
10
tests/cases/compiler/allowSyntheticDefaultImports7.ts
Normal file
@@ -0,0 +1,10 @@
|
||||
// @module: system
|
||||
// @Filename: b.d.ts
|
||||
export function foo();
|
||||
|
||||
export function bar();
|
||||
|
||||
// @Filename: a.ts
|
||||
import { default as Foo } from "./b";
|
||||
Foo.bar();
|
||||
Foo.foo();
|
||||
11
tests/cases/compiler/allowSyntheticDefaultImports8.ts
Normal file
11
tests/cases/compiler/allowSyntheticDefaultImports8.ts
Normal file
@@ -0,0 +1,11 @@
|
||||
// @allowSyntheticDefaultImports: false
|
||||
// @module: system
|
||||
// @Filename: b.d.ts
|
||||
export function foo();
|
||||
|
||||
export function bar();
|
||||
|
||||
// @Filename: a.ts
|
||||
import { default as Foo } from "./b";
|
||||
Foo.bar();
|
||||
Foo.foo();
|
||||
11
tests/cases/compiler/allowSyntheticDefaultImports9.ts
Normal file
11
tests/cases/compiler/allowSyntheticDefaultImports9.ts
Normal file
@@ -0,0 +1,11 @@
|
||||
// @allowSyntheticDefaultImports: true
|
||||
// @module: commonjs
|
||||
// @Filename: b.d.ts
|
||||
export function foo();
|
||||
|
||||
export function bar();
|
||||
|
||||
// @Filename: a.ts
|
||||
import { default as Foo } from "./b";
|
||||
Foo.bar();
|
||||
Foo.foo();
|
||||
Reference in New Issue
Block a user