File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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+ } ) ;
Original file line number Diff line number Diff line change @@ -35,7 +35,7 @@ const EXTERNALS = [
3535function 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" ) {
Original file line number Diff line number Diff 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 )
You can’t perform that action at this time.
0 commit comments