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

Ability to get if a nested namespace does not have a declare keyword #623

Closed
dsherret opened this issue Feb 4, 2020 · 5 comments
Closed

Comments

@dsherret
Copy link
Contributor

dsherret commented Feb 4, 2020

Describe the feature

A TsModuleDecl has declare: true when within a nested namespace.

Ok(TsModuleDecl {
    span: span!(start),
    declare: self.ctx().in_declare,
    id: TsModuleName::Ident(id),
    body: Some(body),
    global: false,
})

So this means there's no way to tell if there's a declare keyword on the nested namespace.

declare module "@dsherret/package" {
    namespace packageName {
    }
}

Would it be possible to change the parser to only have declare on nodes that have a declare keyword?

@kdy1
Copy link
Member

kdy1 commented Feb 4, 2020

@dsherret As declare is invalid in ambient context, all children of a declare module should not be declare.

declare module "@dsherret/package" {
    declare namespace packageName {
    }
}

Results in error

@dsherret
Copy link
Contributor Author

dsherret commented Feb 4, 2020

Yeah, I guess I could keep track of whether it's in a declare context or not.

@kdy1
Copy link
Member

kdy1 commented Feb 4, 2020

@dsherret I found a way to fix the issue. I'll fix it soon.

@dsherret
Copy link
Contributor Author

dsherret commented Feb 4, 2020

Sweet. Thanks! No rush!

Yeah, it seems like babel and typescript both don't mark those nodes as "declare". TypeScript does use some flags to say the node is in an ambient context though.

kdy1 added a commit to kdy1/swc that referenced this issue Feb 4, 2020
@kdy1 kdy1 closed this as completed Feb 4, 2020
@swc-bot
Copy link
Collaborator

swc-bot commented Oct 28, 2022

This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@swc-project swc-project locked as resolved and limited conversation to collaborators Oct 28, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

No branches or pull requests

3 participants