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

Commit 4031a44

Browse files
committed
Update dependencies
1 parent 7f02aee commit 4031a44

File tree

8 files changed

+103
-94
lines changed

8 files changed

+103
-94
lines changed

.babelrc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"presets": [
3+
["env", {
4+
"targets": {
5+
"node": 4
6+
}
7+
}]
8+
]
9+
}

.eslintignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
dist

.eslintrc renamed to .eslintrc.yml

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,9 @@
1-
---
21
root: true
32
extends: eslint:recommended
43

5-
#ecmaFeatures:
6-
# modules: true
7-
8-
env:
9-
# es6: true
10-
browser: true
11-
node: true
4+
parserOptions:
5+
ecmaVersion: 6
6+
sourceType: "module"
127

138
rules:
149
indent: [2, 2] # 2 spaces indentation
@@ -23,16 +18,16 @@ rules:
2318
dot-location: [2, "property"]
2419

2520
one-var: [2, "never"]
26-
# no-var: [2]
27-
# prefer-const: [2]
21+
no-var: [2]
22+
prefer-const: [2]
2823
no-bitwise: [2]
2924

3025
object-curly-spacing: [2, "never"]
3126
array-bracket-spacing: [2, "never"]
3227
computed-property-spacing: [2, "never"]
3328

3429
space-unary-ops: [2, {"words": true, "nonwords": false}]
35-
space-after-keywords: [2, "always"]
30+
keyword-spacing: [2, {"before": true, "after": true}]
3631
space-before-blocks: [2, "always"]
3732
space-before-function-paren: [2, "never"]
3833
space-in-parens: [2, "never"]

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1+
dist
12
node_modules
23
test/fixtures/*.actual.css

.travis.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,6 @@
1+
sudo: false
12
language: node_js
3+
node_js:
4+
- "latest"
5+
- "6"
6+
- "4"

index.js

Lines changed: 49 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,15 @@
1-
/**
2-
* Module dependencies.
3-
*/
4-
5-
var postcss = require("postcss")
6-
var balanced = require("balanced-match")
1+
import postcss from "postcss"
2+
import balanced from "balanced-match"
73

8-
/**
9-
* Constants.
10-
*/
11-
12-
var VAR_PROP_IDENTIFIER = "--"
13-
var VAR_FUNC_IDENTIFIER = "var"
4+
const VAR_PROP_IDENTIFIER = "--"
5+
const VAR_FUNC_IDENTIFIER = "var"
146
// matches `name[, fallback]`, captures "name" and "fallback"
15-
var RE_VAR = /([\w-]+)(?:\s*,\s*)?\s*(.*)?/
7+
const RE_VAR = /([\w-]+)(?:\s*,\s*)?\s*(.*)?/
168

