-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
export declare
sometimes affects JS emit
#60932
Comments
FYI ESBuild consciously chose to match current tsc behavior. |
ESBuild only matches tsc when it comes to |
When this is imported by other modules the emit for them includes appropriate importing statements: @RyanCavanaugh could you clarify what the expected behavior here is? |
Looking at the emit again, I'm not super sure what the defect is actually supposed to be. For CJS we have exports.a = 2; which is a correct output; it's the same as if you wrote export let a: number = 3;
a = 2; which produces exports.a = 3;
exports.a = 2; so we're exactly corresponding to the second line For ESM we have a = 2; which is correct according to the "pretend that someone text-concated" interpretation of Absent a stronger argument, this is maybe just working as intended? |
I was going to ask "what does it mean in namespaces then, since we cannot just pretend to inject something in the middle of it" but then I realized that declaration merging allows marking bindings as exported: So even |
I'm happy to close this issue, with the resolution that the compiled output when there is a |
It's worth noting that the "inconsistency" you have observed here comes from live-binding and not from a variable/export declarations. That's why in the ESM version that assignment "isn't" transformed. If we assume the binding is magically there then |
π Search Terms
export declare js emit
π Version & Regression Information
β― Playground Link
https://www.typescriptlang.org/play/?module=1#code/KYDwDg9gTgLgBAE2AYwDYEMrDq490BccAdgK4C2ARsFANwBQ6cAvHAEwNA
π» Code
π Actual behavior
When compiled to JS, will that code export a variable named
a
? It depends!namespace
, yesπ Expected behavior
Compiling to ESM or to CJS/AMD should behave the same. Specifically, they should all have the ESM behavior (no
a
exported), sincedeclare
means "this statement is only to tell something to the type checker, it should not actually affect the emitted JS code".Maybe referencing locally something declared as
export declare
should be an error.Additional information about the issue
Babel (babel/babel#17038), SWC (swc-project/swc#9821), and OXC (https://playground.oxc.rs/#eNo9TjFuwzAM/IrA2UNToIuKrp37gC60QgcGJFIg5TSB4b+XiuNo0R15d7wVEkRgLGQVEwW2sP5y8Ee3KtrCmVJGpZCpBYyBlzKSfu4SDF/h5HiDAQTiCrpw/+zODW8Qmy40QJ65QZwwmxNLUunY2L2Mkg/WFNkm0bIPtgEqqpH2xKrk6Eo/XoXtmeaKnv1QOH75d0tDvZAfBrL3t9MHuCLJmS7UKzopM8/TfJiTcFPJ31n+uvlKOop50f3Qtv0D8iJmOg==) already have the behavior I'm proposing.
The text was updated successfully, but these errors were encountered: