Closed thlorenz closed 10 years ago
does tolerant change any other behavior other than script level returns?
LGTM as long as we understand any behavior changes.
Quoting from the docs:
tolerant: attempts to continue parsing when an error is encountered
So a more tolerant/stable parse is what we'd want right? All we are trying to do is find require
calls, not validate JavaScript.
@ariya will know more, but as far as I can tell, it fixes the problems that required a function wrapper in the past and yes, mostly that's related to script level returns.
This quote seems to imply that it will ignore all script errors. I guess that is reasonable for this module since it isn't actually interested in validating the JS. Tho maybe a script error could lead to improper detection of a require?
From what I understand, that's not how it works. It still has to understand the code.
In this example it finds a problem/violation and will now throw or just add it to errors array if tolerant: true
.
So all tolerant: true
does is turn off throwing on ECMA spec violations, but if you have totally invalid code where it may improperly detect requires, it'll still blow up.
@substack would really like to see this land since I don't wanna publish browserify-shim while still depending on a github fork. Is there anything I should change so you can pull this?
merged in 2.3.0
Awesome, thanks!
This PR is in two parts.
I put them separately if for whatever reason you have a problem with the 2nd one. The most important is the first commit. However the current implementation has incorrect location information for the first line which is a problem if you want to use detective in order to replace requires instead of just finding them.
tolerant: true
stops esprima from throwing and is a better solution IMO than wrapping the code inside a function.Note
0.6
currently fails on travis (certificate error) if you want I can change it to support0.8
and0.10
instead and add that to this PR.