plugin.js
1.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = plugin;
function plugin(targets, nodeTypes, detect) {
class Plugin {
constructor(result) {
this.nodes = [];
this.result = result;
this.targets = targets;
this.nodeTypes = nodeTypes;
}
push(node, metadata) {
node._stylehacks = Object.assign({}, metadata, {
message: `Bad ${metadata.identifier}: ${metadata.hack}`,
browsers: this.targets
});
this.nodes.push(node);
}
any(node) {
if (~this.nodeTypes.indexOf(node.type)) {
detect.apply(this, arguments);
return !!node._stylehacks;
}
return false;
}
detectAndResolve(...args) {
this.nodes = [];
detect.apply(this, args);
return this.resolve();
}
detectAndWarn(...args) {
this.nodes = [];
detect.apply(this, args);
return this.warn();
}
resolve() {
return this.nodes.forEach(node => node.remove());
}
warn() {
return this.nodes.forEach(node => {
const { message, browsers, identifier, hack } = node._stylehacks;
return node.warn(this.result, message, { browsers, identifier, hack });
});
}
}
return Plugin;
}
module.exports = exports["default"];