mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-06-29 19:42:39 -05:00
Dont bind a local symbol for a default export without a name (#23152)
This commit is contained in:
@@ -288,10 +288,6 @@ namespace ts {
|
||||
}
|
||||
Debug.fail("Unknown binary declaration kind");
|
||||
break;
|
||||
|
||||
case SyntaxKind.FunctionDeclaration:
|
||||
case SyntaxKind.ClassDeclaration:
|
||||
return (hasModifier(node, ModifierFlags.Default) ? InternalSymbolName.Default : undefined);
|
||||
case SyntaxKind.JSDocFunctionType:
|
||||
return (isJSDocConstructSignature(node) ? InternalSymbolName.New : InternalSymbolName.Call);
|
||||
case SyntaxKind.Parameter:
|
||||
@@ -459,6 +455,9 @@ namespace ts {
|
||||
if (node.kind === SyntaxKind.JSDocTypedefTag) Debug.assert(isInJavaScriptFile(node)); // We shouldn't add symbols for JSDoc nodes if not in a JS file.
|
||||
const isJSDocTypedefInJSDocNamespace = isJSDocTypedefTag(node) && node.name && node.name.kind === SyntaxKind.Identifier && node.name.isInJSDocNamespace;
|
||||
if ((!isAmbientModule(node) && (hasExportModifier || container.flags & NodeFlags.ExportContext)) || isJSDocTypedefInJSDocNamespace) {
|
||||
if (hasModifier(node, ModifierFlags.Default) && !getDeclarationName(node)) {
|
||||
return declareSymbol(container.symbol.exports, container.symbol, node, symbolFlags, symbolExcludes); // No local symbol for an unnamed default!
|
||||
}
|
||||
const exportKind = symbolFlags & SymbolFlags.Value ? SymbolFlags.ExportValue : 0;
|
||||
const local = declareSymbol(container.locals, /*parent*/ undefined, node, exportKind, symbolExcludes);
|
||||
local.exportSymbol = declareSymbol(container.symbol.exports, container.symbol, node, symbolFlags, symbolExcludes);
|
||||
|
||||
@@ -1291,7 +1291,7 @@ namespace ts {
|
||||
}
|
||||
}
|
||||
|
||||
if (result = lookup(moduleExports, name, meaning & SymbolFlags.ModuleMember)) {
|
||||
if (name !== InternalSymbolName.Default && (result = lookup(moduleExports, name, meaning & SymbolFlags.ModuleMember))) {
|
||||
break loop;
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
tests/cases/compiler/a.ts(4,24): error TS2304: Cannot find name 'default'.
|
||||
tests/cases/compiler/b.ts(2,24): error TS2304: Cannot find name 'default'.
|
||||
|
||||
|
||||
==== tests/cases/compiler/a.ts (1 errors) ====
|
||||
export default function () {
|
||||
return true;
|
||||
}
|
||||
export type X = typeof default; // expect error
|
||||
~~~~~~~
|
||||
!!! error TS2304: Cannot find name 'default'.
|
||||
|
||||
==== tests/cases/compiler/b.ts (1 errors) ====
|
||||
export default { a: true }
|
||||
export type X = typeof default; // expect error
|
||||
~~~~~~~
|
||||
!!! error TS2304: Cannot find name 'default'.
|
||||
23
tests/baselines/reference/defaultIsNotVisibleInLocalScope.js
Normal file
23
tests/baselines/reference/defaultIsNotVisibleInLocalScope.js
Normal file
@@ -0,0 +1,23 @@
|
||||
//// [tests/cases/compiler/defaultIsNotVisibleInLocalScope.ts] ////
|
||||
|
||||
//// [a.ts]
|
||||
export default function () {
|
||||
return true;
|
||||
}
|
||||
export type X = typeof default; // expect error
|
||||
|
||||
//// [b.ts]
|
||||
export default { a: true }
|
||||
export type X = typeof default; // expect error
|
||||
|
||||
//// [a.js]
|
||||
"use strict";
|
||||
exports.__esModule = true;
|
||||
function default_1() {
|
||||
return true;
|
||||
}
|
||||
exports["default"] = default_1;
|
||||
//// [b.js]
|
||||
"use strict";
|
||||
exports.__esModule = true;
|
||||
exports["default"] = { a: true };
|
||||
@@ -0,0 +1,14 @@
|
||||
=== tests/cases/compiler/a.ts ===
|
||||
export default function () {
|
||||
return true;
|
||||
}
|
||||
export type X = typeof default; // expect error
|
||||
>X : Symbol(X, Decl(a.ts, 2, 1))
|
||||
|
||||
=== tests/cases/compiler/b.ts ===
|
||||
export default { a: true }
|
||||
>a : Symbol(a, Decl(b.ts, 0, 16))
|
||||
|
||||
export type X = typeof default; // expect error
|
||||
>X : Symbol(X, Decl(b.ts, 0, 26))
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
=== tests/cases/compiler/a.ts ===
|
||||
export default function () {
|
||||
return true;
|
||||
>true : true
|
||||
}
|
||||
export type X = typeof default; // expect error
|
||||
>X : any
|
||||
>default : any
|
||||
|
||||
=== tests/cases/compiler/b.ts ===
|
||||
export default { a: true }
|
||||
>{ a: true } : { a: boolean; }
|
||||
>a : boolean
|
||||
>true : true
|
||||
|
||||
export type X = typeof default; // expect error
|
||||
>X : any
|
||||
>default : any
|
||||
|
||||
9
tests/cases/compiler/defaultIsNotVisibleInLocalScope.ts
Normal file
9
tests/cases/compiler/defaultIsNotVisibleInLocalScope.ts
Normal file
@@ -0,0 +1,9 @@
|
||||
// @filename: a.ts
|
||||
export default function () {
|
||||
return true;
|
||||
}
|
||||
export type X = typeof default; // expect error
|
||||
|
||||
// @filename: b.ts
|
||||
export default { a: true }
|
||||
export type X = typeof default; // expect error
|
||||
Reference in New Issue
Block a user