-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Expose parse function to plugins #1945
Expose parse function to plugins #1945
Conversation
This adds a parse method to the transform context.
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.
Very nice! Also love the test! Found one minor comment, otherwise this is good to go!
@@ -51,7 +51,7 @@ function generateChunkName (id: string, chunkNames: { [name: string ]: boolean } | |||
} | |||
|
|||
export default class Graph { | |||
acornOptions: any; | |||
acornOptions: acorn.Options; |
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.
👍
src/Module.ts
Outdated
onComment: (block: boolean, text: string, start: number, end: number) => | ||
module.comments.push({ block, text, start, end }), | ||
preserveParens: false | ||
module.comments.push({ block, text, start, end }) | ||
}, acornOptions)); |
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 think onComment
should actually be added last as we are relying internally on this not being overwritten.
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.
fixed in cd53741
Is there a way for this function to share the Rollup cache at all? Otherwise the internal parsing mechanism remains "privileged" in terms of providing this. |
@guybedford I tried to investigate this. Maybe you can help me to understand the question first. Are you referring to Depending on the answer I will probably have follow-up questions. 🙂 |
Ahh, I just saw your reference to this issue in #1371. So you are probably talking about b) the In this case my follow-up question is this: Right now the |
Oops, I guess the aforementioned order is irrelevant when you're talking about caching across builds in watch mode. But in this case the cached result will be returned before |
@KingHenne yes I'm referring to across builds. It sounds like you may be right in that it would only apply if a plugin for file x happens to parse file y's ast when file y has previously been transformed. Also not completely clear on how the cache layer works myself, just trying to work out the repercussions for future caching architectures of this change. |
Wouldn't it be better to expose the AST too? So there will be only one parsing... and plugins can work on it directly. |
@olstenlarck See discussion above. |
This is motivated by #1512 and basically implements what @Rich-Harris was suggesting a few weeks ago.
By exposing rollup's
parse
function to plugins (via thetransform
context) these plugins can use the same acorn configuration (including injected plugins) if they need to operate on an ast. The most prominent example for this is probablyrollup-plugin-commonjs
, as mentioned in #1512. I opened a PR there as well to switch to theparse
method of the transform context.