Skip to content

Correctly print global augmentations#18660

Merged
DanielRosenwasser merged 5 commits into
masterfrom
globalAugmentationPrinter
Sep 22, 2017
Merged

Correctly print global augmentations#18660
DanielRosenwasser merged 5 commits into
masterfrom
globalAugmentationPrinter

Conversation

@DanielRosenwasser
Copy link
Copy Markdown
Member

Fixes #18657

Comment thread src/compiler/emitter.ts Outdated
write(node.flags & NodeFlags.Namespace ? "namespace " : "module ");
if (node.flags & NodeFlags.GlobalAugmentation) {
if (!hasModifier(node, ModifierFlags.Ambient)) {
// Always emit a 'declare' keyword in case it wasn't provided by a factory function call.
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should just throw an error when factory functions get invalid data? What's the protocol for something like this @rbuckton ?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think throwing an error is better, or changing the type to require the declare keyword.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we do not do this in other places, why not just emit modifiers?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

declare isn't always legal, such as when meeting a global augmentation in a module augmentation:

// assuming there is a "foo" module...
declare module "foo" {
  global {
  }
}

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is a good point, and @rbuckton I didn't realize that was even legal.

Copy link
Copy Markdown
Member

@sandersn sandersn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with preventing construction of bad global augmentations in the first place.

@@ -0,0 +1 @@
declare global { } No newline at end of file
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why does this end up in a .js? I expected a .d.ts or something.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the printer does not care what it prints to. the transforms are the one that do.

Comment thread src/compiler/emitter.ts Outdated
write(node.flags & NodeFlags.Namespace ? "namespace " : "module ");
if (node.flags & NodeFlags.GlobalAugmentation) {
if (!hasModifier(node, ModifierFlags.Ambient)) {
// Always emit a 'declare' keyword in case it wasn't provided by a factory function call.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think throwing an error is better, or changing the type to require the declare keyword.

@DanielRosenwasser DanielRosenwasser merged commit 92b7dcf into master Sep 22, 2017
@DanielRosenwasser DanielRosenwasser deleted the globalAugmentationPrinter branch September 22, 2017 22:01
@microsoft microsoft locked and limited conversation to collaborators Jun 14, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants