Last change
on this file since 76712b2 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago |
initial commit
|
-
Property mode
set to
100644
|
File size:
1.4 KB
|
Line | |
---|
1 | "use strict";
|
---|
2 |
|
---|
3 | Object.defineProperty(exports, "__esModule", {
|
---|
4 | value: true
|
---|
5 | });
|
---|
6 | exports.default = plugin;
|
---|
7 |
|
---|
8 | function plugin(targets, nodeTypes, detect) {
|
---|
9 | class Plugin {
|
---|
10 | constructor(result) {
|
---|
11 | this.nodes = [];
|
---|
12 | this.result = result;
|
---|
13 | this.targets = targets;
|
---|
14 | this.nodeTypes = nodeTypes;
|
---|
15 | }
|
---|
16 |
|
---|
17 | push(node, metadata) {
|
---|
18 | node._stylehacks = Object.assign({}, metadata, {
|
---|
19 | message: `Bad ${metadata.identifier}: ${metadata.hack}`,
|
---|
20 | browsers: this.targets
|
---|
21 | });
|
---|
22 | this.nodes.push(node);
|
---|
23 | }
|
---|
24 |
|
---|
25 | any(node) {
|
---|
26 | if (~this.nodeTypes.indexOf(node.type)) {
|
---|
27 | detect.apply(this, arguments);
|
---|
28 | return !!node._stylehacks;
|
---|
29 | }
|
---|
30 |
|
---|
31 | return false;
|
---|
32 | }
|
---|
33 |
|
---|
34 | detectAndResolve(...args) {
|
---|
35 | this.nodes = [];
|
---|
36 | detect.apply(this, args);
|
---|
37 | return this.resolve();
|
---|
38 | }
|
---|
39 |
|
---|
40 | detectAndWarn(...args) {
|
---|
41 | this.nodes = [];
|
---|
42 | detect.apply(this, args);
|
---|
43 | return this.warn();
|
---|
44 | }
|
---|
45 |
|
---|
46 | resolve() {
|
---|
47 | return this.nodes.forEach(node => node.remove());
|
---|
48 | }
|
---|
49 |
|
---|
50 | warn() {
|
---|
51 | return this.nodes.forEach(node => {
|
---|
52 | const {
|
---|
53 | message,
|
---|
54 | browsers,
|
---|
55 | identifier,
|
---|
56 | hack
|
---|
57 | } = node._stylehacks;
|
---|
58 | return node.warn(this.result, message, {
|
---|
59 | browsers,
|
---|
60 | identifier,
|
---|
61 | hack
|
---|
62 | });
|
---|
63 | });
|
---|
64 | }
|
---|
65 |
|
---|
66 | }
|
---|
67 |
|
---|
68 | return Plugin;
|
---|
69 | }
|
---|
70 |
|
---|
71 | module.exports = exports.default; |
---|
Note:
See
TracBrowser
for help on using the repository browser.