-
-
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
Prevent rollup removing syntax error in try catch. #1946
Comments
Admittedly, I was not expecting people to do that considering you can always do it safely this way: if (typeof undeclaredVariable === 'undefined') console.log('Some error message'); To be more precise, we do not track access errors for undefined globals yet as the expectation is that this would noticeably decrease tree-shaking quality. However we could change that at some point if there is demand (and possibly add a flag to ignore it). |
Because I need to get information from |
I tend to agree that this is a very rare pattern and @LvChengbin what information would you need from the |
@guybedford in this case I encountered, I want to get the file list in trace information in the |
Should implement an option to prevent removal of undeclared globals as per previous discussion: |
Generally there are two reasons for having undeclared globals:
The intentional case is demonstrated above. In the second case Rollup will obscure the problem. Consider: $ cat e.js
if (v) {}
const v = 1;
console.log("success?"); Expected:
Actual:
At the very least a warning would be useful. |
When we can detect TDZ the above may make sense, but for now it seems like we're at a sensible compromise in terms of functionality. |
So there's an acknowledgement of an unaddressed issue with undeclared globals (with or without |
@kzc I don't see a way we can reasonably warn in these cases? TDZ seems unrelated to this issue, but we can certainly provide TDZ warnings along with the feature in future. But tracking TDZ warnings in this issue would likely not get picked up when that development happens unless it was its own explicit issue. |
I may have hijacked this issue with a related problem. It seems that the unknown globals issue has not been addressed by Rollup, nor is it represented in an open issue: |
The thing is all globals are unknown... so in theory If that is the suggestion then certainly let's reopen to alter that, but I'm not sure it makes sense for Rollup? |
Not all. We're talking about undeclared not-well-known globals.
Yes, that's my suggestion. Or at least have Rollup issue a warning.
It would be useful to me and other Rollup users in my opinion, particularly to those of use who never run linters. |
I think there are two different things at play here. TDZ errors are definitely very hard to catch for rollup in its current form but for globals, the prudent approach could be to track access to these variables as if it were a side-effect. One way of handling this without crippling tree-shaking could be to track global definitions and only treat access as a side-effect if there is no definition. This should help with the missing linter 😉. Would like to keep this open to track this (or move it to a new issue) |
Hey folks. This is a saved-form message, but rest assured we mean every word. The Rollup team is attempting to clean up the Issues backlog in the hopes that the active and still-needed, still-relevant issues bubble up to the surface. With that, we're closing issues that have been open for an eon or two, and have gone stale like pirate hard-tack without activity. We really appreciate the folks have taken the time to open and comment on this issue. Please don't confuse this closure with us not caring or dismissing your issue, feature request, discussion, or report. The issue will still be here, just in a closed state. If the issue pertains to a bug, please re-test for the bug on the latest version of Rollup and if present, please tag @shellscape and request a re-open, and we'll be happy to oblige. |
Actually this is fixed now anyway via the default try-catch deoptimization. |
For some reasons, I need to create some error and catch the error message, and I have my code like this:
After I compiled the code with
rollup
, the[undeclared-variable]
was removed byrollup
, and I got the result:I know I can use
throw new Error()
instead, but is there any way to preventrollup
removing the code, or just ignore the line?The text was updated successfully, but these errors were encountered: