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

Commit

Permalink
4.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
MoOx committed Jun 17, 2015
1 parent 996d39a commit b843b93
Show file tree
Hide file tree
Showing 7 changed files with 131 additions and 210 deletions.
28 changes: 17 additions & 11 deletions .eslintrc
Expand Up @@ -7,20 +7,26 @@ env:
browser: true
node: true

# 0: off, 1: warning, 2: error
rules:
# semicolons are useless
semi: [2, "never"]

indent: [2, 2] # 2 spaces indentation
max-len: [2, 80, 4]
quotes: [2, "double"]
semi: [2, "never"]
no-multiple-empty-lines: [2, {"max": 1}]

# 2 spaces indentation
indent: [2, 2]

# trailing coma are cool for diff
brace-style: [2, "stroustrup"]
comma-dangle: [2, "always-multiline"]

# enforce comma at eol (never before)
comma-style: [2, "last"]
computed-property-spacing: [2, "never"]
dot-location: [2, "property"]

one-var: [2, "never"]
no-bitwise: [2]

valid-jsdoc: 2
object-shorthand: [2, "methods"]
space-after-keywords: [2, "always"]
space-before-blocks: [2, "always"]
space-before-function-paren: [2, "never"]
space-in-brackets: [2, "never"]
space-in-parens: [2, "never"]
spaced-line-comment: [2, "always"]
130 changes: 0 additions & 130 deletions .jscsrc

This file was deleted.

9 changes: 0 additions & 9 deletions .jshintrc

This file was deleted.

9 changes: 4 additions & 5 deletions CHANGELOG.md
@@ -1,9 +1,8 @@
# 4.0.0 - Unreleased
# 4.0.0 - 2015-06-17

- Changed: upgade to postcss ^4.1.x
- Changed: messages and exceptions are now using postcss API.
Messages are not outputted by default to console anymore.
# 3.3.0 - 2015-04-0
- Changed: messages and exceptions are now sent using postcss message API.

# 3.3.0 - 2015-04-08

- Added: `preserve` now support `"computed"` so only preserve resolved custom properties (see new option below)
- Added: `appendVariables` allows you (when `preserve` is truthy) to append your variables as custom properties
Expand Down
43 changes: 31 additions & 12 deletions index.js
Expand Up @@ -11,7 +11,8 @@ var balanced = require("balanced-match")

var VAR_PROP_IDENTIFIER = "--"
var VAR_FUNC_IDENTIFIER = "var"
var RE_VAR = /([\w-]+)(?:\s*,\s*)?(.*)?/ // matches `name[, fallback]`, captures "name" and "fallback"
// matches `name[, fallback]`, captures "name" and "fallback"
var RE_VAR = /([\w-]+)(?:\s*,\s*)?(.*)?/

/**
* Resolve CSS variables in a value
Expand All @@ -22,7 +23,8 @@ var RE_VAR = /([\w-]+)(?:\s*,\s*)?(.*)?/ // matches `name[, fallback]`, captures
*
* var(name[, fallback])
*
* @param {String} value A property value known to contain CSS variable functions
* @param {String} value A property value known to contain CSS variable
* functions
* @param {Object} variables A map of variable names and values
* @param {Object} source source object of the declaration containing the rule
* @return {String} A property value with all CSS variables substituted.
Expand Down Expand Up @@ -51,11 +53,19 @@ function resolveValue(value, variables, result, decl) {
var post
// undefined and without fallback, just keep original value
if (!variable && !fallback) {
result.warn("variable '" + name + "' is undefined and used without a fallback", {node: decl})
post = matches.post ? resolveValue(matches.post, variables, result, decl) : [""]
result.warn(
"variable '" + name + "' is undefined and used without a fallback",
{node: decl}
)
post = matches.post
? resolveValue(matches.post, variables, result, decl)
: [""]
// resolve the end of the expression
post.forEach(function(afterValue) {
results.push(value.slice(0, start) + VAR_FUNC_IDENTIFIER + "(" + name + ")" + afterValue)
results.push(
value.slice(0, start) +
VAR_FUNC_IDENTIFIER + "(" + name + ")" + afterValue
)
})
return
}
Expand All @@ -65,7 +75,9 @@ function resolveValue(value, variables, result, decl) {
// resolve fallback values
fallback = resolveValue(fallback, variables, result, decl)
// resolve the end of the expression before the rest
post = matches.post ? resolveValue(matches.post, variables, result, decl) : [""]
post = matches.post
? resolveValue(matches.post, variables, result, decl)
: [""]
fallback.forEach(function(fbValue) {
post.forEach(function(afterValue) {
results.push(value.slice(0, start) + fbValue + afterValue)
Expand Down Expand Up @@ -101,7 +113,9 @@ function resolveValue(value, variables, result, decl) {
return
}
// resolve the end of the expression
post = matches.post ? resolveValue(matches.post, variables, result, decl) : [""]
post = matches.post
? resolveValue(matches.post, variables, result, decl)
: [""]
variable.value.forEach(function(replacementValue) {
post.forEach(function(afterValue) {
results.push(value.slice(0, start) + replacementValue + afterValue)
Expand Down Expand Up @@ -140,14 +154,17 @@ module.exports = postcss.plugin("postcss-custom-properties", function(options) {
var toRemove = []

// only variables declared for `:root` are supported for now
if (rule.selectors.length !== 1 || rule.selectors[0] !== ":root" || rule.parent.type !== "root") {
if (
rule.selectors.length !== 1 ||
rule.selectors[0] !== ":root" ||
rule.parent.type !== "root"
) {
rule.each(function(decl) {
var prop = decl.prop
if (prop && prop.indexOf(VAR_PROP_IDENTIFIER) === 0) {
result.warn(
"Custom property ignored: not scoped to the top-level :root element (" +
rule.selectors +
" { ... " + prop + ": ... })" +
"Custom property ignored: not scoped to the top-level :root " +
"element (" + rule.selectors + " { ... " + prop + ": ... })" +
(rule.parent.type !== "root" ? ", in " + rule.parent.type : ""),
{node: decl}
)
Expand Down Expand Up @@ -238,7 +255,9 @@ module.exports = postcss.plugin("postcss-custom-properties", function(options) {
names.forEach(function(name) {
var variable = map[name]
var val = variable.value
if (variable.resolved) { val = val[val.length - 1] }
if (variable.resolved) {
val = val[val.length - 1]
}
var decl = postcss.decl({
prop: name,
value: val,
Expand Down
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -26,7 +26,7 @@
"postcss": "^4.1.4"
},
"devDependencies": {
"eslint": "^0.18.0",
"eslint": "^0.23.0",
"tape": "^4.0.0"
},
"scripts": {
Expand Down

0 comments on commit b843b93

Please sign in to comment.