@@ -6,6 +6,12 @@ const VAR_FUNC_IDENTIFIER = "var"
6
6
// matches `name[, fallback]`, captures "name" and "fallback"
7
7
const RE_VAR = / ( [ \w - ] + ) (?: \s * , \s * ) ? \s * ( .* ) ? /
8
8
9
+ /**
10
+ * Module variables
11
+ */
12
+
13
+ let globalWarnings
14
+
9
15
/**
10
16
* Resolve CSS variables.
11
17
*
@@ -41,10 +47,12 @@ function resolveValue(value, variables, result, decl) {
41
47
let post
42
48
// undefined and without fallback, just keep original value
43
49
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
+ }
48
56
post = matches . post
49
57
? resolveValue ( matches . post , variables , result , decl )
50
58
: [ "" ]
@@ -82,7 +90,9 @@ function resolveValue(value, variables, result, decl) {
82
90
// circular reference encountered
83
91
if ( variable . deps . indexOf ( name ) !== - 1 ) {
84
92
if ( ! fallback ) {
85
- result . warn ( "Circular variable reference: " + name , { node : decl } )
93
+ if ( globalWarnings ) {
94
+ result . warn ( "Circular variable reference: " + name , { node : decl } )
95
+ }
86
96
variable . value = [ variable . value ]
87
97
variable . circular = true
88
98
}
@@ -142,14 +152,15 @@ export default postcss.plugin("postcss-custom-properties", (options = {}) => {
142
152
}
143
153
144
154
function plugin ( style , result ) {
145
- const warnings = options . warnings === undefined ? true : options . warnings
146
155
const variables = prefixVariables ( options . variables )
147
156
const strict = options . strict === undefined ? true : options . strict
148
157
const appendVariables = options . appendVariables
149
158
const preserve = options . preserve
150
159
const map = { }
151
160
const importantMap = { }
152
161
162
+ globalWarnings = options . warnings === undefined ? true : options . warnings
163
+
153
164
// define variables
154
165
style . walkRules ( ( rule ) => {
155
166
const toRemove = [ ]
@@ -163,7 +174,7 @@ export default postcss.plugin("postcss-custom-properties", (options = {}) => {
163
174
rule . each ( ( decl ) => {
164
175
const prop = decl . prop
165
176
if (
166
- warnings &&
177
+ globalWarnings &&
167
178
prop &&
168
179
prop . indexOf ( VAR_PROP_IDENTIFIER ) === 0
169
180
) {
0 commit comments