You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Useful in userscripts or more generally in cases where you don't want to close the entire webpage or pollute the console with should-be-ignored errors.
Feature Proposal
The closest you can currently get to aborting the current script is throwing an error, which is sub-optimal as it will emit an error event and log to the console.
Functions can end early by the use of the return keyword. When output.format is set to iife, the context already lives in a function and thus, the use of return will cleanly stop execution of the current script.
But top-level returns are blocked by Rollup with the error RollupError: Return statement is not allowed here.
Possible solutions (when IIFE):
allowing the use of top-level returns
aliasing process.exit() to return
aliasing a global exit() (window.exit()) to return
aliasing window.return() to return
The text was updated successfully, but these errors were encountered:
Plugins can already enable this for their own parsing https://rollupjs.org/plugin-development/#this-parse
However, the goal is to deprecate returning an AST from plugins, so this would not fix it. But we might consider exposing allowReturnOutsideFunction as a general option.
In the meantime, you could write a plugin that uses renderChunk to inject returns into the IIFE in the output.
Feature Use Case
Stopping the current script's execution.
Useful in userscripts or more generally in cases where you don't want to close the entire webpage or pollute the console with should-be-ignored errors.
Feature Proposal
The closest you can currently get to aborting the current script is throwing an error, which is sub-optimal as it will emit an error event and log to the console.
Functions can end early by the use of the return keyword. When output.format is set to iife, the context already lives in a function and thus, the use of return will cleanly stop execution of the current script.
But top-level returns are blocked by Rollup with the error
RollupError: Return statement is not allowed here
.Possible solutions (when IIFE):
process.exit()
toreturn
exit()
(window.exit()
) toreturn
window.return()
toreturn
The text was updated successfully, but these errors were encountered: