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

Let "warnings" option silence all warnings #67

Merged
merged 1 commit into from
Jun 27, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 18 additions & 7 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ const VAR_FUNC_IDENTIFIER = "var"
// matches `name[, fallback]`, captures "name" and "fallback"
const RE_VAR = /([\w-]+)(?:\s*,\s*)?\s*(.*)?/

/**
* Module variables
*/

let globalWarnings

/**
* Resolve CSS variables.
*
Expand Down Expand Up @@ -41,10 +47,12 @@ function resolveValue(value, variables, result, decl) {
let 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}
)
if (globalWarnings) {
result.warn(
"variable '" + name + "' is undefined and used without a fallback",
{node: decl}
)
}
post = matches.post
? resolveValue(matches.post, variables, result, decl)
: [""]
Expand Down Expand Up @@ -82,7 +90,9 @@ function resolveValue(value, variables, result, decl) {
// circular reference encountered
if (variable.deps.indexOf(name) !== -1) {
if (!fallback) {
result.warn("Circular variable reference: " + name, {node: decl})
if (globalWarnings) {
result.warn("Circular variable reference: " + name, {node: decl})
}
variable.value = [variable.value]
variable.circular = true
}
Expand Down Expand Up @@ -142,14 +152,15 @@ export default postcss.plugin("postcss-custom-properties", (options = {}) => {
}

function plugin(style, result) {
const warnings = options.warnings === undefined ? true : options.warnings
const variables = prefixVariables(options.variables)
const strict = options.strict === undefined ? true : options.strict
const appendVariables = options.appendVariables
const preserve = options.preserve
const map = {}
const importantMap = {}

globalWarnings = options.warnings === undefined ? true : options.warnings

// define variables
style.walkRules((rule) => {
const toRemove = []
Expand All @@ -163,7 +174,7 @@ export default postcss.plugin("postcss-custom-properties", (options = {}) => {
rule.each((decl) => {
const prop = decl.prop
if (
warnings &&
globalWarnings &&
prop &&
prop.indexOf(VAR_PROP_IDENTIFIER) === 0
) {
Expand Down