Update commentRegExp for better sugared CommonJS syntax dependency parsing#1582
Merged
Conversation
Member
Author
|
Using 2.2.1 Milestone for now, but will convert all the 2.2.1 bugs to 2.3.0 before wrapping up the release. |
This was referenced Sep 4, 2016
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
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:
commentReplacefunction was updated to remove parameters that corresponded to the match groups removed.'"=in the "do not match if starts with those characters" part of the regexp. This allows matching better for protocol relative URLs, and for having an HTML attribute preceding the require('') call on the same line.This does mean though that it will now falsely match on this sort of construct:
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.