stylehacks 2.1.0 → 2.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +27 -0
- package/README.md +12 -5
- package/dist/cli.js +69 -0
- package/dist/dictionary/browsers.js +9 -0
- package/dist/dictionary/identifiers.js +7 -0
- package/dist/dictionary/postcss.js +6 -0
- package/dist/dictionary/tags.js +5 -0
- package/dist/exists.js +4 -8
- package/dist/formatter.js +13 -15
- package/dist/index.js +53 -42
- package/dist/isMixin.js +14 -0
- package/dist/plugin.js +64 -67
- package/dist/plugins/bodyEmpty.js +24 -12
- package/dist/plugins/htmlCombinatorCommentBody.js +26 -12
- package/dist/plugins/htmlFirstChild.js +24 -12
- package/dist/plugins/important.js +12 -9
- package/dist/plugins/leadingStar.js +43 -38
- package/dist/plugins/leadingUnderscore.js +14 -8
- package/dist/plugins/mediaSlash0.js +13 -8
- package/dist/plugins/mediaSlash9.js +13 -8
- package/dist/plugins/slash9.js +26 -0
- package/dist/plugins/starHtml.js +24 -12
- package/dist/plugins/trailingSlashComma.js +24 -12
- package/package.json +42 -17
- package/{bin/usage.txt → usage.txt} +0 -0
- package/bin/cmd.js +0 -49
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,30 @@
|
|
|
1
|
+
# 2.3.2
|
|
2
|
+
|
|
3
|
+
* Resolves an issue where stylehacks would crash on CSS mixins.
|
|
4
|
+
|
|
5
|
+
# 2.3.1
|
|
6
|
+
|
|
7
|
+
* Upgraded postcss-selector-parser to `v2.0.0`.
|
|
8
|
+
* Fixed an issue where stylehacks was not removing `*zoom: 1` from rules
|
|
9
|
+
generated by other PostCSS plugins.
|
|
10
|
+
|
|
11
|
+
# 2.3.0
|
|
12
|
+
|
|
13
|
+
* Each warning now contains more information about the hack; what identifier
|
|
14
|
+
it targets, what the hack is, and the browsers that it affects. E.g:
|
|
15
|
+
|
|
16
|
+
```js
|
|
17
|
+
{
|
|
18
|
+
browsers: [ 'ie 6', 'ie 5.5' ],
|
|
19
|
+
identifier: 'selector',
|
|
20
|
+
hack: '* html h1'
|
|
21
|
+
}
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
# 2.2.0
|
|
25
|
+
|
|
26
|
+
* Added `value\9` hack.
|
|
27
|
+
|
|
1
28
|
# 2.1.0
|
|
2
29
|
|
|
3
30
|
* Added `html ~ /**/ body .selector` hack.
|
package/README.md
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
> Detect/remove browser hacks from CSS files.
|
|
4
4
|
|
|
5
|
+
|
|
5
6
|
## Install
|
|
6
7
|
|
|
7
8
|
With [npm](https://npmjs.org/package/stylehacks) do:
|
|
@@ -10,6 +11,7 @@ With [npm](https://npmjs.org/package/stylehacks) do:
|
|
|
10
11
|
npm install stylehacks --save
|
|
11
12
|
```
|
|
12
13
|
|
|
14
|
+
|
|
13
15
|
## Example
|
|
14
16
|
|
|
15
17
|
In its default mode, stylehacks will remove hacks from your CSS file, based on
|
|
@@ -32,11 +34,12 @@ h1 {
|
|
|
32
34
|
}
|
|
33
35
|
```
|
|
34
36
|
|
|
37
|
+
|
|
35
38
|
## API
|
|
36
39
|
|
|
37
40
|
### `stylehacks.detect(node)`
|
|
38
41
|
|
|
39
|
-
Type: `function`
|
|
42
|
+
Type: `function`
|
|
40
43
|
Returns: `boolean`
|
|
41
44
|
|
|
42
45
|
This method will take any PostCSS *node*, run applicable plugins depending on
|
|
@@ -55,7 +58,7 @@ h1 { _color: red }
|
|
|
55
58
|
|
|
56
59
|
##### browsers
|
|
57
60
|
|
|
58
|
-
Type: `string|array`
|
|
61
|
+
Type: `string|array`
|
|
59
62
|
Default: [browserslist defaults](https://github.com/ai/browserslist)
|
|
60
63
|
|
|
61
64
|
Specify the browsers that you wish to support. The string will be passed
|
|
@@ -64,7 +67,7 @@ stylehacks will use it instead of parsing the browsers itself.
|
|
|
64
67
|
|
|
65
68
|
##### lint
|
|
66
69
|
|
|
67
|
-
Type: `boolean`
|
|
70
|
+
Type: `boolean`
|
|
68
71
|
Default: `false`
|
|
69
72
|
|
|
70
73
|
If lint mode is enabled, stylehacks will not remove hacks from the CSS; instead,
|
|
@@ -73,7 +76,7 @@ you are expected to handle these messages yourself.
|
|
|
73
76
|
|
|
74
77
|
##### silent
|
|
75
78
|
|
|
76
|
-
Type: `boolean`
|
|
79
|
+
Type: `boolean`
|
|
77
80
|
Default: `false`
|
|
78
81
|
|
|
79
82
|
Used in combination with the lint option; disables all logging. When using the
|
|
@@ -81,7 +84,7 @@ CLI, the process will exit with 0 or 1 as usual.
|
|
|
81
84
|
|
|
82
85
|
##### sourcemap
|
|
83
86
|
|
|
84
|
-
Type: `boolean`
|
|
87
|
+
Type: `boolean`
|
|
85
88
|
Default: `false`
|
|
86
89
|
|
|
87
90
|
Generate a sourcemap with the transformed CSS.
|
|
@@ -100,6 +103,7 @@ stylehacks also ships with a CLI app. To see the available options, just run:
|
|
|
100
103
|
$ stylehacks --help
|
|
101
104
|
```
|
|
102
105
|
|
|
106
|
+
|
|
103
107
|
## Related
|
|
104
108
|
|
|
105
109
|
stylehacks works well with your existing PostCSS setup:
|
|
@@ -107,15 +111,18 @@ stylehacks works well with your existing PostCSS setup:
|
|
|
107
111
|
* [stylelint] - Comprehensive & modern CSS linter, to ensure that your code
|
|
108
112
|
style rules are respected.
|
|
109
113
|
|
|
114
|
+
|
|
110
115
|
## Contributing
|
|
111
116
|
|
|
112
117
|
Pull requests are welcome. If you add functionality, then please add unit tests
|
|
113
118
|
to cover it.
|
|
114
119
|
|
|
120
|
+
|
|
115
121
|
## License
|
|
116
122
|
|
|
117
123
|
MIT © [Ben Briggs](http://beneb.info)
|
|
118
124
|
|
|
125
|
+
|
|
119
126
|
[ci]: https://travis-ci.org/ben-eb/stylehacks
|
|
120
127
|
[deps]: https://gemnasium.com/ben-eb/stylehacks
|
|
121
128
|
[npm]: http://badge.fury.io/js/stylehacks
|
package/dist/cli.js
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
var _fs = require('fs');
|
|
5
|
+
|
|
6
|
+
var _fs2 = _interopRequireDefault(_fs);
|
|
7
|
+
|
|
8
|
+
var _readFileStdin = require('read-file-stdin');
|
|
9
|
+
|
|
10
|
+
var _readFileStdin2 = _interopRequireDefault(_readFileStdin);
|
|
11
|
+
|
|
12
|
+
var _writeFileStdout = require('write-file-stdout');
|
|
13
|
+
|
|
14
|
+
var _writeFileStdout2 = _interopRequireDefault(_writeFileStdout);
|
|
15
|
+
|
|
16
|
+
var _minimist = require('minimist');
|
|
17
|
+
|
|
18
|
+
var _minimist2 = _interopRequireDefault(_minimist);
|
|
19
|
+
|
|
20
|
+
var _package = require('../package.json');
|
|
21
|
+
|
|
22
|
+
var _ = require('./');
|
|
23
|
+
|
|
24
|
+
var _2 = _interopRequireDefault(_);
|
|
25
|
+
|
|
26
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
27
|
+
|
|
28
|
+
var opts = (0, _minimist2.default)(process.argv.slice(2), {
|
|
29
|
+
alias: {
|
|
30
|
+
b: 'browsers',
|
|
31
|
+
l: 'lint',
|
|
32
|
+
h: 'help',
|
|
33
|
+
s: 'sourcemap',
|
|
34
|
+
v: 'version'
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
if (opts.version) {
|
|
39
|
+
console.log(_package.version);
|
|
40
|
+
} else {
|
|
41
|
+
var file = opts._[0];
|
|
42
|
+
var out = opts._[1];
|
|
43
|
+
|
|
44
|
+
if (file === 'help' || opts.help) {
|
|
45
|
+
_fs2.default.createReadStream(__dirname + '/../usage.txt').pipe(process.stdout).on('close', function () {
|
|
46
|
+
return process.exit(1);
|
|
47
|
+
});
|
|
48
|
+
} else {
|
|
49
|
+
(0, _readFileStdin2.default)(file, function (err, buf) {
|
|
50
|
+
if (err) {
|
|
51
|
+
throw err;
|
|
52
|
+
}
|
|
53
|
+
if (file) {
|
|
54
|
+
opts.from = file;
|
|
55
|
+
}
|
|
56
|
+
if (out) {
|
|
57
|
+
opts.to = out;
|
|
58
|
+
}
|
|
59
|
+
_2.default.process(String(buf), opts).then(function (result) {
|
|
60
|
+
if (result.warnings().length) {
|
|
61
|
+
process.exit(1);
|
|
62
|
+
}
|
|
63
|
+
if (!opts.lint) {
|
|
64
|
+
(0, _writeFileStdout2.default)(result.css);
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
exports.__esModule = true;
|
|
4
|
+
var FF_2 = exports.FF_2 = 'firefox 2';
|
|
5
|
+
var IE_5_5 = exports.IE_5_5 = 'ie 5.5';
|
|
6
|
+
var IE_6 = exports.IE_6 = 'ie 6';
|
|
7
|
+
var IE_7 = exports.IE_7 = 'ie 7';
|
|
8
|
+
var IE_8 = exports.IE_8 = 'ie 8';
|
|
9
|
+
var OP_9 = exports.OP_9 = 'opera 9';
|
package/dist/exists.js
CHANGED
|
@@ -1,13 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, '__esModule', {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports['default'] = exists;
|
|
1
|
+
"use strict";
|
|
7
2
|
|
|
3
|
+
exports.__esModule = true;
|
|
4
|
+
exports.default = exists;
|
|
8
5
|
function exists(selector, index, value) {
|
|
9
6
|
var node = selector.at(index);
|
|
10
7
|
return node && node.value === value;
|
|
11
8
|
}
|
|
12
|
-
|
|
13
|
-
module.exports = exports['default'];
|
|
9
|
+
module.exports = exports["default"];
|
package/dist/formatter.js
CHANGED
|
@@ -1,19 +1,15 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
3
|
+
exports.__esModule = true;
|
|
6
4
|
|
|
7
|
-
|
|
5
|
+
var _path = require('path');
|
|
6
|
+
|
|
7
|
+
var _path2 = _interopRequireDefault(_path);
|
|
8
8
|
|
|
9
9
|
var _chalk = require('chalk');
|
|
10
10
|
|
|
11
11
|
var _chalk2 = _interopRequireDefault(_chalk);
|
|
12
12
|
|
|
13
|
-
var _path = require('path');
|
|
14
|
-
|
|
15
|
-
var _path2 = _interopRequireDefault(_path);
|
|
16
|
-
|
|
17
13
|
var _textTable = require('text-table');
|
|
18
14
|
|
|
19
15
|
var _textTable2 = _interopRequireDefault(_textTable);
|
|
@@ -26,29 +22,31 @@ var _plur = require('plur');
|
|
|
26
22
|
|
|
27
23
|
var _plur2 = _interopRequireDefault(_plur);
|
|
28
24
|
|
|
25
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
26
|
+
|
|
29
27
|
var logFrom = function logFrom(fromValue) {
|
|
30
28
|
if (!fromValue.indexOf('<')) {
|
|
31
29
|
return fromValue;
|
|
32
30
|
}
|
|
33
|
-
return _path2
|
|
31
|
+
return _path2.default.relative(process.cwd(), fromValue);
|
|
34
32
|
};
|
|
35
33
|
|
|
36
34
|
var hacksFound = function hacksFound(messages) {
|
|
37
|
-
var num = messages.length + (0, _plur2
|
|
38
|
-
return '\n\n ' + _logSymbols2
|
|
35
|
+
var num = messages.length + (0, _plur2.default)(' hack', messages.length);
|
|
36
|
+
return '\n\n ' + _logSymbols2.default.error + ' ' + num + ' found.\n';
|
|
39
37
|
};
|
|
40
38
|
|
|
41
|
-
exports
|
|
39
|
+
exports.default = function (input) {
|
|
42
40
|
var messages = input.messages;
|
|
43
41
|
var source = input.source;
|
|
44
42
|
|
|
45
43
|
if (!messages.length) {
|
|
46
|
-
return ' ' + _logSymbols2
|
|
44
|
+
return ' ' + _logSymbols2.default.success + ' No hacks found.';
|
|
47
45
|
}
|
|
48
46
|
|
|
49
|
-
return _chalk2
|
|
47
|
+
return _chalk2.default.underline(logFrom(source)) + '\n' + (0, _textTable2.default)(messages.map(function (msg) {
|
|
50
48
|
var parts = msg.text.split(': ');
|
|
51
|
-
return ['', _chalk2
|
|
49
|
+
return ['', _chalk2.default.gray('line ' + msg.node.source.start.line), _chalk2.default.gray('col ' + msg.node.source.start.column), parts[0], _chalk2.default.red(parts[1])];
|
|
52
50
|
})) + hacksFound(messages);
|
|
53
51
|
};
|
|
54
52
|
|
package/dist/index.js
CHANGED
|
@@ -1,10 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
|
|
7
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
|
|
3
|
+
exports.__esModule = true;
|
|
8
4
|
|
|
9
5
|
var _postcss = require('postcss');
|
|
10
6
|
|
|
@@ -22,71 +18,86 @@ var _formatter = require('./formatter');
|
|
|
22
18
|
|
|
23
19
|
var _formatter2 = _interopRequireDefault(_formatter);
|
|
24
20
|
|
|
25
|
-
|
|
21
|
+
var _bodyEmpty = require('./plugins/bodyEmpty');
|
|
22
|
+
|
|
23
|
+
var _bodyEmpty2 = _interopRequireDefault(_bodyEmpty);
|
|
24
|
+
|
|
25
|
+
var _htmlCombinatorCommentBody = require('./plugins/htmlCombinatorCommentBody');
|
|
26
26
|
|
|
27
|
-
var
|
|
27
|
+
var _htmlCombinatorCommentBody2 = _interopRequireDefault(_htmlCombinatorCommentBody);
|
|
28
28
|
|
|
29
|
-
var
|
|
29
|
+
var _htmlFirstChild = require('./plugins/htmlFirstChild');
|
|
30
30
|
|
|
31
|
-
var
|
|
31
|
+
var _htmlFirstChild2 = _interopRequireDefault(_htmlFirstChild);
|
|
32
32
|
|
|
33
|
-
var
|
|
33
|
+
var _important = require('./plugins/important');
|
|
34
34
|
|
|
35
|
-
var
|
|
35
|
+
var _important2 = _interopRequireDefault(_important);
|
|
36
36
|
|
|
37
|
-
var
|
|
37
|
+
var _leadingStar = require('./plugins/leadingStar');
|
|
38
38
|
|
|
39
|
-
var
|
|
39
|
+
var _leadingStar2 = _interopRequireDefault(_leadingStar);
|
|
40
40
|
|
|
41
|
-
var
|
|
41
|
+
var _leadingUnderscore = require('./plugins/leadingUnderscore');
|
|
42
42
|
|
|
43
|
-
var
|
|
43
|
+
var _leadingUnderscore2 = _interopRequireDefault(_leadingUnderscore);
|
|
44
44
|
|
|
45
|
-
var
|
|
45
|
+
var _mediaSlash = require('./plugins/mediaSlash0');
|
|
46
46
|
|
|
47
|
-
var
|
|
47
|
+
var _mediaSlash2 = _interopRequireDefault(_mediaSlash);
|
|
48
48
|
|
|
49
|
-
var
|
|
49
|
+
var _mediaSlash3 = require('./plugins/mediaSlash9');
|
|
50
50
|
|
|
51
|
-
var
|
|
51
|
+
var _mediaSlash4 = _interopRequireDefault(_mediaSlash3);
|
|
52
52
|
|
|
53
|
-
var
|
|
53
|
+
var _slash = require('./plugins/slash9');
|
|
54
54
|
|
|
55
|
-
var
|
|
55
|
+
var _slash2 = _interopRequireDefault(_slash);
|
|
56
56
|
|
|
57
|
-
var
|
|
57
|
+
var _starHtml = require('./plugins/starHtml');
|
|
58
58
|
|
|
59
|
-
var
|
|
59
|
+
var _starHtml2 = _interopRequireDefault(_starHtml);
|
|
60
60
|
|
|
61
|
-
var
|
|
61
|
+
var _trailingSlashComma = require('./plugins/trailingSlashComma');
|
|
62
62
|
|
|
63
|
-
var
|
|
63
|
+
var _trailingSlashComma2 = _interopRequireDefault(_trailingSlashComma);
|
|
64
64
|
|
|
65
|
-
|
|
65
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
66
66
|
|
|
67
|
-
var plugins = [
|
|
67
|
+
var plugins = [_bodyEmpty2.default, _htmlCombinatorCommentBody2.default, _htmlFirstChild2.default, _important2.default, _leadingStar2.default, _leadingUnderscore2.default, _mediaSlash2.default, _mediaSlash4.default, _slash2.default, _starHtml2.default, _trailingSlashComma2.default];
|
|
68
68
|
|
|
69
|
-
|
|
70
|
-
|
|
69
|
+
// plugins
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
var stylehacks = _postcss2.default.plugin('stylehacks', function () {
|
|
73
|
+
var opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
71
74
|
|
|
72
75
|
var b = opts.browsers;
|
|
73
|
-
var browsers = b instanceof Array ? b : (0, _browserslist2
|
|
76
|
+
var browsers = b instanceof Array ? b : (0, _browserslist2.default)(b);
|
|
74
77
|
|
|
75
78
|
return function (css, result) {
|
|
76
|
-
plugins.
|
|
77
|
-
var hack = new Plugin(
|
|
79
|
+
var processors = plugins.reduce(function (list, Plugin) {
|
|
80
|
+
var hack = new Plugin(result);
|
|
78
81
|
var applied = browsers.some(function (browser) {
|
|
79
82
|
return hack.targets.some(function (target) {
|
|
80
83
|
return browser === target;
|
|
81
84
|
});
|
|
82
85
|
});
|
|
83
86
|
if (applied) {
|
|
84
|
-
return;
|
|
87
|
+
return list;
|
|
85
88
|
}
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
89
|
+
return [].concat(list, [hack]);
|
|
90
|
+
}, []);
|
|
91
|
+
css.walk(function (node) {
|
|
92
|
+
processors.forEach(function (proc) {
|
|
93
|
+
if (!~proc.nodeTypes.indexOf(node.type)) {
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
if (opts.lint) {
|
|
97
|
+
return proc.detectAndWarn(node);
|
|
98
|
+
}
|
|
99
|
+
return proc.detectAndResolve(node);
|
|
100
|
+
});
|
|
90
101
|
});
|
|
91
102
|
};
|
|
92
103
|
});
|
|
@@ -101,17 +112,17 @@ stylehacks.detect = function (node) {
|
|
|
101
112
|
};
|
|
102
113
|
|
|
103
114
|
stylehacks.process = function (css) {
|
|
104
|
-
var opts = arguments.length
|
|
115
|
+
var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
105
116
|
|
|
106
117
|
opts.reporter = {};
|
|
107
|
-
opts.reporter.formatter = _formatter2
|
|
118
|
+
opts.reporter.formatter = _formatter2.default;
|
|
108
119
|
opts.map = opts.map || (opts.sourcemap ? true : null);
|
|
109
|
-
var processor = (0, _postcss2
|
|
120
|
+
var processor = (0, _postcss2.default)([stylehacks(opts)]);
|
|
110
121
|
if (opts.lint && !opts.silent) {
|
|
111
|
-
processor.use((0, _postcssReporter2
|
|
122
|
+
processor.use((0, _postcssReporter2.default)(opts.reporter));
|
|
112
123
|
}
|
|
113
124
|
return processor.process(css, opts);
|
|
114
125
|
};
|
|
115
126
|
|
|
116
|
-
exports
|
|
127
|
+
exports.default = stylehacks;
|
|
117
128
|
module.exports = exports['default'];
|
package/dist/isMixin.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
exports.__esModule = true;
|
|
4
|
+
exports.default = isMixin;
|
|
5
|
+
function isMixin(node) {
|
|
6
|
+
var selector = node.selector;
|
|
7
|
+
// If the selector ends with a ':' it is likely a part of a custom mixin.
|
|
8
|
+
|
|
9
|
+
if (!selector || selector[selector.length - 1] === ':') {
|
|
10
|
+
return true;
|
|
11
|
+
}
|
|
12
|
+
return false;
|
|
13
|
+
}
|
|
14
|
+
module.exports = exports['default'];
|
package/dist/plugin.js
CHANGED
|
@@ -1,88 +1,85 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
3
|
+
exports.__esModule = true;
|
|
6
4
|
|
|
7
|
-
var
|
|
5
|
+
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
|
|
8
6
|
|
|
9
|
-
exports
|
|
7
|
+
exports.default = plugin;
|
|
10
8
|
|
|
11
|
-
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError(
|
|
9
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
12
10
|
|
|
13
|
-
function plugin(targets, nodeTypes,
|
|
14
|
-
var Plugin =
|
|
15
|
-
function Plugin(
|
|
11
|
+
function plugin(targets, nodeTypes, detect) {
|
|
12
|
+
var Plugin = function () {
|
|
13
|
+
function Plugin(result) {
|
|
16
14
|
_classCallCheck(this, Plugin);
|
|
17
15
|
|
|
18
16
|
this.nodes = [];
|
|
19
|
-
this.css = css;
|
|
20
17
|
this.result = result;
|
|
21
18
|
this.targets = targets;
|
|
22
19
|
this.nodeTypes = nodeTypes;
|
|
23
20
|
}
|
|
24
21
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
if (node._stylehacks) {
|
|
38
|
-
hasHack = true;
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
return hasHack;
|
|
42
|
-
}
|
|
43
|
-
}, {
|
|
44
|
-
key: 'detect',
|
|
45
|
-
value: function detect() {
|
|
46
|
-
this.css.walk((function (node) {
|
|
47
|
-
if (~this.nodeTypes.indexOf(node.type)) {
|
|
48
|
-
_detect.apply(this, arguments);
|
|
49
|
-
}
|
|
50
|
-
}).bind(this));
|
|
51
|
-
}
|
|
52
|
-
}, {
|
|
53
|
-
key: 'detectAndResolve',
|
|
54
|
-
value: function detectAndResolve() {
|
|
55
|
-
this.detect();
|
|
56
|
-
return this.resolve();
|
|
57
|
-
}
|
|
58
|
-
}, {
|
|
59
|
-
key: 'detectAndWarn',
|
|
60
|
-
value: function detectAndWarn() {
|
|
61
|
-
this.detect();
|
|
62
|
-
return this.warn();
|
|
22
|
+
Plugin.prototype.push = function push(node, metadata) {
|
|
23
|
+
node._stylehacks = _extends({}, metadata, {
|
|
24
|
+
message: "Bad " + metadata.identifier + ": " + metadata.hack,
|
|
25
|
+
browsers: this.targets
|
|
26
|
+
});
|
|
27
|
+
this.nodes.push(node);
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
Plugin.prototype.any = function any(node) {
|
|
31
|
+
if (~this.nodeTypes.indexOf(node.type)) {
|
|
32
|
+
detect.apply(this, arguments);
|
|
33
|
+
return !!node._stylehacks;
|
|
63
34
|
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
35
|
+
return false;
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
Plugin.prototype.detectAndResolve = function detectAndResolve() {
|
|
39
|
+
this.nodes = [];
|
|
40
|
+
|
|
41
|
+
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
|
|
42
|
+
args[_key] = arguments[_key];
|
|
70
43
|
}
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
44
|
+
|
|
45
|
+
detect.apply(this, args);
|
|
46
|
+
return this.resolve();
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
Plugin.prototype.detectAndWarn = function detectAndWarn() {
|
|
50
|
+
this.nodes = [];
|
|
51
|
+
|
|
52
|
+
for (var _len2 = arguments.length, args = Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
|
|
53
|
+
args[_key2] = arguments[_key2];
|
|
79
54
|
}
|
|
80
|
-
|
|
55
|
+
|
|
56
|
+
detect.apply(this, args);
|
|
57
|
+
return this.warn();
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
Plugin.prototype.resolve = function resolve() {
|
|
61
|
+
return this.nodes.forEach(function (node) {
|
|
62
|
+
return node.remove();
|
|
63
|
+
});
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
Plugin.prototype.warn = function warn() {
|
|
67
|
+
var _this = this;
|
|
68
|
+
|
|
69
|
+
return this.nodes.forEach(function (node) {
|
|
70
|
+
var _node$_stylehacks = node._stylehacks,
|
|
71
|
+
message = _node$_stylehacks.message,
|
|
72
|
+
browsers = _node$_stylehacks.browsers,
|
|
73
|
+
identifier = _node$_stylehacks.identifier,
|
|
74
|
+
hack = _node$_stylehacks.hack;
|
|
75
|
+
|
|
76
|
+
return node.warn(_this.result, message, { browsers: browsers, identifier: identifier, hack: hack });
|
|
77
|
+
});
|
|
78
|
+
};
|
|
81
79
|
|
|
82
80
|
return Plugin;
|
|
83
|
-
}
|
|
81
|
+
}();
|
|
84
82
|
|
|
85
83
|
return Plugin;
|
|
86
84
|
}
|
|
87
|
-
|
|
88
|
-
module.exports = exports['default'];
|
|
85
|
+
module.exports = exports["default"];
|