-
Notifications
You must be signed in to change notification settings - Fork 61
Fixes #37 #48
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixes #37 #48
Changes from all commits
1a5289f
e5aa5cc
eb04398
65dafc0
412f565
7ae720a
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 | ||
---|---|---|---|---|
|
@@ -5,7 +5,30 @@ var gatherVariableDependencies = require('./gather-variable-dependencies'); | |||
var findNodeAncestorWithSelector = require('./find-node-ancestor-with-selector'); | ||||
var cloneSpliceParentOntoNodeWhen = require('./clone-splice-parent-onto-node-when'); | ||||
|
||||
|
||||
if (typeof Object.assign != 'function') { | ||||
Object.assign = function(target, varArgs) { // .length of function is 2 | ||||
'use strict'; | ||||
if (target == null) { // TypeError if undefined or null | ||||
throw new TypeError('Cannot convert undefined or null to object'); | ||||
} | ||||
|
||||
var to = Object(target); | ||||
|
||||
for (var index = 1; index < arguments.length; index++) { | ||||
var nextSource = arguments[index]; | ||||
|
||||
if (nextSource != null) { // Skip over if undefined or null | ||||
for (var nextKey in nextSource) { | ||||
// Avoid bugs when hasOwnProperty is shadowed | ||||
if (Object.prototype.hasOwnProperty.call(nextSource, nextKey)) { | ||||
to[nextKey] = nextSource[nextKey]; | ||||
} | ||||
} | ||||
} | ||||
} | ||||
return to; | ||||
}; | ||||
} | ||||
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. We already have postcss-css-variables/index.js Line 70 in ddb3b8b
|
||||
|
||||
// var() = var( <custom-property-name> [, <any-value> ]? ) | ||||
// matches `name[, fallback]`, captures "name" and "fallback" | ||||
|
@@ -61,8 +84,14 @@ var resolveValue = function(decl, map, /*optional*/ignorePseudoScope, /*internal | |||
} | ||||
}); | ||||
|
||||
var fallbackValue; | ||||
if(fallback) { | ||||
var cloneDecl = Object.assign({},decl,{value:fallback}); | ||||
fallbackValue = resolveValue(cloneDecl, map, false,true).value; | ||||
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. Let's space this out (sorry no eslint) var cloneDecl = Object.assign({}, decl, { value: fallback });
fallbackValue = resolveValue(cloneDecl, map, false, true).value; |
||||
} | ||||
|
||||
// Default to the calculatedInPlaceValue which might be a previous fallback, then try this declarations fallback | ||||
var replaceValue = (matchingVarDeclMapItem || {}).calculatedInPlaceValue || fallback; | ||||
var replaceValue = (matchingVarDeclMapItem || {}).calculatedInPlaceValue || fallbackValue; | ||||
// Otherwise if the dependency health is good(no circular or self references), dive deeper and resolve | ||||
if(matchingVarDeclMapItem !== undefined && !gatherVariableDependencies(variablesUsedInValue, map).hasCircularOrSelfReference) { | ||||
// Splice the declaration parent onto the matching entry | ||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
:root { | ||
--foo1: 150px; | ||
} | ||
|
||
.box-bar { | ||
width: var(--missing,calc(var(--foo1) + 100px)); | ||
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. Let's space it out |
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.box-bar { | ||
width: calc(150px + 100px); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
:root { | ||
--foo1: 100px; | ||
--foo2: 150px; | ||
} | ||
|
||
.box-bar { | ||
width: var(--missing, var(--missing, var(--foo1))); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.box-bar { | ||
width: 100px; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
:root { | ||
--foo-default: 100px; | ||
--foo-width: 150px; | ||
} | ||
|
||
.box-foo { | ||
width: var(--missing); | ||
} | ||
|
||
.box-bar { | ||
width: var(--missing, var(--foo-default)); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
.box-foo { | ||
width: undefined; | ||
} | ||
|
||
.box-bar { | ||
width: 100px; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,6 @@ | ||
:root { | ||
--foo-width: 150px; | ||
} | ||
|
||
.box-foo { | ||
width: var(--missing); | ||
} | ||
|
||
.box-bar { | ||
width: var(--missing, 30px); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,4 @@ | ||
.box-foo { | ||
width: undefined; | ||
} | ||
|
||
.box-bar { | ||
width: 30px; | ||
} | ||
} |
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.
Rebase this onto the current
master
and squash things down. This is already in the codebase