Skip to content

Commit 2ab09b5

Browse files
committed
Polyfill for Object.values and replace Array.prototype.includes by Array.prototype.indexOf
1 parent fadf40c commit 2ab09b5

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

lib/css-byebye.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const cssbyebye = postcss.plugin('css-byebye', function (options) {
1515
const regex = concatRegexes(remregexes)
1616
let controlDirective = null
1717

18-
css.each(walkNodes)
18+
css.walk(walkNodes)
1919

2020
function walkNodes(node) {
2121

lib/utilities/directives.js

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
/**
2+
* Object.getValues polyfill
3+
* @param {Object} obj object
4+
* @return {Array}
5+
*/
6+
function getValues(obj) {
7+
return Object.keys(obj).map(function (key) {
8+
return obj[key];
9+
});
10+
}
11+
112
const CONTROL_DIRECTIVE_REG_EXP = /^\/\*!? *byebye:?(begin|end)?:(\w+) *\*\/$/
213

314
const CONTROL_DIRECTIVES = {
@@ -9,8 +20,8 @@ const CONTROL_DIRECTIVES_BLOCKS = {
920
END: 'end'
1021
}
1122

12-
const controlDirectivesValues = Object.values(CONTROL_DIRECTIVES)
13-
const controlDirectivesBlockValues = Object.values(CONTROL_DIRECTIVES_BLOCKS)
23+
const controlDirectivesValues = getValues(CONTROL_DIRECTIVES)
24+
const controlDirectivesBlockValues = getValues(CONTROL_DIRECTIVES_BLOCKS)
1425

1526
/**
1627
* Check if a directive match is a valid one
@@ -20,10 +31,10 @@ const controlDirectivesBlockValues = Object.values(CONTROL_DIRECTIVES_BLOCKS)
2031
function isValidMatchDirective(match) {
2132
if (Array.isArray(match)) {
2233
return (
23-
controlDirectivesValues.includes(match[2]) &&
34+
controlDirectivesValues.indexOf(match[2]) >= 0 &&
2435
(
2536
typeof match[1] === 'undefined' ||
26-
controlDirectivesBlockValues.includes(match[1])
37+
controlDirectivesBlockValues.indexOf(match[1]) >= 0
2738
)
2839
)
2940
}

0 commit comments

Comments
 (0)