-
-
Notifications
You must be signed in to change notification settings - Fork 68
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
test: "export const" in .ts module #36
Conversation
111302c
to
5c987c5
Compare
Looks like two bugs with one stone!
|
Hmm, looks like we'll need to prepend the removed comment pragmas post hoc.
|
Alright, the test is passing now! 🎉 With ca5ba31, any |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some coding style suggestions.
Plus, I would very much prefer to use the properties which are defined in the TS API instead of manually typing things.
I will most likely only look at those things tomorrow on my work machine.
src/index.ts
Outdated
@@ -56,6 +46,35 @@ const plugin: PluginImpl<{}> = () => { | |||
return { source, program }; | |||
} | |||
|
|||
// Parse a TypeScript module into an ESTree program. | |||
const references = new Set<string>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don’t really have a better idea right now, just keep in mind that introducing more global state makes it harder to fix watch mode (#35)
src/index.ts
Outdated
|
||
// Collect any reference directives | ||
const pragmas: PragmaMap = (input as any).pragmas; | ||
if (pragmas && pragmas.has("reference")) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
since you check this here, is your type declaration really correct? (nullability?)
Also, your manual type declaration plus the as any
cast suggests that this is not officially documented TS API?
A quick check with https://astexplorer.net/#/gist/577600e28bd89938dc16f5bf445980d4/0213bb7d7515552ab575dabaec61561145080b5d showed me that the sourceFile has a typeReferenceDirectives
array. Maybe using that would be a better idea?
(these is also libReferenceDirectives
)
That way, you can really re-create the tripleslash references manually.
Regarding the issue you opened for rollup
, I think it is guaranteed to remove those comments, right? So we will not end up with a case where we end up with duplicated comments, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice, I didn't see the typeReferenceDirectives
property before.
I think it is guaranteed to remove those comments, right? So we will not end up with a case where we end up with duplicated comments, right?
I don't think so. I see a preserved directive in the .d.ts
bundle of @react-spring/web
. 😕 Looks like we'll need a test case for that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Though, that might be because I'm using the renderChunk
hook to prepend the comment pragmas. There might be a better place to do that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like we'll need a test case for that.
yes, that was also my thought to test that comments that are attached to items are correctly preserved / removed. that pragma is kind of weird, according to astexplorer its attached to the export statement, but that does not really make sense IMO.
Co-Authored-By: Arpad Borsos <arpad.borsos@googlemail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice!
Thank you very much :-) |
This test fails with the following output: