mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
throw an error when no default export present (#35815)
This commit is contained in:
committed by
Wesley Wigham
parent
91ffa1c752
commit
daf786ecd0
@@ -2322,13 +2322,18 @@ namespace ts {
|
||||
else {
|
||||
symbolFromVariable = getPropertyOfVariable(targetSymbol, name.escapedText);
|
||||
}
|
||||
|
||||
// if symbolFromVariable is export - get its final target
|
||||
symbolFromVariable = resolveSymbol(symbolFromVariable, dontResolveAlias);
|
||||
|
||||
let symbolFromModule = getExportOfModule(targetSymbol, name.escapedText, dontResolveAlias);
|
||||
// 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 (!symbolFromModule && allowSyntheticDefaultImports && name.escapedText === InternalSymbolName.Default) {
|
||||
symbolFromModule = resolveExternalModuleSymbol(moduleSymbol, dontResolveAlias) || resolveSymbol(moduleSymbol, dontResolveAlias);
|
||||
if (symbolFromModule === undefined && name.escapedText === InternalSymbolName.Default) {
|
||||
const file = find(moduleSymbol.declarations, isSourceFile);
|
||||
if (canHaveSyntheticDefault(file, moduleSymbol, dontResolveAlias)) {
|
||||
symbolFromModule = resolveExternalModuleSymbol(moduleSymbol, dontResolveAlias) || resolveSymbol(moduleSymbol, dontResolveAlias);
|
||||
}
|
||||
}
|
||||
|
||||
const symbol = symbolFromModule && symbolFromVariable && symbolFromModule !== symbolFromVariable ?
|
||||
combineValueAndTypeSymbols(symbolFromVariable, symbolFromModule) :
|
||||
symbolFromModule || symbolFromVariable;
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
tests/cases/compiler/a.ts(2,10): error TS2305: Module '"./b"' has no exported member 'default'.
|
||||
|
||||
|
||||
==== tests/cases/compiler/b.ts (0 errors) ====
|
||||
export const b = null;
|
||||
|
||||
==== tests/cases/compiler/a.ts (1 errors) ====
|
||||
export { b } from "./b";
|
||||
export { default } from "./b";
|
||||
~~~~~~~
|
||||
!!! error TS2305: Module '"./b"' has no exported member 'default'.
|
||||
@@ -0,0 +1,20 @@
|
||||
//// [tests/cases/compiler/reexportMissingDefault.ts] ////
|
||||
|
||||
//// [b.ts]
|
||||
export const b = null;
|
||||
|
||||
//// [a.ts]
|
||||
export { b } from "./b";
|
||||
export { default } from "./b";
|
||||
|
||||
//// [b.js]
|
||||
"use strict";
|
||||
exports.__esModule = true;
|
||||
exports.b = null;
|
||||
//// [a.js]
|
||||
"use strict";
|
||||
exports.__esModule = true;
|
||||
var b_1 = require("./b");
|
||||
exports.b = b_1.b;
|
||||
var b_2 = require("./b");
|
||||
exports["default"] = b_2["default"];
|
||||
@@ -0,0 +1,11 @@
|
||||
=== tests/cases/compiler/b.ts ===
|
||||
export const b = null;
|
||||
>b : Symbol(b, Decl(b.ts, 0, 12))
|
||||
|
||||
=== tests/cases/compiler/a.ts ===
|
||||
export { b } from "./b";
|
||||
>b : Symbol(b, Decl(a.ts, 0, 8))
|
||||
|
||||
export { default } from "./b";
|
||||
>default : Symbol(default, Decl(a.ts, 1, 8))
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
=== tests/cases/compiler/b.ts ===
|
||||
export const b = null;
|
||||
>b : any
|
||||
>null : null
|
||||
|
||||
=== tests/cases/compiler/a.ts ===
|
||||
export { b } from "./b";
|
||||
>b : any
|
||||
|
||||
export { default } from "./b";
|
||||
>default : any
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
tests/cases/compiler/a.ts(2,10): error TS2305: Module '"./b"' has no exported member 'default'.
|
||||
|
||||
|
||||
==== tests/cases/compiler/b.ts (0 errors) ====
|
||||
export const b = null;
|
||||
|
||||
==== tests/cases/compiler/a.ts (1 errors) ====
|
||||
export { b } from "./b";
|
||||
export { default } from "./b";
|
||||
~~~~~~~
|
||||
!!! error TS2305: Module '"./b"' has no exported member 'default'.
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
//// [tests/cases/compiler/reexportMissingDefault1.ts] ////
|
||||
|
||||
//// [b.ts]
|
||||
export const b = null;
|
||||
|
||||
//// [a.ts]
|
||||
export { b } from "./b";
|
||||
export { default } from "./b";
|
||||
|
||||
|
||||
//// [b.js]
|
||||
"use strict";
|
||||
exports.__esModule = true;
|
||||
exports.b = null;
|
||||
//// [a.js]
|
||||
"use strict";
|
||||
exports.__esModule = true;
|
||||
var b_1 = require("./b");
|
||||
exports.b = b_1.b;
|
||||
var b_2 = require("./b");
|
||||
exports["default"] = b_2["default"];
|
||||
@@ -0,0 +1,11 @@
|
||||
=== tests/cases/compiler/b.ts ===
|
||||
export const b = null;
|
||||
>b : Symbol(b, Decl(b.ts, 0, 12))
|
||||
|
||||
=== tests/cases/compiler/a.ts ===
|
||||
export { b } from "./b";
|
||||
>b : Symbol(b, Decl(a.ts, 0, 8))
|
||||
|
||||
export { default } from "./b";
|
||||
>default : Symbol(default, Decl(a.ts, 1, 8))
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
=== tests/cases/compiler/b.ts ===
|
||||
export const b = null;
|
||||
>b : any
|
||||
>null : null
|
||||
|
||||
=== tests/cases/compiler/a.ts ===
|
||||
export { b } from "./b";
|
||||
>b : any
|
||||
|
||||
export { default } from "./b";
|
||||
>default : any
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
tests/cases/compiler/a.ts(2,10): error TS2305: Module '"./b"' has no exported member 'default'.
|
||||
|
||||
|
||||
==== tests/cases/compiler/b.ts (0 errors) ====
|
||||
export const b = null;
|
||||
|
||||
==== tests/cases/compiler/a.ts (1 errors) ====
|
||||
export { b } from "./b";
|
||||
export { default } from "./b";
|
||||
~~~~~~~
|
||||
!!! error TS2305: Module '"./b"' has no exported member 'default'.
|
||||
@@ -0,0 +1,20 @@
|
||||
//// [tests/cases/compiler/reexportMissingDefault2.ts] ////
|
||||
|
||||
//// [b.ts]
|
||||
export const b = null;
|
||||
|
||||
//// [a.ts]
|
||||
export { b } from "./b";
|
||||
export { default } from "./b";
|
||||
|
||||
//// [b.js]
|
||||
"use strict";
|
||||
exports.__esModule = true;
|
||||
exports.b = null;
|
||||
//// [a.js]
|
||||
"use strict";
|
||||
exports.__esModule = true;
|
||||
var b_1 = require("./b");
|
||||
exports.b = b_1.b;
|
||||
var b_2 = require("./b");
|
||||
exports["default"] = b_2["default"];
|
||||
@@ -0,0 +1,11 @@
|
||||
=== tests/cases/compiler/b.ts ===
|
||||
export const b = null;
|
||||
>b : Symbol(b, Decl(b.ts, 0, 12))
|
||||
|
||||
=== tests/cases/compiler/a.ts ===
|
||||
export { b } from "./b";
|
||||
>b : Symbol(b, Decl(a.ts, 0, 8))
|
||||
|
||||
export { default } from "./b";
|
||||
>default : Symbol(default, Decl(a.ts, 1, 8))
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
=== tests/cases/compiler/b.ts ===
|
||||
export const b = null;
|
||||
>b : any
|
||||
>null : null
|
||||
|
||||
=== tests/cases/compiler/a.ts ===
|
||||
export { b } from "./b";
|
||||
>b : any
|
||||
|
||||
export { default } from "./b";
|
||||
>default : any
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
tests/cases/compiler/a.ts(2,10): error TS2305: Module '"./b"' has no exported member 'default'.
|
||||
|
||||
|
||||
==== tests/cases/compiler/b.ts (0 errors) ====
|
||||
export const b = null;
|
||||
|
||||
==== tests/cases/compiler/a.ts (1 errors) ====
|
||||
export { b } from "./b";
|
||||
export { default as a } from "./b";
|
||||
~~~~~~~
|
||||
!!! error TS2305: Module '"./b"' has no exported member 'default'.
|
||||
@@ -0,0 +1,20 @@
|
||||
//// [tests/cases/compiler/reexportMissingDefault3.ts] ////
|
||||
|
||||
//// [b.ts]
|
||||
export const b = null;
|
||||
|
||||
//// [a.ts]
|
||||
export { b } from "./b";
|
||||
export { default as a } from "./b";
|
||||
|
||||
//// [b.js]
|
||||
"use strict";
|
||||
exports.__esModule = true;
|
||||
exports.b = null;
|
||||
//// [a.js]
|
||||
"use strict";
|
||||
exports.__esModule = true;
|
||||
var b_1 = require("./b");
|
||||
exports.b = b_1.b;
|
||||
var b_2 = require("./b");
|
||||
exports.a = b_2["default"];
|
||||
@@ -0,0 +1,11 @@
|
||||
=== tests/cases/compiler/b.ts ===
|
||||
export const b = null;
|
||||
>b : Symbol(b, Decl(b.ts, 0, 12))
|
||||
|
||||
=== tests/cases/compiler/a.ts ===
|
||||
export { b } from "./b";
|
||||
>b : Symbol(b, Decl(a.ts, 0, 8))
|
||||
|
||||
export { default as a } from "./b";
|
||||
>a : Symbol(a, Decl(a.ts, 1, 8))
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
=== tests/cases/compiler/b.ts ===
|
||||
export const b = null;
|
||||
>b : any
|
||||
>null : null
|
||||
|
||||
=== tests/cases/compiler/a.ts ===
|
||||
export { b } from "./b";
|
||||
>b : any
|
||||
|
||||
export { default as a } from "./b";
|
||||
>default : any
|
||||
>a : any
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
tests/cases/compiler/a.ts(2,10): error TS2305: Module '"./b"' has no exported member 'default'.
|
||||
|
||||
|
||||
==== tests/cases/compiler/b.d.ts (0 errors) ====
|
||||
declare var b: number;
|
||||
export { b };
|
||||
|
||||
==== tests/cases/compiler/a.ts (1 errors) ====
|
||||
export { b } from "./b";
|
||||
export { default } from "./b";
|
||||
~~~~~~~
|
||||
!!! error TS2305: Module '"./b"' has no exported member 'default'.
|
||||
@@ -0,0 +1,17 @@
|
||||
//// [tests/cases/compiler/reexportMissingDefault4.ts] ////
|
||||
|
||||
//// [b.d.ts]
|
||||
declare var b: number;
|
||||
export { b };
|
||||
|
||||
//// [a.ts]
|
||||
export { b } from "./b";
|
||||
export { default } from "./b";
|
||||
|
||||
//// [a.js]
|
||||
"use strict";
|
||||
exports.__esModule = true;
|
||||
var b_1 = require("./b");
|
||||
exports.b = b_1.b;
|
||||
var b_2 = require("./b");
|
||||
exports["default"] = b_2["default"];
|
||||
@@ -0,0 +1,14 @@
|
||||
=== tests/cases/compiler/b.d.ts ===
|
||||
declare var b: number;
|
||||
>b : Symbol(b, Decl(b.d.ts, 0, 11))
|
||||
|
||||
export { b };
|
||||
>b : Symbol(b, Decl(b.d.ts, 1, 8))
|
||||
|
||||
=== tests/cases/compiler/a.ts ===
|
||||
export { b } from "./b";
|
||||
>b : Symbol(b, Decl(a.ts, 0, 8))
|
||||
|
||||
export { default } from "./b";
|
||||
>default : Symbol(default, Decl(a.ts, 1, 8))
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
=== tests/cases/compiler/b.d.ts ===
|
||||
declare var b: number;
|
||||
>b : number
|
||||
|
||||
export { b };
|
||||
>b : number
|
||||
|
||||
=== tests/cases/compiler/a.ts ===
|
||||
export { b } from "./b";
|
||||
>b : number
|
||||
|
||||
export { default } from "./b";
|
||||
>default : any
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
//// [tests/cases/compiler/reexportMissingDefault5.ts] ////
|
||||
|
||||
//// [b.d.ts]
|
||||
declare var b: number;
|
||||
export { b };
|
||||
|
||||
//// [a.ts]
|
||||
export { b } from "./b";
|
||||
export { default as Foo } from "./b";
|
||||
|
||||
//// [a.js]
|
||||
System.register(["./b"], function (exports_1, context_1) {
|
||||
"use strict";
|
||||
var __moduleName = context_1 && context_1.id;
|
||||
return {
|
||||
setters: [
|
||||
function (b_1_1) {
|
||||
exports_1({
|
||||
"b": b_1_1["b"]
|
||||
});
|
||||
exports_1({
|
||||
"Foo": b_1_1["default"]
|
||||
});
|
||||
}
|
||||
],
|
||||
execute: function () {
|
||||
}
|
||||
};
|
||||
});
|
||||
@@ -0,0 +1,15 @@
|
||||
=== tests/cases/compiler/b.d.ts ===
|
||||
declare var b: number;
|
||||
>b : Symbol(b, Decl(b.d.ts, 0, 11))
|
||||
|
||||
export { b };
|
||||
>b : Symbol(b, Decl(b.d.ts, 1, 8))
|
||||
|
||||
=== tests/cases/compiler/a.ts ===
|
||||
export { b } from "./b";
|
||||
>b : Symbol(b, Decl(a.ts, 0, 8))
|
||||
|
||||
export { default as Foo } from "./b";
|
||||
>default : Symbol("tests/cases/compiler/b", Decl(b.d.ts, 0, 0))
|
||||
>Foo : Symbol(Foo, Decl(a.ts, 1, 8))
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
=== tests/cases/compiler/b.d.ts ===
|
||||
declare var b: number;
|
||||
>b : number
|
||||
|
||||
export { b };
|
||||
>b : number
|
||||
|
||||
=== tests/cases/compiler/a.ts ===
|
||||
export { b } from "./b";
|
||||
>b : number
|
||||
|
||||
export { default as Foo } from "./b";
|
||||
>default : typeof import("tests/cases/compiler/b")
|
||||
>Foo : typeof import("tests/cases/compiler/b")
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
tests/cases/compiler/a.ts(2,10): error TS2305: Module '"./b"' has no exported member 'default'.
|
||||
|
||||
|
||||
==== tests/cases/compiler/b.ts (0 errors) ====
|
||||
export const b = null;
|
||||
|
||||
==== tests/cases/compiler/a.ts (1 errors) ====
|
||||
export { b } from "./b";
|
||||
export { default } from "./b";
|
||||
~~~~~~~
|
||||
!!! error TS2305: Module '"./b"' has no exported member 'default'.
|
||||
@@ -0,0 +1,20 @@
|
||||
//// [tests/cases/compiler/reexportMissingDefault6.ts] ////
|
||||
|
||||
//// [b.ts]
|
||||
export const b = null;
|
||||
|
||||
//// [a.ts]
|
||||
export { b } from "./b";
|
||||
export { default } from "./b";
|
||||
|
||||
//// [b.js]
|
||||
"use strict";
|
||||
exports.__esModule = true;
|
||||
exports.b = null;
|
||||
//// [a.js]
|
||||
"use strict";
|
||||
exports.__esModule = true;
|
||||
var b_1 = require("./b");
|
||||
exports.b = b_1.b;
|
||||
var b_2 = require("./b");
|
||||
exports["default"] = b_2["default"];
|
||||
@@ -0,0 +1,11 @@
|
||||
=== tests/cases/compiler/b.ts ===
|
||||
export const b = null;
|
||||
>b : Symbol(b, Decl(b.ts, 0, 12))
|
||||
|
||||
=== tests/cases/compiler/a.ts ===
|
||||
export { b } from "./b";
|
||||
>b : Symbol(b, Decl(a.ts, 0, 8))
|
||||
|
||||
export { default } from "./b";
|
||||
>default : Symbol(default, Decl(a.ts, 1, 8))
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
=== tests/cases/compiler/b.ts ===
|
||||
export const b = null;
|
||||
>b : any
|
||||
>null : null
|
||||
|
||||
=== tests/cases/compiler/a.ts ===
|
||||
export { b } from "./b";
|
||||
>b : any
|
||||
|
||||
export { default } from "./b";
|
||||
>default : any
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
tests/cases/compiler/a.ts(2,10): error TS2305: Module '"./b"' has no exported member 'default'.
|
||||
|
||||
|
||||
==== tests/cases/compiler/b.ts (0 errors) ====
|
||||
export const b = null;
|
||||
|
||||
==== tests/cases/compiler/a.ts (1 errors) ====
|
||||
export { b } from "./b";
|
||||
export { default } from "./b";
|
||||
~~~~~~~
|
||||
!!! error TS2305: Module '"./b"' has no exported member 'default'.
|
||||
@@ -0,0 +1,14 @@
|
||||
//// [tests/cases/compiler/reexportMissingDefault7.ts] ////
|
||||
|
||||
//// [b.ts]
|
||||
export const b = null;
|
||||
|
||||
//// [a.ts]
|
||||
export { b } from "./b";
|
||||
export { default } from "./b";
|
||||
|
||||
//// [b.js]
|
||||
export var b = null;
|
||||
//// [a.js]
|
||||
export { b } from "./b";
|
||||
export { default } from "./b";
|
||||
@@ -0,0 +1,11 @@
|
||||
=== tests/cases/compiler/b.ts ===
|
||||
export const b = null;
|
||||
>b : Symbol(b, Decl(b.ts, 0, 12))
|
||||
|
||||
=== tests/cases/compiler/a.ts ===
|
||||
export { b } from "./b";
|
||||
>b : Symbol(b, Decl(a.ts, 0, 8))
|
||||
|
||||
export { default } from "./b";
|
||||
>default : Symbol(default, Decl(a.ts, 1, 8))
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
=== tests/cases/compiler/b.ts ===
|
||||
export const b = null;
|
||||
>b : any
|
||||
>null : null
|
||||
|
||||
=== tests/cases/compiler/a.ts ===
|
||||
export { b } from "./b";
|
||||
>b : any
|
||||
|
||||
export { default } from "./b";
|
||||
>default : any
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
//// [tests/cases/compiler/reexportMissingDefault8.ts] ////
|
||||
|
||||
//// [b.ts]
|
||||
const b = null;
|
||||
export = b;
|
||||
|
||||
//// [a.ts]
|
||||
export { default } from "./b";
|
||||
|
||||
//// [b.js]
|
||||
"use strict";
|
||||
var b = null;
|
||||
module.exports = b;
|
||||
//// [a.js]
|
||||
"use strict";
|
||||
exports.__esModule = true;
|
||||
var b_1 = require("./b");
|
||||
exports["default"] = b_1["default"];
|
||||
@@ -0,0 +1,11 @@
|
||||
=== tests/cases/compiler/b.ts ===
|
||||
const b = null;
|
||||
>b : Symbol(b, Decl(b.ts, 0, 5))
|
||||
|
||||
export = b;
|
||||
>b : Symbol(b, Decl(b.ts, 0, 5))
|
||||
|
||||
=== tests/cases/compiler/a.ts ===
|
||||
export { default } from "./b";
|
||||
>default : Symbol(default, Decl(a.ts, 0, 8))
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
=== tests/cases/compiler/b.ts ===
|
||||
const b = null;
|
||||
>b : any
|
||||
>null : null
|
||||
|
||||
export = b;
|
||||
>b : any
|
||||
|
||||
=== tests/cases/compiler/a.ts ===
|
||||
export { default } from "./b";
|
||||
>default : any
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
// @filename: b.ts
|
||||
export const b = null;
|
||||
|
||||
// @filename: a.ts
|
||||
export { b } from "./b";
|
||||
export { default } from "./b";
|
||||
@@ -0,0 +1,7 @@
|
||||
// @esModuleInterop: true
|
||||
// @filename: b.ts
|
||||
export const b = null;
|
||||
|
||||
// @filename: a.ts
|
||||
export { b } from "./b";
|
||||
export { default } from "./b";
|
||||
@@ -0,0 +1,7 @@
|
||||
// @allowSyntheticDefaultImports: true
|
||||
// @filename: b.ts
|
||||
export const b = null;
|
||||
|
||||
// @filename: a.ts
|
||||
export { b } from "./b";
|
||||
export { default } from "./b";
|
||||
@@ -0,0 +1,6 @@
|
||||
// @filename: b.ts
|
||||
export const b = null;
|
||||
|
||||
// @filename: a.ts
|
||||
export { b } from "./b";
|
||||
export { default as a } from "./b";
|
||||
@@ -0,0 +1,7 @@
|
||||
// @filename: b.d.ts
|
||||
declare var b: number;
|
||||
export { b };
|
||||
|
||||
// @filename: a.ts
|
||||
export { b } from "./b";
|
||||
export { default } from "./b";
|
||||
@@ -0,0 +1,8 @@
|
||||
// @module: system
|
||||
// @filename: b.d.ts
|
||||
declare var b: number;
|
||||
export { b };
|
||||
|
||||
// @filename: a.ts
|
||||
export { b } from "./b";
|
||||
export { default as Foo } from "./b";
|
||||
@@ -0,0 +1,7 @@
|
||||
// @module: commonjs
|
||||
// @filename: b.ts
|
||||
export const b = null;
|
||||
|
||||
// @filename: a.ts
|
||||
export { b } from "./b";
|
||||
export { default } from "./b";
|
||||
@@ -0,0 +1,7 @@
|
||||
// @module: ES2015
|
||||
// @filename: b.ts
|
||||
export const b = null;
|
||||
|
||||
// @filename: a.ts
|
||||
export { b } from "./b";
|
||||
export { default } from "./b";
|
||||
@@ -0,0 +1,7 @@
|
||||
// @esModuleInterop: true
|
||||
// @filename: b.ts
|
||||
const b = null;
|
||||
export = b;
|
||||
|
||||
// @filename: a.ts
|
||||
export { default } from "./b";
|
||||
Reference in New Issue
Block a user