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.
This commit is contained in:
1 parent
d484431a9c
commit
bb453f7a17
1 file changed
+21
-8
+21
-8
@@ -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)
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user