Merge pull request #30776 from andrewbranch/feature/10178

Add flag to allow access to UMD globals from modules
This commit is contained in:
Andrew Branch 2019-04-18 18:05:44 -07:00 committed by GitHub
commit b6a0988052
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
20 changed files with 100 additions and 1 deletions

View File

@ -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));
}
}
}

View File

@ -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
{

View File

@ -4946,5 +4946,9 @@
"Convert parameters to destructured object": {
"category": "Message",
"code": 95075
},
"Allow accessing UMD globals from modules.": {
"category": "Message",
"code": 95076
}
}

View File

@ -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

View File

@ -2492,6 +2492,7 @@ declare namespace ts {
interface CompilerOptions {
allowJs?: boolean;
allowSyntheticDefaultImports?: boolean;
allowUmdGlobalAccess?: boolean;
allowUnreachableCode?: boolean;
allowUnusedLabels?: boolean;
alwaysStrict?: boolean;

View File

@ -2492,6 +2492,7 @@ declare namespace ts {
interface CompilerOptions {
allowJs?: boolean;
allowSyntheticDefaultImports?: boolean;
allowUmdGlobalAccess?: boolean;
allowUnreachableCode?: boolean;
allowUnusedLabels?: boolean;
alwaysStrict?: boolean;

View File

@ -0,0 +1,5 @@
{
"compilerOptions": {
"allowUmdGlobalAccess": true
}
}

View File

@ -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. */

View File

@ -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. */

View File

@ -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. */

View File

@ -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. */

View File

@ -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. */

View File

@ -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. */

View File

@ -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. */

View File

@ -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. */

View File

@ -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. */

View 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

View 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))

View 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

View 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