-
Notifications
You must be signed in to change notification settings - Fork 16
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
Erroring on module
namespaces
#168
Comments
Sgtm, I wish there was a TS flag that excluded |
Thanks, Marco. I agree. SWC feature request is here: swc-project/swc#10017 |
nodejs/amaro#168 Signed-off-by: Ashley Claymore <[email protected]>
It seems like there's already a pre-pass in the Node side to detect illegal syntax (e.g. From the TypeScript side, we're in general agreement that it'd be best in the long term to not support TL;DR TypeScript also supports this change |
## Context microsoft/TypeScript#51825 nodejs/amaro#168 ## Description This PR is a *breaking change*. Continuing on from #32 but instead of allowing _more_ `ModuleDeclaration` AST nodes, this PR removes support for erasing namespace declarations that use the deprecated `module` keyword. ### Still erased (no error emitted) ```ts declare namespace N1 {} namespace N2 {} declare global {} declare module "./path" {} ``` ### No longer erased (triggers `onError` callback) ```ts declare module M1 {} module M2 {} ``` --------- Signed-off-by: Ashley Claymore <[email protected]> Co-authored-by: Rob Palmer <[email protected]>
Recently
@swc/wasm-typescript
(as used by Amaro) added type-only namespace support to align with TypeScript 5.8's new--erasableTypesOnly
flag.That PR also introduced support for the legacy
module
keyword for namespaces which IMO did not seem desirable for Node. Themodule
keyword for namespaces was superseded by thenamespace
keyword ten years ago in TS 1.5. There are various efforts to reduce usage of the legacy keyword being coordinated in the TypeScript project, including Editor strike-through feedback in TS 5.6. Potentially themodule
keyword will be useful in a future JS proposal. Given Node is aiming for a safe default experience, we should be minimal and avoid the future syntax conflict risk.I checked with @RyanCavanaugh (TS Engineering Manager & author of
--erasableTypesOnly
) who confirmed he is highly supportive of Node preventing the use of themodule
keyword for namespaces and believes all modern code will be able to handle this easily. Specifically for Amaro this means:strip-types
andtransform-types
):module
namespaces should always error:module Foo {}
module
namespaces should always error:declare module Foo {}
declare module "specifier" {}
) are fine and should continue to be erased and not errorImplementation
SWC is the right place to efficiently solve this. My thinking is we should request a new SWC option such as
no_module_for_ts_namespace
with the above semantics. The error message would say something like:We learned that this will require an update to the SWC AST which currently does not preserve knowledge of whether the namespace originated via a
module
ornamespace
source keyword. So I'd like to check here that we are ok making the request to SWC.cc @nodejs/typescript
The text was updated successfully, but these errors were encountered: