Skip to content

Commit 4d2733c

Browse files
committed
chore: fix node 4
1 parent 0892d17 commit 4d2733c

3 files changed

Lines changed: 32 additions & 2 deletions

File tree

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
"use strict";
2+
3+
//
4+
// BEFORE:
5+
// [__something__].includes(__something__)
6+
//
7+
// AFTER:
8+
// [__something__].indexOf(__something__) !== -1
9+
//
10+
11+
module.exports = ({ types: t }) => ({
12+
visitor: {
13+
CallExpression(path) {
14+
const node = path.node;
15+
const callee = node.callee;
16+
if (
17+
t.isMemberExpression(callee, { computed: false }) &&
18+
t.isArrayExpression(callee.object) &&
19+
t.isIdentifier(callee.property, { name: "includes" })
20+
) {
21+
callee.property.name = "indexOf";
22+
path.replaceWith(t.binaryExpression("!==", node, t.numericLiteral(-1)));
23+
}
24+
}
25+
}
26+
});

scripts/build/bundler.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ const EXTERNALS = [
3535
function getBabelConfig(bundle) {
3636
const config = {
3737
babelrc: false,
38-
plugins: [],
38+
plugins: bundle.plugins || [],
3939
compact: bundle.type === "plugin" ? false : "auto"
4040
};
4141
if (bundle.type === "core") {

scripts/build/config.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ const path = require("path");
1313
* @property {CommonJSConfig} [commonjs={}] - options for `rollup-plugin-commonjs`
1414
* @property {string[]} external - array of paths that should not be included in the final bundle
1515
* @property {Object.<string, string>} replace - map of strings to replace when processing the bundle
16+
* @property {string[]} plugins - babel plugins
1617
1718
* @typedef {Object} CommonJSConfig
1819
* @property {Object} namedExports - for cases where rollup can't infer what's exported
@@ -70,7 +71,10 @@ const parsers = [
7071
{
7172
input: "src/language-yaml/parser-yaml.js",
7273
target: "universal",
73-
bundler: "webpack"
74+
bundler: "webpack",
75+
plugins: [
76+
require.resolve("./babel-plugins/replace-array-includes-with-indexof")
77+
]
7478
}
7579
].map(parser => {
7680
const name = getFileOutput(parser)

0 commit comments

Comments
 (0)