Skip to content

Commit b6a0988

Browse files
authored
Merge pull request #30776 from andrewbranch/feature/10178
Add flag to allow access to UMD globals from modules
2 parents 7ccc89b + 786753d commit b6a0988

File tree

20 files changed

+100
-1
lines changed

20 files changed

+100
-1
lines changed

src/compiler/checker.ts

Lines changed: 1 addition & 1 deletion
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
}

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/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;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"compilerOptions": {
3+
"allowUmdGlobalAccess": true
4+
}
5+
}

tests/baselines/reference/tsConfig/Default initialized TSConfig/tsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
// "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */
4949
"esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
5050
// "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */
51+
// "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
5152

5253
/* Source Map Options */
5354
// "sourceRoot": "", /* Specify the location where debugger should locate TypeScript files instead of source locations. */

tests/baselines/reference/tsConfig/Initialized TSConfig with advanced options/tsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
// "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */
4949
"esModuleInterop": true, /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
5050
// "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */
51+
// "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
5152

5253
/* Source Map Options */
5354
// "sourceRoot": "", /* Specify the location where debugger should locate TypeScript files instead of source locations. */

tests/baselines/reference/tsConfig/Initialized TSConfig with boolean value compiler options/tsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
// "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */
4949
"esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
5050
// "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */
51+
// "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
5152

5253
/* Source Map Options */
5354
// "sourceRoot": "", /* Specify the location where debugger should locate TypeScript files instead of source locations. */

0 commit comments

Comments
 (0)