-
Notifications
You must be signed in to change notification settings - Fork 7.5k
**For Review Only** Collect Named CSS Region Flows #4879
Changes from all commits
fb2335d
e10a0b1
941b8a5
e4ab107
47cced3
1e6b546
4954ffb
1186c2c
e5aad2c
9af20b7
e216b3a
c103ace
5bfa210
b0e66fe
bf62d59
a99566c
feb3097
dd76ce4
3227387
e215095
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,7 +22,7 @@ | |
| */ | ||
|
|
||
|
|
||
| /*jslint vars: true, plusplus: true, devel: true, nomen: true, indent: 4, maxerr: 50 */ | ||
| /*jslint vars: true, plusplus: true, devel: true, nomen: true, indent: 4, maxerr: 50, regexp: true */ | ||
| /*global define, $, CodeMirror, _parseRuleList: true */ | ||
|
|
||
| // JSLint Note: _parseRuleList() is cyclical dependency, not a global function. | ||
|
|
@@ -1115,10 +1115,62 @@ define(function (require, exports, module) { | |
| return _stripAtRules(selector); | ||
| } | ||
|
|
||
| // removes css comments from the content | ||
| function _removeComments(_content) { | ||
| return _content.replace(/\/\*(?:(?!\*\/)[\s\S])*\*\//g, ''); | ||
| } | ||
|
|
||
| // removes strings from the content | ||
| function _removeStrings(_content) { | ||
| return _content.replace(/[^\\]\"(.*)[^\\]\"|[^\\]\'(.*)[^\\]\'+/g, ''); | ||
| } | ||
|
|
||
| /** | ||
| * Reduces the style sheet by removing comments and strings | ||
| * so that the content can be parsed using a regular expression | ||
| * @param {!String} content to reduce | ||
| * @return {String} reduced content | ||
| */ | ||
| function reduceStyleSheetForRegExParsing(content) { | ||
| return _removeStrings(_removeComments(content)); | ||
| } | ||
|
|
||
| /** | ||
| * Extracts all named flow instances | ||
| * @param {!String} text to extract from | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here, should be lowercase. |
||
| * @return {?Array.<string>} array of unique flow names | ||
| */ | ||
| function extractAllNamedFlows(text) { | ||
| var namedFlowRegEx = /(?:flow\-(into|from)\:[ \t\n\r]*)([a-z0-9_\-]+)(?:[ \t\n\r]*;)/gi, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I use regexpal.com to build my regular expressions and test them and \s wasn't working there for some reason. I made the change in brackets and it did work so I committed the change. @RaymondLim This branch has been deleted and the pullreques is closed but I did address your JSDoc comments and the whitespace regex change in the pull request #4890 |
||
| result = [], | ||
| names = {}, | ||
| thisMatch; | ||
|
|
||
| // Reduce the content so that matches | ||
| // inside strings and comments are ignored | ||
| text = reduceStyleSheetForRegExParsing(text); | ||
|
|
||
| // Find the first match | ||
| thisMatch = namedFlowRegEx.exec(text); | ||
|
|
||
| // Iterate over the matches and add them to result | ||
| while (thisMatch) { | ||
| var thisName = thisMatch[2]; | ||
| if (!names.hasOwnProperty(thisName)) { | ||
| names[thisName] = result.push(thisName); | ||
| } | ||
| thisMatch = namedFlowRegEx.exec(text); | ||
| } | ||
|
|
||
| return result; | ||
| } | ||
|
|
||
| exports._findAllMatchingSelectorsInText = _findAllMatchingSelectorsInText; // For testing only | ||
| exports.findMatchingRules = findMatchingRules; | ||
| exports.extractAllSelectors = extractAllSelectors; | ||
| exports.extractAllNamedFlows = extractAllNamedFlows; | ||
| exports.findSelectorAtDocumentPos = findSelectorAtDocumentPos; | ||
| exports.reduceStyleSheetForRegExParsing = reduceStyleSheetForRegExParsing; | ||
|
|
||
| exports.SELECTOR = SELECTOR; | ||
| exports.PROP_NAME = PROP_NAME; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| /* basic tests */ | ||
| article.content { | ||
| flow-into: main; | ||
| } | ||
|
|
||
| section.layout > div { | ||
| flow-from: main; | ||
| } | ||
|
|
||
|
|
||
| #jeff.content { | ||
| flow-into: jeff; | ||
| } | ||
|
|
||
| #jeff.layout > div { | ||
| flow-from: jeff; | ||
| } | ||
|
|
||
| /* exclude matches inside comments tests */ | ||
|
|
||
| /* | ||
| p.content { | ||
| flow-into: carter; | ||
| } | ||
|
|
||
| p.layout > div { | ||
| flow-from: carter; | ||
| } | ||
| */ | ||
|
|
||
| /* exclude matches inside strings tests */ | ||
|
|
||
| div { | ||
| content: "/* p.content { flow-into: carter; } p.layout > div { flow-from: carter; } */"; | ||
| } | ||
|
|
||
|
|
||
| div { | ||
| content: "html.content { flow-into: dexter; } html.layout > div { flow-from: dexter; }"; | ||
| } | ||
|
|
||
|
|
||
| /* | ||
| div.content { | ||
| content: "flow-into: martin;"; | ||
| } | ||
|
|
||
| div.layout > div { | ||
| content: "flow-from: martin;"; | ||
| } | ||
| */ | ||
|
|
||
| /* multi-line property tests */ | ||
|
|
||
| #randy.content { | ||
| flow-into: | ||
| randy | ||
| ; | ||
| } | ||
|
|
||
| #randy.layout > div { | ||
| flow-from: randy; | ||
| } | ||
|
|
||
| /* test to exclude duplicates */ | ||
| #yin.content { | ||
| flow-into: jeff; | ||
| } | ||
|
|
||
| #yin.layout > div { | ||
| flow-from: jeff; | ||
| } | ||
|
|
||
| /* flow-from only tests */ | ||
| #raymond.layout > div { | ||
| flow-from: lim; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lowercase for all primitive types.