From bb453f7a17f13bd4ca946c678b7d10e1480986b7 Mon Sep 17 00:00:00 2001 From: DualFroz Date: Mon, 5 Oct 2026 11:38:13 +0200 Subject: [PATCH] Look for ignore next warning comments only from warned nodes Instead of testing every comment in the stylesheet and marking the next node, the warning filter walks back from each warned node over the prefixed copies inserted before it and checks the comment there. --- lib/processor.js | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/lib/processor.js b/lib/processor.js index 50e37f8..91d5a6e 100644 --- a/lib/processor.js +++ b/lib/processor.js @@ -1,14 +1,34 @@ let parser = require('postcss-value-parser') let Value = require('./value') +let vendor = require('./vendor') let insertAreas = require('./hacks/grid-utils').insertAreas const OLD_LINEAR = /(^|[^-])linear-gradient\(\s*(top|left|right|bottom)/i const OLD_RADIAL = /(^|[^-])radial-gradient\(\s*\d+(\w*|%)\s+\d+(\w*|%)\s*,/i const IGNORE_NEXT = /(!\s*)?autoprefixer:\s*ignore\s+next(?!\s+warning)/i const IGNORE_NEXT_WARNING = /(!\s*)?autoprefixer:\s*ignore\s+next\s+warning/i +const PREFIXED_VALUE = /(^|[\s,(])-\w+-/ const GRID_REGEX = /(!\s*)?autoprefixer\s*grid:\s*(on|off|(no-)?autoplace)/i +/** + * Is the node right after an `ignore next warning` control comment? + * Prefixed copies inserted before the node are skipped on the way back. + */ +function hasIgnoreWarningComment(node) { + let prev = node.prev() + while ( + prev && + prev.type === 'decl' && + (vendor.prefix(prev.prop) || PREFIXED_VALUE.test(prev.value)) + ) { + prev = prev.prev() + } + return ( + !!prev && prev.type === 'comment' && IGNORE_NEXT_WARNING.test(prev.text) + ) +} + const SIZES = [ 'width', 'height', @@ -56,13 +76,6 @@ class Processor { * Add necessary prefixes */ add(css, result) { - // Mark nodes before prefixes are inserted between them and comments - css.walkComments(comment => { - if (IGNORE_NEXT_WARNING.test(comment.text) && comment.next()) { - comment.next()._autoprefixerIgnoreWarning = true - } - }) - // At-rules let resolution = this.prefixes.add['@resolution'] let keyframes = this.prefixes.add['@keyframes'] @@ -393,7 +406,7 @@ class Processor { i.type === 'warning' && i.plugin === 'autoprefixer' && i.node && - i.node._autoprefixerIgnoreWarning + hasIgnoreWarningComment(i.node) ) }) }