Skip to content
This repository has been archived by the owner on Feb 18, 2022. It is now read-only.

Commit

Permalink
Added: strict option
Browse files Browse the repository at this point in the history
Close #14
  • Loading branch information
MoOx committed Apr 8, 2015
1 parent 480240c commit 03bbae7
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 1 deletion.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@ Checkout [tests](test) for more.

### Options

#### `strict` (default: `true`)

Per specifications, all fallbacks should be added since we can't verify if a
computed value is valid or not.
This option allows you to avoid adding too many fallback values in your CSS.

#### `preserve` (default: `false`)

Allows you to preserve custom properties & var() usage in output.
Expand Down
7 changes: 6 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ module.exports = function(options) {
delete variables[name]
}
})
var strict = options.strict === undefined ? true : options.strict
var appendVariables = options.appendVariables
var preserve = options.preserve
var map = {}
Expand Down Expand Up @@ -214,7 +215,11 @@ module.exports = function(options) {
}

helpers.try(function resolve() {
resolveValue(value, map, decl.source).forEach(function(resolvedValue) {
var resolved = resolveValue(value, map, decl.source)
if (!strict) {
resolved = [resolved.pop()]

This comment has been minimized.

Copy link
@hgl

hgl Apr 8, 2015

This still compounds specified value with fallback value while resolving the value. I can send a PR to completely bypass this step if you want.

This comment has been minimized.

Copy link
@MoOx

MoOx Apr 8, 2015

Author Contributor

Why not. :)

}
resolved.forEach(function(resolvedValue) {
var clone = decl.cloneBefore()
clone.value = resolvedValue
})
Expand Down
10 changes: 10 additions & 0 deletions test/fixtures/substitution-strict.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
:root {
--a: "a";
--b: var(--bUndef, bFallback);
}

div {
aProp: var(--a, aPropFallback);
bProp: var(--b, bPropFallback);
bProp: var(--cUndef, cPropFallback);
}
5 changes: 5 additions & 0 deletions test/fixtures/substitution-strict.expected.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
div {
aProp: "a";
bProp: bFallback;
bProp: cPropFallback;
}
8 changes: 8 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,3 +136,11 @@ test("append variables", function(t) {
})
t.end()
})

test("strict option", function(t) {
compareFixtures(t, "substitution-strict", {
strict: false,
})

t.end()
})

0 comments on commit 03bbae7

Please sign in to comment.