From b7bb00ee7f1b77a53a14eb3516ed139c2c58a491 Mon Sep 17 00:00:00 2001 From: Boopathi Rajaa Date: Mon, 27 Feb 2017 15:44:05 +0100 Subject: [PATCH 1/2] Remove minify-empty-function --- .../.npmignore | 4 -- .../README.md | 52 ------------------- .../__tests__/empty-function-test.js | 41 --------------- .../package.json | 18 ------- .../src/index.js | 41 --------------- 5 files changed, 156 deletions(-) delete mode 100644 packages/babel-plugin-minify-empty-function/.npmignore delete mode 100644 packages/babel-plugin-minify-empty-function/README.md delete mode 100644 packages/babel-plugin-minify-empty-function/__tests__/empty-function-test.js delete mode 100644 packages/babel-plugin-minify-empty-function/package.json delete mode 100644 packages/babel-plugin-minify-empty-function/src/index.js diff --git a/packages/babel-plugin-minify-empty-function/.npmignore b/packages/babel-plugin-minify-empty-function/.npmignore deleted file mode 100644 index 22250660e..000000000 --- a/packages/babel-plugin-minify-empty-function/.npmignore +++ /dev/null @@ -1,4 +0,0 @@ -src -__tests__ -node_modules -*.log diff --git a/packages/babel-plugin-minify-empty-function/README.md b/packages/babel-plugin-minify-empty-function/README.md deleted file mode 100644 index 48b7c8f70..000000000 --- a/packages/babel-plugin-minify-empty-function/README.md +++ /dev/null @@ -1,52 +0,0 @@ -# babel-plugin-minify-empty-function - -This is mostly a Facebook-specific transform that removes noop function calls. However, can be generalized to detect and remove noops. - -## Example - -**In** - -```javascript -function emptyFunction(){} -emptyFunction('how long','?'); -foo(emptyFunction('how long', '?')); -``` - -**Out** - -```javascript -function emptyFunction(){} -foo(false); -``` - -## Installation - -```sh -npm install babel-plugin-minify-empty-function -``` - -## Usage - -### Via `.babelrc` (Recommended) - -**.babelrc** - -```json -{ - "plugins": ["minify-empty-function"] -} -``` - -### Via CLI - -```sh -babel --plugins minify-empty-function script.js -``` - -### Via Node API - -```javascript -require("babel-core").transform("code", { - plugins: ["minify-empty-function"] -}); -``` diff --git a/packages/babel-plugin-minify-empty-function/__tests__/empty-function-test.js b/packages/babel-plugin-minify-empty-function/__tests__/empty-function-test.js deleted file mode 100644 index fd71e7427..000000000 --- a/packages/babel-plugin-minify-empty-function/__tests__/empty-function-test.js +++ /dev/null @@ -1,41 +0,0 @@ -jest.autoMockOff(); - -const babel = require("babel-core"); -const unpad = require("../../../utils/unpad"); - -function transform(code) { - return babel.transform(code, { - plugins: [require("../src/index")], - }).code; -} - -describe("constant-folding-plugin", () => { - it("should remove call expressions", () => { - const source = unpad(` - emptyFunction('how long', '?'); - `); - - const expected = ""; - expect(transform(source)).toBe(expected); - }); - - it("should replace with emptyStatement", () => { - const source = unpad(` - if (1) emptyFunction('how long', '?'); - `); - - const expected = "if (1) ;"; - expect(transform(source)).toBe(expected); - }); - - it("should convert to expressions to false", () => { - const source = unpad(` - foo(emptyFunction('how long', '?')); - `); - - const expected = unpad(` - foo(false); - `); - expect(transform(source)).toBe(expected); - }); -}); diff --git a/packages/babel-plugin-minify-empty-function/package.json b/packages/babel-plugin-minify-empty-function/package.json deleted file mode 100644 index ee3939e2a..000000000 --- a/packages/babel-plugin-minify-empty-function/package.json +++ /dev/null @@ -1,18 +0,0 @@ -{ - "name": "babel-plugin-minify-empty-function", - "version": "0.0.1", - "description": "", - "homepage": "https://github.com/babel/babili#readme", - "repository": "https://github.com/babel/babili/tree/master/packages/babel-plugin-minify-empty-function", - "bugs": "https://github.com/babel/babili/issues", - "author": "amasad", - "license": "MIT", - "main": "lib/index.js", - "keywords": [ - "babel-plugin" - ], - "dependencies": { - "babel-helper-remove-or-void": "^0.0.1" - }, - "devDependencies": {} -} diff --git a/packages/babel-plugin-minify-empty-function/src/index.js b/packages/babel-plugin-minify-empty-function/src/index.js deleted file mode 100644 index f845809d0..000000000 --- a/packages/babel-plugin-minify-empty-function/src/index.js +++ /dev/null @@ -1,41 +0,0 @@ -"use strict"; - -module.exports = ({ types: t }) => { - const removeOrVoid = require("babel-helper-remove-or-void")(t); - - const visitor = { - // Remove the call if it stands on it's own. - ExpressionStatement(path) { - const { node } = path; - if (isEmptyFunction(node.expression)) { - removeOrVoid(path); - } - }, - - // If we're not in an expression statement we can't remove - // the call. - CallExpression(path) { - const { node } = path; - if (isEmptyFunction(node)) { - path.replaceWith(t.booleanLiteral(false)); - } - }, - }; - - return { - name: "minify-empty-function", - visitor: { - // Unfortunately we have to do it in a seperate pass to ensure that - // the expression statements are removed otherwise the calls may - // end in conditionals or sequence expressions. - Program(path) { - path.traverse(visitor, {}); - }, - }, - }; - - function isEmptyFunction(node) { - return t.isCallExpression(node) && - t.isIdentifier(node.callee, { name: "emptyFunction" }); - } -}; From 735929f31d9524b3c4d5d8c48d0d601d4d722b22 Mon Sep 17 00:00:00 2001 From: Boopathi Rajaa Date: Mon, 27 Feb 2017 15:51:34 +0100 Subject: [PATCH 2/2] Update README --- README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/README.md b/README.md index b3bedbef8..8ead78050 100644 --- a/README.md +++ b/README.md @@ -163,7 +163,6 @@ Add to your `.babelrc`'s plugins array. | Package | Version | Dependencies | |--------|-------|------------| -| [`babel-plugin-minify-empty-function`](/packages/babel-plugin-minify-empty-function) | [![npm](https://img.shields.io/npm/v/babel-plugin-minify-empty-function.svg?maxAge=86400)](https://www.npmjs.com/package/babel-plugin-minify-empty-function) | [![Dependency Status](https://david-dm.org/babel/babili.svg?path=packages/babel-plugin-minify-empty-function)](https://david-dm.org/babel/babili?path=packages/babel-plugin-minify-empty-function) | | [`babel-plugin-transform-inline-environment-variables`](/packages/babel-plugin-transform-inline-environment-variables) | [![npm](https://img.shields.io/npm/v/babel-plugin-transform-inline-environment-variables.svg?maxAge=86400)](https://www.npmjs.com/package/babel-plugin-transform-inline-environment-variables) | [![Dependency Status](https://david-dm.org/babel/babili.svg?path=packages/babel-plugin-transform-inline-environment-variables)](https://david-dm.org/babel/babili?path=packages/babel-plugin-transform-inline-environment-variables) | | [`babel-plugin-transform-node-env-inline`](/packages/babel-plugin-transform-node-env-inline) | [![npm](https://img.shields.io/npm/v/babel-plugin-transform-node-env-inline.svg?maxAge=86400)](https://www.npmjs.com/package/babel-plugin-transform-node-env-inline) | [![Dependency Status](https://david-dm.org/babel/babili.svg?path=packages/babel-plugin-transform-node-env-inline)](https://david-dm.org/babel/babili?path=packages/babel-plugin-transform-node-env-inline) | | [`babel-plugin-transform-remove-console`](/packages/babel-plugin-transform-remove-console) | [![npm](https://img.shields.io/npm/v/babel-plugin-transform-remove-console.svg?maxAge=86400)](https://www.npmjs.com/package/babel-plugin-transform-remove-console) | [![Dependency Status](https://david-dm.org/babel/babili.svg?path=packages/babel-plugin-transform-remove-console)](https://david-dm.org/babel/babili?path=packages/babel-plugin-transform-remove-console) |