Skip to content
This repository has been archived by the owner on Sep 14, 2021. It is now read-only.

Do not replace "inherit" and "initial" in fallbacks #215

Merged
merged 2 commits into from
Sep 28, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions apply-shim.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion apply-shim.min.js.map

Large diffs are not rendered by default.

13 changes: 10 additions & 3 deletions src/apply-shim.js
Original file line number Diff line number Diff line change
Expand Up @@ -386,9 +386,10 @@ class ApplyShim {
* "parse" a mixin definition into a map of properties and values
* cssTextToMap('border: 2px solid black') -> ('border', '2px solid black')
* @param {string} text
* @param {boolean=} replaceInitialOrInherit
* @return {!Object<string, string>}
*/
_cssTextToMap(text) {
_cssTextToMap(text, replaceInitialOrInherit = false) {
let props = text.split(';');
let property, value;
let out = {};
Expand All @@ -400,7 +401,10 @@ class ApplyShim {
if (sp.length > 1) {
property = sp[0].trim();
// some properties may have ':' in the value, like data urls
value = this._replaceInitialOrInherit(property, sp.slice(1).join(':'));
value = sp.slice(1).join(':');
if (replaceInitialOrInherit) {
value = this._replaceInitialOrInherit(property, value);
}
out[property] = value;
}
}
Expand Down Expand Up @@ -445,7 +449,10 @@ class ApplyShim {
}
let mixinAsProperties = this._consumeCssProperties('' + valueMixin, rule);
let prefix = matchText.slice(0, matchText.indexOf('--'));
let mixinValues = this._cssTextToMap(mixinAsProperties);
// `initial` and `inherit` as properties in a map should be replaced because
// these keywords are eagerly evaluated when the mixin becomes CSS Custom Properties,
// and would set the variable value, rather than carry the keyword to the `var()` usage.
let mixinValues = this._cssTextToMap(mixinAsProperties, true);
let combinedProps = mixinValues;
let mixinEntry = this._map.get(propertyName);
let oldProps = mixinEntry && mixinEntry.properties;
Expand Down
15 changes: 15 additions & 0 deletions tests/apply-shim.html
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,14 @@
border: 1px dotted orange;
@apply --mixin;
}
span {
border: inherit;
@apply --mixin;
}
span {
border: initial;
@apply --mixin;
}
</style>
</template>

Expand Down Expand Up @@ -204,6 +212,13 @@
var application = ast.rules[1];
assert.match(application.cssText, /border:\s*var\(--mixin_-_border,\s*1px dotted orange\)/);
});

test('inherit and initial default values are preserved', function() {
var application = ast.rules[2];
assert.match(application.cssText, /border:\s*var\(--mixin_-_border,\s*inherit\)/);
application = ast.rules[3];
assert.match(application.cssText, /border:\s*var\(--mixin_-_border,\s*initial\)/);
});
});

suite('override', function() {
Expand Down
15 changes: 15 additions & 0 deletions tests/no-scopingshim/apply-shim.html
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,14 @@
border: 1px dotted orange;
@apply --mixin;
}
span {
border: inherit;
@apply --mixin;
}
span {
border: initial;
@apply --mixin;
}
</style>
</template>

Expand Down Expand Up @@ -184,6 +192,13 @@
var application = ast.rules[1];
assert.match(application.cssText, /border:\s*var\(--mixin_-_border,\s*1px dotted orange\)/);
});

test('inherit and initial default values are preserved', function () {
var application = ast.rules[2];
assert.match(application.cssText, /border:\s*var\(--mixin_-_border,\s*inherit\)/);
application = ast.rules[3];
assert.match(application.cssText, /border:\s*var\(--mixin_-_border,\s*initial\)/);
});
});

suite('override', function() {
Expand Down