**For Review Only** Collect Named CSS Region Flows#4879
Conversation
There was a problem hiding this comment.
Don't we have to collect flow-from also?
You only need [a-z0-9_\-] since you have i flag used.
There was a problem hiding this comment.
I'm not sure about flow-from. Not too tough to add that but I'm not sure how the CSS hints will be used.
The flow-into is what "creates" the named flow. But I guess you may have flow-into in a different css and have several instances of "flow-from" that you've used and you want to remember that name.
There was a problem hiding this comment.
Yes, just replace " " with "\s*".
There was a problem hiding this comment.
Drive-by comment: removing comments first simplifies the regex to use to extract flow properties, but I don't think removing whitespace has any benefit. Actually, I think it would be faster to leave in the whitespace to reduce the amount of string rebuilding done by replace (and the amount of scanning would be equal in both cases). Maybe change this to a removeComments() function?
There was a problem hiding this comment.
well then the regex has to change to accommodate tabs, newlines, carriage returns, etc...
There was a problem hiding this comment.
Since we execute the regex twice, once to get the properties and again to extract the name -- i wonder if it's better to remove the whitespace or just execute the regex twice that excludes the whitespace
There was a problem hiding this comment.
You can use the regex exec() method to only extract 1 (flow property) match at a time, which returns an array where the name is already parsed out. You have to setup a loop to go through each hit, but there's only a single regex. There's only a single pass, so less need to remove whitespace beforehand.
|
@RaymondLim @redmunds all feedback have been addressed. Thanks @RaymondLim and @peterflynn for your input on flow-from -- tests were added and code was modified to handle flow-from as well. @RaymondLim, @redmunds Let me know when you're done with the review and I'll rebase |
|
Much cleaner! |
There was a problem hiding this comment.
Should these 3 functions become StringUtils APIs? #4885 could use the remove comments one.
There was a problem hiding this comment.
I think this pull request should get merged then @redmunds can refactor them into something reusable for #4885.
We should probably just expose a single export from CSSUtils (not StringUtils) for this to reducing the content for CSS parsers because it doesn't work for JavaScript or other languages. CSS doesn't have the // comment syntax whereas JS does.
Perhaps the exported name should be something like reduceStyleSheetForRegExParsing() because it removes strings as well as comments. It's generally not a good idea to remove strings but we want to avoid parsing matches in quoted strings so that's why it's here.
There was a problem hiding this comment.
That sounds good too. But since the APIs will stay in CSSUtils and they receive a string which might only be a single line, the names could be the same as now or get a bit shorter (like reduceForRegExParsing).
There was a problem hiding this comment.
Go ahead and refactor those regex/functions into CSSUtils, and then I'll update my code to use them.
There was a problem hiding this comment.
Note that while CSS does not support // style line comments, LESS does support them. I'm not sure about SASS or scss.
|
Rebased into a new pull -- closing |
This pull still needs to be squashed but it should be good to go.
Mostly curious about the regex being used and if there is any more efficient way to collect names.