mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-12 04:17:34 -06:00
Merge pull request #30776 from andrewbranch/feature/10178
Add flag to allow access to UMD globals from modules
This commit is contained in:
commit
b6a0988052
@ -1648,7 +1648,7 @@ namespace ts {
|
||||
if (result && isInExternalModule && (meaning & SymbolFlags.Value) === SymbolFlags.Value && !(originalLocation!.flags & NodeFlags.JSDoc)) {
|
||||
const merged = getMergedSymbol(result);
|
||||
if (length(merged.declarations) && every(merged.declarations, d => isNamespaceExportDeclaration(d) || isSourceFile(d) && !!d.symbol.globalExports)) {
|
||||
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
|
||||
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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -588,6 +588,13 @@ namespace ts {
|
||||
category: Diagnostics.Module_Resolution_Options,
|
||||
description: Diagnostics.Do_not_resolve_the_real_path_of_symlinks,
|
||||
},
|
||||
{
|
||||
name: "allowUmdGlobalAccess",
|
||||
type: "boolean",
|
||||
affectsSemanticDiagnostics: true,
|
||||
category: Diagnostics.Module_Resolution_Options,
|
||||
description: Diagnostics.Allow_accessing_UMD_globals_from_modules,
|
||||
},
|
||||
|
||||
// Source Maps
|
||||
{
|
||||
|
||||
@ -4946,5 +4946,9 @@
|
||||
"Convert parameters to destructured object": {
|
||||
"category": "Message",
|
||||
"code": 95075
|
||||
},
|
||||
"Allow accessing UMD globals from modules.": {
|
||||
"category": "Message",
|
||||
"code": 95076
|
||||
}
|
||||
}
|
||||
|
||||
@ -4589,6 +4589,7 @@ namespace ts {
|
||||
allowJs?: boolean;
|
||||
/*@internal*/ allowNonTsExtensions?: boolean;
|
||||
allowSyntheticDefaultImports?: boolean;
|
||||
allowUmdGlobalAccess?: boolean;
|
||||
allowUnreachableCode?: boolean;
|
||||
allowUnusedLabels?: boolean;
|
||||
alwaysStrict?: boolean; // Always combine with strict property
|
||||
|
||||
@ -2492,6 +2492,7 @@ declare namespace ts {
|
||||
interface CompilerOptions {
|
||||
allowJs?: boolean;
|
||||
allowSyntheticDefaultImports?: boolean;
|
||||
allowUmdGlobalAccess?: boolean;
|
||||
allowUnreachableCode?: boolean;
|
||||
allowUnusedLabels?: boolean;
|
||||
alwaysStrict?: boolean;
|
||||
|
||||
@ -2492,6 +2492,7 @@ declare namespace ts {
|
||||
interface CompilerOptions {
|
||||
allowJs?: boolean;
|
||||
allowSyntheticDefaultImports?: boolean;
|
||||
allowUmdGlobalAccess?: boolean;
|
||||
allowUnreachableCode?: boolean;
|
||||
allowUnusedLabels?: boolean;
|
||||
alwaysStrict?: boolean;
|
||||
|
||||
@ -0,0 +1,5 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"allowUmdGlobalAccess": true
|
||||
}
|
||||
}
|
||||
@ -48,6 +48,7 @@
|
||||
// "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */
|
||||
"esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
|
||||
// "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */
|
||||
// "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
|
||||
|
||||
/* Source Map Options */
|
||||
// "sourceRoot": "", /* Specify the location where debugger should locate TypeScript files instead of source locations. */
|
||||
|
||||
@ -48,6 +48,7 @@
|
||||
// "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */
|
||||
"esModuleInterop": true, /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
|
||||
// "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */
|
||||
// "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
|
||||
|
||||
/* Source Map Options */
|
||||
// "sourceRoot": "", /* Specify the location where debugger should locate TypeScript files instead of source locations. */
|
||||
|
||||
@ -48,6 +48,7 @@
|
||||
// "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */
|
||||
"esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
|
||||
// "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */
|
||||
// "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
|
||||
|
||||
/* Source Map Options */
|
||||
// "sourceRoot": "", /* Specify the location where debugger should locate TypeScript files instead of source locations. */
|
||||
|
||||
@ -48,6 +48,7 @@
|
||||
// "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */
|
||||
"esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
|
||||
// "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */
|
||||
// "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
|
||||
|
||||
/* Source Map Options */
|
||||
// "sourceRoot": "", /* Specify the location where debugger should locate TypeScript files instead of source locations. */
|
||||
|
||||
@ -48,6 +48,7 @@
|
||||
// "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */
|
||||
"esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
|
||||
// "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */
|
||||
// "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
|
||||
|
||||
/* Source Map Options */
|
||||
// "sourceRoot": "", /* Specify the location where debugger should locate TypeScript files instead of source locations. */
|
||||
|
||||
@ -48,6 +48,7 @@
|
||||
// "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */
|
||||
"esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
|
||||
// "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */
|
||||
// "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
|
||||
|
||||
/* Source Map Options */
|
||||
// "sourceRoot": "", /* Specify the location where debugger should locate TypeScript files instead of source locations. */
|
||||
|
||||
@ -48,6 +48,7 @@
|
||||
// "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */
|
||||
"esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
|
||||
// "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */
|
||||
// "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
|
||||
|
||||
/* Source Map Options */
|
||||
// "sourceRoot": "", /* Specify the location where debugger should locate TypeScript files instead of source locations. */
|
||||
|
||||
@ -48,6 +48,7 @@
|
||||
// "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */
|
||||
"esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
|
||||
// "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */
|
||||
// "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
|
||||
|
||||
/* Source Map Options */
|
||||
// "sourceRoot": "", /* Specify the location where debugger should locate TypeScript files instead of source locations. */
|
||||
|
||||
@ -48,6 +48,7 @@
|
||||
// "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */
|
||||
"esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
|
||||
// "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */
|
||||
// "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
|
||||
|
||||
/* Source Map Options */
|
||||
// "sourceRoot": "", /* Specify the location where debugger should locate TypeScript files instead of source locations. */
|
||||
|
||||
19
tests/baselines/reference/umd9.js
Normal file
19
tests/baselines/reference/umd9.js
Normal file
@ -0,0 +1,19 @@
|
||||
//// [tests/cases/conformance/externalModules/umd9.ts] ////
|
||||
|
||||
//// [foo.d.ts]
|
||||
declare class Thing {
|
||||
foo(): number;
|
||||
}
|
||||
export = Thing;
|
||||
export as namespace Foo;
|
||||
|
||||
//// [a.ts]
|
||||
/// <reference path="foo.d.ts" />
|
||||
export const x = Foo; // OK in value position because allowUmdGlobalAccess: true
|
||||
|
||||
|
||||
//// [a.js]
|
||||
"use strict";
|
||||
exports.__esModule = true;
|
||||
/// <reference path="foo.d.ts" />
|
||||
exports.x = Foo; // OK in value position because allowUmdGlobalAccess: true
|
||||
19
tests/baselines/reference/umd9.symbols
Normal file
19
tests/baselines/reference/umd9.symbols
Normal file
@ -0,0 +1,19 @@
|
||||
=== tests/cases/conformance/externalModules/a.ts ===
|
||||
/// <reference path="foo.d.ts" />
|
||||
export const x = Foo; // OK in value position because allowUmdGlobalAccess: true
|
||||
>x : Symbol(x, Decl(a.ts, 1, 12))
|
||||
>Foo : Symbol(Foo, Decl(foo.d.ts, 3, 15))
|
||||
|
||||
=== tests/cases/conformance/externalModules/foo.d.ts ===
|
||||
declare class Thing {
|
||||
>Thing : Symbol(Thing, Decl(foo.d.ts, 0, 0))
|
||||
|
||||
foo(): number;
|
||||
>foo : Symbol(Thing.foo, Decl(foo.d.ts, 0, 21))
|
||||
}
|
||||
export = Thing;
|
||||
>Thing : Symbol(Thing, Decl(foo.d.ts, 0, 0))
|
||||
|
||||
export as namespace Foo;
|
||||
>Foo : Symbol(Foo, Decl(foo.d.ts, 3, 15))
|
||||
|
||||
19
tests/baselines/reference/umd9.types
Normal file
19
tests/baselines/reference/umd9.types
Normal file
@ -0,0 +1,19 @@
|
||||
=== tests/cases/conformance/externalModules/a.ts ===
|
||||
/// <reference path="foo.d.ts" />
|
||||
export const x = Foo; // OK in value position because allowUmdGlobalAccess: true
|
||||
>x : typeof Thing
|
||||
>Foo : typeof Thing
|
||||
|
||||
=== tests/cases/conformance/externalModules/foo.d.ts ===
|
||||
declare class Thing {
|
||||
>Thing : Thing
|
||||
|
||||
foo(): number;
|
||||
>foo : () => number
|
||||
}
|
||||
export = Thing;
|
||||
>Thing : Thing
|
||||
|
||||
export as namespace Foo;
|
||||
>Foo : typeof Thing
|
||||
|
||||
14
tests/cases/conformance/externalModules/umd9.ts
Normal file
14
tests/cases/conformance/externalModules/umd9.ts
Normal file
@ -0,0 +1,14 @@
|
||||
// @module: commonjs
|
||||
// @noImplicitReferences: true
|
||||
// @allowUmdGlobalAccess: true
|
||||
|
||||
// @filename: foo.d.ts
|
||||
declare class Thing {
|
||||
foo(): number;
|
||||
}
|
||||
export = Thing;
|
||||
export as namespace Foo;
|
||||
|
||||
// @filename: a.ts
|
||||
/// <reference path="foo.d.ts" />
|
||||
export const x = Foo; // OK in value position because allowUmdGlobalAccess: true
|
||||
Loading…
x
Reference in New Issue
Block a user