Skip to content
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

feat: allow global declarations in modules #302

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

crawford
Copy link

TypeScript allows declarations in the global namespace from within
ambient module declarations. This form is used in several of the
declaration files for Node.js (e.g. buffer.d.ts, console.d.ts).

TypeScript allows declarations in the global namespace from within
ambient module declarations. This form is used in several of the
declaration files for Node.js (e.g. buffer.d.ts, console.d.ts).
@amaanq
Copy link
Member

amaanq commented Jul 6, 2024

Hey, thanks for the PR! After taking a look at the TS handbook and AST output, I think a better name might be global_module, what do you think? Also, throw it under internal_module to group it a little more nicely, and rebase if you can, I just pushed some changes

@crawford
Copy link
Author

crawford commented Jul 8, 2024

@amaanq I agree, global_module makes more sense. And I'll rebase your changes. I want to make sure I understand your comment about internal_module though. How do you expect the following snippet to parse?

declare module "foo" {
  global {
  }
}

Like this?

...
      (statement_block
        (expression_statement
          (internal_module
            (identifier)
            (statement_block
...

Or like this?

...
      (statement_block
        (expression_statement
          (global_module
            (statement_block
...

I experimented with a few different options but I noticed ambiguity with the existing support for global namespace declarations. The following isn't understood to be a global module currently:

declare global {
}

It just parses as follows:

(program
  (ambient_declaration
    (statement_block)))

Is it going to cause downstream trouble if we change this to parse as something like this?

(program
  (ambient_declaration
    (global_module
      (statement_block))))

Ultimately, what I'm trying to do is identify objects defined in the global namespace so I can track them separately.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants