pax_global_header00006660000000000000000000000064126521451540014517gustar00rootroot0000000000000052 comment=821cbf980e96ac9a7fc2fa373b43cba0121baf46 babel-plugin-array-includes-2.0.3/000077500000000000000000000000001265214515400170025ustar00rootroot00000000000000babel-plugin-array-includes-2.0.3/.babelrc000066400000000000000000000000361265214515400203740ustar00rootroot00000000000000{ "presets": ["es2015"] } babel-plugin-array-includes-2.0.3/.gitignore000066400000000000000000000000731265214515400207720ustar00rootroot00000000000000# Logs logs *.log # Dependency directory node_modules lib babel-plugin-array-includes-2.0.3/.npmignore000066400000000000000000000000271265214515400210000ustar00rootroot00000000000000node_modules *.log src babel-plugin-array-includes-2.0.3/LICENSE000066400000000000000000000020751265214515400200130ustar00rootroot00000000000000The MIT License (MIT) Copyright (c) 2015 Christoph Hermann Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. babel-plugin-array-includes-2.0.3/README.md000066400000000000000000000015311265214515400202610ustar00rootroot00000000000000# babel-plugin-array-includes > Replaces `arr.includes(val)` with `arr.indexOf(val) >= 0`. Thanks to [@sebmck](https://github.com/sebmck) for the help. ## Example **In** ```javascript [1, 2, 3, 5, 8, 13].includes(4); ``` **Out** ```javascript "use strict"; [1, 2, 3, 5, 8, 13].indexOf(4) >= 0; ``` ## Pitfalls This doesn't work: **In** ```js function foo(arr) { return arr.includes('foo'); } ``` **Out** ```js function foo(arr) { return arr.includes('foo'); // still includes } ``` ## Installation ```sh $ npm install babel-plugin-array-includes ``` ## Usage ### Via `.babelrc` (Recommended) **.babelrc** ```json { "plugins": ["array-includes"] } ``` ### Via CLI ```sh $ babel --plugins array-includes script.js ``` ### Via Node API ```javascript require("babel-core").transform("code", { plugins: ["array-includes"] }); ``` babel-plugin-array-includes-2.0.3/package.json000066400000000000000000000017101265214515400212670ustar00rootroot00000000000000{ "name": "babel-plugin-array-includes", "version": "2.0.3", "description": "Replaces `arr.includes(val)' with `arr.indexOf(val) >= 0`.", "author": "Christoph Hermann", "license": "MIT", "repository": { "type": "git", "url": "https://github.com/stoeffel/babel-plugin-array-includes.git" }, "main": "lib/index.js", "devDependencies": { "babel-cli": "^6.3.15", "babel-preset-es2015": "^6.3.13", "babel-register": "^6.3.13", "chai": "^3.4.1", "mocha": "^2.3.4" }, "scripts": { "build": "babel -D src -d lib", "test": "mocha", "prepublish": "npm run build", "patch-release": "npm version patch && npm publish && git push --follow-tags", "minor-release": "npm version minor && npm publish && git push --follow-tags", "major-release": "npm version major && npm publish && git push --follow-tags" }, "keywords": [ "babel", "babel-plugin", "array", "includes", "polyfill" ] } babel-plugin-array-includes-2.0.3/src/000077500000000000000000000000001265214515400175715ustar00rootroot00000000000000babel-plugin-array-includes-2.0.3/src/index.js000066400000000000000000000007271265214515400212440ustar00rootroot00000000000000export default function ({ types: t }) { return { visitor: { CallExpression(path) { const callee = path.node.callee; if (t.isMemberExpression(callee, { computed: false }) && t.isIdentifier(callee.property, { name: "includes" })) { callee.property.name = 'indexOf'; path.replaceWith( t.binaryExpression("!==", path.node, t.numericLiteral(-1)) ); } } } }; } babel-plugin-array-includes-2.0.3/test/000077500000000000000000000000001265214515400177615ustar00rootroot00000000000000babel-plugin-array-includes-2.0.3/test/mocha.opts000066400000000000000000000000351265214515400217550ustar00rootroot00000000000000--compilers js:babel-registerbabel-plugin-array-includes-2.0.3/test/test.js000066400000000000000000000013731265214515400213020ustar00rootroot00000000000000var babel = require('babel-core'); import {expect} from 'chai'; import plugin from '../src'; describe('babel-plugin-transform-array-includes', function() { it('[1,2,3].includes(1)', function() { expect(babel.transform('[1,2,3].includes(1);', {plugins: [plugin], compact: true}).code) .to.equal('[1,2,3].indexOf(1)!==-1;'); }); it('var a=[]; a.includes(1)', function() { expect(babel.transform('var a=[]; a.includes(1);', {plugins: [plugin], compact: true}).code) .to.equal('var a=[];a.indexOf(1)!==-1;'); }); it('var a=[]; b=a.map(...); b.includes(1)', function() { expect(babel.transform('var a=[];b=a.map(x=>x+1);b.includes(1);', {plugins: [plugin], compact: true}).code) .to.equal('var a=[];b=a.map(x => x+1);b.indexOf(1)!==-1;'); }); });