Fix __PURE__ annotation placement #1919
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Currently there are some arrow functions that have /#PURE/
annotation before function call to identify that that function call is
side effect free.
However since this project is built to es5 target, which doesn't have
arrow functions support, the code is then translated into regular
function that loos something like this:
However this makes some built tools (Vite (which uses Rollup under the
hood) in our case) unhappy, and build produces a lot of warnings about
that PURE annotation being in the wrong place.
Checking the Rollup docs [0], it seems that pure annotation should be
placed right before function invocation, so in this particular case
between
return
keyword and the actual function.So this simply changes arrow functions in question to have explicit
return keyword and annotation before the function call, which leaves no
interpretation to ts compiler, and makes our code build process
warning-free.
This also potentially fixes #1916
[0] https://rollupjs.org/configuration-options/#pure