Preserve export context of export statements #219
superguineapig
started this conversation in
Ideas
Replies: 1 comment 3 replies
-
This is an interesting proposition. So far Instead of handling this in the pre-processor, this would need to happen in post-processing, after rollup itself has done its magic and you end up with a final |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hi there! First, this is a very useful plugin so thanks!
Ok, so I've got a project that rolls-up the .d.ts files using this plugin. All good. However, I've got a peculiar situation where I'm performing additional post-processing on the output as part of my build toolchain. (part of a phased adoption of TS in a very large codebase).
The post-processing relies upon the use of explicit
export ...
andexport type ...
statements. (added way back in TS v3.8) It seems that rollup-plugin-dts outputs the more-common generalexport { ... }
form when collecting things-to-be-exported. That's totally reasonable and probably fits everyone's use-case but mine.An example of what currently happens:
input_file1.d.ts
The exports of
input_file1.d.ts
are collected, stripped, and consolidated into a single export like so:output_file1.d.ts
What I'd like to happen
Ideally, in my situation, I'd like to have the original (input file's) export context preserved in the output. I.e. Value-ish declarations are
export
ed, and Type-ish declarations areexport type
ed like so:(still using 'input_file1.d.ts')
output_file2.d.ts
This preserves the original exported context.
Implementation
I was taking a look through the code and at first glance, this behavior should be possible through modifications in the pre-processing algorithm
I was thinking maybe store a tuple or simple object in the
exportedNames
Set instead of just a string to also carry information about the original context:rollup-plugin-dts/src/transform/preprocess.ts
Lines 39 to 40 in 900367a
Perhaps something like this?
Then while walking the
sourceFile.statements
nodes:Then later during "Pass 2"
rollup-plugin-dts/src/transform/preprocess.ts
Lines 216 to 218 in 900367a
It would be possible to filter the
exportedNames
Set into multiple iterables for each kind of export statement;export { <value-ish> }
andexport type { <type-ish> }
Opt-in
Assuming it's possible to do this, it should also be possible to put this new output behavior behind a plugin config parameter that defaults to not doing this, to avoid breaking anyone's existing setup/assumptions/expectations of the output.
Something like
exportsWithContext: true
would do.Thoughts?
Like I said, my crazy setup requires that there be both
export { ... }
andexport type { ... }
present in '.d.ts' files to differentiate between values and types at a later stage of my build process.This seems like adding this output behavior could be a decent addition to the plugin since the semantics of using
export type
are fairly well-established by TS.However, I'm neither super familiar with TS nor the architecture of this plugin to confidently state whether or not implementing this behavior would be possible/challenging/far-reaching/etc. Thoughts are welcome from maintainers/contributors!
And, hey, thanks for reading this.
Beta Was this translation helpful? Give feedback.
All reactions