Skip to content

Commit

Permalink
Fix parsing of parenthesis in default of variable declaration
Browse files Browse the repository at this point in the history
  • Loading branch information
TimvdLippe committed Feb 10, 2016
1 parent 4411031 commit 926d0e5
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
13 changes: 7 additions & 6 deletions src/lib/style-properties.html
Original file line number Diff line number Diff line change
Expand Up @@ -160,12 +160,13 @@
if (m) {
p = this.valueForProperty(props[m[1]], props);
} else {
var pp = p.split(':');
if (pp[1]) {
pp[1] = pp[1].trim();
pp[1] = this.valueForProperty(pp[1], props) || pp[1];
var colon = p.indexOf(':');
if (colon !== -1) {
var pp = p.substring(colon);
pp = pp.trim();
pp = this.valueForProperty(pp, props) || pp;
p = p.substring(0, colon) + pp;
}
p = pp.join(':');
}
parts[i] = (p && p.lastIndexOf(';') === p.length - 1) ?
// strip trailing ;
Expand Down Expand Up @@ -449,7 +450,7 @@
// var(--a, --b)
// var(--a, fallback-literal)
// var(--a, fallback-literal(with-one-nested-parentheses))
VAR_MATCH: /(^|\W+)var\([\s]*([^,)]*)[\s]*,?[\s]*((?:[^,)]*)|(?:[^;]*\([^;)]*\)))[\s]*?\)/gi,
VAR_MATCH: /(^|\W+)var\([\s]*([^,)]*)[\s]*,?[\s]*((?:[^,()]*)|(?:[^;()]*\([^;)]*\)))[\s]*?\)/gi,
VAR_CAPTURE: /\([\s]*(--[^,\s)]*)(?:,[\s]*(--[^,\s)]*))?(?:\)|,)/gi,
ANIMATION_MATCH: /(animation\s*:)|(animation-name\s*:)/,
IS_VAR: /^--/,
Expand Down
13 changes: 11 additions & 2 deletions test/unit/styling-cross-scope-var.html
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,10 @@
}

#endTerm {border: var(--end-term)}

#parenthesis {
background-image: var(--foo-background-image, url(http://placehold.it/400x300));
}
</style>
<div id="me">x-scope</div>
<x-keyframes id="keyframes"></x-keyframes>
Expand Down Expand Up @@ -473,6 +477,7 @@
<x-dynamic id="dynamic"></x-dynamic>
<div id="wsTerm">new line var</div>
<div id="endTerm">end var</div>
<div id="parenthesis">parenthesis</div>
</template>
<script>
HTMLImports.whenReady(function() {
Expand Down Expand Up @@ -556,8 +561,8 @@
<script>
suite('scoped-styling-var', function() {

function assertComputed(element, value, pseudo) {
var name = 'border-top-width';
function assertComputed(element, value, pseudo, name) {
var name = name || 'border-top-width';
var computed = element.getComputedStyleValue && !pseudo ?
element.getComputedStyleValue(name) :
getComputedStyle(element, pseudo)[name];
Expand Down Expand Up @@ -794,6 +799,10 @@
assertComputed(styled.$.endTerm, '19px');
});

test('variable with parenthesis', function() {
assertComputed(styled.$.parenthesis, 'url("http://placehold.it/400x300")', false, 'background-image');
});

// skip for now, until #3326 is fixed
test.skip('custom style class overrides css variable', function() {
var d = document.createElement('x-variable-override');
Expand Down

0 comments on commit 926d0e5

Please sign in to comment.