-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Add flag to allow access to UMD globals from modules #30776
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
2ee93bf
6d1d680
11e4516
57b9e38
28b21df
6c06507
98cd89f
786753d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1635,7 +1635,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)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should this diagnostic change to additionally mention There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since this is There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd leave as-is. In general for errors we think are usually correct, we try not to mention commandline flags to disable the error, since people will often try disabling the error before even checking if their code works or not |
||
} | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"compilerOptions": { | ||
"allowUmdGlobalAccess": true | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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)) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// @module: commonjs | ||
andrewbranch marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// @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" /> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this a requirement in this file? Given the original issue #1078 is sooo convoluted, it may be well worth a bit of write-up how this new feature works. P.S. I have a feeling it may be extremely useful in some scenarios I am involved, but need a more defined behaviour/usage/spec to know for sure. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You're right, the original issue is a lot to absorb, but this “feature” is actually quite simple. All it does is suppress a particular error message. This one: The triple slash reference isn't related to this feature at all; it's related to the Does that clear things up, or do you have any additional specific questions? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks, all clear. It's awesome: from complex to trivial in a couple sentences. |
||
export const x = Foo; // OK in value position because allowUmdGlobalAccess: true |
Uh oh!
There was an error while loading. Please reload this page.