Skip to content

Commit a2aefd4

Browse files
committed
Merge branch 'master' into use-assignability-not-subtype-in-substitution-instantiation
2 parents 2c31e6c + 1a4c15f commit a2aefd4

File tree

30 files changed

+292
-6
lines changed

30 files changed

+292
-6
lines changed

src/compiler/checker.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1648,7 +1648,7 @@ namespace ts {
16481648
if (result && isInExternalModule && (meaning & SymbolFlags.Value) === SymbolFlags.Value && !(originalLocation!.flags & NodeFlags.JSDoc)) {
16491649
const merged = getMergedSymbol(result);
16501650
if (length(merged.declarations) && every(merged.declarations, d => isNamespaceExportDeclaration(d) || isSourceFile(d) && !!d.symbol.globalExports)) {
1651-
error(errorLocation!, Diagnostics._0_refers_to_a_UMD_global_but_the_current_file_is_a_module_Consider_adding_an_import_instead, unescapeLeadingUnderscores(name)); // TODO: GH#18217
1651+
errorOrSuggestion(!compilerOptions.allowUmdGlobalAccess, errorLocation!, Diagnostics._0_refers_to_a_UMD_global_but_the_current_file_is_a_module_Consider_adding_an_import_instead, unescapeLeadingUnderscores(name));
16521652
}
16531653
}
16541654
}
@@ -20443,7 +20443,7 @@ namespace ts {
2044320443

2044420444
function getArrayifiedType(type: Type) {
2044520445
if (forEachType(type, t => !(t.flags & (TypeFlags.Any | TypeFlags.Instantiable) || isArrayType(t) || isTupleType(t)))) {
20446-
return createArrayType(getIndexTypeOfType(type, IndexKind.Number) || errorType);
20446+
return createArrayType(getIndexedAccessType(type, numberType));
2044720447
}
2044820448
return type;
2044920449
}

src/compiler/commandLineParser.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -588,6 +588,13 @@ namespace ts {
588588
category: Diagnostics.Module_Resolution_Options,
589589
description: Diagnostics.Do_not_resolve_the_real_path_of_symlinks,
590590
},
591+
{
592+
name: "allowUmdGlobalAccess",
593+
type: "boolean",
594+
affectsSemanticDiagnostics: true,
595+
category: Diagnostics.Module_Resolution_Options,
596+
description: Diagnostics.Allow_accessing_UMD_globals_from_modules,
597+
},
591598

592599
// Source Maps
593600
{

src/compiler/diagnosticMessages.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4946,5 +4946,9 @@
49464946
"Convert parameters to destructured object": {
49474947
"category": "Message",
49484948
"code": 95075
4949+
},
4950+
"Allow accessing UMD globals from modules.": {
4951+
"category": "Message",
4952+
"code": 95076
49494953
}
49504954
}

src/compiler/transformers/declarations.ts

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ namespace ts {
6363
let enclosingDeclaration: Node;
6464
let necessaryTypeReferences: Map<true> | undefined;
6565
let lateMarkedStatements: LateVisibilityPaintedStatement[] | undefined;
66-
let lateStatementReplacementMap: Map<VisitResult<LateVisibilityPaintedStatement>>;
66+
let lateStatementReplacementMap: Map<VisitResult<LateVisibilityPaintedStatement | ExportAssignment>>;
6767
let suppressNewDiagnosticContexts: boolean;
6868
let exportedModulesFromDeclarationEmit: Symbol[] | undefined;
6969

@@ -701,12 +701,12 @@ namespace ts {
701701
}
702702
}
703703

704-
function isExternalModuleIndicator(result: LateVisibilityPaintedStatement) {
704+
function isExternalModuleIndicator(result: LateVisibilityPaintedStatement | ExportAssignment) {
705705
// Exported top-level member indicates moduleness
706706
return isAnyImportOrReExport(result) || isExportAssignment(result) || hasModifier(result, ModifierFlags.Export);
707707
}
708708

709-
function needsScopeMarker(result: LateVisibilityPaintedStatement) {
709+
function needsScopeMarker(result: LateVisibilityPaintedStatement | ExportAssignment) {
710710
return !isAnyImportOrReExport(result) && !isExportAssignment(result) && !hasModifier(result, ModifierFlags.Export) && !isAmbientModule(result);
711711
}
712712

@@ -1047,7 +1047,43 @@ namespace ts {
10471047
return createVariableStatement(/*modifiers*/ undefined, createVariableDeclarationList([varDecl]));
10481048
});
10491049
const namespaceDecl = createModuleDeclaration(/*decorators*/ undefined, ensureModifiers(input, isPrivate), input.name!, createModuleBlock(declarations), NodeFlags.Namespace);
1050-
return [clean, namespaceDecl];
1050+
1051+
if (!hasModifier(clean, ModifierFlags.ExportDefault)) {
1052+
return [clean, namespaceDecl];
1053+
}
1054+
1055+
const modifiers = createModifiersFromModifierFlags((getModifierFlags(clean) & ~ModifierFlags.ExportDefault) | ModifierFlags.Ambient);
1056+
const cleanDeclaration = updateFunctionDeclaration(
1057+
clean,
1058+
/*decorators*/ undefined,
1059+
modifiers,
1060+
/*asteriskToken*/ undefined,
1061+
clean.name,
1062+
clean.typeParameters,
1063+
clean.parameters,
1064+
clean.type,
1065+
/*body*/ undefined
1066+
);
1067+
1068+
const namespaceDeclaration = updateModuleDeclaration(
1069+
namespaceDecl,
1070+
/*decorators*/ undefined,
1071+
modifiers,
1072+
namespaceDecl.name,
1073+
namespaceDecl.body
1074+
);
1075+
1076+
const exportDefaultDeclaration = createExportAssignment(
1077+
/*decorators*/ undefined,
1078+
/*modifiers*/ undefined,
1079+
/*isExportEquals*/ false,
1080+
namespaceDecl.name
1081+
);
1082+
1083+
resultHasExternalModuleIndicator = true;
1084+
resultHasScopeMarker = true;
1085+
1086+
return [cleanDeclaration, namespaceDeclaration, exportDefaultDeclaration];
10511087
}
10521088
else {
10531089
return clean;

src/compiler/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4589,6 +4589,7 @@ namespace ts {
45894589
allowJs?: boolean;
45904590
/*@internal*/ allowNonTsExtensions?: boolean;
45914591
allowSyntheticDefaultImports?: boolean;
4592+
allowUmdGlobalAccess?: boolean;
45924593
allowUnreachableCode?: boolean;
45934594
allowUnusedLabels?: boolean;
45944595
alwaysStrict?: boolean; // Always combine with strict property

tests/baselines/reference/api/tsserverlibrary.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2492,6 +2492,7 @@ declare namespace ts {
24922492
interface CompilerOptions {
24932493
allowJs?: boolean;
24942494
allowSyntheticDefaultImports?: boolean;
2495+
allowUmdGlobalAccess?: boolean;
24952496
allowUnreachableCode?: boolean;
24962497
allowUnusedLabels?: boolean;
24972498
alwaysStrict?: boolean;

tests/baselines/reference/api/typescript.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2492,6 +2492,7 @@ declare namespace ts {
24922492
interface CompilerOptions {
24932493
allowJs?: boolean;
24942494
allowSyntheticDefaultImports?: boolean;
2495+
allowUmdGlobalAccess?: boolean;
24952496
allowUnreachableCode?: boolean;
24962497
allowUnusedLabels?: boolean;
24972498
alwaysStrict?: boolean;
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
//// [exportDefaultNamespace.ts]
2+
export default function someFunc() {
3+
return 'hello!';
4+
}
5+
6+
someFunc.someProp = 'yo';
7+
8+
9+
//// [exportDefaultNamespace.js]
10+
"use strict";
11+
exports.__esModule = true;
12+
function someFunc() {
13+
return 'hello!';
14+
}
15+
exports["default"] = someFunc;
16+
someFunc.someProp = 'yo';
17+
18+
19+
//// [exportDefaultNamespace.d.ts]
20+
declare function someFunc(): string;
21+
declare namespace someFunc {
22+
var someProp: string;
23+
}
24+
export default someFunc;
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
=== tests/cases/conformance/declarationEmit/exportDefaultNamespace.ts ===
2+
export default function someFunc() {
3+
>someFunc : Symbol(someFunc, Decl(exportDefaultNamespace.ts, 0, 0), Decl(exportDefaultNamespace.ts, 2, 1))
4+
5+
return 'hello!';
6+
}
7+
8+
someFunc.someProp = 'yo';
9+
>someFunc.someProp : Symbol(someFunc.someProp, Decl(exportDefaultNamespace.ts, 2, 1))
10+
>someFunc : Symbol(someFunc, Decl(exportDefaultNamespace.ts, 0, 0), Decl(exportDefaultNamespace.ts, 2, 1))
11+
>someProp : Symbol(someFunc.someProp, Decl(exportDefaultNamespace.ts, 2, 1))
12+
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
=== tests/cases/conformance/declarationEmit/exportDefaultNamespace.ts ===
2+
export default function someFunc() {
3+
>someFunc : typeof someFunc
4+
5+
return 'hello!';
6+
>'hello!' : "hello!"
7+
}
8+
9+
someFunc.someProp = 'yo';
10+
>someFunc.someProp = 'yo' : "yo"
11+
>someFunc.someProp : string
12+
>someFunc : typeof someFunc
13+
>someProp : string
14+
>'yo' : "yo"
15+

0 commit comments

Comments
 (0)