Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Update commentRegExp for better sugared CommonJS syntax dependency parsing #1582
This is a combo fix for the issues described here:
It uses some of the same techniques described in those tickets, but combined and with tests and passing code validation requirements. The main changes to the regexp:
This does mean though that it will now falsely match on this sort of construct:
var something = 'something'// require('bad');
However, this sort of regexp based approach will always have edge cases, and for the case above, it seems unlikely to happen in the wild:
So the benefits on catching more true positives seem worth this tradeoff.
Note that this regexp is only used for dynamic loading when there is no dependency array passed in the define call. If the r.js optimizer is used, it finds dependencies via an AST so it would not have any false positives or negatives associated with this regexp, and is always an option if a workaround is needed. The r.js optimizer also writes out a dependency array in the define calls, so it avoids this regexp work at runtime when an optimized build is used.
However, since this is a long-standing regexp in the system, I will rev the release version with this change to 2.3.0 to indicate a feature change. alameda will also be updated to match.