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

Commit 20458f8

Browse files
committed
Let "warnings" option silence all warnings.
1 parent 7f02aee commit 20458f8

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

index.js

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,16 @@ var VAR_FUNC_IDENTIFIER = "var"
1414
// matches `name[, fallback]`, captures "name" and "fallback"
1515
var RE_VAR = /([\w-]+)(?:\s*,\s*)?\s*(.*)?/
1616

17+
/**
18+
* Module variables
19+
*/
20+
21+
var warnings
22+
1723
/**
1824
* Resolve CSS variables.
1925
*
20-
* The second argument to the CSS variable function, var(name[, fallback]),
26+
* The second argument to the CSS variable function, var(name[, fallback]),
2127
* is used in the event that first argument cannot be resolved.
2228
*
2329
* @param {String} value May contain the CSS variable function
@@ -50,10 +56,12 @@ function resolveValue(value, variables, result, decl) {
5056
var post
5157
// undefined and without fallback, just keep original value
5258
if (!variable && !fallback) {
53-
result.warn(
54-
"variable '" + name + "' is undefined and used without a fallback",
55-
{node: decl}
56-
)
59+
if (warnings) {
60+
result.warn(
61+
"variable '" + name + "' is undefined and used without a fallback",
62+
{node: decl}
63+
)
64+
}
5765
post = matches.post
5866
? resolveValue(matches.post, variables, result, decl)
5967
: [""]
@@ -91,7 +99,9 @@ function resolveValue(value, variables, result, decl) {
9199
// circular reference encountered
92100
if (variable.deps.indexOf(name) !== -1) {
93101
if (!fallback) {
94-
result.warn("Circular variable reference: " + name, {node: decl})
102+
if (warnings) {
103+
result.warn("Circular variable reference: " + name, {node: decl})
104+
}
95105
variable.value = [variable.value]
96106
variable.circular = true
97107
}
@@ -153,14 +163,15 @@ module.exports = postcss.plugin("postcss-custom-properties", function(options) {
153163
}
154164

155165
function plugin(style, result) {
156-
var warnings = options.warnings === undefined ? true : options.warnings
157166
var variables = prefixVariables(options.variables)
158167
var strict = options.strict === undefined ? true : options.strict
159168
var appendVariables = options.appendVariables
160169
var preserve = options.preserve
161170
var map = {}
162171
var importantMap = {}
163172

173+
warnings = options.warnings === undefined ? true : options.warnings
174+
164175
// define variables
165176
style.walkRules(function(rule) {
166177
var toRemove = []

0 commit comments

Comments
 (0)