Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
See #290 - reworks
border
overriding.
Why: * Border is a complex case where both `border` and all its components: `border-color`, `border-style`, and `border-width` are components. Also `border-(bottom|left|right|top)` are shorthands too. * this commit restores aggressive merging shorthand overriding right inside shorthand compacting code.
- Loading branch information
1 parent
e1d88d3
commit 04b4958
Showing
23 changed files
with
1,014 additions
and
165 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
var compactable = require('../compactable'); | ||
|
||
function findComponentIn(shorthand, longhand) { | ||
var comparator = nameComparator(longhand); | ||
|
||
return findInDirectComponents(shorthand, comparator) || findInSubComponents(shorthand, comparator); | ||
} | ||
|
||
function nameComparator(to) { | ||
return function (property) { | ||
return to.name === property.name; | ||
}; | ||
} | ||
|
||
function findInDirectComponents(shorthand, comparator) { | ||
return shorthand.components.filter(comparator)[0]; | ||
} | ||
|
||
function findInSubComponents(shorthand, comparator) { | ||
var shorthandComponent; | ||
var longhandMatch; | ||
var i, l; | ||
|
||
if (!compactable[shorthand.name].shorthandComponents) { | ||
return; | ||
} | ||
|
||
for (i = 0, l = shorthand.components.length; i < l; i++) { | ||
shorthandComponent = shorthand.components[i]; | ||
longhandMatch = findInDirectComponents(shorthandComponent, comparator); | ||
|
||
if (longhandMatch) { | ||
return longhandMatch; | ||
} | ||
} | ||
|
||
return; | ||
} | ||
|
||
module.exports = findComponentIn; |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
var compactable = require('../compactable'); | ||
|
||
function isComponentOf(property1, property2, shallow) { | ||
return isDirectComponentOf(property1, property2) || | ||
!shallow && !!compactable[property1.name].shorthandComponents && isSubComponentOf(property1, property2); | ||
} | ||
|
||
function isDirectComponentOf(property1, property2) { | ||
var descriptor = compactable[property1.name]; | ||
|
||
return 'components' in descriptor && descriptor.components.indexOf(property2.name) > -1; | ||
} | ||
|
||
function isSubComponentOf(property1, property2) { | ||
return property1 | ||
.components | ||
.some(function (component) { | ||
return isDirectComponentOf(component, property2); | ||
}); | ||
} | ||
|
||
module.exports = isComponentOf; |
This file contains 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
This file contains 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
9 changes: 9 additions & 0 deletions
9
lib/optimizer/level-2/compacting/overrides-non-component-shorthand.js
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
var compactable = require('../compactable'); | ||
|
||
function overridesNonComponentShorthand(property1, property2) { | ||
return property1.name in compactable && | ||
'overridesShorthands' in compactable[property1.name] && | ||
compactable[property1.name].overridesShorthands.indexOf(property2.name) > -1; | ||
} | ||
|
||
module.exports = overridesNonComponentShorthand; |
This file contains 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
This file contains 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
Oops, something went wrong.