179
/**
1810
* Resolve CSS variables.
1911
*
20-
* The second argument to the CSS variable function, var(name[, fallback]),
12+
* The second argument to the CSS variable function, var(name[, fallback]),
2113
* is used in the event that first argument cannot be resolved.
2214
*
2315
* @param {String} value May contain the CSS variable function
@@ -26,28 +18,27 @@ var RE_VAR = /([\w-]+)(?:\s*,\s*)?\s*(.*)?/
2618
* @param {Object} decl The declaration containing the rule
2719
* @return {String} A property value with all CSS variables substituted.
2820
*/
29-
3021
function resolveValue(value, variables, result, decl) {
31-
var results = []
22+
const results = []
3223

33-
var start = value.indexOf(VAR_FUNC_IDENTIFIER + "(")
24+
const start = value.indexOf(VAR_FUNC_IDENTIFIER + "(")
3425
if (start === -1) {
3526
return [value]
3627
}
3728

38-
var matches = balanced("(", ")", value.substring(start))
29+
const matches = balanced("(", ")", value.substring(start))
3930

4031
if (!matches) {
41-
throw decl.error("missing closing ')' in the value '" + value + "'")
32+
throw decl.error(`missing closing ')' in the value '${value}'`)
4233
}
4334

4435
if (matches.body === "") {
4536
throw decl.error("var() must contain a non-whitespace string")
4637
}
4738

4839
matches.body.replace(RE_VAR, function(_, name, fallback) {
49-
var variable = variables[name]
50-
var post
40+
const variable = variables[name]
41+
let post
5142
// undefined and without fallback, just keep original value
5243
if (!variable && !fallback) {
5344
result.warn(
@@ -75,8 +66,8 @@ function resolveValue(value, variables, result, decl) {
7566
post = matches.post
7667
? resolveValue(matches.post, variables, result, decl)
7768
: [""]
78-
fallback.forEach(function(fbValue) {
79-
post.forEach(function(afterValue) {
69+
fallback.forEach((fbValue) => {
70+
post.forEach((afterValue) => {
8071
results.push(value.slice(0, start) + fbValue + afterValue)
8172
})
8273
})
@@ -113,8 +104,8 @@ function resolveValue(value, variables, result, decl) {
113104
post = matches.post
114105
? resolveValue(matches.post, variables, result, decl)
115106
: [""]
116-
variable.value.forEach(function(replacementValue) {
117-
post.forEach(function(afterValue) {
107+
variable.value.forEach((replacementValue) => {
108+
post.forEach((afterValue) => {
118109
results.push(value.slice(0, start) + replacementValue + afterValue)
119110
})
120111
})
@@ -124,14 +115,14 @@ function resolveValue(value, variables, result, decl) {
124115
}
125116

126117
function prefixVariables(variables) {
127-
var prefixedVariables = {}
118+
const prefixedVariables = {}
128119

129120
if (!variables) {
130121
return prefixVariables
131122
}
132123

133-
Object.keys(variables).forEach(function(name) {
134-
var val = variables[name]
124+
Object.keys(variables).forEach((name) => {
125+
const val = variables[name]
135126
if (name.slice(0, 2) !== "--") {
136127
name = "--" + name
137128
}
@@ -144,43 +135,41 @@ function prefixVariables(variables) {
144135
/**
145136
* Module export.
146137
*/
147-
148-
module.exports = postcss.plugin("postcss-custom-properties", function(options) {
149-
options = options || {}
138+
export default postcss.plugin("postcss-custom-properties", (options = {}) => {
150139

151140
function setVariables(variables) {
152141
options.variables = prefixVariables(variables)
153142
}
154143

155144
function plugin(style, result) {
156-
var warnings = options.warnings === undefined ? true : options.warnings
157-
var variables = prefixVariables(options.variables)
158-
var strict = options.strict === undefined ? true : options.strict
159-
var appendVariables = options.appendVariables
160-
var preserve = options.preserve
161-
var map = {}
162-
var importantMap = {}
145+
const warnings = options.warnings === undefined ? true : options.warnings
146+
const variables = prefixVariables(options.variables)
147+
const strict = options.strict === undefined ? true : options.strict
148+
const appendVariables = options.appendVariables
149+
const preserve = options.preserve
150+
const map = {}
151+
const importantMap = {}
163152

164153
// define variables
165-
style.walkRules(function(rule) {
166-
var toRemove = []
154+
style.walkRules((rule) => {
155+
const toRemove = []
167156

168157
// only variables declared for `:root` are supported for now
169158
if (
170159
rule.selectors.length !== 1 ||
171160
rule.selectors[0] !== ":root" ||
172161
rule.parent.type !== "root"
173162
) {
174-
rule.each(function(decl) {
175-
var prop = decl.prop
163+
rule.each((decl) => {
164+
const prop = decl.prop
176165
if (
177166
warnings &&
178167
prop &&
179168
prop.indexOf(VAR_PROP_IDENTIFIER) === 0
180169
) {
181170
result.warn(
182171
"Custom property ignored: not scoped to the top-level :root " +
183-
"element (" + rule.selectors + " { ... " + prop + ": ... })" +
172+
`element (${rule.selectors} { ... ${prop}: ... })` +
184173
(rule.parent.type !== "root" ? ", in " + rule.parent.type : ""),
185174
{node: decl}
186175
)
@@ -189,8 +178,8 @@ module.exports = postcss.plugin("postcss-custom-properties", function(options) {
189178
return
190179
}
191180

192-
rule.each(function(decl, index) {
193-
var prop = decl.prop
181+
rule.each((decl, index) => {
182+
const prop = decl.prop
194183
if (prop && prop.indexOf(VAR_PROP_IDENTIFIER) === 0) {
195184
if (!map[prop] || !importantMap[prop] || decl.important) {
196185
map[prop] = {
@@ -207,7 +196,7 @@ module.exports = postcss.plugin("postcss-custom-properties", function(options) {
207196

208197
// optionally remove `--*` properties from the rule
209198
if (!preserve) {
210-
for (var i = toRemove.length - 1; i >= 0; i--) {
199+
for (let i = toRemove.length - 1; i >= 0; i--) {
211200
rule.nodes.splice(toRemove[i], 1)
212201
}
213202

@@ -219,7 +208,7 @@ module.exports = postcss.plugin("postcss-custom-properties", function(options) {
219208
})
220209

221210
// apply js-defined custom properties
222-
Object.keys(variables).forEach(function(variable) {
211+
Object.keys(variables).forEach((variable) => {
223212
map[variable] = {
224213
value: variables[variable],
225214
deps: [],
@@ -229,8 +218,8 @@ module.exports = postcss.plugin("postcss-custom-properties", function(options) {
229218
})
230219

231220
if (preserve) {
232-
Object.keys(map).forEach(function(name) {
233-
var variable = map[name]
221+
Object.keys(map).forEach((name) => {
222+
const variable = map[name]
234223
if (!variable.resolved) {
235224
variable.value = resolveValue(variable.value, map, result)
236225
variable.resolved = true
@@ -239,20 +228,20 @@ module.exports = postcss.plugin("postcss-custom-properties", function(options) {
239228
}
240229

241230
// resolve variables
242-
style.walkDecls(function(decl) {
243-
var value = decl.value
231+
style.walkDecls((decl) => {
232+
const value = decl.value
244233

245234
// skip values that don’t contain variable functions
246235
if (!value || value.indexOf(VAR_FUNC_IDENTIFIER + "(") === -1) {
247236
return
248237
}
249238

250-
var resolved = resolveValue(value, map, result, decl)
239+
let resolved = resolveValue(value, map, result, decl)
251240
if (!strict) {
252241
resolved = [resolved.pop()]
253242
}
254-
resolved.forEach(function(resolvedValue) {
255-
var clone = decl.cloneBefore()
243+
resolved.forEach((resolvedValue) => {
244+
const clone = decl.cloneBefore()
256245
clone.value = resolvedValue
257246
})
258247

@@ -262,19 +251,19 @@ module.exports = postcss.plugin("postcss-custom-properties", function(options) {
262251
})
263252

264253
if (preserve && appendVariables) {
265-
var names = Object.keys(map)
254+
const names = Object.keys(map)
266255
if (names.length) {
267-
var container = postcss.rule({
256+
const container = postcss.rule({
268257
selector: ":root",
269258
raws: {semicolon: true},
270259
})
271-
names.forEach(function(name) {
272-
var variable = map[name]
273-
var val = variable.value
260+
names.forEach((name) => {
261+
const variable = map[name]
262+
let val = variable.value
274263
if (variable.resolved) {
275264
val = val[val.length - 1]
276265
}
277-
var decl = postcss.decl({
266+
const decl = postcss.decl({
278267
prop: name,
279268
value: val,
280269
})

package.json

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,28 @@
1313
"author": "Maxime Thirouin",
1414
"license": "MIT",
1515
"repository": "https://github.com/postcss/postcss-custom-properties.git",
16+
"main": "dist/index.js",
1617
"files": [
17-
"index.js"
18+
"dist"
1819
],
1920
"dependencies": {
2021
"balanced-match": "^0.4.2",
21-
"postcss": "^5.0.0"
22+
"postcss": "^6.0.1"
2223
},
2324
"devDependencies": {
24-
"eslint": "^1.0.0",
25+
"babel-cli": "^6.24.1",
26+
"babel-preset-env": "^1.4.0",
27+
"babel-register": "^6.24.1",
28+
"eslint": "^3.19.0",
2529
"npmpub": "^3.1.0",
26-
"tape": "^4.0.0"
30+
"tape": "^4.6.3"
2731
},
2832
"scripts": {
29-
"test": "eslint . && tape test",
33+
"lint": "eslint *.js index.js ./test/",
34+
"tape": "tape -r babel-register test/*.js",
35+
"test": "npm run lint && npm run babelify && npm run tape",
36+
"babelify": "babel index.js --out-dir dist",
37+
"prepublish": "npm run babelify",
3038
"release": "npmpub"
3139
}
3240
}

0 commit comments

Comments
 (0)