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

Commit c371abe

Browse files
committed
Let "warnings" option silence all warnings.
1 parent 8e74957 commit c371abe

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
@@ -6,6 +6,12 @@ const VAR_FUNC_IDENTIFIER = "var"
66
// matches `name[, fallback]`, captures "name" and "fallback"
77
const RE_VAR = /([\w-]+)(?:\s*,\s*)?\s*(.*)?/
88

9+
/**
10+
* Module variables
11+
*/
12+
13+
let globalWarnings
14+
915
/**
1016
* Resolve CSS variables.
1117
*
@@ -41,10 +47,12 @@ function resolveValue(value, variables, result, decl) {
4147
let post
4248
// undefined and without fallback, just keep original value
4349
if (!variable && !fallback) {
44-
result.warn(
45-
"variable '" + name + "' is undefined and used without a fallback",
46-
{node: decl}
47-
)
50+
if (globalWarnings) {
51+
result.warn(
52+
"variable '" + name + "' is undefined and used without a fallback",
53+
{node: decl}
54+
)
55+
}
4856
post = matches.post
4957
? resolveValue(matches.post, variables, result, decl)
5058
: [""]
@@ -82,7 +90,9 @@ function resolveValue(value, variables, result, decl) {
8290
// circular reference encountered
8391
if (variable.deps.indexOf(name) !== -1) {
8492
if (!fallback) {
85-
result.warn("Circular variable reference: " + name, {node: decl})
93+
if (globalWarnings) {
94+
result.warn("Circular variable reference: " + name, {node: decl})
95+
}
8696
variable.value = [variable.value]
8797
variable.circular = true
8898
}
@@ -142,14 +152,15 @@ export default postcss.plugin("postcss-custom-properties", (options = {}) => {
142152
}
143153

144154
function plugin(style, result) {
145-
const warnings = options.warnings === undefined ? true : options.warnings
146155
const variables = prefixVariables(options.variables)
147156
const strict = options.strict === undefined ? true : options.strict
148157
const appendVariables = options.appendVariables
149158
const preserve = options.preserve
150159
const map = {}
151160
const importantMap = {}
152161

162+
globalWarnings = options.warnings === undefined ? true : options.warnings
163+
153164
// define variables
154165
style.walkRules((rule) => {
155166
const toRemove = []
@@ -163,7 +174,7 @@ export default postcss.plugin("postcss-custom-properties", (options = {}) => {
163174
rule.each((decl) => {
164175
const prop = decl.prop
165176
if (
166-
warnings &&
177+
globalWarnings &&
167178
prop &&
168179
prop.indexOf(VAR_PROP_IDENTIFIER) === 0
169180
) {

0 commit comments

Comments
 (0)