diff --git a/node_modules/babel-preset-babili/.npmignore b/node_modules/babel-helper-evaluate-path/.npmignore similarity index 100% rename from node_modules/babel-preset-babili/.npmignore rename to node_modules/babel-helper-evaluate-path/.npmignore diff --git a/node_modules/babel-helper-evaluate-path/README.md b/node_modules/babel-helper-evaluate-path/README.md new file mode 100644 index 00000000000..50eebc4bd6e --- /dev/null +++ b/node_modules/babel-helper-evaluate-path/README.md @@ -0,0 +1,9 @@ +# # babel-helper-evaluate-path + +`path.evaluate` wrapped in a try catch + +## Installation + +```sh +npm install babel-helper-evaluate-path +``` diff --git a/node_modules/babel-preset-babili/node_modules/babel-plugin-minify-builtins/node_modules/babel-helper-evaluate-path/lib/index.js b/node_modules/babel-helper-evaluate-path/lib/index.js similarity index 100% rename from node_modules/babel-preset-babili/node_modules/babel-plugin-minify-builtins/node_modules/babel-helper-evaluate-path/lib/index.js rename to node_modules/babel-helper-evaluate-path/lib/index.js diff --git a/node_modules/babel-helper-evaluate-path/package.json b/node_modules/babel-helper-evaluate-path/package.json new file mode 100644 index 00000000000..d836fecdeb7 --- /dev/null +++ b/node_modules/babel-helper-evaluate-path/package.json @@ -0,0 +1,50 @@ +{ + "_from": "babel-helper-evaluate-path@^0.1.0", + "_id": "babel-helper-evaluate-path@0.1.0", + "_inBundle": false, + "_integrity": "sha1-ldmMTqNhUEg9sufT7J4ZVKcmKcs=", + "_location": "/babel-helper-evaluate-path", + "_phantomChildren": {}, + "_requested": { + "type": "range", + "registry": true, + "raw": "babel-helper-evaluate-path@^0.1.0", + "name": "babel-helper-evaluate-path", + "escapedName": "babel-helper-evaluate-path", + "rawSpec": "^0.1.0", + "saveSpec": null, + "fetchSpec": "^0.1.0" + }, + "_requiredBy": [ + "/babel-plugin-minify-builtins", + "/babel-plugin-minify-constant-folding" + ], + "_resolved": "https://registry.npmjs.org/babel-helper-evaluate-path/-/babel-helper-evaluate-path-0.1.0.tgz", + "_shasum": "95d98c4ea36150483db2e7d3ec9e1954a72629cb", + "_spec": "babel-helper-evaluate-path@^0.1.0", + "_where": "/Users/chris/appc/titanium_mobile/node_modules/babel-plugin-minify-builtins", + "author": { + "name": "boopathi" + }, + "bugs": { + "url": "https://github.com/babel/babili/issues" + }, + "bundleDependencies": false, + "dependencies": {}, + "deprecated": false, + "description": "path.evaluate wrapped in a try catch", + "devDependencies": {}, + "homepage": "https://github.com/babel/babili#readme", + "keywords": [ + "babel-plugin", + "babili" + ], + "license": "MIT", + "main": "lib/index.js", + "name": "babel-helper-evaluate-path", + "repository": { + "type": "git", + "url": "https://github.com/babel/babili/tree/master/packages/babel-helper-evaluate-path" + }, + "version": "0.1.0" +} diff --git a/node_modules/babel-preset-babili/node_modules/babel-plugin-minify-builtins/.npmignore b/node_modules/babel-helper-flip-expressions/.npmignore similarity index 100% rename from node_modules/babel-preset-babili/node_modules/babel-plugin-minify-builtins/.npmignore rename to node_modules/babel-helper-flip-expressions/.npmignore diff --git a/node_modules/babel-preset-babili/node_modules/babel-plugin-minify-guarded-expressions/node_modules/babel-helper-flip-expressions/README.md b/node_modules/babel-helper-flip-expressions/README.md similarity index 100% rename from node_modules/babel-preset-babili/node_modules/babel-plugin-minify-guarded-expressions/node_modules/babel-helper-flip-expressions/README.md rename to node_modules/babel-helper-flip-expressions/README.md diff --git a/node_modules/babel-helper-flip-expressions/lib/index.js b/node_modules/babel-helper-flip-expressions/lib/index.js new file mode 100644 index 00000000000..6d9d7599e6a --- /dev/null +++ b/node_modules/babel-helper-flip-expressions/lib/index.js @@ -0,0 +1,99 @@ +"use strict"; + +var flipSeen = Symbol("flipSeen"); + +module.exports = function (t) { + return { + hasSeen(node) { + return !!node[flipSeen]; + }, + + // Takes an expressions and determines if it has + // more nodes that could benifit from flipping than not. + shouldFlip(topNode) { + var savings = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0; + + visit(topNode); + return savings > 0; + + function visit(node) { + if (t.isUnaryExpression(node, { operator: "!" })) { + savings++; + return; + } + + if (t.isLogicalExpression(node)) { + visit(node.left); + visit(node.right); + return; + } + + if (!(t.isBinaryExpression(node) && t.EQUALITY_BINARY_OPERATORS.indexOf(node.operator) > -1)) { + // Binary expressions wouldn't hurut because we know how to flip them + savings--; + } + } + }, + + flip(node, resultNotUsed) { + var lastNodeDesc = void 0; + var ret = visit(node); + + ret[flipSeen] = true; + + if (resultNotUsed && lastNodeDesc) { + var _lastNodeDesc = lastNodeDesc, + parent = _lastNodeDesc.parent, + key = _lastNodeDesc.key; + + if (parent && key && t.isUnaryExpression(parent[key], { operator: "!" })) { + parent[key] = parent[key].argument; + } + } + + return ret; + + function visit(node, parent, key) { + lastNodeDesc = { parent, key }; + + if (t.isUnaryExpression(node, { operator: "!" })) { + return node.argument; + } + + if (t.isLogicalExpression(node)) { + node.operator = node.operator === "&&" ? "||" : "&&"; + node.left = visit(node.left, node, "left"); + node.right = visit(node.right, node, "right"); + return node; + } + + if (t.isBinaryExpression(node)) { + var operator = void 0; + switch (node.operator) { + case "!==": + operator = "==="; + break; + case "===": + operator = "!=="; + break; + case "!=": + operator = "=="; + break; + case "==": + operator = "!="; + break; + } + + if (operator) { + node.operator = operator; + return node; + } + + // Falls through to unary expression + } + + return t.unaryExpression("!", node, true); + } + } + }; +}; \ No newline at end of file diff --git a/node_modules/babel-helper-flip-expressions/package.json b/node_modules/babel-helper-flip-expressions/package.json new file mode 100644 index 00000000000..a37b1d2f0b5 --- /dev/null +++ b/node_modules/babel-helper-flip-expressions/package.json @@ -0,0 +1,47 @@ +{ + "_from": "babel-helper-flip-expressions@^0.1.2", + "_id": "babel-helper-flip-expressions@0.1.2", + "_inBundle": false, + "_integrity": "sha1-d/ZlL53pxCQB2Ce9RuvSEJ4+8Yo=", + "_location": "/babel-helper-flip-expressions", + "_phantomChildren": {}, + "_requested": { + "type": "range", + "registry": true, + "raw": "babel-helper-flip-expressions@^0.1.2", + "name": "babel-helper-flip-expressions", + "escapedName": "babel-helper-flip-expressions", + "rawSpec": "^0.1.2", + "saveSpec": null, + "fetchSpec": "^0.1.2" + }, + "_requiredBy": [ + "/babel-plugin-minify-guarded-expressions", + "/babel-plugin-minify-simplify" + ], + "_resolved": "https://registry.npmjs.org/babel-helper-flip-expressions/-/babel-helper-flip-expressions-0.1.2.tgz", + "_shasum": "77f6652f9de9c42401d827bd46ebd2109e3ef18a", + "_spec": "babel-helper-flip-expressions@^0.1.2", + "_where": "/Users/chris/appc/titanium_mobile/node_modules/babel-plugin-minify-guarded-expressions", + "author": { + "name": "amasad" + }, + "bugs": { + "url": "https://github.com/babel/babili/issues" + }, + "bundleDependencies": false, + "deprecated": false, + "description": "## Installation", + "homepage": "https://github.com/babel/babili#readme", + "keywords": [ + "babel-plugin" + ], + "license": "MIT", + "main": "lib/index.js", + "name": "babel-helper-flip-expressions", + "repository": { + "type": "git", + "url": "https://github.com/babel/babili/tree/master/packages/babel-helper-flip-expressions" + }, + "version": "0.1.2" +} diff --git a/node_modules/babel-preset-babili/node_modules/babel-plugin-minify-builtins/node_modules/babel-helper-evaluate-path/.npmignore b/node_modules/babel-helper-is-nodes-equiv/.npmignore similarity index 100% rename from node_modules/babel-preset-babili/node_modules/babel-plugin-minify-builtins/node_modules/babel-helper-evaluate-path/.npmignore rename to node_modules/babel-helper-is-nodes-equiv/.npmignore diff --git a/node_modules/babel-preset-babili/node_modules/babel-plugin-minify-simplify/node_modules/babel-helper-is-nodes-equiv/README.md b/node_modules/babel-helper-is-nodes-equiv/README.md similarity index 100% rename from node_modules/babel-preset-babili/node_modules/babel-plugin-minify-simplify/node_modules/babel-helper-is-nodes-equiv/README.md rename to node_modules/babel-helper-is-nodes-equiv/README.md diff --git a/node_modules/babel-preset-babili/node_modules/babel-plugin-minify-simplify/node_modules/babel-helper-is-nodes-equiv/lib/index.js b/node_modules/babel-helper-is-nodes-equiv/lib/index.js similarity index 100% rename from node_modules/babel-preset-babili/node_modules/babel-plugin-minify-simplify/node_modules/babel-helper-is-nodes-equiv/lib/index.js rename to node_modules/babel-helper-is-nodes-equiv/lib/index.js diff --git a/node_modules/babel-helper-is-nodes-equiv/package.json b/node_modules/babel-helper-is-nodes-equiv/package.json new file mode 100644 index 00000000000..5b6dd6543a5 --- /dev/null +++ b/node_modules/babel-helper-is-nodes-equiv/package.json @@ -0,0 +1,48 @@ +{ + "_from": "babel-helper-is-nodes-equiv@^0.0.1", + "_id": "babel-helper-is-nodes-equiv@0.0.1", + "_inBundle": false, + "_integrity": "sha1-NOmzALFHnd2Y7HfqC76TQt/jloQ=", + "_location": "/babel-helper-is-nodes-equiv", + "_phantomChildren": {}, + "_requested": { + "type": "range", + "registry": true, + "raw": "babel-helper-is-nodes-equiv@^0.0.1", + "name": "babel-helper-is-nodes-equiv", + "escapedName": "babel-helper-is-nodes-equiv", + "rawSpec": "^0.0.1", + "saveSpec": null, + "fetchSpec": "^0.0.1" + }, + "_requiredBy": [ + "/babel-plugin-minify-simplify" + ], + "_resolved": "https://registry.npmjs.org/babel-helper-is-nodes-equiv/-/babel-helper-is-nodes-equiv-0.0.1.tgz", + "_shasum": "34e9b300b1479ddd98ec77ea0bbe9342dfe39684", + "_spec": "babel-helper-is-nodes-equiv@^0.0.1", + "_where": "/Users/chris/appc/titanium_mobile/node_modules/babel-plugin-minify-simplify", + "author": { + "name": "amasad" + }, + "bugs": { + "url": "https://github.com/babel/babili/issues" + }, + "bundleDependencies": false, + "dependencies": {}, + "deprecated": false, + "description": "## Installation", + "devDependencies": {}, + "homepage": "https://github.com/babel/babili#readme", + "keywords": [ + "babel-plugin" + ], + "license": "MIT", + "main": "lib/index.js", + "name": "babel-helper-is-nodes-equiv", + "repository": { + "type": "git", + "url": "https://github.com/babel/babili/tree/master/packages/babel-helper-is-nodes-equiv" + }, + "version": "0.0.1" +} diff --git a/node_modules/babel-preset-babili/node_modules/babel-plugin-minify-constant-folding/.npmignore b/node_modules/babel-helper-is-void-0/.npmignore similarity index 100% rename from node_modules/babel-preset-babili/node_modules/babel-plugin-minify-constant-folding/.npmignore rename to node_modules/babel-helper-is-void-0/.npmignore diff --git a/node_modules/babel-helper-is-void-0/README.md b/node_modules/babel-helper-is-void-0/README.md new file mode 100644 index 00000000000..858cdd8a5a8 --- /dev/null +++ b/node_modules/babel-helper-is-void-0/README.md @@ -0,0 +1,7 @@ +# babel-helper-is-void-0 + +## Installation + +```sh +npm install babel-helper-is-void-0 +``` diff --git a/node_modules/babel-preset-babili/node_modules/babel-plugin-minify-flip-comparisons/node_modules/babel-helper-is-void-0/lib/index.js b/node_modules/babel-helper-is-void-0/lib/index.js similarity index 100% rename from node_modules/babel-preset-babili/node_modules/babel-plugin-minify-flip-comparisons/node_modules/babel-helper-is-void-0/lib/index.js rename to node_modules/babel-helper-is-void-0/lib/index.js diff --git a/node_modules/babel-helper-is-void-0/package.json b/node_modules/babel-helper-is-void-0/package.json new file mode 100644 index 00000000000..fcb9bae11d1 --- /dev/null +++ b/node_modules/babel-helper-is-void-0/package.json @@ -0,0 +1,49 @@ +{ + "_from": "babel-helper-is-void-0@^0.1.1", + "_id": "babel-helper-is-void-0@0.1.1", + "_inBundle": false, + "_integrity": "sha1-cvIaOrugvvODf5F0/KcxrtmgKIg=", + "_location": "/babel-helper-is-void-0", + "_phantomChildren": {}, + "_requested": { + "type": "range", + "registry": true, + "raw": "babel-helper-is-void-0@^0.1.1", + "name": "babel-helper-is-void-0", + "escapedName": "babel-helper-is-void-0", + "rawSpec": "^0.1.1", + "saveSpec": null, + "fetchSpec": "^0.1.1" + }, + "_requiredBy": [ + "/babel-plugin-minify-flip-comparisons", + "/babel-plugin-minify-type-constructors" + ], + "_resolved": "https://registry.npmjs.org/babel-helper-is-void-0/-/babel-helper-is-void-0-0.1.1.tgz", + "_shasum": "72f21a3abba0bef3837f9174fca731aed9a02888", + "_spec": "babel-helper-is-void-0@^0.1.1", + "_where": "/Users/chris/appc/titanium_mobile/node_modules/babel-plugin-minify-flip-comparisons", + "author": { + "name": "amasad" + }, + "bugs": { + "url": "https://github.com/babel/babili/issues" + }, + "bundleDependencies": false, + "dependencies": {}, + "deprecated": false, + "description": "## Installation", + "devDependencies": {}, + "homepage": "https://github.com/babel/babili#readme", + "keywords": [ + "babel-plugin" + ], + "license": "MIT", + "main": "lib/index.js", + "name": "babel-helper-is-void-0", + "repository": { + "type": "git", + "url": "https://github.com/babel/babili/tree/master/packages/babel-helper-is-void-0" + }, + "version": "0.1.1" +} diff --git a/node_modules/babel-preset-babili/node_modules/babel-plugin-minify-dead-code-elimination/node_modules/babel-helper-mark-eval-scopes/README.md b/node_modules/babel-helper-mark-eval-scopes/README.md similarity index 100% rename from node_modules/babel-preset-babili/node_modules/babel-plugin-minify-dead-code-elimination/node_modules/babel-helper-mark-eval-scopes/README.md rename to node_modules/babel-helper-mark-eval-scopes/README.md diff --git a/node_modules/babel-helper-mark-eval-scopes/__tests__/helper-mark-eval-scopes-test.js b/node_modules/babel-helper-mark-eval-scopes/__tests__/helper-mark-eval-scopes-test.js new file mode 100644 index 00000000000..18fed9900dd --- /dev/null +++ b/node_modules/babel-helper-mark-eval-scopes/__tests__/helper-mark-eval-scopes-test.js @@ -0,0 +1,48 @@ +jest.autoMockOff(); + +const babel = require("babel-core"); +const helper = require("../src"); + +function getPath(source) { + let path; + + babel.transform(source, { + babelrc: false, + plugins: [ + function({ traverse }) { + traverse.clearCache(); + return { + visitor: { + Program(programPath) { + path = programPath; + } + } + }; + } + ] + }); + + return path; +} + +describe("babel-helper-mark-eval-scopes", () => { + it("getEvalScopes - should give a set of scopes which contains eval", () => { + const source = ` + function foo() { + function bar() { + eval(";"); + } + function baz() { + noeval(); + } + } + `; + + const program = getPath(source); + const evalScopes = [...helper.getEvalScopes(program)]; + + expect(evalScopes).toContain(program.scope); + expect(evalScopes).toContain(program.get("body.0.body.body.0").scope); + expect(evalScopes).not.toContain(program.get("body.0.body.body.1").scope); + }); +}); diff --git a/node_modules/babel-preset-babili/node_modules/babel-plugin-minify-dead-code-elimination/node_modules/babel-helper-mark-eval-scopes/lib/index.js b/node_modules/babel-helper-mark-eval-scopes/lib/index.js similarity index 100% rename from node_modules/babel-preset-babili/node_modules/babel-plugin-minify-dead-code-elimination/node_modules/babel-helper-mark-eval-scopes/lib/index.js rename to node_modules/babel-helper-mark-eval-scopes/lib/index.js diff --git a/node_modules/babel-helper-mark-eval-scopes/package.json b/node_modules/babel-helper-mark-eval-scopes/package.json new file mode 100644 index 00000000000..1464be896ca --- /dev/null +++ b/node_modules/babel-helper-mark-eval-scopes/package.json @@ -0,0 +1,50 @@ +{ + "_from": "babel-helper-mark-eval-scopes@^0.1.1", + "_id": "babel-helper-mark-eval-scopes@0.1.1", + "_inBundle": false, + "_integrity": "sha1-RVQ0Xt+fJUlCe9IJjlMCU/ivKZI=", + "_location": "/babel-helper-mark-eval-scopes", + "_phantomChildren": {}, + "_requested": { + "type": "range", + "registry": true, + "raw": "babel-helper-mark-eval-scopes@^0.1.1", + "name": "babel-helper-mark-eval-scopes", + "escapedName": "babel-helper-mark-eval-scopes", + "rawSpec": "^0.1.1", + "saveSpec": null, + "fetchSpec": "^0.1.1" + }, + "_requiredBy": [ + "/babel-plugin-minify-dead-code-elimination", + "/babel-plugin-minify-mangle-names" + ], + "_resolved": "https://registry.npmjs.org/babel-helper-mark-eval-scopes/-/babel-helper-mark-eval-scopes-0.1.1.tgz", + "_shasum": "4554345edf9f2549427bd2098e530253f8af2992", + "_spec": "babel-helper-mark-eval-scopes@^0.1.1", + "_where": "/Users/chris/appc/titanium_mobile/node_modules/babel-plugin-minify-dead-code-elimination", + "author": { + "name": "boopathi" + }, + "bugs": { + "url": "https://github.com/babel/babili/issues" + }, + "bundleDependencies": false, + "dependencies": {}, + "deprecated": false, + "description": "Mark scopes for deopt which contain a direct eval call", + "devDependencies": {}, + "homepage": "https://github.com/babel/babili#readme", + "keywords": [ + "babel-plugin", + "babili" + ], + "license": "MIT", + "main": "lib/index.js", + "name": "babel-helper-mark-eval-scopes", + "repository": { + "type": "git", + "url": "https://github.com/babel/babili/tree/master/packages/babel-helper-mark-eval-scopes" + }, + "version": "0.1.1" +} diff --git a/node_modules/babel-helper-mark-eval-scopes/src/index.js b/node_modules/babel-helper-mark-eval-scopes/src/index.js new file mode 100644 index 00000000000..f1108e9c254 --- /dev/null +++ b/node_modules/babel-helper-mark-eval-scopes/src/index.js @@ -0,0 +1,56 @@ +"use strict"; + +const EVAL_SCOPE_MARKER = Symbol("evalInScope"); + +module.exports = { + EVAL_SCOPE_MARKER, + getEvalScopes, + markEvalScopes, + isMarked, + hasEval +}; + +function getEvalScopes(path) { + const evalScopes = new Set(); + + function add(scope) { + let evalScope = scope; + do { + evalScopes.add(evalScope); + } while ((evalScope = evalScope.parent)); + } + + path.traverse({ + CallExpression(evalPath) { + const callee = evalPath.get("callee"); + + if ( + callee.isIdentifier() && + callee.node.name === "eval" && + !callee.scope.getBinding("eval") + ) { + add(callee.scope); + } + } + }); + + return evalScopes; +} + +function markEvalScopes(path, key = EVAL_SCOPE_MARKER) { + const evalScopes = getEvalScopes(path); + [...evalScopes].forEach(scope => { + scope[key] = true; + }); +} + +function isMarked(scope, key = EVAL_SCOPE_MARKER) { + return Object.prototype.hasOwnProperty.call(scope, key); +} + +function hasEval(scope, key = EVAL_SCOPE_MARKER) { + if (!isMarked(scope, key)) { + markEvalScopes(scope, key); + } + return scope[key]; +} diff --git a/node_modules/babel-preset-babili/node_modules/babel-plugin-minify-constant-folding/node_modules/babel-helper-evaluate-path/.npmignore b/node_modules/babel-helper-remove-or-void/.npmignore similarity index 100% rename from node_modules/babel-preset-babili/node_modules/babel-plugin-minify-constant-folding/node_modules/babel-helper-evaluate-path/.npmignore rename to node_modules/babel-helper-remove-or-void/.npmignore diff --git a/node_modules/babel-helper-remove-or-void/README.md b/node_modules/babel-helper-remove-or-void/README.md new file mode 100644 index 00000000000..ec1770b8136 --- /dev/null +++ b/node_modules/babel-helper-remove-or-void/README.md @@ -0,0 +1,7 @@ +# babel-helper-remove-or-void + +## Installation + +```sh +npm install babel-helper-remove-or-void +``` diff --git a/node_modules/babel-preset-babili/node_modules/babel-plugin-minify-dead-code-elimination/node_modules/babel-helper-remove-or-void/lib/index.js b/node_modules/babel-helper-remove-or-void/lib/index.js similarity index 100% rename from node_modules/babel-preset-babili/node_modules/babel-plugin-minify-dead-code-elimination/node_modules/babel-helper-remove-or-void/lib/index.js rename to node_modules/babel-helper-remove-or-void/lib/index.js diff --git a/node_modules/babel-helper-remove-or-void/package.json b/node_modules/babel-helper-remove-or-void/package.json new file mode 100644 index 00000000000..201a97c0442 --- /dev/null +++ b/node_modules/babel-helper-remove-or-void/package.json @@ -0,0 +1,48 @@ +{ + "_from": "babel-helper-remove-or-void@^0.1.1", + "_id": "babel-helper-remove-or-void@0.1.1", + "_inBundle": false, + "_integrity": "sha1-nX4YVtxvr8tBsoOkFnMNwYRPZtc=", + "_location": "/babel-helper-remove-or-void", + "_phantomChildren": {}, + "_requested": { + "type": "range", + "registry": true, + "raw": "babel-helper-remove-or-void@^0.1.1", + "name": "babel-helper-remove-or-void", + "escapedName": "babel-helper-remove-or-void", + "rawSpec": "^0.1.1", + "saveSpec": null, + "fetchSpec": "^0.1.1" + }, + "_requiredBy": [ + "/babel-plugin-minify-dead-code-elimination" + ], + "_resolved": "https://registry.npmjs.org/babel-helper-remove-or-void/-/babel-helper-remove-or-void-0.1.1.tgz", + "_shasum": "9d7e1856dc6fafcb41b283a416730dc1844f66d7", + "_spec": "babel-helper-remove-or-void@^0.1.1", + "_where": "/Users/chris/appc/titanium_mobile/node_modules/babel-plugin-minify-dead-code-elimination", + "author": { + "name": "amasad" + }, + "bugs": { + "url": "https://github.com/babel/babili/issues" + }, + "bundleDependencies": false, + "dependencies": {}, + "deprecated": false, + "description": "## Installation", + "devDependencies": {}, + "homepage": "https://github.com/babel/babili#readme", + "keywords": [ + "babel-plugin" + ], + "license": "MIT", + "main": "lib/index.js", + "name": "babel-helper-remove-or-void", + "repository": { + "type": "git", + "url": "https://github.com/babel/babili/tree/master/packages/babel-helper-remove-or-void" + }, + "version": "0.1.1" +} diff --git a/node_modules/babel-preset-babili/node_modules/babel-plugin-minify-dead-code-elimination/.npmignore b/node_modules/babel-helper-to-multiple-sequence-expressions/.npmignore similarity index 100% rename from node_modules/babel-preset-babili/node_modules/babel-plugin-minify-dead-code-elimination/.npmignore rename to node_modules/babel-helper-to-multiple-sequence-expressions/.npmignore diff --git a/node_modules/babel-preset-babili/node_modules/babel-plugin-minify-simplify/node_modules/babel-helper-to-multiple-sequence-expressions/README.md b/node_modules/babel-helper-to-multiple-sequence-expressions/README.md similarity index 100% rename from node_modules/babel-preset-babili/node_modules/babel-plugin-minify-simplify/node_modules/babel-helper-to-multiple-sequence-expressions/README.md rename to node_modules/babel-helper-to-multiple-sequence-expressions/README.md diff --git a/node_modules/babel-preset-babili/node_modules/babel-plugin-minify-simplify/node_modules/babel-helper-to-multiple-sequence-expressions/lib/index.js b/node_modules/babel-helper-to-multiple-sequence-expressions/lib/index.js similarity index 100% rename from node_modules/babel-preset-babili/node_modules/babel-plugin-minify-simplify/node_modules/babel-helper-to-multiple-sequence-expressions/lib/index.js rename to node_modules/babel-helper-to-multiple-sequence-expressions/lib/index.js diff --git a/node_modules/babel-helper-to-multiple-sequence-expressions/package.json b/node_modules/babel-helper-to-multiple-sequence-expressions/package.json new file mode 100644 index 00000000000..a5177a9ac49 --- /dev/null +++ b/node_modules/babel-helper-to-multiple-sequence-expressions/package.json @@ -0,0 +1,48 @@ +{ + "_from": "babel-helper-to-multiple-sequence-expressions@^0.1.1", + "_id": "babel-helper-to-multiple-sequence-expressions@0.1.1", + "_inBundle": false, + "_integrity": "sha1-XxuDKznkrPlU6RN/AlE5XHEZazU=", + "_location": "/babel-helper-to-multiple-sequence-expressions", + "_phantomChildren": {}, + "_requested": { + "type": "range", + "registry": true, + "raw": "babel-helper-to-multiple-sequence-expressions@^0.1.1", + "name": "babel-helper-to-multiple-sequence-expressions", + "escapedName": "babel-helper-to-multiple-sequence-expressions", + "rawSpec": "^0.1.1", + "saveSpec": null, + "fetchSpec": "^0.1.1" + }, + "_requiredBy": [ + "/babel-plugin-minify-simplify" + ], + "_resolved": "https://registry.npmjs.org/babel-helper-to-multiple-sequence-expressions/-/babel-helper-to-multiple-sequence-expressions-0.1.1.tgz", + "_shasum": "5f1b832b39e4acf954e9137f0251395c71196b35", + "_spec": "babel-helper-to-multiple-sequence-expressions@^0.1.1", + "_where": "/Users/chris/appc/titanium_mobile/node_modules/babel-plugin-minify-simplify", + "author": { + "name": "amasad" + }, + "bugs": { + "url": "https://github.com/babel/babili/issues" + }, + "bundleDependencies": false, + "dependencies": {}, + "deprecated": false, + "description": "## Installation", + "devDependencies": {}, + "homepage": "https://github.com/babel/babili#readme", + "keywords": [ + "babel-plugin" + ], + "license": "MIT", + "main": "lib/index.js", + "name": "babel-helper-to-multiple-sequence-expressions", + "repository": { + "type": "git", + "url": "https://github.com/babel/babili/tree/master/packages/babel-helper-to-multiple-sequence-expressions" + }, + "version": "0.1.1" +} diff --git a/node_modules/babel-preset-babili/node_modules/babel-plugin-minify-dead-code-elimination/node_modules/babel-helper-remove-or-void/.npmignore b/node_modules/babel-plugin-minify-builtins/.npmignore similarity index 100% rename from node_modules/babel-preset-babili/node_modules/babel-plugin-minify-dead-code-elimination/node_modules/babel-helper-remove-or-void/.npmignore rename to node_modules/babel-plugin-minify-builtins/.npmignore diff --git a/node_modules/babel-preset-babili/node_modules/babel-plugin-minify-builtins/README.md b/node_modules/babel-plugin-minify-builtins/README.md similarity index 100% rename from node_modules/babel-preset-babili/node_modules/babel-plugin-minify-builtins/README.md rename to node_modules/babel-plugin-minify-builtins/README.md diff --git a/node_modules/babel-plugin-minify-builtins/lib/index.js b/node_modules/babel-plugin-minify-builtins/lib/index.js new file mode 100644 index 00000000000..7b68e52a6bb --- /dev/null +++ b/node_modules/babel-plugin-minify-builtins/lib/index.js @@ -0,0 +1,351 @@ +"use strict"; + +var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }(); + +var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); + +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } + +var evaluate = require("babel-helper-evaluate-path"); +// Assuming all the static methods from below array are side effect free evaluation +// except Math.random +var VALID_CALLEES = ["String", "Number", "Math"]; +var INVALID_METHODS = ["random"]; + +module.exports = function (_ref) { + var t = _ref.types; + + var BuiltInReplacer = function () { + function BuiltInReplacer(program) { + _classCallCheck(this, BuiltInReplacer); + + this.program = program; + // map; + this.pathsToUpdate = new Map(); + } + + _createClass(BuiltInReplacer, [{ + key: "run", + value: function run() { + this.collect(); + this.replace(); + } + }, { + key: "collect", + value: function collect() { + var context = this; + + var collectVisitor = { + MemberExpression(path) { + if (path.parentPath.isCallExpression()) { + return; + } + + if (!isComputed(path) && isBuiltin(path) && !path.getFunctionParent().isProgram()) { + var expName = memberToString(path.node); + addToMap(context.pathsToUpdate, expName, path); + } + }, + + CallExpression: { + exit(path) { + var callee = path.get("callee"); + if (!callee.isMemberExpression()) { + return; + } + + // computed property should be not optimized + // Math[max]() -> Math.max() + if (!isComputed(callee) && isBuiltin(callee)) { + var result = evaluate(path); + // deopt when we have side effecty evaluate-able arguments + // Math.max(foo(), 1) --> untouched + // Math.floor(1) --> 1 + if (result.confident && hasPureArgs(path)) { + path.replaceWith(t.valueToNode(result.value)); + } else if (!callee.getFunctionParent().isProgram()) { + var expName = memberToString(callee.node); + addToMap(context.pathsToUpdate, expName, callee); + } + } + } + } + }; + + this.program.traverse(collectVisitor); + } + }, { + key: "replace", + value: function replace() { + var _iteratorNormalCompletion = true; + var _didIteratorError = false; + var _iteratorError = undefined; + + try { + for (var _iterator = this.pathsToUpdate[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { + var _ref2 = _step.value; + + var _ref3 = _slicedToArray(_ref2, 2); + + var expName = _ref3[0]; + var paths = _ref3[1]; + + // transform only if there is more than 1 occurence + if (paths.length <= 1) { + continue; + } + + var segmentsMap = getSegmentedSubPaths(paths); + var _iteratorNormalCompletion2 = true; + var _didIteratorError2 = false; + var _iteratorError2 = undefined; + + try { + for (var _iterator2 = segmentsMap[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) { + var _ref4 = _step2.value; + + var _ref5 = _slicedToArray(_ref4, 2); + + var parent = _ref5[0]; + var subpaths = _ref5[1]; + + if (subpaths.length <= 1) { + continue; + } + var uniqueIdentifier = parent.scope.generateUidIdentifier(expName); + var newNode = t.variableDeclaration("var", [t.variableDeclarator(uniqueIdentifier, subpaths[0].node)]); + + var _iteratorNormalCompletion3 = true; + var _didIteratorError3 = false; + var _iteratorError3 = undefined; + + try { + for (var _iterator3 = subpaths[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) { + var path = _step3.value; + + path.replaceWith(t.clone(uniqueIdentifier)); + } + // hoist the created var to the top of the function scope + } catch (err) { + _didIteratorError3 = true; + _iteratorError3 = err; + } finally { + try { + if (!_iteratorNormalCompletion3 && _iterator3.return) { + _iterator3.return(); + } + } finally { + if (_didIteratorError3) { + throw _iteratorError3; + } + } + } + + parent.get("body").unshiftContainer("body", newNode); + } + } catch (err) { + _didIteratorError2 = true; + _iteratorError2 = err; + } finally { + try { + if (!_iteratorNormalCompletion2 && _iterator2.return) { + _iterator2.return(); + } + } finally { + if (_didIteratorError2) { + throw _iteratorError2; + } + } + } + } + } catch (err) { + _didIteratorError = true; + _iteratorError = err; + } finally { + try { + if (!_iteratorNormalCompletion && _iterator.return) { + _iterator.return(); + } + } finally { + if (_didIteratorError) { + throw _iteratorError; + } + } + } + } + }]); + + return BuiltInReplacer; + }(); + + return { + name: "minify-builtins", + visitor: { + Program(path) { + var builtInReplacer = new BuiltInReplacer(path); + builtInReplacer.run(); + } + } + }; + + function memberToString(memberExpr) { + var object = memberExpr.object, + property = memberExpr.property; + + var result = ""; + + if (t.isIdentifier(object)) result += object.name; + if (t.isMemberExpression(object)) result += memberToString(object); + if (t.isIdentifier(property)) result += property.name; + + return result; + } + + function isBuiltin(memberExpr) { + var _memberExpr$node = memberExpr.node, + object = _memberExpr$node.object, + property = _memberExpr$node.property; + + + if (t.isIdentifier(object) && t.isIdentifier(property) && VALID_CALLEES.indexOf(object.name) >= 0 && INVALID_METHODS.indexOf(property.name) < 0) { + return true; + } + return false; + } +}; + +function addToMap(map, key, value) { + if (!map.has(key)) { + map.set(key, []); + } + map.get(key).push(value); +} + +// Creates a segmented map that contains the earliest common Ancestor +// as the key and array of subpaths that are descendats of the LCA as value +function getSegmentedSubPaths(paths) { + var segments = new Map(); + + // Get earliest Path in tree where paths intersect + paths[0].getDeepestCommonAncestorFrom(paths, function (lastCommon, index, ancestries) { + // found the LCA + if (!lastCommon.isProgram()) { + var fnParent = void 0; + if (lastCommon.isFunction() && lastCommon.get("body").isBlockStatement()) { + segments.set(lastCommon, paths); + return; + } else if (!(fnParent = lastCommon.getFunctionParent()).isProgram() && fnParent.get("body").isBlockStatement()) { + segments.set(fnParent, paths); + return; + } + } + // Deopt and construct segments otherwise + + var _loop = function _loop(ancestor) { + var fnPath = getChildFuncion(ancestor); + if (fnPath === void 0) { + return "continue"; + } + var validDescendants = paths.filter(function (p) { + return p.isDescendant(fnPath); + }); + segments.set(fnPath, validDescendants); + }; + + var _iteratorNormalCompletion4 = true; + var _didIteratorError4 = false; + var _iteratorError4 = undefined; + + try { + for (var _iterator4 = ancestries[Symbol.iterator](), _step4; !(_iteratorNormalCompletion4 = (_step4 = _iterator4.next()).done); _iteratorNormalCompletion4 = true) { + var ancestor = _step4.value; + + var _ret = _loop(ancestor); + + if (_ret === "continue") continue; + } + } catch (err) { + _didIteratorError4 = true; + _iteratorError4 = err; + } finally { + try { + if (!_iteratorNormalCompletion4 && _iterator4.return) { + _iterator4.return(); + } + } finally { + if (_didIteratorError4) { + throw _iteratorError4; + } + } + } + }); + return segments; +} + +function getChildFuncion() { + var ancestors = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : []; + var _iteratorNormalCompletion5 = true; + var _didIteratorError5 = false; + var _iteratorError5 = undefined; + + try { + for (var _iterator5 = ancestors[Symbol.iterator](), _step5; !(_iteratorNormalCompletion5 = (_step5 = _iterator5.next()).done); _iteratorNormalCompletion5 = true) { + var path = _step5.value; + + if (path.isFunction() && path.get("body").isBlockStatement()) { + return path; + } + } + } catch (err) { + _didIteratorError5 = true; + _iteratorError5 = err; + } finally { + try { + if (!_iteratorNormalCompletion5 && _iterator5.return) { + _iterator5.return(); + } + } finally { + if (_didIteratorError5) { + throw _iteratorError5; + } + } + } +} + +function hasPureArgs(path) { + var args = path.get("arguments"); + var _iteratorNormalCompletion6 = true; + var _didIteratorError6 = false; + var _iteratorError6 = undefined; + + try { + for (var _iterator6 = args[Symbol.iterator](), _step6; !(_iteratorNormalCompletion6 = (_step6 = _iterator6.next()).done); _iteratorNormalCompletion6 = true) { + var arg = _step6.value; + + if (!arg.isPure()) { + return false; + } + } + } catch (err) { + _didIteratorError6 = true; + _iteratorError6 = err; + } finally { + try { + if (!_iteratorNormalCompletion6 && _iterator6.return) { + _iterator6.return(); + } + } finally { + if (_didIteratorError6) { + throw _iteratorError6; + } + } + } + + return true; +} + +function isComputed(path) { + var node = path.node; + + return node.computed; +} \ No newline at end of file diff --git a/node_modules/babel-plugin-minify-builtins/package.json b/node_modules/babel-plugin-minify-builtins/package.json new file mode 100644 index 00000000000..a987f45bc75 --- /dev/null +++ b/node_modules/babel-plugin-minify-builtins/package.json @@ -0,0 +1,52 @@ +{ + "_from": "babel-plugin-minify-builtins@^0.1.3", + "_id": "babel-plugin-minify-builtins@0.1.3", + "_inBundle": false, + "_integrity": "sha1-TyGn3LUfkaBOpx1H/w6OOwX+wCE=", + "_location": "/babel-plugin-minify-builtins", + "_phantomChildren": {}, + "_requested": { + "type": "range", + "registry": true, + "raw": "babel-plugin-minify-builtins@^0.1.3", + "name": "babel-plugin-minify-builtins", + "escapedName": "babel-plugin-minify-builtins", + "rawSpec": "^0.1.3", + "saveSpec": null, + "fetchSpec": "^0.1.3" + }, + "_requiredBy": [ + "/node-titanium-sdk/babel-preset-babili" + ], + "_resolved": "https://registry.npmjs.org/babel-plugin-minify-builtins/-/babel-plugin-minify-builtins-0.1.3.tgz", + "_shasum": "4f21a7dcb51f91a04ea71d47ff0e8e3b05fec021", + "_spec": "babel-plugin-minify-builtins@^0.1.3", + "_where": "/Users/chris/appc/titanium_mobile/node_modules/node-titanium-sdk/node_modules/babel-preset-babili", + "author": { + "name": "Vignesh Shanmugam", + "email": "vignesh.shanmugam22@gmail.com", + "url": "https://vigneshh.in" + }, + "bugs": { + "url": "https://github.com/babel/babili/issues" + }, + "bundleDependencies": false, + "dependencies": { + "babel-helper-evaluate-path": "^0.1.0" + }, + "deprecated": false, + "description": "Minify Standard built-in Objects", + "homepage": "https://github.com/babel/babili#readme", + "keywords": [ + "babel-plugin", + "transform-built-ins" + ], + "license": "MIT", + "main": "lib/index.js", + "name": "babel-plugin-minify-builtins", + "repository": { + "type": "git", + "url": "https://github.com/babel/babili/tree/master/packages/babel-plugin-minify-builtins" + }, + "version": "0.1.3" +} diff --git a/node_modules/babel-preset-babili/node_modules/babel-plugin-minify-flip-comparisons/.npmignore b/node_modules/babel-plugin-minify-constant-folding/.npmignore similarity index 100% rename from node_modules/babel-preset-babili/node_modules/babel-plugin-minify-flip-comparisons/.npmignore rename to node_modules/babel-plugin-minify-constant-folding/.npmignore diff --git a/node_modules/babel-plugin-minify-constant-folding/README.md b/node_modules/babel-plugin-minify-constant-folding/README.md new file mode 100644 index 00000000000..6e4eeb2dd5b --- /dev/null +++ b/node_modules/babel-plugin-minify-constant-folding/README.md @@ -0,0 +1,86 @@ +# babel-plugin-minify-constant-folding + +Tries to evaluate expressions and inline the result. + +## Example + +**In** + +```javascript +"a" + "b" +2 * 3; +4 | 3; +"b" + a + "c" + "d" + g + z + "f" + "h" + "i" + +[a, b, c].concat([d, e], f, g, [h]); +["a", "b", "c"].join(); +["a", "b", "c"].join('@'); +[1, 2, 3].length; +[1, 2, 3][1]; +[1, 2, 3].shift(); +[1, 2, 3].slice(0, 2); +[a, b, c].pop(); +[a, b, c].reverse(); +"a,b,c".split(","); +"abc"[0]; +"abc".charAt(); +"abc".charAt(1); +"abc".length; +``` + +**Out** + +```javascript +"ab"; +6; +7; +"b" + a + "cd" + g + z + "fhi"; + +[a, b, c, d, e, f, g, h]; +"a,b,c"; +"a@b@c"; +3; +2; +2; +[1, 2]; +c; +[c, b, a]; +["a", "b", "c"]; +"a"; +"a"; +"a"; +"b"; +3; +``` + +## Installation + +```sh +npm install babel-plugin-minify-constant-folding +``` + +## Usage + +### Via `.babelrc` (Recommended) + +**.babelrc** + +```json +{ + "plugins": ["minify-constant-folding"] +} +``` + +### Via CLI + +```sh +babel --plugins minify-constant-folding script.js +``` + +### Via Node API + +```javascript +require("babel-core").transform("code", { + plugins: ["minify-constant-folding"] +}); +``` diff --git a/node_modules/babel-plugin-minify-constant-folding/lib/index.js b/node_modules/babel-plugin-minify-constant-folding/lib/index.js new file mode 100644 index 00000000000..02ff024a805 --- /dev/null +++ b/node_modules/babel-plugin-minify-constant-folding/lib/index.js @@ -0,0 +1,183 @@ +"use strict"; + +function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } } + +var evaluate = require("babel-helper-evaluate-path"); + +var _require = require("./replacements"), + FALLBACK_HANDLER = _require.FALLBACK_HANDLER; + +function getName(member) { + if (member.computed) { + switch (member.property.type) { + case "StringLiteral": + case "NumericLiteral": + return member.property.value; + case "TemplateLiteral": + return; + } + } else { + return member.property.name; + } +} + +function swap(path, member, handlers) { + var key = getName(member); + if (key === undefined) return; + var handler = handlers[key]; + if (typeof handler !== "function" || !Object.hasOwnProperty.call(handlers, key)) { + if (typeof handlers[FALLBACK_HANDLER] === "function") { + handler = handlers[FALLBACK_HANDLER].bind(member.object, key); + } else { + return false; + } + } + + for (var _len = arguments.length, args = Array(_len > 3 ? _len - 3 : 0), _key = 3; _key < _len; _key++) { + args[_key - 3] = arguments[_key]; + } + + var replacement = handler.apply(member.object, args); + if (replacement) { + path.replaceWith(replacement); + return true; + } + return false; +} + +module.exports = function (babel) { + var replacements = require("./replacements.js")(babel); + var seen = Symbol("seen"); + var t = babel.types, + traverse = babel.traverse; + + + return { + name: "minify-constant-folding", + visitor: { + // Evaluate string expressions that are next to each other + // but are not actually a binary expression. + // "a" + b + "c" + "d" -> "a" + b + "cd" + BinaryExpression(path) { + var literal = void 0, + bin = void 0; + if (path.get("right").isStringLiteral()) { + literal = path.get("right"); + if (path.get("left").isBinaryExpression({ operator: "+" })) { + bin = path.get("left"); + } else { + return; + } + } else if (path.get("left").isStringLiteral()) { + literal = path.get("left"); + if (path.get("right").isBinaryExpression({ operator: "+" })) { + bin = path.get("right"); + } else { + return; + } + } else { + return; + } + + var relevant = getLeaf(bin, literal.key); + + if (!relevant) { + return; + } + + var value = literal.key === "right" ? relevant.node.value + literal.node.value : literal.node.value + relevant.node.value; + + relevant.replaceWith(t.stringLiteral(value)); + path.replaceWith(bin.node); + + function getLeaf(path, direction) { + if (path.isStringLiteral()) { + return path; + } else if (path.isBinaryExpression({ operator: "+" })) { + return getLeaf(path.get(direction), direction); + } + } + }, + + // TODO: look into evaluating binding too (could result in more code, but gzip?) + Expression(path) { + var node = path.node; + + + if (node[seen]) { + return; + } + + if (path.isLiteral()) { + return; + } + + if (!path.isPure()) { + return; + } + + if (traverse.hasType(node, path.scope, "Identifier", t.FUNCTION_TYPES)) { + return; + } + + // -0 maybe compared via dividing and then checking against -Infinity + // Also -X will always be -X. + if (t.isUnaryExpression(node, { operator: "-" }) && t.isNumericLiteral(node.argument)) { + return; + } + + // We have a transform that converts true/false to !0/!1 + if (t.isUnaryExpression(node, { operator: "!" }) && t.isNumericLiteral(node.argument)) { + if (node.argument.value === 0 || node.argument.value === 1) { + return; + } + } + + // void 0 is used for undefined. + if (t.isUnaryExpression(node, { operator: "void" }) && t.isNumericLiteral(node.argument, { value: 0 })) { + return; + } + + var res = evaluate(path); + if (res.confident) { + // Avoid fractions because they can be longer than the original expression. + // There is also issues with number percision? + if (typeof res.value === "number" && !Number.isInteger(res.value)) { + return; + } + + // Preserve -0 + if (typeof res.value === "number" && res.value === 0) { + if (1 / res.value === -Infinity) { + var _node2 = t.unaryExpression("-", t.numericLiteral(0), true); + _node2[seen] = true; + path.replaceWith(_node2); + return; + } + } + + var _node = t.valueToNode(res.value); + _node[seen] = true; + path.replaceWith(_node); + } + }, + CallExpression(path) { + var node = path.node; + var member = node.callee; + + if (t.isMemberExpression(member)) { + var helpers = replacements[member.object.type]; + if (!helpers || !helpers.calls) return; + swap.apply(undefined, [path, member, helpers.calls].concat(_toConsumableArray(node.arguments))); + } + }, + MemberExpression(path) { + var member = path.node; + + var helpers = replacements[member.object.type]; + if (!helpers || !helpers.members) return; + swap(path, member, helpers.members); + } + } + }; +}; \ No newline at end of file diff --git a/node_modules/babel-plugin-minify-constant-folding/lib/replacements.js b/node_modules/babel-plugin-minify-constant-folding/lib/replacements.js new file mode 100644 index 00000000000..55e8eda1696 --- /dev/null +++ b/node_modules/babel-plugin-minify-constant-folding/lib/replacements.js @@ -0,0 +1,142 @@ +"use strict"; + +var FALLBACK_HANDLER = Symbol("fallback handler"); + +module.exports = function (_ref) { + var t = _ref.types; + + var undef = t.unaryExpression("void", t.numericLiteral(0)); + + function isUndef(ob) { + return ob === undefined || t.isIdentifier(ob, { name: "undefined" }) || t.isUnaryExpression(ob, { operator: "void" }); + } + + function defaultZero(cb) { + return function () { + var i = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : t.numericLiteral(0); + + if (t.isNumericLiteral(i)) { + for (var _len = arguments.length, args = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { + args[_key - 1] = arguments[_key]; + } + + return cb.call.apply(cb, [this, this, i.value].concat(args)); + } + }; + } + + return { + ArrayExpression: { + members: { + length() { + return t.numericLiteral(this.elements.length); + }, + [FALLBACK_HANDLER](i) { + if (typeof i === "number" || i.match(/^\d+$/)) { + return this.elements[i] || undef; + } + } + }, + calls: { + join() { + var sep = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : t.stringLiteral(","); + + if (!t.isStringLiteral(sep)) return; + var bad = false; + var str = this.elements.map(function (el) { + if (!t.isLiteral(el)) { + bad = true; + return; + } + return el.value; + }).join(sep.value); + return bad ? undefined : t.stringLiteral(str); + }, + push() { + return t.numericLiteral(this.elements.length + arguments.length); + }, + shift() { + if (this.elements.length === 0) { + return undef; + } + return t.numericLiteral(this.elements.length - 1); + }, + slice() { + var start = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : t.numericLiteral(0); + var end = arguments[1]; + + if (!t.isNumericLiteral(start) || end && !t.isNumericLiteral(end)) { + return; + } + return t.arrayExpression(this.elements.slice(start.value, end && end.value)); + }, + pop() { + return this.elements[this.elements.length - 1] || undef; + }, + reverse() { + return t.arrayExpression(this.elements.reverse()); + }, + splice(start, end) { + var _elements$slice; + + if (!t.isNumericLiteral(start) || end && !t.isNumericLiteral(end)) { + return; + } + + for (var _len2 = arguments.length, args = Array(_len2 > 2 ? _len2 - 2 : 0), _key2 = 2; _key2 < _len2; _key2++) { + args[_key2 - 2] = arguments[_key2]; + } + + if (end) { + args.unshift(end.value); + } + return t.arrayExpression((_elements$slice = this.elements.slice()).splice.apply(_elements$slice, [start.value].concat(args))); + } + } + }, + StringLiteral: { + members: { + length() { + return t.numericLiteral(this.value.length); + }, + [FALLBACK_HANDLER](i) { + if (typeof i === "number" || i.match(/^\d+$/)) { + var ch = this.value[i]; + return ch ? t.stringLiteral(ch) : undef; + } + } + }, + calls: { + split() { + var sep = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : undef; + + var realSep = null; + if (t.isStringLiteral(sep)) { + realSep = sep.value; + } + if (isUndef(sep)) { + realSep = sep; + } + if (realSep !== null) { + return t.arrayExpression(this.value.split(realSep).map(function (str) { + return t.stringLiteral(str); + })); + } + }, + charAt: defaultZero(function (_ref2, i) { + var value = _ref2.value; + return t.stringLiteral(value.charAt(i)); + }), + charCodeAt: defaultZero(function (_ref3, i) { + var value = _ref3.value; + return t.numericLiteral(value.charCodeAt(i)); + }), + codePointAt: defaultZero(function (_ref4, i) { + var value = _ref4.value; + return t.numericLiteral(value.codePointAt(i)); + }) + } + } + }; +}; +module.exports.FALLBACK_HANDLER = FALLBACK_HANDLER; \ No newline at end of file diff --git a/node_modules/babel-plugin-minify-constant-folding/package.json b/node_modules/babel-plugin-minify-constant-folding/package.json new file mode 100644 index 00000000000..7cf3faa7fad --- /dev/null +++ b/node_modules/babel-plugin-minify-constant-folding/package.json @@ -0,0 +1,49 @@ +{ + "_from": "babel-plugin-minify-constant-folding@^0.1.3", + "_id": "babel-plugin-minify-constant-folding@0.1.3", + "_inBundle": false, + "_integrity": "sha1-V70XKt+LjXStfJlhLrlQQU6+o8o=", + "_location": "/babel-plugin-minify-constant-folding", + "_phantomChildren": {}, + "_requested": { + "type": "range", + "registry": true, + "raw": "babel-plugin-minify-constant-folding@^0.1.3", + "name": "babel-plugin-minify-constant-folding", + "escapedName": "babel-plugin-minify-constant-folding", + "rawSpec": "^0.1.3", + "saveSpec": null, + "fetchSpec": "^0.1.3" + }, + "_requiredBy": [ + "/node-titanium-sdk/babel-preset-babili" + ], + "_resolved": "https://registry.npmjs.org/babel-plugin-minify-constant-folding/-/babel-plugin-minify-constant-folding-0.1.3.tgz", + "_shasum": "57bd172adf8b8d74ad7c99612eb950414ebea3ca", + "_spec": "babel-plugin-minify-constant-folding@^0.1.3", + "_where": "/Users/chris/appc/titanium_mobile/node_modules/node-titanium-sdk/node_modules/babel-preset-babili", + "author": { + "name": "amasad" + }, + "bugs": { + "url": "https://github.com/babel/babili/issues" + }, + "bundleDependencies": false, + "dependencies": { + "babel-helper-evaluate-path": "^0.1.0" + }, + "deprecated": false, + "description": "Tries to evaluate expressions and inline the result.", + "homepage": "https://github.com/babel/babili#readme", + "keywords": [ + "babel-plugin" + ], + "license": "MIT", + "main": "lib/index.js", + "name": "babel-plugin-minify-constant-folding", + "repository": { + "type": "git", + "url": "https://github.com/babel/babili/tree/master/packages/babel-plugin-minify-constant-folding" + }, + "version": "0.1.3" +} diff --git a/node_modules/babel-preset-babili/node_modules/babel-plugin-minify-flip-comparisons/node_modules/babel-helper-is-void-0/.npmignore b/node_modules/babel-plugin-minify-dead-code-elimination/.npmignore similarity index 100% rename from node_modules/babel-preset-babili/node_modules/babel-plugin-minify-flip-comparisons/node_modules/babel-helper-is-void-0/.npmignore rename to node_modules/babel-plugin-minify-dead-code-elimination/.npmignore diff --git a/node_modules/babel-preset-babili/node_modules/babel-plugin-minify-dead-code-elimination/README.md b/node_modules/babel-plugin-minify-dead-code-elimination/README.md similarity index 100% rename from node_modules/babel-preset-babili/node_modules/babel-plugin-minify-dead-code-elimination/README.md rename to node_modules/babel-plugin-minify-dead-code-elimination/README.md diff --git a/node_modules/babel-plugin-minify-dead-code-elimination/lib/index.js b/node_modules/babel-plugin-minify-dead-code-elimination/lib/index.js new file mode 100644 index 00000000000..9940c006371 --- /dev/null +++ b/node_modules/babel-plugin-minify-dead-code-elimination/lib/index.js @@ -0,0 +1,1330 @@ +"use strict"; + +function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } } + +var some = require("lodash.some"); + +var _require = require("babel-helper-mark-eval-scopes"), + markEvalScopes = _require.markEvalScopes, + hasEval = _require.hasEval; + +var removeUseStrict = require("./remove-use-strict"); + +function prevSiblings(path) { + var parentPath = path.parentPath; + var siblings = []; + + var key = parentPath.key; + + while ((path = parentPath.getSibling(--key)).type) { + siblings.push(path); + } + return siblings; +} + +function forEachAncestor(path, callback) { + while (path = path.parentPath) { + callback(path); + } +} + +module.exports = function (_ref) { + var t = _ref.types, + traverse = _ref.traverse; + + var removeOrVoid = require("babel-helper-remove-or-void")(t); + var shouldRevisit = Symbol("shouldRevisit"); + + // this is used for tracking fn params that can be removed + // as traversal takes place from left and + // unused params can be removed only on the right + var markForRemoval = Symbol("markForRemoval"); + + var main = { + // remove side effectless statement + ExpressionStatement(path) { + if (path.get("expression").isPure()) { + removeOrVoid(path); + } + }, + + Function: { + // Let's take all the vars in a function that are not in the top level scope and hoist them + // with the first var declaration in the top-level scope. This transform in itself may + // not yield much returns (or even can be marginally harmful to size). However it's great + // for taking away statements from blocks that can be only expressions which the `simplify` + // plugin can turn into other things (e.g. if => conditional). + exit(path) { + // This hurts gzip size. + if (!this.optimizeRawSize) { + return; + } + + var node = path.node, + scope = path.scope; + + var seen = new Set(); + var declars = []; + var mutations = []; + + var _loop = function _loop(name) { + var binding = scope.bindings[name]; + if (!binding.path.isVariableDeclarator()) { + return "continue"; + } + + var declarPath = binding.path.parentPath; + if (seen.has(declarPath)) { + return "continue"; + } + seen.add(declarPath); + + if (declarPath.parentPath.isForInStatement()) { + return "continue"; + } + + if (declarPath.parentPath.parentPath.isFunction()) { + return "continue"; + } + + if (!declarPath.node || !declarPath.node.declarations) { + return "continue"; + } + + var assignmentSequence = []; + + var _loop2 = function _loop2(declar) { + declars.push(declar); + if (declar.init) { + assignmentSequence.push(t.assignmentExpression("=", declar.id, declar.init)); + mutations.push(function () { + declar.init = null; + }); + } + }; + + var _iteratorNormalCompletion2 = true; + var _didIteratorError2 = false; + var _iteratorError2 = undefined; + + try { + for (var _iterator2 = declarPath.node.declarations[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) { + var declar = _step2.value; + + _loop2(declar); + } + } catch (err) { + _didIteratorError2 = true; + _iteratorError2 = err; + } finally { + try { + if (!_iteratorNormalCompletion2 && _iterator2.return) { + _iterator2.return(); + } + } finally { + if (_didIteratorError2) { + throw _iteratorError2; + } + } + } + + if (assignmentSequence.length) { + mutations.push(function () { + return declarPath.replaceWith(t.sequenceExpression(assignmentSequence)); + }); + } else { + mutations.push(function () { + return removeOrVoid(declarPath); + }); + } + }; + + for (var name in scope.bindings) { + var _ret = _loop(name); + + if (_ret === "continue") continue; + } + + if (declars.length) { + mutations.forEach(function (f) { + return f(); + }); + var _iteratorNormalCompletion = true; + var _didIteratorError = false; + var _iteratorError = undefined; + + try { + for (var _iterator = node.body.body[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { + var statement = _step.value; + + if (t.isVariableDeclaration(statement)) { + var _statement$declaratio; + + (_statement$declaratio = statement.declarations).push.apply(_statement$declaratio, declars); + return; + } + } + } catch (err) { + _didIteratorError = true; + _iteratorError = err; + } finally { + try { + if (!_iteratorNormalCompletion && _iterator.return) { + _iterator.return(); + } + } finally { + if (_didIteratorError) { + throw _iteratorError; + } + } + } + + var varDecl = t.variableDeclaration("var", declars); + node.body.body.unshift(varDecl); + } + } + }, + + // Remove bindings with no references. + Scope: { + exit(path) { + if (path.node[shouldRevisit]) { + delete path.node[shouldRevisit]; + path.visit(); + } + }, + + enter(path) { + var _this = this; + + if (path.isProgram()) { + return; + } + + if (hasEval(path.scope)) { + return; + } + + var scope = path.scope; + + // if the scope is created by a function, we obtain its + // parameter list + + var canRemoveParams = path.isFunction() && path.node.kind !== "set"; + var paramsList = canRemoveParams ? path.get("params") : []; + + for (var i = paramsList.length - 1; i >= 0; i--) { + var param = paramsList[i]; + + if (param.isIdentifier()) { + var binding = scope.bindings[param.node.name]; + if (!binding) continue; + + if (binding.referenced) { + // when the first binding is referenced (right to left) + // exit without marking anything after this + break; + } + + binding[markForRemoval] = true; + continue; + } else if (param.isAssignmentPattern()) { + var left = param.get("left"); + var right = param.get("right"); + + if (left.isIdentifier() && right.isPure()) { + var _binding = scope.bindings[left.node.name]; + if (_binding.referenced) { + // when the first binding is referenced (right to left) + // exit without marking anything after this + break; + } + + _binding[markForRemoval] = true; + continue; + } + } + + // other patterns - assignment, object have side-effects + // and cannot be safely removed + break; + } + + var _loop3 = function _loop3(name) { + var binding = scope.bindings[name]; + + if (!binding.referenced && binding.kind !== "module") { + if (binding.kind === "param" && (_this.keepFnArgs || !binding[markForRemoval])) { + return "continue"; + } else if (binding.path.isVariableDeclarator()) { + if (binding.path.parentPath.parentPath && binding.path.parentPath.parentPath.isForXStatement()) { + // Can't remove if in a for-in/for-of/for-await statement `for (var x in wat)`. + return "continue"; + } + } else if (!scope.isPure(binding.path.node)) { + // TODO: AssignmentPattern are marked as impure and unused ids aren't removed yet + return "continue"; + } else if (binding.path.isFunctionExpression() || binding.path.isClassExpression()) { + // `bar(function foo() {})` foo is not referenced but it's used. + return "continue"; + } + + var mutations = []; + var bail = false; + // Make sure none of the assignments value is used + binding.constantViolations.forEach(function (p) { + if (bail || p === binding.path) { + return; + } + + if (!p.parentPath.isExpressionStatement()) { + bail = true; + } + + if (p.isAssignmentExpression() && !p.get("right").isPure()) { + mutations.push(function () { + return p.replaceWith(p.get("right")); + }); + } else { + mutations.push(function () { + return removeOrVoid(p); + }); + } + }); + + if (bail) { + return "continue"; + } + + if (binding.path.isVariableDeclarator() && binding.path.node.init && !scope.isPure(binding.path.node.init) && binding.path.parentPath.node.declarations) { + if (binding.path.parentPath.node.declarations.length !== 1) { + return "continue"; + } + // Bail out for ArrayPattern and ObjectPattern + if (!binding.path.get("id").isIdentifier()) { + return "continue"; + } + + binding.path.parentPath.replaceWith(binding.path.node.init); + } else { + updateReferences(binding.path, _this); + removeOrVoid(binding.path); + } + + mutations.forEach(function (f) { + return f(); + }); + scope.removeBinding(name); + } else if (binding.constant) { + if (binding.path.isFunctionDeclaration() || binding.path.isVariableDeclarator() && binding.path.get("init").isFunction()) { + var _ret4 = function () { + var fun = binding.path.isFunctionDeclaration() ? binding.path : binding.path.get("init"); + var allInside = true; + var _iteratorNormalCompletion3 = true; + var _didIteratorError3 = false; + var _iteratorError3 = undefined; + + try { + for (var _iterator3 = binding.referencePaths[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) { + var ref = _step3.value; + + if (!ref.find(function (p) { + return p.node === fun.node; + })) { + allInside = false; + break; + } + } + } catch (err) { + _didIteratorError3 = true; + _iteratorError3 = err; + } finally { + try { + if (!_iteratorNormalCompletion3 && _iterator3.return) { + _iterator3.return(); + } + } finally { + if (_didIteratorError3) { + throw _iteratorError3; + } + } + } + + if (allInside) { + scope.removeBinding(name); + updateReferences(binding.path, _this); + removeOrVoid(binding.path); + return { + v: "continue" + }; + } + }(); + + if (typeof _ret4 === "object") return _ret4.v; + } + + if (binding.references === 1 && binding.kind !== "param" && binding.kind !== "module" && binding.constant) { + var replacement = binding.path.node; + var replacementPath = binding.path; + var isReferencedBefore = false; + + if (binding.referencePaths.length > 1) { + throw new Error("Expected only one reference"); + } + var refPath = binding.referencePaths[0]; + + if (t.isVariableDeclarator(replacement)) { + var _prevSiblings = prevSiblings(replacementPath); + + // traverse ancestors of a reference checking if it's before declaration + forEachAncestor(refPath, function (ancestor) { + if (_prevSiblings.indexOf(ancestor) > -1) { + isReferencedBefore = true; + } + }); + + // deopt if reference is in different scope than binding + // since we don't know if it's sync or async execition + // (i.e. whether value has been assigned to a reference or not) + if (isReferencedBefore && refPath.scope !== binding.scope) { + return "continue"; + } + + // simulate hoisting by replacing value + // with undefined if declaration is after reference + replacement = isReferencedBefore ? t.unaryExpression("void", t.numericLiteral(0), true) : replacement.init; + + // Bail out for ArrayPattern and ObjectPattern + // TODO: maybe a more intelligent approach instead of simply bailing out + if (!replacementPath.get("id").isIdentifier()) { + return "continue"; + } + replacementPath = replacementPath.get("init"); + } + + if (!replacement) { + return "continue"; + } + + if (!scope.isPure(replacement, true) && !isReferencedBefore) { + return "continue"; + } + + var _bail = false; + + if (replacementPath.isIdentifier()) { + _bail = refPath.scope.getBinding(replacement.name) !== scope.getBinding(replacement.name); + } else { + replacementPath.traverse({ + Function(path) { + path.skip(); + }, + + ReferencedIdentifier(_ref2) { + var node = _ref2.node; + + if (_bail) { + return; + } + _bail = refPath.scope.getBinding(node.name) !== scope.getBinding(node.name); + } + }); + } + + if (_bail) { + return "continue"; + } + + var parent = binding.path.parent; + if (t.isVariableDeclaration(parent)) { + parent = binding.path.parentPath.parent; + } + + // 1. Make sure we share the parent with the node. In other words it's lexically defined + // and not in an if statement or otherwise. + // 2. If the replacement is an object then we have to make sure we are not in a loop or a function + // because otherwise we'll be inlining and doing a lot more allocation than we have to + // which would also could affect correctness in that they are not the same reference. + var mayLoop = false; + var sharesRoot = refPath.find(function (_ref3) { + var node = _ref3.node; + + if (!mayLoop) { + mayLoop = t.isWhileStatement(node) || t.isFor(node) || t.isFunction(node); + } + return node === parent; + }); + + // Anything that inherits from Object. + var isObj = function isObj(n) { + return t.isFunction(n) || t.isObjectExpression(n) || t.isArrayExpression(n); + }; + var isReplacementObj = isObj(replacement) || some(replacement, isObj); + + if (!sharesRoot || isReplacementObj && mayLoop) { + return "continue"; + } + + var replaced = replace(binding.referencePaths[0], { + binding, + scope, + replacement + }); + + if (replaced) { + scope.removeBinding(name); + if (binding.path.node) { + removeOrVoid(binding.path); + } + } + } + } + }; + + for (var name in scope.bindings) { + var _ret3 = _loop3(name); + + if (_ret3 === "continue") continue; + } + } + }, + + // Remove unreachable code. + BlockStatement(path) { + var paths = path.get("body"); + + var purge = false; + + for (var i = 0; i < paths.length; i++) { + var p = paths[i]; + + if (!purge && p.isCompletionStatement()) { + purge = true; + continue; + } + + if (purge && !canExistAfterCompletion(p)) { + removeOrVoid(p); + } + } + }, + + // Double check unreachable code and remove return statements that + // have no semantic meaning + ReturnStatement(path) { + var node = path.node; + + if (!path.inList) { + return; + } + + // Not last in its block? (See BlockStatement visitor) + if (path.container.length - 1 !== path.key && !canExistAfterCompletion(path.getSibling(path.key + 1)) && path.parentPath.isBlockStatement()) { + // This is probably a new oppurtinity by some other transform + // let's call the block visitor on this again before proceeding. + path.parentPath.pushContext(path.context); + path.parentPath.visit(); + path.parentPath.popContext(); + + return; + } + + if (node.argument) { + return; + } + + var noNext = true; + var parentPath = path.parentPath; + while (parentPath && !parentPath.isFunction() && noNext) { + // https://github.com/babel/babili/issues/265 + if (hasLoopParent(parentPath)) { + noNext = false; + break; + } + + var nextPath = parentPath.getSibling(parentPath.key + 1); + if (nextPath.node) { + if (nextPath.isReturnStatement()) { + nextPath.pushContext(path.context); + nextPath.visit(); + nextPath.popContext(); + if (parentPath.getSibling(parentPath.key + 1).node) { + noNext = false; + break; + } + } else { + noNext = false; + break; + } + } + + parentPath = parentPath.parentPath; + } + + if (noNext) { + removeOrVoid(path); + } + }, + + ConditionalExpression(path) { + var node = path.node; + + var evaluateTest = path.get("test").evaluateTruthy(); + if (evaluateTest === true) { + path.replaceWith(node.consequent); + } else if (evaluateTest === false) { + path.replaceWith(node.alternate); + } + }, + + SwitchStatement: { + exit(path) { + var evaluated = path.get("discriminant").evaluate(); + + if (!evaluated.confident) return; + + var discriminant = evaluated.value; + var cases = path.get("cases"); + + var matchingCaseIndex = -1; + var defaultCaseIndex = -1; + + for (var i = 0; i < cases.length; i++) { + var test = cases[i].get("test"); + + // handle default case + if (test.node === null) { + defaultCaseIndex = i; + continue; + } + + var testResult = test.evaluate(); + + // if we are not able to deternine a test during + // compile time, we terminate immediately + if (!testResult.confident) return; + + if (testResult.value === discriminant) { + matchingCaseIndex = i; + break; + } + } + + var result = void 0; + + if (matchingCaseIndex === -1) { + if (defaultCaseIndex === -1) { + path.skip(); + path.replaceWithMultiple(extractVars(path)); + return; + } else { + result = getStatementsUntilBreak(defaultCaseIndex); + } + } else { + result = getStatementsUntilBreak(matchingCaseIndex); + } + + if (result.bail) return; + + // we extract vars from the entire switch statement + // and there will be duplicates which + // will be again removed by DCE + replaceSwitch([].concat(_toConsumableArray(extractVars(path)), _toConsumableArray(result.statements))); + + function getStatementsUntilBreak(start) { + var result = { + bail: false, + statements: [] + }; + + for (var _i = start; _i < cases.length; _i++) { + var consequent = cases[_i].get("consequent"); + + for (var j = 0; j < consequent.length; j++) { + var _isBreaking = isBreaking(consequent[j], path); + if (_isBreaking.bail) { + result.bail = true; + return result; + } + if (_isBreaking.break) { + // compute no more + // exit out of the loop + return result; + } else { + result.statements.push(consequent[j].node); + } + } + } + + return result; + } + + function replaceSwitch(statements) { + var isBlockRequired = false; + + for (var _i2 = 0; _i2 < statements.length; _i2++) { + if (t.isVariableDeclaration(statements[_i2], { kind: "let" })) { + isBlockRequired = true; + break; + } + if (t.isVariableDeclaration(statements[_i2], { kind: "const" })) { + isBlockRequired = true; + break; + } + } + + if (isBlockRequired) { + path.replaceWith(t.BlockStatement(statements)); + } else { + path.replaceWithMultiple(statements); + } + } + } + }, + + WhileStatement(path) { + var test = path.get("test"); + var result = test.evaluate(); + if (result.confident && test.isPure() && !result.value) { + path.remove(); + } + }, + + ForStatement(path) { + var test = path.get("test"); + if (!test.isPure()) return; + + var result = test.evaluate(); + if (result.confident) { + if (result.value) { + test.remove(); + } else { + path.remove(); + } + } + }, + + DoWhileStatement(path) { + var test = path.get("test"); + var result = test.evaluate(); + if (result.confident && test.isPure() && !result.value) { + var body = path.get("body"); + + if (body.isBlockStatement()) { + var stmts = body.get("body"); + var _iteratorNormalCompletion4 = true; + var _didIteratorError4 = false; + var _iteratorError4 = undefined; + + try { + for (var _iterator4 = stmts[Symbol.iterator](), _step4; !(_iteratorNormalCompletion4 = (_step4 = _iterator4.next()).done); _iteratorNormalCompletion4 = true) { + var stmt = _step4.value; + + var _isBreaking = isBreaking(stmt, path); + if (_isBreaking.bail || _isBreaking.break) return; + var _isContinuing = isContinuing(stmt, path); + if (_isContinuing.bail || isContinuing.continue) return; + } + } catch (err) { + _didIteratorError4 = true; + _iteratorError4 = err; + } finally { + try { + if (!_iteratorNormalCompletion4 && _iterator4.return) { + _iterator4.return(); + } + } finally { + if (_didIteratorError4) { + throw _iteratorError4; + } + } + } + + path.replaceWith(body.node); + } else if (body.isBreakStatement()) { + var _isBreaking2 = isBreaking(body, path); + if (_isBreaking2.bail) return; + if (_isBreaking2.break) path.remove(); + } else if (body.isContinueStatement()) { + return; + } else { + path.replaceWith(body.node); + } + } + }, + + // Join assignment and definition when in sequence. + // var x; x = 1; -> var x = 1; + AssignmentExpression(path) { + if (!path.get("left").isIdentifier() || !path.parentPath.isExpressionStatement()) { + return; + } + + var prev = path.parentPath.getSibling(path.parentPath.key - 1); + if (!(prev && prev.isVariableDeclaration())) { + return; + } + + var declars = prev.node.declarations; + if (declars.length !== 1 || declars[0].init || declars[0].id.name !== path.get("left").node.name) { + return; + } + declars[0].init = path.node.right; + removeOrVoid(path); + }, + + // Remove named function expression name. While this is dangerous as it changes + // `function.name` all minifiers do it and hence became a standard. + FunctionExpression(path) { + if (!this.keepFnName) { + removeUnreferencedId(path); + } + }, + + // remove class names + ClassExpression(path) { + if (!this.keepClassName) { + removeUnreferencedId(path); + } + }, + + // Put the `var` in the left if feasible. + ForInStatement(path) { + var left = path.get("left"); + if (!left.isIdentifier()) { + return; + } + + var binding = path.scope.getBinding(left.node.name); + if (!binding) { + return; + } + + if (binding.scope.getFunctionParent() !== path.scope.getFunctionParent()) { + return; + } + + if (!binding.path.isVariableDeclarator()) { + return; + } + + if (binding.path.parentPath.parentPath.isForInStatement({ + left: binding.path.parent + })) { + return; + } + + // If it has company then it's probably more efficient to keep. + if (binding.path.parent.declarations.length > 1) { + return; + } + + // meh + if (binding.path.node.init) { + return; + } + + removeOrVoid(binding.path); + path.node.left = t.variableDeclaration("var", [t.variableDeclarator(left.node)]); + binding.path = path.get("left").get("declarations")[0]; + } + }; + + return { + name: "minify-dead-code-elimination", + visitor: { + Function: { + exit(path) { + /** + * Use exit handler to traverse in a dfs post-order fashion + * to remove use strict + */ + var body = path.get("body"); + if (body.isBlockStatement()) { + removeUseStrict(body); + } + } + }, + IfStatement: { + exit(path) { + var consequent = path.get("consequent"); + var alternate = path.get("alternate"); + var test = path.get("test"); + + var evalResult = test.evaluate(); + var isPure = test.isPure(); + + var replacements = []; + + if (evalResult.confident && !isPure && test.isSequenceExpression()) { + replacements.push(t.expressionStatement(extractSequenceImpure(test))); + } + + // we can check if a test will be truthy 100% and if so then we can inline + // the consequent and completely ignore the alternate + // + // if (true) { foo; } -> { foo; } + // if ("foo") { foo; } -> { foo; } + // + if (evalResult.confident && evalResult.value) { + path.replaceWithMultiple([].concat(replacements, _toConsumableArray(toStatements(consequent)), _toConsumableArray(extractVars(alternate)))); + return; + } + + // we can check if a test will be falsy 100% and if so we can inline the + // alternate if there is one and completely remove the consequent + // + // if ("") { bar; } else { foo; } -> { foo; } + // if ("") { bar; } -> + // + if (evalResult.confident && !evalResult.value) { + if (alternate.node) { + path.replaceWithMultiple([].concat(replacements, _toConsumableArray(toStatements(alternate)), _toConsumableArray(extractVars(consequent)))); + return; + } else { + path.replaceWithMultiple([].concat(replacements, _toConsumableArray(extractVars(consequent)))); + } + } + + // remove alternate blocks that are empty + // + // if (foo) { foo; } else {} -> if (foo) { foo; } + // + if (alternate.isBlockStatement() && !alternate.node.body.length) { + alternate.remove(); + // For if-statements babel-traverse replaces with an empty block + path.node.alternate = null; + } + + // if the consequent block is empty turn alternate blocks into a consequent + // and flip the test + // + // if (foo) {} else { bar; } -> if (!foo) { bar; } + // + if (consequent.isBlockStatement() && !consequent.node.body.length && alternate.isBlockStatement() && alternate.node.body.length) { + consequent.replaceWith(alternate.node); + alternate.remove(); + // For if-statements babel-traverse replaces with an empty block + path.node.alternate = null; + test.replaceWith(t.unaryExpression("!", test.node, true)); + } + } + }, + + EmptyStatement(path) { + if (path.parentPath.isBlockStatement() || path.parentPath.isProgram()) { + path.remove(); + } + }, + + Program: { + exit(path) { + var _ref4 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}, + _ref4$opts = _ref4.opts; + + _ref4$opts = _ref4$opts === undefined ? {} : _ref4$opts; + var _ref4$opts$optimizeRa = _ref4$opts.optimizeRawSize, + optimizeRawSize = _ref4$opts$optimizeRa === undefined ? false : _ref4$opts$optimizeRa, + _ref4$opts$keepFnName = _ref4$opts.keepFnName, + keepFnName = _ref4$opts$keepFnName === undefined ? false : _ref4$opts$keepFnName, + _ref4$opts$keepClassN = _ref4$opts.keepClassName, + keepClassName = _ref4$opts$keepClassN === undefined ? false : _ref4$opts$keepClassN, + _ref4$opts$keepFnArgs = _ref4$opts.keepFnArgs, + keepFnArgs = _ref4$opts$keepFnArgs === undefined ? false : _ref4$opts$keepFnArgs; + + traverse.clearCache(); + path.scope.crawl(); + + markEvalScopes(path); + + // We need to run this plugin in isolation. + path.traverse(main, { + functionToBindings: new Map(), + optimizeRawSize, + keepFnName, + keepClassName, + keepFnArgs + }); + } + } + } + }; + + function toStatements(path) { + var node = path.node; + + if (path.isBlockStatement()) { + var hasBlockScoped = false; + + for (var i = 0; i < node.body.length; i++) { + var bodyNode = node.body[i]; + if (t.isBlockScoped(bodyNode)) { + hasBlockScoped = true; + } + } + + if (!hasBlockScoped) { + return node.body; + } + } + return [node]; + } + + // Extracts vars from a path + // Useful for removing blocks or paths that can contain + // variable declarations inside them + // Note: + // drops are inits + // extractVars({ var x = 5, y = x }) => var x, y; + function extractVars(path) { + var declarators = []; + + if (path.isVariableDeclaration({ kind: "var" })) { + var _iteratorNormalCompletion5 = true; + var _didIteratorError5 = false; + var _iteratorError5 = undefined; + + try { + for (var _iterator5 = path.node.declarations[Symbol.iterator](), _step5; !(_iteratorNormalCompletion5 = (_step5 = _iterator5.next()).done); _iteratorNormalCompletion5 = true) { + var decl = _step5.value; + + declarators.push(t.variableDeclarator(decl.id)); + } + } catch (err) { + _didIteratorError5 = true; + _iteratorError5 = err; + } finally { + try { + if (!_iteratorNormalCompletion5 && _iterator5.return) { + _iterator5.return(); + } + } finally { + if (_didIteratorError5) { + throw _iteratorError5; + } + } + } + } else { + path.traverse({ + VariableDeclaration(varPath) { + if (!varPath.isVariableDeclaration({ kind: "var" })) return; + if (!isSameFunctionScope(varPath, path)) return; + + var _iteratorNormalCompletion6 = true; + var _didIteratorError6 = false; + var _iteratorError6 = undefined; + + try { + for (var _iterator6 = varPath.node.declarations[Symbol.iterator](), _step6; !(_iteratorNormalCompletion6 = (_step6 = _iterator6.next()).done); _iteratorNormalCompletion6 = true) { + var _decl = _step6.value; + + declarators.push(t.variableDeclarator(_decl.id)); + } + } catch (err) { + _didIteratorError6 = true; + _iteratorError6 = err; + } finally { + try { + if (!_iteratorNormalCompletion6 && _iterator6.return) { + _iterator6.return(); + } + } finally { + if (_didIteratorError6) { + throw _iteratorError6; + } + } + } + } + }); + } + + if (declarators.length <= 0) return []; + + return [t.variableDeclaration("var", declarators)]; + } + + function replace(path, options) { + var replacement = options.replacement, + scope = options.scope, + binding = options.binding; + + // Same name, different binding. + + if (scope.getBinding(path.node.name) !== binding) { + return; + } + + // We don't want to move code around to different scopes because: + // 1. Original bindings that is referenced could be shadowed + // 2. Moving defintions to potentially hot code is bad + if (scope !== path.scope) { + if (t.isClass(replacement) || t.isFunction(replacement)) { + return; + } + + var bail = false; + traverse(replacement, { + Function(path) { + if (bail) { + return; + } + bail = true; + path.stop(); + } + }, scope); + + if (bail) { + return; + } + } + + // Avoid recursion. + if (path.find(function (_ref5) { + var node = _ref5.node; + return node === replacement; + })) { + return; + } + + // https://github.com/babel/babili/issues/130 + if (!t.isExpression(replacement)) { + t.toExpression(replacement); + } + + // We don't remove fn name here, we let the FnExpr & ClassExpr visitors + // check its references and remove unreferenced ones + // if (t.isFunction(replacement)) { + // replacement.id = null; + // } + + path.replaceWith(replacement); + return true; + } + + function updateReferences(fnToDeletePath) { + if (!fnToDeletePath.isFunction()) { + return; + } + + fnToDeletePath.traverse({ + ReferencedIdentifier(path) { + var node = path.node, + scope = path.scope; + + var binding = scope.getBinding(node.name); + + if (!binding || !binding.path.isFunction() || binding.scope === scope || !binding.constant) { + return; + } + + var index = binding.referencePaths.indexOf(path); + if (index === -1) { + return; + } + binding.references--; + binding.referencePaths.splice(index, 1); + if (binding.references === 0) { + binding.referenced = false; + } + + if (binding.references <= 1 && binding.scope.path.node) { + binding.scope.path.node[shouldRevisit] = true; + } + } + }); + } + + function removeUnreferencedId(path) { + var id = path.get("id").node; + if (!id) { + return; + } + + var node = path.node, + scope = path.scope; + + var binding = scope.getBinding(id.name); + + // Check if shadowed or is not referenced. + if (binding && (binding.path.node !== node || !binding.referenced)) { + node.id = null; + } + } + + // path1 -> path2 + // is path1 an ancestor of path2 + function isAncestor(path1, path2) { + return !!path2.findParent(function (parent) { + return parent === path1; + }); + } + + function isSameFunctionScope(path1, path2) { + return path1.scope.getFunctionParent() === path2.scope.getFunctionParent(); + } + + function isBreaking(stmt, path) { + return isControlTransfer(stmt, path, "break"); + } + + function isContinuing(stmt, path) { + return isControlTransfer(stmt, path, "continue"); + } + + // tells if a "stmt" is a break/continue statement + function isControlTransfer(stmt, path) { + var control = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : "break"; + var _break$continue = { + break: "BreakStatement", + continue: "ContinueStatement" + }, + type = _break$continue[control]; + + if (!type) { + throw new Error("Can only handle break and continue statements"); + } + var checker = `is${type}`; + + if (stmt[checker]()) { + return _isControlTransfer(stmt, path); + } + + var isTransferred = false; + var result = { + [control]: false, + bail: false + }; + + stmt.traverse({ + [type](cPath) { + // if we already detected a break/continue statement, + if (isTransferred) return; + + result = _isControlTransfer(cPath, path); + + if (result.bail || result[control]) { + isTransferred = true; + } + } + }); + + return result; + + function _isControlTransfer(cPath, path) { + var label = cPath.get("label"); + + if (label.node !== null) { + // labels are fn scoped and not accessible by inner functions + // path is the switch statement + if (!isSameFunctionScope(path, cPath)) { + // we don't have to worry about this break statement + return { + break: false, + bail: false + }; + } + + // here we handle the break labels + // if they are outside switch, we bail out + // if they are within the case, we keep them + var labelPath = void 0; + if (path.scope.getLabel) { + labelPath = getLabel(label.node.name, path); + } else { + labelPath = path.scope.getBinding(label.node.name).path; + } + var _isAncestor = isAncestor(labelPath, path); + + return { + bail: _isAncestor, + [control]: _isAncestor + }; + } + + // set the flag that it is indeed breaking + var isCTransfer = true; + + // this flag is to capture + // switch(0) { case 0: while(1) if (x) break; } + var possibleRunTimeControlTransfer = false; + + // and compute if it's breaking the correct thing + var parent = cPath.parentPath; + + while (parent !== stmt.parentPath) { + // loops and nested switch cases + if (parent.isLoop() || parent.isSwitchCase()) { + // invalidate all the possible runtime breaks captured + // while (1) { if (x) break; } + possibleRunTimeControlTransfer = false; + + // and set that it's not breaking our switch statement + isCTransfer = false; + break; + } + // + // this is a special case and depends on + // the fact that SwitchStatement is handled in the + // exit hook of the traverse + // + // switch (0) { + // case 0: if (x) break; + // } + // + // here `x` is runtime only. + // in this case, we need to bail out. So we depend on exit hook + // of switch so that, it would have visited the IfStatement first + // before the SwitchStatement and would have removed the + // IfStatement if it was a compile time determined + // + if (parent.isIfStatement()) { + possibleRunTimeControlTransfer = true; + } + parent = parent.parentPath; + } + + return { + [control]: possibleRunTimeControlTransfer || isCTransfer, + bail: possibleRunTimeControlTransfer + }; + } + } + + // things that are hoisted + function canExistAfterCompletion(path) { + return path.isFunctionDeclaration() || path.isVariableDeclaration({ kind: "var" }); + } + + function getLabel(name, _path) { + var label = void 0, + path = _path; + do { + label = path.scope.getLabel(name); + if (label) { + return label; + } + } while (path = path.parentPath); + return null; + } + + function hasLoopParent(path) { + var parent = path; + do { + if (parent.isLoop()) { + return true; + } + } while (parent = parent.parentPath); + return false; + } + + function extractSequenceImpure(seq) { + var expressions = seq.get("expressions"); + var result = []; + for (var i = 0; i < expressions.length; i++) { + if (!expressions[i].isPure()) { + result.push(expressions[i].node); + } + } + return t.sequenceExpression(result); + } +}; \ No newline at end of file diff --git a/node_modules/babel-plugin-minify-dead-code-elimination/lib/remove-use-strict.js b/node_modules/babel-plugin-minify-dead-code-elimination/lib/remove-use-strict.js new file mode 100644 index 00000000000..bc312088d40 --- /dev/null +++ b/node_modules/babel-plugin-minify-dead-code-elimination/lib/remove-use-strict.js @@ -0,0 +1,53 @@ +"use strict"; + +module.exports = removeUseStrict; + +var newIssueUrl = "https://github.com/babel/babili/issues/new"; + +var useStrict = "use strict"; + +/** + * Remove redundant use strict + * If the parent has a "use strict" directive, it is not required in + * the children + * + * @param {NodePath} block BlockStatement + */ +function removeUseStrict(block) { + if (!block.isBlockStatement()) { + throw new Error(`Received ${block.type}. Expected BlockStatement. ` + `Please report at ${newIssueUrl}`); + } + + var useStricts = getUseStrictDirectives(block); + + // early exit + if (useStricts.length < 1) return; + + // only keep the first use strict + if (useStricts.length > 1) { + for (var i = 1; i < useStricts.length; i++) { + useStricts[i].remove(); + } + } + + // check if parent has an use strict + if (hasStrictParent(block)) { + useStricts[0].remove(); + } +} + +function hasStrictParent(path) { + return path.findParent(function (parent) { + return parent.isBlockStatement() && isStrict(parent); + }); +} + +function isStrict(block) { + return getUseStrictDirectives(block).length > 0; +} + +function getUseStrictDirectives(block) { + return block.get("directives").filter(function (directive) { + return directive.node.value.value === useStrict; + }); +} \ No newline at end of file diff --git a/node_modules/babel-plugin-minify-dead-code-elimination/package.json b/node_modules/babel-plugin-minify-dead-code-elimination/package.json new file mode 100644 index 00000000000..4a986ce6644 --- /dev/null +++ b/node_modules/babel-plugin-minify-dead-code-elimination/package.json @@ -0,0 +1,51 @@ +{ + "_from": "babel-plugin-minify-dead-code-elimination@^0.1.7", + "_id": "babel-plugin-minify-dead-code-elimination@0.1.7", + "_inBundle": false, + "_integrity": "sha1-d09TbzR7mDk6J7qnF4cpaIE8NCw=", + "_location": "/babel-plugin-minify-dead-code-elimination", + "_phantomChildren": {}, + "_requested": { + "type": "range", + "registry": true, + "raw": "babel-plugin-minify-dead-code-elimination@^0.1.7", + "name": "babel-plugin-minify-dead-code-elimination", + "escapedName": "babel-plugin-minify-dead-code-elimination", + "rawSpec": "^0.1.7", + "saveSpec": null, + "fetchSpec": "^0.1.7" + }, + "_requiredBy": [ + "/node-titanium-sdk/babel-preset-babili" + ], + "_resolved": "https://registry.npmjs.org/babel-plugin-minify-dead-code-elimination/-/babel-plugin-minify-dead-code-elimination-0.1.7.tgz", + "_shasum": "774f536f347b98393a27baa717872968813c342c", + "_spec": "babel-plugin-minify-dead-code-elimination@^0.1.7", + "_where": "/Users/chris/appc/titanium_mobile/node_modules/node-titanium-sdk/node_modules/babel-preset-babili", + "author": { + "name": "amasad" + }, + "bugs": { + "url": "https://github.com/babel/babili/issues" + }, + "bundleDependencies": false, + "dependencies": { + "babel-helper-mark-eval-scopes": "^0.1.1", + "babel-helper-remove-or-void": "^0.1.1", + "lodash.some": "^4.6.0" + }, + "deprecated": false, + "description": "Inlines bindings when possible. Tries to evaluate expressions and prunes unreachable as a result.", + "homepage": "https://github.com/babel/babili#readme", + "keywords": [ + "babel-plugin" + ], + "license": "MIT", + "main": "lib/index.js", + "name": "babel-plugin-minify-dead-code-elimination", + "repository": { + "type": "git", + "url": "https://github.com/babel/babili/tree/master/packages/babel-plugin-minify-dead-code-elimination" + }, + "version": "0.1.7" +} diff --git a/node_modules/babel-preset-babili/node_modules/babel-plugin-minify-guarded-expressions/.npmignore b/node_modules/babel-plugin-minify-flip-comparisons/.npmignore similarity index 100% rename from node_modules/babel-preset-babili/node_modules/babel-plugin-minify-guarded-expressions/.npmignore rename to node_modules/babel-plugin-minify-flip-comparisons/.npmignore diff --git a/node_modules/babel-preset-babili/node_modules/babel-plugin-minify-flip-comparisons/README.md b/node_modules/babel-plugin-minify-flip-comparisons/README.md similarity index 100% rename from node_modules/babel-preset-babili/node_modules/babel-plugin-minify-flip-comparisons/README.md rename to node_modules/babel-plugin-minify-flip-comparisons/README.md diff --git a/node_modules/babel-plugin-minify-flip-comparisons/lib/index.js b/node_modules/babel-plugin-minify-flip-comparisons/lib/index.js new file mode 100644 index 00000000000..d0e61bc08a6 --- /dev/null +++ b/node_modules/babel-plugin-minify-flip-comparisons/lib/index.js @@ -0,0 +1,57 @@ +"use strict"; + +module.exports = function (_ref) { + var t = _ref.types; + + var isVoid0 = require("babel-helper-is-void-0")(t); + + return { + name: "minify-flip-comparisons", + visitor: { + // flip comparisons with a pure right hand value, this ensures + // consistency with comparisons and increases the length of + // strings that gzip can match + // typeof blah === 'function' -> 'function' === typeof blah + BinaryExpression(path) { + var node = path.node; + var right = node.right, + left = node.left; + + // Make sure we have a constant on the right. + + if (!t.isLiteral(right) && !isVoid0(right) && !(t.isUnaryExpression(right) && t.isLiteral(right.argument)) && !t.isObjectExpression(right) && !t.isArrayExpression(right)) { + return; + } + + // Commutative operators. + if (t.EQUALITY_BINARY_OPERATORS.indexOf(node.operator) >= 0 || ["*", "^", "&", "|"].indexOf(node.operator) >= 0) { + node.left = right; + node.right = left; + return; + } + + if (t.BOOLEAN_NUMBER_BINARY_OPERATORS.indexOf(node.operator) >= 0) { + node.left = right; + node.right = left; + var operator = void 0; + switch (node.operator) { + case ">": + operator = "<"; + break; + case "<": + operator = ">"; + break; + case ">=": + operator = "<="; + break; + case "<=": + operator = ">="; + break; + } + node.operator = operator; + return; + } + } + } + }; +}; \ No newline at end of file diff --git a/node_modules/babel-plugin-minify-flip-comparisons/package.json b/node_modules/babel-plugin-minify-flip-comparisons/package.json new file mode 100644 index 00000000000..0f7760fc898 --- /dev/null +++ b/node_modules/babel-plugin-minify-flip-comparisons/package.json @@ -0,0 +1,49 @@ +{ + "_from": "babel-plugin-minify-flip-comparisons@^0.1.2", + "_id": "babel-plugin-minify-flip-comparisons@0.1.2", + "_inBundle": false, + "_integrity": "sha1-4oa0C3WZsY3+oZUHHkJ5Rlz8GIQ=", + "_location": "/babel-plugin-minify-flip-comparisons", + "_phantomChildren": {}, + "_requested": { + "type": "range", + "registry": true, + "raw": "babel-plugin-minify-flip-comparisons@^0.1.2", + "name": "babel-plugin-minify-flip-comparisons", + "escapedName": "babel-plugin-minify-flip-comparisons", + "rawSpec": "^0.1.2", + "saveSpec": null, + "fetchSpec": "^0.1.2" + }, + "_requiredBy": [ + "/node-titanium-sdk/babel-preset-babili" + ], + "_resolved": "https://registry.npmjs.org/babel-plugin-minify-flip-comparisons/-/babel-plugin-minify-flip-comparisons-0.1.2.tgz", + "_shasum": "e286b40b7599b18dfea195071e4279465cfc1884", + "_spec": "babel-plugin-minify-flip-comparisons@^0.1.2", + "_where": "/Users/chris/appc/titanium_mobile/node_modules/node-titanium-sdk/node_modules/babel-preset-babili", + "author": { + "name": "amasad" + }, + "bugs": { + "url": "https://github.com/babel/babili/issues" + }, + "bundleDependencies": false, + "dependencies": { + "babel-helper-is-void-0": "^0.1.1" + }, + "deprecated": false, + "description": "**Note:** while this plugin doesn’t shorten the output in any way, it does optimize it for repetition-based compression algorithms such as gzip.", + "homepage": "https://github.com/babel/babili#readme", + "keywords": [ + "babel-plugin" + ], + "license": "MIT", + "main": "lib/index.js", + "name": "babel-plugin-minify-flip-comparisons", + "repository": { + "type": "git", + "url": "https://github.com/babel/babili/tree/master/packages/babel-plugin-minify-flip-comparisons" + }, + "version": "0.1.2" +} diff --git a/node_modules/babel-preset-babili/node_modules/babel-plugin-minify-guarded-expressions/node_modules/babel-helper-flip-expressions/.npmignore b/node_modules/babel-plugin-minify-guarded-expressions/.npmignore similarity index 100% rename from node_modules/babel-preset-babili/node_modules/babel-plugin-minify-guarded-expressions/node_modules/babel-helper-flip-expressions/.npmignore rename to node_modules/babel-plugin-minify-guarded-expressions/.npmignore diff --git a/node_modules/babel-preset-babili/node_modules/babel-plugin-minify-guarded-expressions/README.md b/node_modules/babel-plugin-minify-guarded-expressions/README.md similarity index 100% rename from node_modules/babel-preset-babili/node_modules/babel-plugin-minify-guarded-expressions/README.md rename to node_modules/babel-plugin-minify-guarded-expressions/README.md diff --git a/node_modules/babel-preset-babili/node_modules/babel-plugin-minify-guarded-expressions/lib/index.js b/node_modules/babel-plugin-minify-guarded-expressions/lib/index.js similarity index 100% rename from node_modules/babel-preset-babili/node_modules/babel-plugin-minify-guarded-expressions/lib/index.js rename to node_modules/babel-plugin-minify-guarded-expressions/lib/index.js diff --git a/node_modules/babel-plugin-minify-guarded-expressions/package.json b/node_modules/babel-plugin-minify-guarded-expressions/package.json new file mode 100644 index 00000000000..67eeddd1d93 --- /dev/null +++ b/node_modules/babel-plugin-minify-guarded-expressions/package.json @@ -0,0 +1,49 @@ +{ + "_from": "babel-plugin-minify-guarded-expressions@^0.1.2", + "_id": "babel-plugin-minify-guarded-expressions@0.1.2", + "_inBundle": false, + "_integrity": "sha1-38PUc7A2LZYF084KweIjKMYNEAc=", + "_location": "/babel-plugin-minify-guarded-expressions", + "_phantomChildren": {}, + "_requested": { + "type": "range", + "registry": true, + "raw": "babel-plugin-minify-guarded-expressions@^0.1.2", + "name": "babel-plugin-minify-guarded-expressions", + "escapedName": "babel-plugin-minify-guarded-expressions", + "rawSpec": "^0.1.2", + "saveSpec": null, + "fetchSpec": "^0.1.2" + }, + "_requiredBy": [ + "/node-titanium-sdk/babel-preset-babili" + ], + "_resolved": "https://registry.npmjs.org/babel-plugin-minify-guarded-expressions/-/babel-plugin-minify-guarded-expressions-0.1.2.tgz", + "_shasum": "dfc3d473b0362d9605d3ce0ac1e22328c60d1007", + "_spec": "babel-plugin-minify-guarded-expressions@^0.1.2", + "_where": "/Users/chris/appc/titanium_mobile/node_modules/node-titanium-sdk/node_modules/babel-preset-babili", + "author": { + "name": "amasad" + }, + "bugs": { + "url": "https://github.com/babel/babili/issues" + }, + "bundleDependencies": false, + "dependencies": { + "babel-helper-flip-expressions": "^0.1.2" + }, + "deprecated": false, + "description": "## Example", + "homepage": "https://github.com/babel/babili#readme", + "keywords": [ + "babel-plugin" + ], + "license": "MIT", + "main": "lib/index.js", + "name": "babel-plugin-minify-guarded-expressions", + "repository": { + "type": "git", + "url": "https://github.com/babel/babili/tree/master/packages/babel-plugin-minify-guarded-expressions" + }, + "version": "0.1.2" +} diff --git a/node_modules/babel-preset-babili/node_modules/babel-plugin-minify-infinity/.npmignore b/node_modules/babel-plugin-minify-infinity/.npmignore similarity index 100% rename from node_modules/babel-preset-babili/node_modules/babel-plugin-minify-infinity/.npmignore rename to node_modules/babel-plugin-minify-infinity/.npmignore diff --git a/node_modules/babel-plugin-minify-infinity/README.md b/node_modules/babel-plugin-minify-infinity/README.md new file mode 100644 index 00000000000..2e27f6314bc --- /dev/null +++ b/node_modules/babel-plugin-minify-infinity/README.md @@ -0,0 +1,47 @@ +# babel-plugin-minify-infinity + +## Example + +**In** + +```javascript +Infinity; +``` + +**Out** + +```javascript +1 / 0; +``` + +## Installation + +```sh +npm install babel-plugin-minify-infinity +``` + +## Usage + +### Via `.babelrc` (Recommended) + +**.babelrc** + +```json +{ + "plugins": ["minify-infinity"] +} +``` + +### Via CLI + +```sh +babel --plugins minify-infinity script.js +``` + +### Via Node API + +```javascript +require("babel-core").transform("code", { + plugins: ["minify-infinity"] +}); +``` diff --git a/node_modules/babel-plugin-minify-infinity/lib/index.js b/node_modules/babel-plugin-minify-infinity/lib/index.js new file mode 100644 index 00000000000..5f2d1b3b752 --- /dev/null +++ b/node_modules/babel-plugin-minify-infinity/lib/index.js @@ -0,0 +1,37 @@ +"use strict"; + +module.exports = function (_ref) { + var t = _ref.types; + + var INFINITY = t.binaryExpression("/", t.numericLiteral(1), t.numericLiteral(0)); + return { + name: "minify-infinity", + visitor: { + // Infinity -> 1 / 0 + Identifier(path) { + if (path.node.name !== "Infinity") { + return; + } + + // It's a referenced identifier + if (path.scope.getBinding("Infinity")) { + return; + } + + if (path.parentPath.isObjectProperty({ key: path.node })) { + return; + } + + if (path.parentPath.isMemberExpression()) { + return; + } + + if (path.isLVal() && !path.parentPath.isExpressionStatement()) { + return; + } + + path.replaceWith(INFINITY); + } + } + }; +}; \ No newline at end of file diff --git a/node_modules/babel-plugin-minify-infinity/package.json b/node_modules/babel-plugin-minify-infinity/package.json new file mode 100644 index 00000000000..ed9cf32f79e --- /dev/null +++ b/node_modules/babel-plugin-minify-infinity/package.json @@ -0,0 +1,46 @@ +{ + "_from": "babel-plugin-minify-infinity@^0.1.2", + "_id": "babel-plugin-minify-infinity@0.1.2", + "_inBundle": false, + "_integrity": "sha1-Xxz2fd7cuhPIoA2oMlQt8AkaHNQ=", + "_location": "/babel-plugin-minify-infinity", + "_phantomChildren": {}, + "_requested": { + "type": "range", + "registry": true, + "raw": "babel-plugin-minify-infinity@^0.1.2", + "name": "babel-plugin-minify-infinity", + "escapedName": "babel-plugin-minify-infinity", + "rawSpec": "^0.1.2", + "saveSpec": null, + "fetchSpec": "^0.1.2" + }, + "_requiredBy": [ + "/node-titanium-sdk/babel-preset-babili" + ], + "_resolved": "https://registry.npmjs.org/babel-plugin-minify-infinity/-/babel-plugin-minify-infinity-0.1.2.tgz", + "_shasum": "5f1cf67ddedcba13c8a00da832542df0091a1cd4", + "_spec": "babel-plugin-minify-infinity@^0.1.2", + "_where": "/Users/chris/appc/titanium_mobile/node_modules/node-titanium-sdk/node_modules/babel-preset-babili", + "author": { + "name": "amasad" + }, + "bugs": { + "url": "https://github.com/babel/babili/issues" + }, + "bundleDependencies": false, + "deprecated": false, + "description": "## Example", + "homepage": "https://github.com/babel/babili#readme", + "keywords": [ + "babel-plugin" + ], + "license": "MIT", + "main": "lib/index.js", + "name": "babel-plugin-minify-infinity", + "repository": { + "type": "git", + "url": "https://github.com/babel/babili/tree/master/packages/babel-plugin-minify-infinity" + }, + "version": "0.1.2" +} diff --git a/node_modules/babel-preset-babili/node_modules/babel-plugin-minify-mangle-names/.npmignore b/node_modules/babel-plugin-minify-mangle-names/.npmignore similarity index 100% rename from node_modules/babel-preset-babili/node_modules/babel-plugin-minify-mangle-names/.npmignore rename to node_modules/babel-plugin-minify-mangle-names/.npmignore diff --git a/node_modules/babel-preset-babili/node_modules/babel-plugin-minify-mangle-names/README.md b/node_modules/babel-plugin-minify-mangle-names/README.md similarity index 100% rename from node_modules/babel-preset-babili/node_modules/babel-plugin-minify-mangle-names/README.md rename to node_modules/babel-plugin-minify-mangle-names/README.md diff --git a/node_modules/babel-plugin-minify-mangle-names/lib/bfs-traverse.js b/node_modules/babel-plugin-minify-mangle-names/lib/bfs-traverse.js new file mode 100644 index 00000000000..55553c2d65e --- /dev/null +++ b/node_modules/babel-plugin-minify-mangle-names/lib/bfs-traverse.js @@ -0,0 +1,110 @@ +"use strict"; + +module.exports = function bfsTraverseCreator(_ref) { + var t = _ref.types, + traverse = _ref.traverse; + + function getFields(path) { + return t.VISITOR_KEYS[path.type]; + } + + return function bfsTraverse(path, _visitor) { + if (!path.node) { + throw new Error("Not a valid path"); + } + var visitor = traverse.explode(_visitor); + + var queue = [path]; + var current = void 0; + + while (queue.length > 0) { + current = queue.shift(); + + // call + if (visitor && visitor[current.type] && Array.isArray(visitor[current.type].enter)) { + var fns = visitor[current.type].enter; + var _iteratorNormalCompletion = true; + var _didIteratorError = false; + var _iteratorError = undefined; + + try { + for (var _iterator = fns[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { + var fn = _step.value; + + if (typeof fn === "function") fn(current); + } + } catch (err) { + _didIteratorError = true; + _iteratorError = err; + } finally { + try { + if (!_iteratorNormalCompletion && _iterator.return) { + _iterator.return(); + } + } finally { + if (_didIteratorError) { + throw _iteratorError; + } + } + } + } + + var fields = getFields(current); + + var _iteratorNormalCompletion2 = true; + var _didIteratorError2 = false; + var _iteratorError2 = undefined; + + try { + for (var _iterator2 = fields[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) { + var field = _step2.value; + + var child = current.get(field); + + if (Array.isArray(child)) { + // visit container left to right + var _iteratorNormalCompletion3 = true; + var _didIteratorError3 = false; + var _iteratorError3 = undefined; + + try { + for (var _iterator3 = child[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) { + var c = _step3.value; + + if (c.node) queue.push(c); + } + } catch (err) { + _didIteratorError3 = true; + _iteratorError3 = err; + } finally { + try { + if (!_iteratorNormalCompletion3 && _iterator3.return) { + _iterator3.return(); + } + } finally { + if (_didIteratorError3) { + throw _iteratorError3; + } + } + } + } else { + if (child.node) queue.push(child); + } + } + } catch (err) { + _didIteratorError2 = true; + _iteratorError2 = err; + } finally { + try { + if (!_iteratorNormalCompletion2 && _iterator2.return) { + _iterator2.return(); + } + } finally { + if (_didIteratorError2) { + throw _iteratorError2; + } + } + } + } + }; +}; \ No newline at end of file diff --git a/node_modules/babel-plugin-minify-mangle-names/lib/charset.js b/node_modules/babel-plugin-minify-mangle-names/lib/charset.js new file mode 100644 index 00000000000..915a3108754 --- /dev/null +++ b/node_modules/babel-plugin-minify-mangle-names/lib/charset.js @@ -0,0 +1,71 @@ +"use strict"; + +var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); + +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } + +var CHARSET = ("abcdefghijklmnopqrstuvwxyz" + "ABCDEFGHIJKLMNOPQRSTUVWXYZ$_").split(""); + +module.exports = function () { + function Charset(shouldConsider) { + var _this = this; + + _classCallCheck(this, Charset); + + this.shouldConsider = shouldConsider; + this.chars = CHARSET.slice(); + this.frequency = {}; + this.chars.forEach(function (c) { + _this.frequency[c] = 0; + }); + this.finalized = false; + } + + _createClass(Charset, [{ + key: "consider", + value: function consider(str) { + var _this2 = this; + + if (!this.shouldConsider) { + return; + } + + str.split("").forEach(function (c) { + if (_this2.frequency[c] != null) { + _this2.frequency[c]++; + } + }); + } + }, { + key: "sort", + value: function sort() { + var _this3 = this; + + if (this.shouldConsider) { + this.chars = this.chars.sort(function (a, b) { + return _this3.frequency[b] - _this3.frequency[a]; + }); + } + + this.finalized = true; + } + }, { + key: "getIdentifier", + value: function getIdentifier(num) { + if (!this.finalized) { + throw new Error("Should sort first"); + } + + var ret = ""; + num++; + do { + num--; + ret += this.chars[num % this.chars.length]; + num = Math.floor(num / this.chars.length); + } while (num > 0); + return ret; + } + }]); + + return Charset; +}(); \ No newline at end of file diff --git a/node_modules/babel-plugin-minify-mangle-names/lib/counted-set.js b/node_modules/babel-plugin-minify-mangle-names/lib/counted-set.js new file mode 100644 index 00000000000..5f93850e00e --- /dev/null +++ b/node_modules/babel-plugin-minify-mangle-names/lib/counted-set.js @@ -0,0 +1,50 @@ +"use strict"; + +var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); + +function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } } + +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } + +// Set that counts +module.exports = function () { + function CountedSet() { + _classCallCheck(this, CountedSet); + + // because you can't simply extend Builtins yet + this.map = new Map(); + } + + _createClass(CountedSet, [{ + key: "keys", + value: function keys() { + return [].concat(_toConsumableArray(this.map.keys())); + } + }, { + key: "has", + value: function has(value) { + return this.map.has(value); + } + }, { + key: "add", + value: function add(value) { + if (!this.has(value)) { + this.map.set(value, 0); + } + this.map.set(value, this.map.get(value) + 1); + } + }, { + key: "delete", + value: function _delete(value) { + if (!this.has(value)) return; + var count = this.map.get(value); + if (count <= 1) { + this.map.delete(value); + } else { + this.map.set(value, count - 1); + } + } + }]); + + return CountedSet; +}(); \ No newline at end of file diff --git a/node_modules/babel-plugin-minify-mangle-names/lib/fixup-var-scoping.js b/node_modules/babel-plugin-minify-mangle-names/lib/fixup-var-scoping.js new file mode 100644 index 00000000000..736e6071c41 --- /dev/null +++ b/node_modules/babel-plugin-minify-mangle-names/lib/fixup-var-scoping.js @@ -0,0 +1,55 @@ +"use strict"; + +// this fixes a bug where converting let to var +// doesn't change the binding's scope to function scope +// https://github.com/babel/babel/issues/4818 +module.exports = function (mangler) { + mangler.program.traverse({ + VariableDeclaration(path) { + if (path.node.kind !== "var") { + return; + } + var fnScope = path.scope.getFunctionParent(); + var bindingIds = path.getOuterBindingIdentifierPaths(); + + for (var name in bindingIds) { + var binding = path.scope.getBinding(name); + + // var isn't hoisted to fnScope + if (binding.scope !== fnScope) { + var existingBinding = fnScope.bindings[name]; + // make sure we are clear that the fnScope doesn't already have + // an existing binding + if (!existingBinding) { + // move binding to the function scope + + // update our scopeTracker first before + // we mutate the scope + mangler.scopeTracker.moveBinding(binding, fnScope); + + fnScope.bindings[name] = binding; + binding.scope = fnScope; + delete binding.scope.bindings[name]; + } else { + // we need a new binding that's valid in both the scopes + // binding.scope and fnScope + var newName = fnScope.generateUid(binding.scope.generateUid(name)); + + // rename binding in the original scope + mangler.rename(binding.scope, binding, name, newName); + + // move binding to fnScope as newName + + // update our scopeTracker first before + // we mutate the scope + mangler.scopeTracker.moveBinding(binding, fnScope); + + fnScope.bindings[newName] = binding; + binding.scope = fnScope; + delete binding.scope.bindings[newName]; + } + } + } + } + }); +}; \ No newline at end of file diff --git a/node_modules/babel-plugin-minify-mangle-names/lib/index.js b/node_modules/babel-plugin-minify-mangle-names/lib/index.js new file mode 100644 index 00000000000..c6bb39d4d1f --- /dev/null +++ b/node_modules/babel-plugin-minify-mangle-names/lib/index.js @@ -0,0 +1,617 @@ +"use strict"; + +var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); + +function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } } + +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } + +var Charset = require("./charset"); +var ScopeTracker = require("./scope-tracker"); +var isLabelIdentifier = require("./is-label-identifier"); +var bfsTraverseCreator = require("./bfs-traverse"); +var fixupVarScoping = require("./fixup-var-scoping"); + +var _require = require("babel-helper-mark-eval-scopes"), + markEvalScopes = _require.markEvalScopes, + isEvalScopesMarked = _require.isMarked, + hasEval = _require.hasEval; + +var newIssueUrl = "https://github.com/babel/babili/issues/new"; + +module.exports = function (babel) { + var t = babel.types, + traverse = babel.traverse; + + var bfsTraverse = bfsTraverseCreator(babel); + var hop = Object.prototype.hasOwnProperty; + + var Mangler = function () { + function Mangler(charset, program) { + var _ref = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}, + _ref$blacklist = _ref.blacklist, + blacklist = _ref$blacklist === undefined ? {} : _ref$blacklist, + _ref$keepFnName = _ref.keepFnName, + keepFnName = _ref$keepFnName === undefined ? false : _ref$keepFnName, + _ref$keepClassName = _ref.keepClassName, + keepClassName = _ref$keepClassName === undefined ? false : _ref$keepClassName, + _ref$eval = _ref.eval, + _eval = _ref$eval === undefined ? false : _ref$eval, + _ref$topLevel = _ref.topLevel, + topLevel = _ref$topLevel === undefined ? false : _ref$topLevel; + + _classCallCheck(this, Mangler); + + this.charset = charset; + this.program = program; + + // user passed options + this.blacklist = toObject(blacklist); + this.keepFnName = keepFnName; + this.keepClassName = keepClassName; + this.topLevel = topLevel; + this.eval = _eval; + + // tracking + this.visitedScopes = new Set(); + this.scopeTracker = new ScopeTracker(); + this.renamedNodes = new Set(); + } + + /** + * Run the mangler + */ + + + _createClass(Mangler, [{ + key: "run", + value: function run() { + this.crawlScope(); + this.collect(); + this.fixup(); + this.charset.sort(); + this.mangle(); + } + + /** + * Tells if a variable name is blacklisted + * @param {String} name + */ + + }, { + key: "isBlacklist", + value: function isBlacklist(name) { + return hop.call(this.blacklist, name) && this.blacklist[name]; + } + + /** + * Clears traverse cache and recrawls the AST + * + * to recompute the bindings, references, other scope information + * and paths because the other transformations in the same pipeline + * (other plugins and presets) changes the AST and does NOT update + * the scope objects + */ + + }, { + key: "crawlScope", + value: function crawlScope() { + traverse.clearCache(); + this.program.scope.crawl(); + } + + /** + * Re-crawling comes with a side-effect that let->var conversion + * reverts the update of the binding information (block to fn scope). + * This function takes care of it by updating it again. + * + * TODO: This is unnecessary work and needs to be fixed in babel. + * https://github.com/babel/babel/issues/4818 + * + * When this is removed, remember to remove fixup's dependency in + * ScopeTracker + */ + + }, { + key: "fixup", + value: function fixup() { + fixupVarScoping(this); + } + + /** + * A single pass through the AST to collect info for + * + * 1. Scope Tracker + * 2. Unsafe Scopes (direct eval scopes) + * 3. Charset considerations for better gzip compression + * + * Traversed in the same fashion(BFS) the mangling is done + */ + + }, { + key: "collect", + value: function collect() { + var mangler = this; + var scopeTracker = mangler.scopeTracker; + + + scopeTracker.addScope(this.program.scope); + + /** + * Same usage as in DCE, whichever runs first + */ + if (!isEvalScopesMarked(mangler.program.scope)) { + markEvalScopes(mangler.program); + } + + /** + * The visitors to be used in traversal. + * + * Note: BFS traversal supports only the `enter` handlers, `exit` + * handlers are simply dropped without Errors + * + * Collects items defined in the ScopeTracker + */ + var collectVisitor = { + Scopable(_ref2) { + var scope = _ref2.scope; + + scopeTracker.addScope(scope); + + // Collect bindings defined in the scope + Object.keys(scope.bindings).forEach(function (name) { + scopeTracker.addBinding(scope.bindings[name]); + }); + }, + /** + * This is necessary because, in Babel, the scope.references + * does NOT contain the references in that scope. Only the program + * scope (top most level) contains all the references. + * + * We collect the references in a fashion where all the scopes between + * and including the referenced scope and scope where it is declared + * is considered as scope referencing that identifier + */ + ReferencedIdentifier(path) { + if (isLabelIdentifier(path)) return; + var scope = path.scope, + name = path.node.name; + + var binding = scope.getBinding(name); + if (!binding) { + // Do not collect globals as they are already available via + // babel's API + if (scope.hasGlobal(name)) return; + // This should NOT happen ultimately. Panic if this code block is + // reached + throw new Error(`Binding not found for ReferencedIdentifier "${name}" ` + `present in "${path.parentPath.type}". ` + `Please report this at ${newIssueUrl}`); + } else { + // Add it to our scope tracker if everything is fine + scopeTracker.addReference(scope, binding, name); + } + }, + + /** + * This is useful to detect binding ids and add them to the + * scopeTracker's bindings + * + * TODO: + * + * This visitor is probably unnecessary. It was added to capture the + * bindings that was not present in scope.bindings. But, now, it looks + * like the unit and smoke tests pass without this. + */ + BindingIdentifier(path) { + if (isLabelIdentifier(path)) return; + + var scope = path.scope, + name = path.node.name; + + var binding = scope.getBinding(name); + + /** + * We have already captured the bindings when traversing through + * Scopables, if a binding identifier doesn't have a binding, it + * probably means that another transformation created a new binding, + * refer https://github.com/babel/babili/issues/549 for example - + * binding created by plugin transform-es2015-function-name + * + * So we just don't care about bindings that do not exist + * + * TODO: + * + * this deopts in DCE as this name can be removed for this particular + * case (es2015-function-name) + */ + if (!binding) return; + + /** + * Detect constant violations + * + * If it's a constant violation, then add the Identifier Path as + * a Reference instead of Binding - This is because the ScopeTracker + * tracks these Re-declaration and mutation of variables as References + * as it is simple to rename them + */ + if (binding.identifier === path.node) { + scopeTracker.addBinding(binding); + } else { + // constant violation + scopeTracker.addReference(scope, binding, name); + } + } + }; + + /** + * These visitors are for collecting the Characters used in the program + * to measure the frequency and generate variable names for mangling so + * as to improve the gzip compression - as gzip likes repetition + */ + if (this.charset.shouldConsider) { + collectVisitor.Identifier = function Identifer(path) { + var node = path.node; + + // We don't mangle properties, so we collect them as they contribute + // to the frequency of characters + + if (path.parentPath.isMemberExpression({ property: node }) || path.parentPath.isObjectProperty({ key: node })) { + mangler.charset.consider(node.name); + } + }; + collectVisitor.Literal = function Literal(_ref3) { + var node = _ref3.node; + + mangler.charset.consider(String(node.value)); + }; + } + + // Traverse the AST + bfsTraverse(mangler.program, collectVisitor); + } + + /** + * Tells if a binding is exported as a NamedExport - so as to NOT mangle + * + * Babel treats NamedExports as a binding referenced by this NamedExport decl + * @param {Binding} binding + */ + + }, { + key: "isExportedWithName", + value: function isExportedWithName(binding) { + // short circuit + if (!this.topLevel) { + return false; + } + + var refs = binding.referencePaths; + + var _iteratorNormalCompletion = true; + var _didIteratorError = false; + var _iteratorError = undefined; + + try { + for (var _iterator = refs[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { + var ref = _step.value; + + if (ref.isExportNamedDeclaration()) { + return true; + } + } + + // default + } catch (err) { + _didIteratorError = true; + _iteratorError = err; + } finally { + try { + if (!_iteratorNormalCompletion && _iterator.return) { + _iterator.return(); + } + } finally { + if (_didIteratorError) { + throw _iteratorError; + } + } + } + + return false; + } + + /** + * Mangle the scope + * @param {Scope} scope + */ + + }, { + key: "mangleScope", + value: function mangleScope(scope) { + var mangler = this; + var scopeTracker = mangler.scopeTracker; + + // Unsafe Scope + + if (!mangler.eval && hasEval(scope)) return; + + // Already visited + // This is because for a function, in Babel, the function and + // the function body's BlockStatement has the same scope, and will + // be visited twice by the Scopable handler, and we want to mangle + // it only once + if (mangler.visitedScopes.has(scope)) return; + mangler.visitedScopes.add(scope); + + // Helpers to generate names + var i = 0; + function getNext() { + return mangler.charset.getIdentifier(i++); + } + function resetNext() { + i = 0; + } + + var bindings = scopeTracker.bindings.get(scope); + var names = [].concat(_toConsumableArray(bindings.keys())); + + /** + * 1. Iterate through the list of BindingIdentifiers + * 2. Rename each of them in-place + * 3. Update the scope tree. + */ + for (var _i = 0; _i < names.length; _i++) { + var oldName = names[_i]; + var binding = bindings.get(oldName); + + // Names which should NOT be mangled + if ( + // arguments - for non-strict mode + oldName === "arguments" || + // labels + binding.path.isLabeledStatement() || + // ClassDeclaration has binding in two scopes + // 1. The scope in which it is declared + // 2. The class's own scope + binding.path.isClassDeclaration() && binding.path === scope.path || + // blacklisted + mangler.isBlacklist(oldName) || ( + // function names + mangler.keepFnName ? isFunction(binding.path) : false) || ( + // class names + mangler.keepClassName ? isClass(binding.path) : false) || + // named export + mangler.isExportedWithName(binding)) { + continue; + } + + var next = void 0; + do { + next = getNext(); + } while (!t.isValidIdentifier(next) || scopeTracker.hasBinding(scope, next) || scope.hasGlobal(next) || scopeTracker.hasReference(scope, next) || !scopeTracker.canUseInReferencedScopes(binding, next)); + + // Reset so variables which are removed can be reused + resetNext(); + + // Once we detected a valid `next` Identifier which could be used, + // call the renamer + mangler.rename(scope, binding, oldName, next); + } + } + + /** + * The mangle function that traverses through all the Scopes in a BFS + * fashion - calls mangleScope + */ + + }, { + key: "mangle", + value: function mangle() { + var mangler = this; + + bfsTraverse(this.program, { + Scopable(path) { + if (!path.isProgram() || mangler.topLevel) mangler.mangleScope(path.scope); + } + }); + } + + /** + * Given a NodePath, collects all the Identifiers which are BindingIdentifiers + * and replaces them with the new name + * + * For example, + * var a = 1, { b } = c; // a and b are BindingIdentifiers + * + * @param {NodePath} path + * @param {String} oldName + * @param {String} newName + * @param {Function} predicate + */ + + }, { + key: "renameBindingIds", + value: function renameBindingIds(path, oldName, newName) { + var predicate = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : function () { + return true; + }; + + var bindingIds = path.getBindingIdentifierPaths(true, false); + for (var name in bindingIds) { + if (name !== oldName) continue; + var _iteratorNormalCompletion2 = true; + var _didIteratorError2 = false; + var _iteratorError2 = undefined; + + try { + for (var _iterator2 = bindingIds[name][Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) { + var idPath = _step2.value; + + if (predicate(idPath)) { + this.renamedNodes.add(idPath.node); + idPath.replaceWith(t.identifier(newName)); + this.renamedNodes.add(idPath.node); + } + } + } catch (err) { + _didIteratorError2 = true; + _iteratorError2 = err; + } finally { + try { + if (!_iteratorNormalCompletion2 && _iterator2.return) { + _iterator2.return(); + } + } finally { + if (_didIteratorError2) { + throw _iteratorError2; + } + } + } + } + } + + /** + * The Renamer: + * Renames the following for one Binding in a Scope + * + * 1. Binding in that Scope + * 2. All the Binding's constant violations + * 3. All its References + * 4. Updates mangler.scopeTracker + * 5. Updates Babel's Scope tracking + * + * @param {Scope} scope + * @param {Binding} binding + * @param {String} oldName + * @param {String} newName + */ + + }, { + key: "rename", + value: function rename(scope, binding, oldName, newName) { + var mangler = this; + var scopeTracker = mangler.scopeTracker; + + // rename at the declaration level + + this.renameBindingIds(binding.path, oldName, newName, function (idPath) { + return idPath.node === binding.identifier; + }); + + // update mangler's ScopeTracker + scopeTracker.renameBinding(scope, oldName, newName); + + // update all constant violations + var violations = binding.constantViolations; + for (var i = 0; i < violations.length; i++) { + if (violations[i].isLabeledStatement()) continue; + + this.renameBindingIds(violations[i], oldName, newName); + scopeTracker.updateReference(violations[i].scope, binding, oldName, newName); + } + + // update all referenced places + var refs = binding.referencePaths; + for (var _i2 = 0; _i2 < refs.length; _i2++) { + var path = refs[_i2]; + + var node = path.node; + + + if (!path.isIdentifier()) { + // Ideally, this should not happen + // it happens in these places now - + // case 1: Export Statements + // This is a bug in babel + // https://github.com/babel/babel/pull/3629 + // case 2: Replacements in other plugins + // eg: https://github.com/babel/babili/issues/122 + // replacement in dce from `x` to `!x` gives referencePath as `!x` + path.traverse({ + ReferencedIdentifier(refPath) { + if (refPath.node.name !== oldName) { + return; + } + var actualBinding = refPath.scope.getBinding(oldName); + if (actualBinding !== binding) { + return; + } + mangler.renamedNodes.add(refPath.node); + refPath.replaceWith(t.identifier(newName)); + mangler.renamedNodes.add(refPath.node); + + scopeTracker.updateReference(refPath.scope, binding, oldName, newName); + } + }); + } else if (!isLabelIdentifier(path)) { + if (path.node.name === oldName) { + mangler.renamedNodes.add(path.node); + path.replaceWith(t.identifier(newName)); + mangler.renamedNodes.add(path.node); + scopeTracker.updateReference(path.scope, binding, oldName, newName); + } else if (mangler.renamedNodes.has(path.node)) { + // already renamed, + // just update the references + scopeTracker.updateReference(path.scope, binding, oldName, newName); + } else { + throw new Error(`Unexpected Rename Error: ` + `Trying to replace "${node.name}": from "${oldName}" to "${newName}". ` + `Please report it at ${newIssueUrl}`); + } + } + // else label identifier - silently ignore + } + + // update babel's scope tracking + var bindings = scope.bindings; + + bindings[newName] = binding; + delete bindings[oldName]; + } + }]); + + return Mangler; + }(); + + return { + name: "minify-mangle-names", + visitor: { + /** + * Mangler is run as a single pass. It's the same pattern as used in DCE + */ + Program: { + exit(path) { + // If the source code is small then we're going to assume that the user + // is running on this on single files before bundling. Therefore we + // need to achieve as much determinisim and we will not do any frequency + // sorting on the character set. Currently the number is pretty arbitrary. + var shouldConsiderSource = path.getSource().length > 70000; + + var charset = new Charset(shouldConsiderSource); + + var mangler = new Mangler(charset, path, this.opts); + mangler.run(); + } + } + } + }; +}; + +// convert value to object +function toObject(value) { + if (!Array.isArray(value)) { + return value; + } + + var map = {}; + for (var i = 0; i < value.length; i++) { + map[value[i]] = true; + } + return map; +} + +// for keepFnName +function isFunction(path) { + return path.isFunctionExpression() || path.isFunctionDeclaration(); +} + +// for keepClassName +function isClass(path) { + return path.isClassExpression() || path.isClassDeclaration(); +} \ No newline at end of file diff --git a/node_modules/babel-plugin-minify-mangle-names/lib/is-label-identifier.js b/node_modules/babel-plugin-minify-mangle-names/lib/is-label-identifier.js new file mode 100644 index 00000000000..372425fd7ed --- /dev/null +++ b/node_modules/babel-plugin-minify-mangle-names/lib/is-label-identifier.js @@ -0,0 +1,9 @@ +"use strict"; + +module.exports = isLabelIdentifier; + +function isLabelIdentifier(path) { + var node = path.node; + + return path.parentPath.isLabeledStatement({ label: node }) || path.parentPath.isBreakStatement({ label: node }) || path.parentPath.isContinueStatement({ label: node }); +} \ No newline at end of file diff --git a/node_modules/babel-plugin-minify-mangle-names/lib/scope-tracker.js b/node_modules/babel-plugin-minify-mangle-names/lib/scope-tracker.js new file mode 100644 index 00000000000..d79ce9fb564 --- /dev/null +++ b/node_modules/babel-plugin-minify-mangle-names/lib/scope-tracker.js @@ -0,0 +1,265 @@ +"use strict"; + +var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); + +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } + +var CountedSet = require("./counted-set"); +var isLabelIdentifier = require("./is-label-identifier"); + +var newIssueUrl = "https://github.com/babel/babili/issues/new"; + +/** + * ScopeTracker + * references: Map > + * bindings: Map > + */ +module.exports = function () { + function ScopeTracker() { + _classCallCheck(this, ScopeTracker); + + this.references = new Map(); + this.bindings = new Map(); + } + + /** + * Register a new Scope and initiliaze it with empty sets + * @param {Scope} scope + */ + + + _createClass(ScopeTracker, [{ + key: "addScope", + value: function addScope(scope) { + if (!this.references.has(scope)) { + this.references.set(scope, new CountedSet()); + } + if (!this.bindings.has(scope)) { + this.bindings.set(scope, new Map()); + } + } + + /** + * Add reference to all Scopes between and including the ReferencedScope + * and Binding's Scope + * @param {Scope} scope + * @param {Binding} binding + * @param {String} name + */ + + }, { + key: "addReference", + value: function addReference(scope, binding, name) { + var parent = scope; + do { + this.references.get(parent).add(name); + if (!binding) { + throw new Error(`Binding Not Found for ${name} during scopeTracker.addRefernce. ` + `Please report at ${newIssueUrl}`); + } + if (binding.scope === parent) break; + } while (parent = parent.parent); + } + + /** + * has a Reference in the given {Scope} or a child Scope + * + * Refer {addReference} to know why the following call will be valid + * for detecting references in child Scopes + * + * @param {Scope} scope + * @param {String} name + */ + + }, { + key: "hasReference", + value: function hasReference(scope, name) { + return this.references.get(scope).has(name); + } + + /** + * Update reference count in all scopes between and including the + * Referenced Scope and the Binding's Scope + * + * @param {Scope} scope + * @param {Binding} binding + * @param {String} oldName + * @param {String} newName + */ + + }, { + key: "updateReference", + value: function updateReference(scope, binding, oldName, newName) { + var parent = scope; + do { + var ref = this.references.get(parent); + + ref.delete(oldName); + ref.add(newName); + + if (!binding) { + // Something went wrong - panic + throw new Error("Binding Not Found during scopeTracker.updateRefernce " + `while updating "${oldName}" to "${newName}". ` + `Please report at ${newIssueUrl}`); + } + + if (binding.scope === parent) break; + } while (parent = parent.parent); + } + + /** + * has either a Binding or a Reference + * @param {Scope} scope + * @param {Binding} binding + * @param {String} name + */ + + }, { + key: "hasBindingOrReference", + value: function hasBindingOrReference(scope, binding, name) { + return this.hasReference(scope, name) || this.hasBinding(scope, name); + } + + /** + * For a Binding visit all places where the Binding is used and detect + * if the newName {next} can be used in all these places + * + * 1. binding's own scope + * 2. constant violations' scopes + * 3. referencePaths' scopes + * + * @param {Binding} binding + * @param {String} next + */ + + }, { + key: "canUseInReferencedScopes", + value: function canUseInReferencedScopes(binding, next) { + var tracker = this; + + if (tracker.hasBindingOrReference(binding.scope, binding, next)) { + return false; + } + + // Safari raises a syntax error for a `let` or `const` declaration in a + // `for` loop initialization that shadows a parent function's parameter. + // https://github.com/babel/babili/issues/559 + // https://bugs.webkit.org/show_bug.cgi?id=171041 + // https://trac.webkit.org/changeset/217200/webkit/trunk/Source + var maybeDecl = binding.path.parentPath; + var isBlockScoped = maybeDecl.isVariableDeclaration({ kind: "let" }) || maybeDecl.isVariableDeclaration({ kind: "const" }); + if (isBlockScoped) { + var maybeFor = maybeDecl.parentPath; + var isForLoopBinding = maybeFor.isForStatement({ init: maybeDecl.node }) || maybeFor.isForXStatement({ left: maybeDecl.node }); + if (isForLoopBinding) { + var fnParent = maybeFor.getFunctionParent(); + if (fnParent.isFunction({ body: maybeFor.parent })) { + var parentFunctionBinding = this.bindings.get(fnParent.scope).get(next); + if (parentFunctionBinding) { + var parentFunctionHasParamBinding = parentFunctionBinding.kind === "param"; + if (parentFunctionHasParamBinding) { + return false; + } + } + } + } + } + + for (var i = 0; i < binding.constantViolations.length; i++) { + var violation = binding.constantViolations[i]; + if (tracker.hasBindingOrReference(violation.scope, binding, next)) { + return false; + } + } + + for (var _i = 0; _i < binding.referencePaths.length; _i++) { + var ref = binding.referencePaths[_i]; + if (!ref.isIdentifier()) { + var canUse = true; + ref.traverse({ + ReferencedIdentifier(path) { + if (path.node.name !== next) return; + if (tracker.hasBindingOrReference(path.scope, binding, next)) { + canUse = false; + } + } + }); + if (!canUse) { + return canUse; + } + } else if (!isLabelIdentifier(ref)) { + if (tracker.hasBindingOrReference(ref.scope, binding, next)) { + return false; + } + } + } + + return true; + } + + /** + * Add a binding to Tracker in binding's own Scope + * @param {Binding} binding + */ + + }, { + key: "addBinding", + value: function addBinding(binding) { + if (!binding) { + return; + } + + var bindings = this.bindings.get(binding.scope); + var existingBinding = bindings.get(binding.identifier.name); + + if (existingBinding && existingBinding !== binding) { + throw new Error(`scopeTracker.addBinding: ` + `Binding "${existingBinding.identifier.name}" already exists. ` + `Trying to add "${binding.identifier.name}" again.`); + } + + bindings.set(binding.identifier.name, binding); + } + + /** + * Moves Binding from it's own Scope to {toScope} + * + * required for fixup-var-scope + * + * @param {Binding} binding + * @param {Scope} toScope + */ + + }, { + key: "moveBinding", + value: function moveBinding(binding, toScope) { + this.bindings.get(binding.scope).delete(binding.identifier.name); + this.bindings.get(toScope).set(binding.identifier.name, binding); + } + + /** + * has a Binding in the current {Scope} + * @param {Scope} scope + * @param {String} name + */ + + }, { + key: "hasBinding", + value: function hasBinding(scope, name) { + return this.bindings.get(scope).has(name); + } + + /** + * Update the ScopeTracker on rename + * @param {Scope} scope + * @param {String} oldName + * @param {String} newName + */ + + }, { + key: "renameBinding", + value: function renameBinding(scope, oldName, newName) { + var bindings = this.bindings.get(scope); + bindings.set(newName, bindings.get(oldName)); + bindings.delete(oldName); + } + }]); + + return ScopeTracker; +}(); \ No newline at end of file diff --git a/node_modules/babel-plugin-minify-mangle-names/package.json b/node_modules/babel-plugin-minify-mangle-names/package.json new file mode 100644 index 00000000000..a68641c8b05 --- /dev/null +++ b/node_modules/babel-plugin-minify-mangle-names/package.json @@ -0,0 +1,49 @@ +{ + "_from": "babel-plugin-minify-mangle-names@^0.1.3", + "_id": "babel-plugin-minify-mangle-names@0.1.3", + "_inBundle": false, + "_integrity": "sha1-v6JGYaZ5T7A4M1h+VYKLZUSeBv4=", + "_location": "/babel-plugin-minify-mangle-names", + "_phantomChildren": {}, + "_requested": { + "type": "range", + "registry": true, + "raw": "babel-plugin-minify-mangle-names@^0.1.3", + "name": "babel-plugin-minify-mangle-names", + "escapedName": "babel-plugin-minify-mangle-names", + "rawSpec": "^0.1.3", + "saveSpec": null, + "fetchSpec": "^0.1.3" + }, + "_requiredBy": [ + "/node-titanium-sdk/babel-preset-babili" + ], + "_resolved": "https://registry.npmjs.org/babel-plugin-minify-mangle-names/-/babel-plugin-minify-mangle-names-0.1.3.tgz", + "_shasum": "bfa24661a6794fb03833587e55828b65449e06fe", + "_spec": "babel-plugin-minify-mangle-names@^0.1.3", + "_where": "/Users/chris/appc/titanium_mobile/node_modules/node-titanium-sdk/node_modules/babel-preset-babili", + "author": { + "name": "amasad" + }, + "bugs": { + "url": "https://github.com/babel/babili/issues" + }, + "bundleDependencies": false, + "dependencies": { + "babel-helper-mark-eval-scopes": "^0.1.1" + }, + "deprecated": false, + "description": "Context- and scope- aware variable renaming.", + "homepage": "https://github.com/babel/babili#readme", + "keywords": [ + "babel-plugin" + ], + "license": "MIT", + "main": "lib/index.js", + "name": "babel-plugin-minify-mangle-names", + "repository": { + "type": "git", + "url": "https://github.com/babel/babili/tree/master/packages/babel-plugin-minify-mangle-names" + }, + "version": "0.1.3" +} diff --git a/node_modules/babel-preset-babili/node_modules/babel-plugin-minify-numeric-literals/.npmignore b/node_modules/babel-plugin-minify-numeric-literals/.npmignore similarity index 100% rename from node_modules/babel-preset-babili/node_modules/babel-plugin-minify-numeric-literals/.npmignore rename to node_modules/babel-plugin-minify-numeric-literals/.npmignore diff --git a/node_modules/babel-plugin-minify-numeric-literals/README.md b/node_modules/babel-plugin-minify-numeric-literals/README.md new file mode 100644 index 00000000000..25a9e5efae6 --- /dev/null +++ b/node_modules/babel-plugin-minify-numeric-literals/README.md @@ -0,0 +1,49 @@ +# babel-plugin-minify-mangle-names + +Shortening of numeric literals via scientific notation + +## Example + +**In** + +```javascript +[1000, -20000] +``` + +**Out** + +```javascript +[1e3, -2e4] +``` + +## Installation + +```sh +npm install babel-plugin-minify-numeric-literals +``` + +## Usage + +### Via `.babelrc` (Recommended) + +**.babelrc** + +```json +{ + "plugins": ["minify-numeric-literals"] +} +``` + +### Via CLI + +```sh +babel --plugins minify-numeric-literals script.js +``` + +### Via Node API + +```javascript +require("babel-core").transform("code", { + plugins: ["minify-numeric-literals"] +}); +``` diff --git a/node_modules/babel-plugin-minify-numeric-literals/lib/index.js b/node_modules/babel-plugin-minify-numeric-literals/lib/index.js new file mode 100644 index 00000000000..0e85c0392d7 --- /dev/null +++ b/node_modules/babel-plugin-minify-numeric-literals/lib/index.js @@ -0,0 +1,25 @@ +"use strict"; + +module.exports = function (_ref) { + var t = _ref.types; + + return { + name: "minify-numeric-literals", + visitor: { + NumericLiteral(path) { + if (!path.node.extra) return; + + var exponential = path.node.value.toExponential().replace(/\+/g, "").replace(/e0/, ""); + + if (path.node.extra.raw.length > exponential.length) { + var literal = t.numericLiteral(path.node.value); + literal.extra = { + raw: exponential, + rawValue: path.node.value + }; + path.replaceWith(literal); + } + } + } + }; +}; \ No newline at end of file diff --git a/node_modules/babel-plugin-minify-numeric-literals/package.json b/node_modules/babel-plugin-minify-numeric-literals/package.json new file mode 100644 index 00000000000..6be5e2d36ed --- /dev/null +++ b/node_modules/babel-plugin-minify-numeric-literals/package.json @@ -0,0 +1,49 @@ +{ + "_from": "babel-plugin-minify-numeric-literals@^0.1.1", + "_id": "babel-plugin-minify-numeric-literals@0.1.1", + "_inBundle": false, + "_integrity": "sha1-1LiwySX4dHFO4z7ksmZ4WD185/s=", + "_location": "/babel-plugin-minify-numeric-literals", + "_phantomChildren": {}, + "_requested": { + "type": "range", + "registry": true, + "raw": "babel-plugin-minify-numeric-literals@^0.1.1", + "name": "babel-plugin-minify-numeric-literals", + "escapedName": "babel-plugin-minify-numeric-literals", + "rawSpec": "^0.1.1", + "saveSpec": null, + "fetchSpec": "^0.1.1" + }, + "_requiredBy": [ + "/node-titanium-sdk/babel-preset-babili" + ], + "_resolved": "https://registry.npmjs.org/babel-plugin-minify-numeric-literals/-/babel-plugin-minify-numeric-literals-0.1.1.tgz", + "_shasum": "d4b8b0c925f874714ee33ee4b26678583d7ce7fb", + "_spec": "babel-plugin-minify-numeric-literals@^0.1.1", + "_where": "/Users/chris/appc/titanium_mobile/node_modules/node-titanium-sdk/node_modules/babel-preset-babili", + "author": { + "name": "kangax" + }, + "bugs": { + "url": "https://github.com/babel/babili/issues" + }, + "bundleDependencies": false, + "dependencies": {}, + "deprecated": false, + "description": "Shortens numeric literals using scientific notation", + "devDependencies": {}, + "homepage": "https://github.com/babel/babili#readme", + "keywords": [ + "babel-plugin", + "babili" + ], + "license": "MIT", + "main": "lib/index.js", + "name": "babel-plugin-minify-numeric-literals", + "repository": { + "type": "git", + "url": "https://github.com/babel/babili/tree/master/packages/babel-plugin-minify-numeric-literals" + }, + "version": "0.1.1" +} diff --git a/node_modules/babel-preset-babili/node_modules/babel-plugin-minify-replace/.npmignore b/node_modules/babel-plugin-minify-replace/.npmignore similarity index 100% rename from node_modules/babel-preset-babili/node_modules/babel-plugin-minify-replace/.npmignore rename to node_modules/babel-plugin-minify-replace/.npmignore diff --git a/node_modules/babel-plugin-minify-replace/README.md b/node_modules/babel-plugin-minify-replace/README.md new file mode 100644 index 00000000000..49769d00f34 --- /dev/null +++ b/node_modules/babel-plugin-minify-replace/README.md @@ -0,0 +1,91 @@ +# babel-plugin-minify-replace + +Configurable "search and replace" plugin. Replaces matching nodes in the tree with a given replacement node. For example you can replace `process.NODE_ENV` with `"production"`. + +## Example + +**Options** + +```javascript +[ + { + identifierName: "__DEV__", + replacement: { + type: "numericLiteral", + value: 0, + }, + }, +] +``` + +**In** + +```javascript +if (!__DEV__) { + foo(); +} +if (a.__DEV__) { + foo(); +} +``` + +**Out** + +```javascript +if (!0) { + foo(); +} +if (a.__DEV__) { + foo(); +} +``` + +## Installation + +```sh +npm install babel-plugin-minify-replace +``` + +## Usage + +### Via `.babelrc` (Recommended) + +**.babelrc** + +```json +// without options +{ + "plugins": ["minify-replace"] +} +``` + +```json +// with options +{ + "plugins": [ + ["minify-replace", { + "replacements": [{ + "identifierName": "__DEV__", + "replacement": { + "type": "booleanLiteral", + "value": true + } + }] + }] + ] +} +``` + +### Via CLI + +```sh +babel --plugins minify-replace script.js +``` + +### Via Node API + +```javascript +require("babel-core").transform("code", { + plugins: ["minify-replace"] +}); +``` diff --git a/node_modules/babel-plugin-minify-replace/lib/index.js b/node_modules/babel-plugin-minify-replace/lib/index.js new file mode 100644 index 00000000000..c5a0d51195a --- /dev/null +++ b/node_modules/babel-plugin-minify-replace/lib/index.js @@ -0,0 +1,96 @@ +"use strict"; + +module.exports = function (_ref) { + var t = _ref.types; + + var NO_MEMBER = Symbol("no member"); + + var replaceVisitor = { + ReferencedIdentifier(path) { + var _path = path, + node = _path.node; + + var optionsMap = this.replacements[node.name]; + if (!optionsMap) { + return; + } + + var options = void 0; + if (path.parentPath.isMemberExpression({ object: node })) { + var property = path.parent.property; + + var key = t.isIdentifier(property) && property.name; + if (typeof key === "string") { + options = optionsMap[key]; + path = path.parentPath; + } + } + + if (!options) { + options = optionsMap[NO_MEMBER]; + } + + if (!options) { + return; + } + + path.replaceWith(options.node); + } + }; + + return { + name: "minify-replace", + visitor: { + Program(path) { + /** + Replacements is an array of objects like this: + { + identifierName: 'console', + member: 'log', // optional + replacement: { + type: 'identifier', + value: '', + }, + } + **/ + + if (!this.opts.replacements) { + // No replacements. Bail. + return; + } + + var map = Object.create(null); + this.opts.replacements.forEach(function (_ref2) { + var identifierName = _ref2.identifierName, + replacement = _ref2.replacement, + member = _ref2.member; + + if (path.scope.globals[identifierName]) { + // Convert to a node, we only allow identifiers and literals as replacements + if (!replacement.type.match(/literal|identifier/i)) { + throw new Error("Only literals and identifier are supported as replacements"); + } + + var node = t[replacement.type](replacement.value); + var options = { + identifierName, + node, + member + }; + + if (!map[identifierName]) { + map[identifierName] = {}; + } + + if (member && map[identifierName][member]) { + throw new Error(`Replacement collision ${identifierName}.${member}`); + } + map[identifierName][member || NO_MEMBER] = options; + } + }); + + path.traverse(replaceVisitor, { replacements: map }); + } + } + }; +}; \ No newline at end of file diff --git a/node_modules/babel-plugin-minify-replace/package.json b/node_modules/babel-plugin-minify-replace/package.json new file mode 100644 index 00000000000..fc8e3e083f6 --- /dev/null +++ b/node_modules/babel-plugin-minify-replace/package.json @@ -0,0 +1,46 @@ +{ + "_from": "babel-plugin-minify-replace@^0.1.2", + "_id": "babel-plugin-minify-replace@0.1.2", + "_inBundle": false, + "_integrity": "sha1-uQuecatNOzYyVimpG+q+E7CxasE=", + "_location": "/babel-plugin-minify-replace", + "_phantomChildren": {}, + "_requested": { + "type": "range", + "registry": true, + "raw": "babel-plugin-minify-replace@^0.1.2", + "name": "babel-plugin-minify-replace", + "escapedName": "babel-plugin-minify-replace", + "rawSpec": "^0.1.2", + "saveSpec": null, + "fetchSpec": "^0.1.2" + }, + "_requiredBy": [ + "/node-titanium-sdk/babel-preset-babili" + ], + "_resolved": "https://registry.npmjs.org/babel-plugin-minify-replace/-/babel-plugin-minify-replace-0.1.2.tgz", + "_shasum": "b90b9e71ab4d3b36325629a91beabe13b0b16ac1", + "_spec": "babel-plugin-minify-replace@^0.1.2", + "_where": "/Users/chris/appc/titanium_mobile/node_modules/node-titanium-sdk/node_modules/babel-preset-babili", + "author": { + "name": "amasad" + }, + "bugs": { + "url": "https://github.com/babel/babili/issues" + }, + "bundleDependencies": false, + "deprecated": false, + "description": "Configurable \"search and replace\" plugin. Replaces matching nodes in the tree with a given replacement node. For example you can replace `process.NODE_ENV` with `\"production\"`.", + "homepage": "https://github.com/babel/babili#readme", + "keywords": [ + "babel-plugin" + ], + "license": "MIT", + "main": "lib/index.js", + "name": "babel-plugin-minify-replace", + "repository": { + "type": "git", + "url": "https://github.com/babel/babili/tree/master/packages/babel-plugin-minify-replace" + }, + "version": "0.1.2" +} diff --git a/node_modules/babel-preset-babili/node_modules/babel-plugin-minify-simplify/.npmignore b/node_modules/babel-plugin-minify-simplify/.npmignore similarity index 100% rename from node_modules/babel-preset-babili/node_modules/babel-plugin-minify-simplify/.npmignore rename to node_modules/babel-plugin-minify-simplify/.npmignore diff --git a/node_modules/babel-preset-babili/node_modules/babel-plugin-minify-simplify/README.md b/node_modules/babel-plugin-minify-simplify/README.md similarity index 100% rename from node_modules/babel-preset-babili/node_modules/babel-plugin-minify-simplify/README.md rename to node_modules/babel-plugin-minify-simplify/README.md diff --git a/node_modules/babel-plugin-minify-simplify/lib/index.js b/node_modules/babel-plugin-minify-simplify/lib/index.js new file mode 100644 index 00000000000..c97eafe87e8 --- /dev/null +++ b/node_modules/babel-plugin-minify-simplify/lib/index.js @@ -0,0 +1,1663 @@ +"use strict"; + +var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }(); + +function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } } + +var PatternMatch = require("./pattern-match"); + +module.exports = function (_ref) { + var t = _ref.types; + + var flipExpressions = require("babel-helper-flip-expressions")(t); + var toMultipleSequenceExpressions = require("babel-helper-to-multiple-sequence-expressions")(t); + + var VOID_0 = t.unaryExpression("void", t.numericLiteral(0), true); + var condExprSeen = Symbol("condExprSeen"); + var seqExprSeen = Symbol("seqExprSeen"); + var shouldRevisit = Symbol("shouldRevisit"); + + // Types as symbols for comparisions + var types = {}; + t.TYPES.forEach(function (type) { + types[type] = Symbol.for(type); + }); + var isNodeOfType = function isNodeOfType(node, typeSymbol) { + if (typeof typeSymbol !== "symbol") return false; + return t["is" + Symbol.keyFor(typeSymbol)](node); + }; + + // small abstractions + var not = function not(node) { + return t.unaryExpression("!", node); + }; + var notnot = function notnot(node) { + return not(not(node)); + }; + var or = function or(a, b) { + return t.logicalExpression("||", a, b); + }; + var and = function and(a, b) { + return t.logicalExpression("&&", a, b); + }; + + var operators = new Set(["+", "-", "*", "%", "<<", ">>", ">>>", "&", "|", "^", "/", "**"]); + + var updateOperators = new Set(["+", "-"]); + + function areArraysEqual(arr1, arr2) { + return arr1.every(function (value, index) { + return String(value) === String(arr2[index]); + }); + } + + function getName(node) { + if (node.type === "ThisExpression") { + return "this"; + } + if (node.type === "Super") { + return "super"; + } + if (node.type === "NullLiteral") { + return "null"; + } + // augment identifiers so that they don't match + // string/number literals + // but still match against each other + return node.name ? node.name + "_" : node.value /* Literal */; + } + + function getPropNames(path) { + if (!path.isMemberExpression()) { + return; + } + + var obj = path.get("object"); + + var prop = path.get("property"); + var propNames = [getName(prop.node)]; + + while (obj.type === "MemberExpression") { + var node = obj.get("property").node; + if (node) { + propNames.push(getName(node)); + } + obj = obj.get("object"); + } + propNames.push(getName(obj.node)); + + return propNames; + } + var OP_AND = function OP_AND(input) { + return input === "&&"; + }; + var OP_OR = function OP_OR(input) { + return input === "||"; + }; + + return { + name: "minify-simplify", + visitor: { + Statement: { + exit(path) { + if (path.node[shouldRevisit]) { + delete path.node[shouldRevisit]; + path.visit(); + } + } + }, + + // CallExpression(path) { + // const { node } = path; + + /* (function() {})() -> !function() {}() + There is a bug in babel in printing this. Disabling for now. + if (t.isFunctionExpression(node.callee) && + (t.isExpressionStatement(parent) || + (t.isSequenceExpression(parent) && parent.expressions[0] === node)) + ) { + path.replaceWith( + t.callExpression( + t.unaryExpression("!", node.callee, true), + node.arguments + ) + ); + return; + }*/ + // }, + + UnaryExpression: { + enter: [ + // Demorgans. + function (path) { + var node = path.node; + + + if (node.operator !== "!" || flipExpressions.hasSeen(node)) { + return; + } + + var expr = node.argument; + + // We need to make sure that the return type will always be boolean. + if (!(t.isLogicalExpression(expr) || t.isConditionalExpression(expr) || t.isBinaryExpression(expr))) { + return; + } + if (t.isBinaryExpression(expr) && t.COMPARISON_BINARY_OPERATORS.indexOf(expr.operator) === -1) { + return; + } + + if (flipExpressions.shouldFlip(expr, 1)) { + var newNode = flipExpressions.flip(expr); + path.replaceWith(newNode); + } + }, + + // !(a, b, c) -> a, b, !c + function (path) { + var node = path.node; + + + if (node.operator !== "!") { + return; + } + + if (!t.isSequenceExpression(node.argument)) { + return; + } + + var seq = node.argument.expressions; + var expr = seq[seq.length - 1]; + seq[seq.length - 1] = t.unaryExpression("!", expr, true); + path.replaceWith(node.argument); + }, + + // !(a ? b : c) -> a ? !b : !c + function (path) { + var node = path.node; + + + if (node.operator !== "!") { + return; + } + + if (!t.isConditional(node.argument)) { + return; + } + + var cond = node.argument; + cond.alternate = t.unaryExpression("!", cond.alternate, true); + cond.consequent = t.unaryExpression("!", cond.consequent, true); + path.replaceWith(node.argument); + }] + }, + + LogicalExpression: { + exit(path) { + // cache of path.evaluate() + var evaluateMemo = new Map(); + + var TRUTHY = function TRUTHY(input) { + // !NaN and !undefined are truthy + // separate check here as they are considered impure by babel + if (input.isUnaryExpression() && input.get("argument").isIdentifier()) { + if (input.node.argument.name === "NaN" || input.node.argument.name === "undefined") { + return true; + } + } + var evalResult = input.evaluate(); + evaluateMemo.set(input, evalResult); + return evalResult.confident && input.isPure() && evalResult.value; + }; + + var FALSY = function FALSY(input) { + // NaN and undefined are falsy + // separate check here as they are considered impure by babel + if (input.isIdentifier()) { + if (input.node.name === "NaN" || input.node.name === "undefined") { + return true; + } + } + var evalResult = input.evaluate(); + evaluateMemo.set(input, evalResult); + return evalResult.confident && input.isPure() && !evalResult.value; + }; + + var EX = types.Expression; + + // Convention: + // [left, operator, right, handler(leftNode, rightNode)] + + var matcher = new PatternMatch([[TRUTHY, OP_AND, EX, function (l, r) { + return r; + }], [FALSY, OP_AND, EX, function (l) { + return l; + }], [TRUTHY, OP_OR, EX, function (l) { + return l; + }], [FALSY, OP_OR, EX, function (l, r) { + return r; + }]]); + + var left = path.get("left"); + var right = path.get("right"); + var operator = path.node.operator; + + var result = matcher.match([left, operator, right], isPatternMatchesPath); + + if (result.match) { + // here we are sure that left.evaluate is always confident becuase + // it satisfied one of TRUTHY/FALSY paths + var value = void 0; + if (evaluateMemo.has(left)) { + value = evaluateMemo.get(left).value; + } else { + value = left.evaluate().value; + } + path.replaceWith(result.value(t.valueToNode(value), right.node)); + } + } + }, + + AssignmentExpression(path) { + var rightExpr = path.get("right"); + var leftExpr = path.get("left"); + + if (path.node.operator !== "=") { + return; + } + + var canBeUpdateExpression = rightExpr.get("right").isNumericLiteral() && rightExpr.get("right").node.value === 1 && updateOperators.has(rightExpr.node.operator); + + if (leftExpr.isMemberExpression()) { + var leftPropNames = getPropNames(leftExpr); + var rightPropNames = getPropNames(rightExpr.get("left")); + + if (!leftPropNames || leftPropNames.indexOf(undefined) > -1 || !rightPropNames || rightPropNames.indexOf(undefined) > -1 || !operators.has(rightExpr.node.operator) || !areArraysEqual(leftPropNames, rightPropNames)) { + return; + } + } else { + if (!rightExpr.isBinaryExpression() || !operators.has(rightExpr.node.operator) || leftExpr.node.name !== rightExpr.node.left.name) { + return; + } + } + + var newExpression = void 0; + + // special case x=x+1 --> ++x + if (canBeUpdateExpression) { + newExpression = t.updateExpression(rightExpr.node.operator + rightExpr.node.operator, t.clone(leftExpr.node), true /* prefix */ + ); + } else { + newExpression = t.assignmentExpression(rightExpr.node.operator + "=", t.clone(leftExpr.node), t.clone(rightExpr.node.right)); + } + + path.replaceWith(newExpression); + }, + + ConditionalExpression: { + enter: [ + // !foo ? 'foo' : 'bar' -> foo ? 'bar' : 'foo' + // foo !== 'lol' ? 'foo' : 'bar' -> foo === 'lol' ? 'bar' : 'foo' + function flipIfOrConditional(path) { + var node = path.node; + + if (!path.get("test").isLogicalExpression()) { + flipNegation(node); + return; + } + + if (flipExpressions.shouldFlip(node.test)) { + node.test = flipExpressions.flip(node.test); + var _ref2 = [node.consequent, node.alternate]; + node.alternate = _ref2[0]; + node.consequent = _ref2[1]; + } + }, function simplifyPatterns(path) { + var test = path.get("test"); + var consequent = path.get("consequent"); + var alternate = path.get("alternate"); + + var EX = types.Expression, + LE = types.LogicalExpression; + + // Convention: + // =============== + // for each pattern [test, consequent, alternate, handler(expr, cons, alt)] + + var matcher = new PatternMatch([[LE, true, false, function (e) { + return e; + }], [EX, true, false, function (e) { + return notnot(e); + }], [EX, false, true, function (e) { + return not(e); + }], [LE, true, EX, function (e, c, a) { + return or(e, a); + }], [EX, true, EX, function (e, c, a) { + return or(notnot(e), a); + }], [EX, false, EX, function (e, c, a) { + return and(not(e), a); + }], [EX, EX, true, function (e, c) { + return or(not(e), c); + }], [LE, EX, false, function (e, c) { + return and(e, c); + }], [EX, EX, false, function (e, c) { + return and(notnot(e), c); + }]]); + + var result = matcher.match([test, consequent, alternate], isPatternMatchesPath); + + if (result.match) { + path.replaceWith(result.value(test.node, consequent.node, alternate.node)); + } + }], + + exit: [ + // a ? x = foo : b ? x = bar : x = baz; + // x = a ? foo : b ? bar : baz; + function (topPath) { + if (!topPath.parentPath.isExpressionStatement() && !topPath.parentPath.isSequenceExpression()) { + return; + } + + var mutations = []; + var firstLeft = null; + var operator = null; + function visit(path) { + if (path.isConditionalExpression()) { + var _bail = visit(path.get("consequent")); + if (_bail) { + return true; + } + _bail = visit(path.get("alternate")); + return _bail; + } + + if (operator == null) { + operator = path.node.operator; + } else if (path.node.operator !== operator) { + return true; + } + + if (!path.isAssignmentExpression() || !(path.get("left").isIdentifier() || path.get("left").isMemberExpression())) { + return true; + } + + var left = path.get("left").node; + if (firstLeft == null) { + firstLeft = left; + } else if (!t.isNodesEquivalent(left, firstLeft)) { + return true; + } + + mutations.push(function () { + return path.replaceWith(path.get("right").node); + }); + } + + var bail = visit(topPath); + if (bail) { + return; + } + + mutations.forEach(function (f) { + return f(); + }); + topPath.replaceWith(t.assignmentExpression(operator, firstLeft, topPath.node)); + }, + + // bar ? void 0 : void 0 + // (bar, void 0) + // TODO: turn this into general equiv check + function (path) { + var node = path.node; + + if (isVoid0(node.consequent) && isVoid0(node.alternate)) { + path.replaceWith(t.sequenceExpression([path.node.test, VOID_0])); + } + }, + + // bar ? void 0 : foo ? void 0 : + // bar || foo : void 0 + // TODO: turn this into general equiv check + function (path) { + var node = path.node; + + + if (node[condExprSeen] || !isVoid0(node.consequent)) { + return; + } + + node[condExprSeen] = true; + + var tests = [node.test]; + var mutations = []; + var alt = void 0; + + var _loop = function _loop(next) { + next.node[condExprSeen] = true; + alt = next.node.alternate; + + if (isVoid0(next.node.consequent)) { + tests.push(next.node.test); + mutations.push(function () { + return next.remove(); + }); + } else { + alt = next.node; + return "break"; + } + }; + + for (var next = path.get("alternate"); next.isConditionalExpression(); next = next.get("alternate")) { + var _ret = _loop(next); + + if (_ret === "break") break; + } + + if (tests.length === 1) { + return; + } + + var test = tests.reduce(function (expr, curTest) { + return t.logicalExpression("||", expr, curTest); + }); + + path.replaceWith(t.conditionalExpression(test, VOID_0, alt)); + }] + }, + + // concat + VariableDeclaration: { + enter: [ + // Put vars with no init at the top. + function (path) { + var node = path.node; + + + if (node.declarations.length < 2) { + return; + } + + var inits = []; + var empty = []; + var _iteratorNormalCompletion = true; + var _didIteratorError = false; + var _iteratorError = undefined; + + try { + for (var _iterator = node.declarations[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { + var decl = _step.value; + + if (!decl.init) { + empty.push(decl); + } else { + inits.push(decl); + } + } + + // This is based on exprimintation but there is a significant + // imrpovement when we place empty vars at the top in smaller + // files. Whereas it hurts in larger files. + } catch (err) { + _didIteratorError = true; + _iteratorError = err; + } finally { + try { + if (!_iteratorNormalCompletion && _iterator.return) { + _iterator.return(); + } + } finally { + if (_didIteratorError) { + throw _iteratorError; + } + } + } + + if (this.fitsInSlidingWindow) { + node.declarations = empty.concat(inits); + } else { + node.declarations = inits.concat(empty); + } + }] + }, + + Function: { + exit(path) { + earlyReturnTransform(path); + + if (!path.node[shouldRevisit]) { + return; + } + + delete path.node[shouldRevisit]; + path.visit(); + } + }, + + For: { + enter: earlyContinueTransform, + exit: earlyContinueTransform + }, + + ForStatement: { + // Merge previous expressions in the init part of the for. + enter(path) { + var node = path.node; + + if (!path.inList || node.init && !t.isExpression(node.init)) { + return; + } + + var prev = path.getSibling(path.key - 1); + var consumed = false; + if (prev.isVariableDeclaration()) { + var referencedOutsideLoop = false; + + // we don't care if vars are referenced outside the loop as they are fn scope + if (prev.node.kind === "let" || prev.node.kind === "const") { + var ids = Object.keys(prev.getBindingIdentifiers()); + + idloop: for (var i = 0; i < ids.length; i++) { + var binding = prev.scope.bindings[ids[i]]; + // TODO + // Temporary Fix + // if there is no binding, we assume it is referenced outside + // and deopt to avoid bugs + if (!binding) { + referencedOutsideLoop = true; + break idloop; + } + var refs = binding.referencePaths; + for (var j = 0; j < refs.length; j++) { + if (!isAncestor(path, refs[j])) { + referencedOutsideLoop = true; + break idloop; + } + } + } + } + + if (!node.init && !referencedOutsideLoop) { + node.init = prev.node; + consumed = true; + } + } else if (prev.isExpressionStatement()) { + var expr = prev.node.expression; + if (node.init) { + if (t.isSequenceExpression(expr)) { + expr.expressions.push(node.init); + node.init = expr; + } else { + node.init = t.sequenceExpression([expr, node.init]); + } + } else { + node.init = expr; + } + consumed = true; + } + if (consumed) { + prev.remove(); + } + }, + + exit(path) { + var node = path.node; + + if (!node.test) { + return; + } + + if (!path.get("body").isBlockStatement()) { + var bodyNode = path.get("body").node; + if (!t.isIfStatement(bodyNode)) { + return; + } + + if (t.isBreakStatement(bodyNode.consequent, { label: null })) { + node.test = t.logicalExpression("&&", node.test, t.unaryExpression("!", bodyNode.test, true)); + node.body = bodyNode.alternate || t.emptyStatement(); + return; + } + + if (t.isBreakStatement(bodyNode.alternate, { label: null })) { + node.test = t.logicalExpression("&&", node.test, bodyNode.test); + node.body = bodyNode.consequent || t.emptyStatement(); + return; + } + + return; + } + + var statements = node.body.body; + var exprs = []; + var ifStatement = null; + var breakAt = null; + var i = 0; + for (var statement; statement = statements[i]; i++) { + if (t.isIfStatement(statement)) { + if (t.isBreakStatement(statement.consequent, { label: null })) { + ifStatement = statement; + breakAt = "consequent"; + } else if (t.isBreakStatement(statement.alternate, { label: null })) { + ifStatement = statement; + breakAt = "alternate"; + } + break; + } + + // A statement appears before the break statement then bail. + if (!t.isExpressionStatement(statement)) { + return; + } + + exprs.push(statement.expression); + } + + if (!ifStatement) { + return; + } + + var rest = []; + + if (breakAt === "consequent") { + if (t.isBlockStatement(ifStatement.alternate)) { + rest.push.apply(rest, _toConsumableArray(ifStatement.alternate.body)); + } else if (ifStatement.alternate) { + rest.push(ifStatement.alternate); + } + } else { + if (t.isBlockStatement(ifStatement.consequent)) { + rest.push.apply(rest, _toConsumableArray(ifStatement.consequent.body)); + } else if (ifStatement.consequent) { + rest.push(ifStatement.consequent); + } + } + + rest.push.apply(rest, _toConsumableArray(statements.slice(i + 1))); + + var test = breakAt === "consequent" ? t.unaryExpression("!", ifStatement.test, true) : ifStatement.test; + var expr = void 0; + if (exprs.length === 1) { + expr = t.sequenceExpression([exprs[0], test]); + } else if (exprs.length) { + exprs.push(test); + expr = t.sequenceExpression(exprs); + } else { + expr = test; + } + + node.test = t.logicalExpression("&&", node.test, expr); + if (rest.length === 1) { + node.body = rest[0]; + } else if (rest.length) { + node.body = t.blockStatement(rest); + } else { + node.body = t.emptyStatement(); + } + } + }, + + Program(path) { + // An approximation of the resultant gzipped code after minification + this.fitsInSlidingWindow = path.getSource().length / 10 < 33000; + + var node = path.node; + + var statements = toMultipleSequenceExpressions(node.body); + if (!statements.length) { + return; + } + node.body = statements; + + // this additional traversal is horrible but it's done to fix + // https://github.com/babel/babili/issues/323 + // in which type annotation somehow gets messed up + // during sequence expression transformation + path.traverse({ + Identifier: function Identifier(path) { + path.getTypeAnnotation(); + } + }); + }, + + BlockStatement: { + enter(path) { + var node = path.node, + parent = path.parent; + + + var top = []; + var bottom = []; + + for (var i = 0; i < node.body.length; i++) { + var bodyNode = node.body[i]; + if (t.isFunctionDeclaration(bodyNode)) { + top.push(bodyNode); + } else { + bottom.push(bodyNode); + } + } + + var statements = top.concat(toMultipleSequenceExpressions(bottom)); + + if (!statements.length) { + return; + } + + if (statements.length > 1 || needsBlock(node, parent) || node.directives) { + node.body = statements; + return; + } + + if (statements.length) { + path.replaceWith(statements[0]); + return; + } + }, + + exit(path) { + var node = path.node, + parent = path.parent; + + + if (needsBlock(node, parent)) { + return; + } + + if (node.body.length === 1) { + path.get("body")[0].inList = false; + path.replaceWith(node.body[0]); + return; + } + + if (node.body.length === 0) { + path.replaceWith(t.emptyStatement()); + return; + } + + // Check if oppurtinties to merge statements are available. + var statements = node.body; + if (!statements.length) { + return; + } + + var _iteratorNormalCompletion2 = true; + var _didIteratorError2 = false; + var _iteratorError2 = undefined; + + try { + for (var _iterator2 = statements[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) { + var statement = _step2.value; + + if (!t.isExpressionStatement(statement)) { + return; + } + } + } catch (err) { + _didIteratorError2 = true; + _iteratorError2 = err; + } finally { + try { + if (!_iteratorNormalCompletion2 && _iterator2.return) { + _iterator2.return(); + } + } finally { + if (_didIteratorError2) { + throw _iteratorError2; + } + } + } + + path.visit(); + } + }, + + ThrowStatement: createPrevExpressionEater("throw"), + + // Try to merge previous statements into a sequence + ReturnStatement: { + enter: [createPrevExpressionEater("return"), + + // Remove return if last statement with no argument. + // Replace return with `void` argument with argument. + function (path) { + var node = path.node; + + + if (!path.parentPath.parentPath.isFunction() || path.getSibling(path.key + 1).node) { + return; + } + + if (!node.argument) { + path.remove(); + return; + } + + if (t.isUnaryExpression(node.argument, { operator: "void" })) { + path.replaceWith(node.argument.argument); + } + }] + }, + + // turn blocked ifs into single statements + IfStatement: { + exit: [ + // Merge nested if statements if possible + function (_ref3) { + var node = _ref3.node; + + if (!t.isIfStatement(node.consequent)) { + return; + } + + if (node.alternate || node.consequent.alternate) { + return; + } + + node.test = t.logicalExpression("&&", node.test, node.consequent.test); + node.consequent = node.consequent.consequent; + }, function (path) { + var node = path.node; + + // No alternate, make into a guarded expression + + if (node.consequent && !node.alternate && node.consequent.type === "ExpressionStatement") { + var op = "&&"; + if (t.isUnaryExpression(node.test, { operator: "!" })) { + node.test = node.test.argument; + op = "||"; + } + + path.replaceWith(t.expressionStatement(t.logicalExpression(op, node.test, node.consequent.expression))); + return; + } + + // Easy, both are expressions, turn into ternary + if (t.isExpressionStatement(node.consequent) && t.isExpressionStatement(node.alternate)) { + path.replaceWith(t.conditionalExpression(node.test, node.consequent.expression, node.alternate.expression)); + return; + } + + // Easy: consequent and alternate are return -- conditional. + if (t.isReturnStatement(node.consequent) && t.isReturnStatement(node.alternate)) { + if (!node.consequent.argument && !node.alternate.argument) { + path.replaceWith(t.expressionStatement(node.test)); + return; + } + + path.replaceWith(t.returnStatement(t.conditionalExpression(node.test, node.consequent.argument || VOID_0, node.alternate.argument || VOID_0))); + return; + } + + // There is nothing after this block. And one or both + // of the consequent and alternate are either expression statment + // or return statements. + if (!path.getSibling(path.key + 1).node && path.parentPath && path.parentPath.parentPath && path.parentPath.parentPath.isFunction()) { + // Only the consequent is a return, void the alternate. + if (t.isReturnStatement(node.consequent) && t.isExpressionStatement(node.alternate)) { + if (!node.consequent.argument) { + path.replaceWith(t.expressionStatement(t.logicalExpression("||", node.test, node.alternate.expression))); + return; + } + + path.replaceWith(t.returnStatement(t.conditionalExpression(node.test, node.consequent.argument || VOID_0, t.unaryExpression("void", node.alternate.expression, true)))); + return; + } + + // Only the alternate is a return, void the consequent. + if (t.isReturnStatement(node.alternate) && t.isExpressionStatement(node.consequent)) { + if (!node.alternate.argument) { + path.replaceWith(t.expressionStatement(t.logicalExpression("&&", node.test, node.consequent.expression))); + return; + } + + path.replaceWith(t.returnStatement(t.conditionalExpression(node.test, t.unaryExpression("void", node.consequent.expression, true), node.alternate.argument || VOID_0))); + return; + } + + if (t.isReturnStatement(node.consequent) && !node.alternate) { + if (!node.consequent.argument) { + path.replaceWith(t.expressionStatement(node.test)); + return; + } + + // This would only be worth it if the previous statement was an if + // because then we may merge to create a conditional. + if (path.getSibling(path.key - 1).isIfStatement()) { + path.replaceWith(t.returnStatement(t.conditionalExpression(node.test, node.consequent.argument || VOID_0, VOID_0))); + return; + } + } + + if (t.isReturnStatement(node.alternate) && !node.consequent) { + if (!node.alternate.argument) { + path.replaceWith(t.expressionStatement(node.test)); + return; + } + + // Same as above. + if (path.getSibling(path.key - 1).isIfStatement()) { + path.replaceWith(t.returnStatement(t.conditionalExpression(node.test, node.alternate.argument || VOID_0, VOID_0))); + return; + } + } + } + + var next = path.getSibling(path.key + 1); + + // If the next satatement(s) is an if statement and we can simplify that + // to potentailly be an expression (or a return) then this will make it + // easier merge. + if (next.isIfStatement()) { + next.pushContext(path.context); + next.visit(); + next.popContext(); + next = path.getSibling(path.key + 1); + } + + // Some other visitor might have deleted our node. OUR NODE ;_; + if (!path.node) { + return; + } + + // No alternate but the next statement is a return + // also turn into a return conditional + if (t.isReturnStatement(node.consequent) && !node.alternate && next.isReturnStatement()) { + var nextArg = next.node.argument || VOID_0; + next.remove(); + path.replaceWith(t.returnStatement(t.conditionalExpression(node.test, node.consequent.argument || VOID_0, nextArg))); + return; + } + + // Next is the last expression, turn into a return while void'ing the exprs + if (path.parentPath && path.parentPath.parentPath && path.parentPath.parentPath.isFunction() && !path.getSibling(path.key + 2).node && t.isReturnStatement(node.consequent) && !node.alternate && next.isExpressionStatement()) { + var nextExpr = next.node.expression; + next.remove(); + if (node.consequent.argument) { + path.replaceWith(t.returnStatement(t.conditionalExpression(node.test, node.consequent.argument, t.unaryExpression("void", nextExpr, true)))); + return; + } + + path.replaceWith(t.logicalExpression("||", node.test, nextExpr)); + return; + } + + if (node.consequent && node.alternate && (t.isReturnStatement(node.consequent) || t.isBlockStatement(node.consequent) && t.isReturnStatement(node.consequent.body[node.consequent.body.length - 1]))) { + path.insertAfter(t.isBlockStatement(node.alternate) ? node.alternate.body : node.alternate); + node.alternate = null; + return; + } + }, + + // If the consequent is if and the altenrate is not then + // switch them out. That way we know we don't have to print + // a block.x + function (path) { + var node = path.node; + + + if (!node.alternate) { + return; + } + + if (!t.isIfStatement(node.consequent)) { + return; + } + + if (t.isIfStatement(node.alternate)) { + return; + } + + node.test = t.unaryExpression("!", node.test, true); + var _ref4 = [node.consequent, node.alternate]; + node.alternate = _ref4[0]; + node.consequent = _ref4[1]; + }, + + // Make if statements with conditional returns in the body into + // an if statement that guards the rest of the block. + function (path) { + var node = path.node; + + + if (!path.inList || !path.get("consequent").isBlockStatement() || node.alternate) { + return; + } + + var ret = void 0; + var test = void 0; + var exprs = []; + var statements = node.consequent.body; + + for (var i = 0, statement; statement = statements[i]; i++) { + if (t.isExpressionStatement(statement)) { + exprs.push(statement.expression); + } else if (t.isIfStatement(statement)) { + if (i < statements.length - 1) { + // This isn't the last statement. Bail. + return; + } + if (statement.alternate) { + return; + } + if (!t.isReturnStatement(statement.consequent)) { + return; + } + ret = statement.consequent; + test = statement.test; + } else { + return; + } + } + + if (!test || !ret) { + return; + } + + exprs.push(test); + + var expr = exprs.length === 1 ? exprs[0] : t.sequenceExpression(exprs); + + var replacement = t.logicalExpression("&&", node.test, expr); + + path.replaceWith(t.ifStatement(replacement, ret, null)); + }, createPrevExpressionEater("if")] + }, + + WhileStatement(path) { + var node = path.node; + + path.replaceWith(t.forStatement(null, node.test, null, node.body)); + }, + + ForInStatement: createPrevExpressionEater("for-in"), + + // Flatten sequence expressions. + SequenceExpression: { + exit(path) { + if (path.node[seqExprSeen]) { + return; + } + + function flatten(node) { + node[seqExprSeen] = true; + var ret = []; + var _iteratorNormalCompletion3 = true; + var _didIteratorError3 = false; + var _iteratorError3 = undefined; + + try { + for (var _iterator3 = node.expressions[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) { + var n = _step3.value; + + if (t.isSequenceExpression(n)) { + ret.push.apply(ret, _toConsumableArray(flatten(n))); + } else { + ret.push(n); + } + } + } catch (err) { + _didIteratorError3 = true; + _iteratorError3 = err; + } finally { + try { + if (!_iteratorNormalCompletion3 && _iterator3.return) { + _iterator3.return(); + } + } finally { + if (_didIteratorError3) { + throw _iteratorError3; + } + } + } + + return ret; + } + + path.node.expressions = flatten(path.node); + } + }, + + SwitchCase(path) { + var node = path.node; + + + if (!node.consequent.length) { + return; + } + + node.consequent = toMultipleSequenceExpressions(node.consequent); + }, + + SwitchStatement: { + exit: [ + // Convert switch statements with all returns in their cases + // to return conditional. + function (path) { + var node = path.node; + + // Need to be careful of side-effects. + + if (!t.isIdentifier(node.discriminant)) { + return; + } + + if (!node.cases.length) { + return; + } + + var consTestPairs = []; + var fallThru = []; + var defaultRet = void 0; + var _iteratorNormalCompletion4 = true; + var _didIteratorError4 = false; + var _iteratorError4 = undefined; + + try { + for (var _iterator4 = node.cases[Symbol.iterator](), _step4; !(_iteratorNormalCompletion4 = (_step4 = _iterator4.next()).done); _iteratorNormalCompletion4 = true) { + var switchCase = _step4.value; + + if (switchCase.consequent.length > 1) { + return; + } + + var cons = switchCase.consequent[0]; + + // default case + if (!switchCase.test) { + if (!t.isReturnStatement(cons)) { + return; + } + defaultRet = cons; + continue; + } + + if (!switchCase.consequent.length) { + fallThru.push(switchCase.test); + continue; + } + + // TODO: can we void it? + if (!t.isReturnStatement(cons)) { + return; + } + + var test = t.binaryExpression("===", node.discriminant, switchCase.test); + + if (fallThru.length && !defaultRet) { + test = fallThru.reduceRight(function (right, test) { + return t.logicalExpression("||", t.binaryExpression("===", node.discriminant, test), right); + }, test); + } + fallThru = []; + + consTestPairs.push([test, cons.argument || VOID_0]); + } + + // Bail if we have any remaining fallthrough + } catch (err) { + _didIteratorError4 = true; + _iteratorError4 = err; + } finally { + try { + if (!_iteratorNormalCompletion4 && _iterator4.return) { + _iterator4.return(); + } + } finally { + if (_didIteratorError4) { + throw _iteratorError4; + } + } + } + + if (fallThru.length) { + return; + } + + // We need the default to be there to make sure there is an oppurtinity + // not to return. + if (!defaultRet) { + if (path.inList) { + var nextPath = path.getSibling(path.key + 1); + if (nextPath.isReturnStatement()) { + defaultRet = nextPath.node; + nextPath.remove(); + } else if (!nextPath.node && path.parentPath.parentPath.isFunction()) { + // If this is the last statement in a function we just fake a void return. + defaultRet = t.returnStatement(VOID_0); + } else { + return; + } + } else { + return; + } + } + + var cond = consTestPairs.reduceRight(function (alt, _ref5) { + var _ref6 = _slicedToArray(_ref5, 2), + test = _ref6[0], + cons = _ref6[1]; + + return t.conditionalExpression(test, cons, alt); + }, defaultRet.argument || VOID_0); + + path.replaceWith(t.returnStatement(cond)); + + // Maybe now we can merge with some previous switch statement. + if (path.inList) { + var prev = path.getSibling(path.key - 1); + if (prev.isSwitchStatement()) { + prev.visit(); + } + } + }, + + // Convert switches into conditionals. + function (path) { + var node = path.node; + + // Need to be careful of side-effects. + + if (!t.isIdentifier(node.discriminant)) { + return; + } + + if (!node.cases.length) { + return; + } + + var exprTestPairs = []; + var fallThru = []; + var defaultExpr = void 0; + var _iteratorNormalCompletion5 = true; + var _didIteratorError5 = false; + var _iteratorError5 = undefined; + + try { + for (var _iterator5 = node.cases[Symbol.iterator](), _step5; !(_iteratorNormalCompletion5 = (_step5 = _iterator5.next()).done); _iteratorNormalCompletion5 = true) { + var switchCase = _step5.value; + + if (!switchCase.test) { + if (switchCase.consequent.length !== 1) { + return; + } + if (!t.isExpressionStatement(switchCase.consequent[0])) { + return; + } + defaultExpr = switchCase.consequent[0].expression; + continue; + } + + if (!switchCase.consequent.length) { + fallThru.push(switchCase.test); + continue; + } + + var _switchCase$consequen = _slicedToArray(switchCase.consequent, 2), + cons = _switchCase$consequen[0], + breakStatement = _switchCase$consequen[1]; + + if (switchCase === node.cases[node.cases.length - 1]) { + if (breakStatement && !t.isBreakStatement(breakStatement)) { + return; + } + } else if (!t.isBreakStatement(breakStatement)) { + return; + } + + if (!t.isExpressionStatement(cons) || switchCase.consequent.length > 2) { + return; + } + + var test = t.binaryExpression("===", node.discriminant, switchCase.test); + if (fallThru.length && !defaultExpr) { + test = fallThru.reduceRight(function (right, test) { + return t.logicalExpression("||", t.binaryExpression("===", node.discriminant, test), right); + }, test); + } + fallThru = []; + + exprTestPairs.push([test, cons.expression]); + } + } catch (err) { + _didIteratorError5 = true; + _iteratorError5 = err; + } finally { + try { + if (!_iteratorNormalCompletion5 && _iterator5.return) { + _iterator5.return(); + } + } finally { + if (_didIteratorError5) { + throw _iteratorError5; + } + } + } + + if (fallThru.length) { + return; + } + + var cond = exprTestPairs.reduceRight(function (alt, _ref7) { + var _ref8 = _slicedToArray(_ref7, 2), + test = _ref8[0], + cons = _ref8[1]; + + return t.conditionalExpression(test, cons, alt); + }, defaultExpr || VOID_0); + + path.replaceWith(cond); + }, function (path) { + var node = path.node; + + + if (!node.cases.length) { + return; + } + + var lastCase = path.get("cases")[node.cases.length - 1]; + if (!lastCase.node.consequent.length) { + return; + } + + var potentialBreak = lastCase.get("consequent")[lastCase.node.consequent.length - 1]; + if (t.isBreakStatement(potentialBreak) && potentialBreak.node.label === null) { + potentialBreak.remove(); + } + }, createPrevExpressionEater("switch")] + } + } + }; + + function flipNegation(node) { + if (!node.consequent || !node.alternate) { + return; + } + + var test = node.test; + var flip = false; + + if (t.isBinaryExpression(test)) { + if (test.operator === "!==") { + test.operator = "==="; + flip = true; + } + + if (test.operator === "!=") { + test.operator = "=="; + flip = true; + } + } + + if (t.isUnaryExpression(test, { operator: "!" })) { + node.test = test.argument; + flip = true; + } + + if (flip) { + var consequent = node.consequent; + node.consequent = node.alternate; + node.alternate = consequent; + } + } + + function needsBlock(node, parent) { + return t.isFunction(parent) && node === parent.body || t.isTryStatement(parent) || t.isCatchClause(parent) || t.isSwitchStatement(parent) || isSingleBlockScopeDeclaration(node) && t.isIfStatement(parent); + } + + function isSingleBlockScopeDeclaration(block) { + return t.isBlockStatement(block) && block.body.length === 1 && (t.isVariableDeclaration(block.body[0], { kind: "let" }) || t.isVariableDeclaration(block.body[0], { kind: "const" }) || t.isFunctionDeclaration(block.body[0])); + } + + function isVoid0(expr) { + return expr === VOID_0 || t.isUnaryExpression(expr, { operator: "void" }) && t.isNumericLiteral(expr.argument, { value: 0 }); + } + + function earlyReturnTransform(path) { + var node = path.node; + + + if (!t.isBlockStatement(node.body)) { + return; + } + + for (var i = node.body.body.length; i >= 0; i--) { + var statement = node.body.body[i]; + if (t.isIfStatement(statement) && !statement.alternate && t.isReturnStatement(statement.consequent) && !statement.consequent.argument) { + genericEarlyExitTransform(path.get("body").get("body")[i]); + } + } + } + + function earlyContinueTransform(path) { + var node = path.node; + + + if (!t.isBlockStatement(node.body)) { + return; + } + + for (var i = node.body.body.length; i >= 0; i--) { + var statement = node.body.body[i]; + if (t.isIfStatement(statement) && !statement.alternate && t.isContinueStatement(statement.consequent) && !statement.consequent.label) { + genericEarlyExitTransform(path.get("body").get("body")[i]); + } + } + + // We may have reduced the body to a single statement. + if (node.body.body.length === 1) { + path.get("body").replaceWith(node.body.body[0]); + } + } + + function genericEarlyExitTransform(path) { + var node = path.node; + + + var statements = path.parentPath.get(path.listKey).slice(path.key + 1).filter(function (stmt) { + return !stmt.isFunctionDeclaration(); + }); + + // deopt for any block scoped bindings + // issue#399 + var deopt = !statements.every(function (stmt) { + if (!(stmt.isVariableDeclaration({ kind: "let" }) || stmt.isVariableDeclaration({ kind: "const" }))) { + return true; + } + var ids = Object.keys(stmt.getBindingIdentifiers()); + var _iteratorNormalCompletion6 = true; + var _didIteratorError6 = false; + var _iteratorError6 = undefined; + + try { + for (var _iterator6 = ids[Symbol.iterator](), _step6; !(_iteratorNormalCompletion6 = (_step6 = _iterator6.next()).done); _iteratorNormalCompletion6 = true) { + var id = _step6.value; + + var binding = path.scope.getBinding(id); + + // TODO + // Temporary Fix + // if there is no binding, we assume it is referenced outside + // and deopt to avoid bugs + if (!binding) { + return false; + } + + var refs = [].concat(_toConsumableArray(binding.referencePaths), _toConsumableArray(binding.constantViolations)); + var _iteratorNormalCompletion7 = true; + var _didIteratorError7 = false; + var _iteratorError7 = undefined; + + try { + for (var _iterator7 = refs[Symbol.iterator](), _step7; !(_iteratorNormalCompletion7 = (_step7 = _iterator7.next()).done); _iteratorNormalCompletion7 = true) { + var ref = _step7.value; + + if (!ref.isIdentifier()) return false; + var fnParent = ref.getFunctionParent(); + + // TODO + // Usage of scopes and bindings in simplify plugin results in + // undefined bindings because scope changes are not updated in the + // scope tree. So, we deopt whenever we encounter one such issue + // and not perform the transformation + if (!fnParent) { + return false; + } + if (fnParent.scope !== path.scope) return false; + } + } catch (err) { + _didIteratorError7 = true; + _iteratorError7 = err; + } finally { + try { + if (!_iteratorNormalCompletion7 && _iterator7.return) { + _iterator7.return(); + } + } finally { + if (_didIteratorError7) { + throw _iteratorError7; + } + } + } + } + } catch (err) { + _didIteratorError6 = true; + _iteratorError6 = err; + } finally { + try { + if (!_iteratorNormalCompletion6 && _iterator6.return) { + _iterator6.return(); + } + } finally { + if (_didIteratorError6) { + throw _iteratorError6; + } + } + } + + return true; + }); + + if (deopt) { + path.visit(); + return false; + } + + if (!statements.length) { + path.replaceWith(t.expressionStatement(node.test)); + return; + } + + var test = node.test; + if (t.isBinaryExpression(test) && test.operator === "!==") { + test.operator = "==="; + } else if (t.isBinaryExpression(test) && test.operator === "!=") { + test.operator = "=="; + } else if (t.isUnaryExpression(test, { operator: "!" })) { + node.test = test.argument; + } else { + node.test = t.unaryExpression("!", node.test, true); + } + + path.get("consequent").replaceWith(t.blockStatement(statements.map(function (stmt) { + return t.clone(stmt.node); + }))); + + var l = statements.length; + while (l-- > 0) { + if (!statements[l].isFunctionDeclaration()) { + path.getSibling(path.key + 1).remove(); + } + } + + // this should take care of removing the block + path.visit(); + } + + function createPrevExpressionEater(keyword) { + var key = void 0; + switch (keyword) { + case "switch": + key = "discriminant"; + break; + case "throw": + case "return": + key = "argument"; + break; + case "if": + key = "test"; + break; + case "for-in": + key = "right"; + break; + } + + return function (path) { + if (!path.inList) { + return; + } + + var node = path.node; + + var prev = path.getSibling(path.key - 1); + if (!prev.isExpressionStatement()) { + return; + } + + var seq = prev.node.expression; + if (node[key]) { + if (t.isSequenceExpression(seq)) { + seq.expressions.push(node[key]); + } else { + seq = t.sequenceExpression([seq, node[key]]); + } + } else { + if (t.isSequenceExpression(seq)) { + var lastExpr = seq.expressions[seq.expressions.length - 1]; + seq.expressions[seq.expressions.length - 1] = t.unaryExpression("void", lastExpr, true); + } else { + seq = t.unaryExpression("void", seq, true); + } + } + + if (seq) { + node[key] = seq; + prev.remove(); + + // Since we were able to merge some stuff it's possible that this has opened + // oppurtinties for other transforms to happen. + // TODO: Look into changing the traversal order from bottom to up to avoid + // having to revisit things. + if (path.parentPath.parent) { + path.parentPath.parent[shouldRevisit] = true; + } + } + }; + } + + function isPatternMatchesPath(patternValue, inputPath) { + if (Array.isArray(patternValue)) { + for (var i = 0; i < patternValue.length; i++) { + if (isPatternMatchesPath(patternValue[i], inputPath)) { + return true; + } + } + return false; + } + if (typeof patternValue === "function") { + return patternValue(inputPath); + } + if (isNodeOfType(inputPath.node, patternValue)) return true; + var evalResult = inputPath.evaluate(); + if (!evalResult.confident || !inputPath.isPure()) return false; + return evalResult.value === patternValue; + } + + // path1 -> path2 + // is path1 an ancestor of path2 + function isAncestor(path1, path2) { + return !!path2.findParent(function (parent) { + return parent === path1; + }); + } +}; \ No newline at end of file diff --git a/node_modules/babel-preset-babili/node_modules/babel-plugin-minify-simplify/lib/pattern-match.js b/node_modules/babel-plugin-minify-simplify/lib/pattern-match.js similarity index 100% rename from node_modules/babel-preset-babili/node_modules/babel-plugin-minify-simplify/lib/pattern-match.js rename to node_modules/babel-plugin-minify-simplify/lib/pattern-match.js diff --git a/node_modules/babel-plugin-minify-simplify/package.json b/node_modules/babel-plugin-minify-simplify/package.json new file mode 100644 index 00000000000..17505a15bdb --- /dev/null +++ b/node_modules/babel-plugin-minify-simplify/package.json @@ -0,0 +1,51 @@ +{ + "_from": "babel-plugin-minify-simplify@^0.1.2", + "_id": "babel-plugin-minify-simplify@0.1.2", + "_inBundle": false, + "_integrity": "sha1-qWjxZY/esvx1noH+Mx2Jgp3w9rk=", + "_location": "/babel-plugin-minify-simplify", + "_phantomChildren": {}, + "_requested": { + "type": "range", + "registry": true, + "raw": "babel-plugin-minify-simplify@^0.1.2", + "name": "babel-plugin-minify-simplify", + "escapedName": "babel-plugin-minify-simplify", + "rawSpec": "^0.1.2", + "saveSpec": null, + "fetchSpec": "^0.1.2" + }, + "_requiredBy": [ + "/node-titanium-sdk/babel-preset-babili" + ], + "_resolved": "https://registry.npmjs.org/babel-plugin-minify-simplify/-/babel-plugin-minify-simplify-0.1.2.tgz", + "_shasum": "a968f1658fdeb2fc759e81fe331d89829df0f6b9", + "_spec": "babel-plugin-minify-simplify@^0.1.2", + "_where": "/Users/chris/appc/titanium_mobile/node_modules/node-titanium-sdk/node_modules/babel-preset-babili", + "author": { + "name": "amasad" + }, + "bugs": { + "url": "https://github.com/babel/babili/issues" + }, + "bundleDependencies": false, + "dependencies": { + "babel-helper-flip-expressions": "^0.1.2", + "babel-helper-is-nodes-equiv": "^0.0.1", + "babel-helper-to-multiple-sequence-expressions": "^0.1.1" + }, + "deprecated": false, + "description": "> Simplifies code for minification by reducing statements into expressions and making expressions uniform where possible.", + "homepage": "https://github.com/babel/babili#readme", + "keywords": [ + "babel-plugin" + ], + "license": "MIT", + "main": "lib/index.js", + "name": "babel-plugin-minify-simplify", + "repository": { + "type": "git", + "url": "https://github.com/babel/babili/tree/master/packages/babel-plugin-minify-simplify" + }, + "version": "0.1.2" +} diff --git a/node_modules/babel-preset-babili/node_modules/babel-plugin-minify-simplify/node_modules/babel-helper-flip-expressions/.npmignore b/node_modules/babel-plugin-minify-type-constructors/.npmignore similarity index 100% rename from node_modules/babel-preset-babili/node_modules/babel-plugin-minify-simplify/node_modules/babel-helper-flip-expressions/.npmignore rename to node_modules/babel-plugin-minify-type-constructors/.npmignore diff --git a/node_modules/babel-preset-babili/node_modules/babel-plugin-minify-type-constructors/README.md b/node_modules/babel-plugin-minify-type-constructors/README.md similarity index 100% rename from node_modules/babel-preset-babili/node_modules/babel-plugin-minify-type-constructors/README.md rename to node_modules/babel-plugin-minify-type-constructors/README.md diff --git a/node_modules/babel-plugin-minify-type-constructors/lib/index.js b/node_modules/babel-plugin-minify-type-constructors/lib/index.js new file mode 100644 index 00000000000..4ac8d98d4b1 --- /dev/null +++ b/node_modules/babel-plugin-minify-type-constructors/lib/index.js @@ -0,0 +1,165 @@ +"use strict"; + +function replaceArray(t, path) { + var node = path.node; + // arguments is taken :( + + var constructorArgs = path.get("arguments"); + if (t.isIdentifier(node.callee, { name: "Array" }) && !path.scope.getBinding("Array")) { + if (constructorArgs.length === 0) { + // Array() -> [] + path.replaceWith(t.arrayExpression([])); + } else if (constructorArgs.length === 1) { + var arg = constructorArgs[0]; + var result = arg.evaluate(); + + if (result.confident) { + if (typeof result.value === "number") { + if (result.value >= 0 && result.value <= 6 && result.value % 1 === 0) { + // "Array(7)" is shorter than "[,,,,,,,]" + path.replaceWith(t.arrayExpression(Array(result.value).fill(null))); + } else { + dropNewIfPresent(); + } + } else { + // Array("Asdf"), Array(true), Array(false) + path.replaceWith(t.arrayExpression([t.valueToNode(result.value)])); + } + } else { + var transformables = ["ArrayExpression", "ObjectExpression", "FunctionExpression", "ArrowFunctionExpression", "ClassExpression"]; + if (transformables.indexOf(arg.node.type) !== -1) { + // Array([]), Array({}) + // Array(()=>{}), Array(class{}), Array(function(){}) + path.replaceWith(t.arrayExpression([arg.node])); + } else { + // Array(x); Array(a.b); + dropNewIfPresent(); + } + } + } else { + // Array(2,3), Array(a,b) => [2,3], [a,b] + path.replaceWith(t.arrayExpression(node.arguments)); + } + return true; + } + + function dropNewIfPresent() { + if (path.isNewExpression()) { + path.replaceWith(t.callExpression(node.callee, node.arguments)); + } + } +} + +function replaceObject(t, path) { + var node = path.node; + + if (t.isIdentifier(node.callee, { name: "Object" }) && !path.scope.getBinding("Object")) { + var isVoid0 = require("babel-helper-is-void-0")(t); + var arg = node.arguments[0]; + var binding = arg && t.isIdentifier(arg) && path.scope.getBinding(arg.name); + + // Object() -> {} + if (node.arguments.length === 0) { + path.replaceWith(t.objectExpression([])); + + // Object([]) -> [] + } else if (arg.type === "ArrayExpression" || t.isFunctionExpression(arg)) { + path.replaceWith(arg); + + // Object(null) -> {} + } else if (isVoid0(arg) || arg.name === "undefined" || arg.type === "NullLiteral" || arg.type === "ObjectExpression" && arg.properties.length === 0) { + path.replaceWith(t.objectExpression([])); + + // Object(localFn) -> localFn + } else if (binding && binding.path.isFunction()) { + path.replaceWith(arg); + + // Object({a:b}) -> {a:b} + } else if (arg.type === "ObjectExpression") { + path.replaceWith(arg); + + // new Object(a) -> Object(a) + } else if (node.type === "NewExpression") { + path.replaceWith(t.callExpression(node.callee, node.arguments)); + } + return true; + } +} + +function defaults() { + var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}, + _ref$boolean = _ref.boolean, + boolean = _ref$boolean === undefined ? true : _ref$boolean, + _ref$number = _ref.number, + number = _ref$number === undefined ? true : _ref$number, + _ref$string = _ref.string, + string = _ref$string === undefined ? true : _ref$string, + _ref$array = _ref.array, + array = _ref$array === undefined ? true : _ref$array, + _ref$object = _ref.object, + object = _ref$object === undefined ? true : _ref$object; + + return { + boolean, + number, + string, + array, + object + }; +} + +module.exports = function (_ref2) { + var t = _ref2.types; + + return { + name: "minify-type-constructors", + visitor: { + CallExpression(path) { + var node = path.node; + + var opts = defaults(this.opts); + + // Boolean(foo) -> !!foo + if (opts.boolean && t.isIdentifier(node.callee, { name: "Boolean" }) && node.arguments.length === 1 && !path.scope.getBinding("Boolean")) { + path.replaceWith(t.unaryExpression("!", t.unaryExpression("!", node.arguments[0], true), true)); + return; + } + + // Number(foo) -> +foo + if (opts.number && t.isIdentifier(node.callee, { name: "Number" }) && node.arguments.length === 1 && !path.scope.getBinding("Number")) { + path.replaceWith(t.unaryExpression("+", node.arguments[0], true)); + return; + } + + // String(foo) -> foo + '' + if (opts.string && t.isIdentifier(node.callee, { name: "String" }) && node.arguments.length === 1 && !path.scope.getBinding("String")) { + path.replaceWith(t.binaryExpression("+", node.arguments[0], t.stringLiteral(""))); + return; + } + + // Array() -> [] + if (opts.array && replaceArray(t, path)) { + return; + } + + // Object() -> {} + if (opts.object && replaceObject(t, path)) { + return; + } + }, + NewExpression(path) { + var opts = defaults(this.opts); + + // new Array() -> [] + if (opts.array && replaceArray(t, path)) { + return; + } + + // new Object() -> {} + if (opts.object && replaceObject(t, path)) { + return; + } + } + } + }; +}; \ No newline at end of file diff --git a/node_modules/babel-plugin-minify-type-constructors/package.json b/node_modules/babel-plugin-minify-type-constructors/package.json new file mode 100644 index 00000000000..bd733b84afb --- /dev/null +++ b/node_modules/babel-plugin-minify-type-constructors/package.json @@ -0,0 +1,49 @@ +{ + "_from": "babel-plugin-minify-type-constructors@^0.1.2", + "_id": "babel-plugin-minify-type-constructors@0.1.2", + "_inBundle": false, + "_integrity": "sha1-21PFt2y44vzUXYYvFxBMeHYTN+4=", + "_location": "/babel-plugin-minify-type-constructors", + "_phantomChildren": {}, + "_requested": { + "type": "range", + "registry": true, + "raw": "babel-plugin-minify-type-constructors@^0.1.2", + "name": "babel-plugin-minify-type-constructors", + "escapedName": "babel-plugin-minify-type-constructors", + "rawSpec": "^0.1.2", + "saveSpec": null, + "fetchSpec": "^0.1.2" + }, + "_requiredBy": [ + "/node-titanium-sdk/babel-preset-babili" + ], + "_resolved": "https://registry.npmjs.org/babel-plugin-minify-type-constructors/-/babel-plugin-minify-type-constructors-0.1.2.tgz", + "_shasum": "db53c5b76cb8e2fcd45d862f17104c78761337ee", + "_spec": "babel-plugin-minify-type-constructors@^0.1.2", + "_where": "/Users/chris/appc/titanium_mobile/node_modules/node-titanium-sdk/node_modules/babel-preset-babili", + "author": { + "name": "amasad" + }, + "bugs": { + "url": "https://github.com/babel/babili/issues" + }, + "bundleDependencies": false, + "dependencies": { + "babel-helper-is-void-0": "^0.1.1" + }, + "deprecated": false, + "description": "**Note:** Not recommended if full support for IE8 and lower is required. [Details](https://github.com/babel/babili/pull/45#discussion_r70181249)", + "homepage": "https://github.com/babel/babili#readme", + "keywords": [ + "babel-plugin" + ], + "license": "MIT", + "main": "lib/index.js", + "name": "babel-plugin-minify-type-constructors", + "repository": { + "type": "git", + "url": "https://github.com/babel/babili/tree/master/packages/babel-plugin-minify-type-constructors" + }, + "version": "0.1.2" +} diff --git a/node_modules/babel-preset-babili/node_modules/babel-plugin-minify-simplify/node_modules/babel-helper-is-nodes-equiv/.npmignore b/node_modules/babel-plugin-transform-inline-consecutive-adds/.npmignore similarity index 100% rename from node_modules/babel-preset-babili/node_modules/babel-plugin-minify-simplify/node_modules/babel-helper-is-nodes-equiv/.npmignore rename to node_modules/babel-plugin-transform-inline-consecutive-adds/.npmignore diff --git a/node_modules/babel-preset-babili/node_modules/babel-plugin-transform-inline-consecutive-adds/README.md b/node_modules/babel-plugin-transform-inline-consecutive-adds/README.md similarity index 100% rename from node_modules/babel-preset-babili/node_modules/babel-plugin-transform-inline-consecutive-adds/README.md rename to node_modules/babel-plugin-transform-inline-consecutive-adds/README.md diff --git a/node_modules/babel-preset-babili/node_modules/babel-plugin-transform-inline-consecutive-adds/lib/array-collapser.js b/node_modules/babel-plugin-transform-inline-consecutive-adds/lib/array-collapser.js similarity index 100% rename from node_modules/babel-preset-babili/node_modules/babel-plugin-transform-inline-consecutive-adds/lib/array-collapser.js rename to node_modules/babel-plugin-transform-inline-consecutive-adds/lib/array-collapser.js diff --git a/node_modules/babel-preset-babili/node_modules/babel-plugin-transform-inline-consecutive-adds/lib/array-property-collapser.js b/node_modules/babel-plugin-transform-inline-consecutive-adds/lib/array-property-collapser.js similarity index 98% rename from node_modules/babel-preset-babili/node_modules/babel-plugin-transform-inline-consecutive-adds/lib/array-property-collapser.js rename to node_modules/babel-plugin-transform-inline-consecutive-adds/lib/array-property-collapser.js index 42d81a98236..e056f677b07 100644 --- a/node_modules/babel-preset-babili/node_modules/babel-plugin-transform-inline-consecutive-adds/lib/array-property-collapser.js +++ b/node_modules/babel-plugin-transform-inline-consecutive-adds/lib/array-property-collapser.js @@ -134,10 +134,9 @@ var ArrayPropertyCollapser = function (_Collapser) { rval = _ref9[1]; return rval.node.end - rval.node.start + 1; - }) // add 1 for space in front - .reduce(function (a, b) { + }).reduce(function (a, b) { return a + b; - }, 0); // sum + }, 0); // add 1 for space in front // sum return numCommaAdded + sizeOfRvals < statementsLength; } diff --git a/node_modules/babel-preset-babili/node_modules/babel-plugin-transform-inline-consecutive-adds/lib/collapser.js b/node_modules/babel-plugin-transform-inline-consecutive-adds/lib/collapser.js similarity index 100% rename from node_modules/babel-preset-babili/node_modules/babel-plugin-transform-inline-consecutive-adds/lib/collapser.js rename to node_modules/babel-plugin-transform-inline-consecutive-adds/lib/collapser.js diff --git a/node_modules/babel-plugin-transform-inline-consecutive-adds/lib/index.js b/node_modules/babel-plugin-transform-inline-consecutive-adds/lib/index.js new file mode 100644 index 00000000000..c83481fe505 --- /dev/null +++ b/node_modules/babel-plugin-transform-inline-consecutive-adds/lib/index.js @@ -0,0 +1,229 @@ +"use strict"; + +var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }(); + +var COLLAPSERS = [require("./object-collapser"), require("./array-collapser"), require("./array-property-collapser"), require("./set-collapser")].map(function (Collapser) { + return new Collapser(); +}); + +function getFunctionParent(path, scopeParent) { + var parent = path.findParent(function (p) { + return p.isFunction(); + }); + // don"t traverse higher than the function the var is defined in. + return parent === scopeParent ? null : parent; +} + +function getFunctionReferences(path, scopeParent) { + var references = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : new Set(); + + for (var func = getFunctionParent(path, scopeParent); func; func = getFunctionParent(func, scopeParent)) { + var id = func.node.id; + var binding = id && func.scope.getBinding(id.name); + + if (!binding) { + continue; + } + + binding.referencePaths.forEach(function (path) { + if (!references.has(path)) { + references.add(path); + getFunctionReferences(path, scopeParent, references); + } + }); + } + return references; +} + +function getIdAndFunctionReferences(name, parent) { + // Returns false if there's an error. Otherwise returns a list of references. + var binding = parent.scope.getBinding(name); + if (!binding) { + return false; + } + + var references = binding.referencePaths.reduce(function (references, ref) { + references.add(ref); + getFunctionReferences(ref, parent, references); + return references; + }, new Set()); + + return Array.from(references); +} + +function validateTopLevel(path) { + // Ensures the structure is of the form (roughly): + // { + // ... + // var foo = expr; + // ... + // } + // returns null if not of this form + // otherwise returns [foo as string, ?rval, index of the variable declaration] + + var declarations = path.get("declarations"); + if (declarations.length !== 1) { + return; + } + + var declaration = declarations[0]; + var id = declaration.get("id"), + init = declaration.get("init"); + if (!id.isIdentifier()) { + return; + } + + var parent = path.parentPath; + if (!parent.isBlockParent() || !parent.isScopable()) { + return; + } + + var body = parent.get("body"); + if (!Array.isArray(body)) { + return; + } + var startIndex = body.indexOf(path); + if (startIndex === -1) { + return; + } + + return [id.node.name, init, startIndex]; +} + +function collectExpressions(path, isExprTypeValid) { + // input: ExprStatement => 'a | SequenceExpression + // SequenceExpression => 'a list + // Validates 'a is of the right type + // returns null if found inconsistency, else returns Array<"a> + if (path.isExpressionStatement()) { + var exprs = collectExpressions(path.get("expression"), isExprTypeValid); + return exprs !== null ? exprs : null; + } + + if (path.isSequenceExpression()) { + var _exprs = path.get("expressions").map(function (p) { + return collectExpressions(p, isExprTypeValid); + }); + if (_exprs.some(function (e) { + return e === null; + })) { + return null; + } else { + return _exprs.reduce(function (s, n) { + return s.concat(n); + }, []); // === Array.flatten + } + } + + if (isExprTypeValid(path)) { + return [path]; + } + + return null; +} + +function getContiguousStatementsAndExpressions(body, start, end, isExprTypeValid, checkExpr) { + var statements = []; + var allExprs = []; + for (var i = start; i < end; i++) { + var exprs = collectExpressions(body[i], isExprTypeValid); + if (exprs === null || !exprs.every(function (e) { + return checkExpr(e); + })) { + break; + } + statements.push(body[i]); + allExprs = allExprs.concat(exprs); + } + return [statements, allExprs]; +} + +function getReferenceChecker(references) { + // returns a function s.t. given an expr, returns true iff expr is an ancestor of a reference + return function (expr) { + return references.some(function (r) { + return r === expr || r.isDescendant(expr); + }); + }; +} + +function tryUseCollapser(t, collapser, varDecl, topLevel, checkReference) { + // Returns true iff successfully used the collapser. Otherwise returns undefined. + var _topLevel = _slicedToArray(topLevel, 3), + name = _topLevel[0], + init = _topLevel[1], + startIndex = _topLevel[2]; + + var body = varDecl.parentPath.get("body"); + if (!collapser.isInitTypeValid(init)) { + return; + } + + var _getContiguousStateme = getContiguousStatementsAndExpressions(body, startIndex + 1, body.length, collapser.isExpressionTypeValid, collapser.getExpressionChecker(name, checkReference)), + _getContiguousStateme2 = _slicedToArray(_getContiguousStateme, 2), + statements = _getContiguousStateme2[0], + exprs = _getContiguousStateme2[1]; + + if (statements.length === 0) { + return; + } + + var assignments = exprs.map(function (e) { + return collapser.extractAssignment(e); + }); + var oldInit = init.node; + var newInit = t.cloneDeep(oldInit); + if (!assignments.every(function (assignment) { + return collapser.addSuccessfully(t, assignment, newInit); + })) { + return; + } + + // some collapses may increase the size + if (!collapser.isSizeSmaller({ + newInit, + oldInit, + varDecl, + assignments, + statements + })) { + return; + } + + init.replaceWith(newInit); + statements.forEach(function (s) { + return s.remove(); + }); + return true; +} + +module.exports = function (_ref) { + var t = _ref.types; + + return { + name: "transform-inline-consecutive-adds", + visitor: { + VariableDeclaration(varDecl) { + var topLevel = validateTopLevel(varDecl); + if (!topLevel) { + return; + } + + var _topLevel2 = _slicedToArray(topLevel, 1), + name = _topLevel2[0]; + + var references = getIdAndFunctionReferences(name, varDecl.parentPath); + if (references === false) { + return; + } + var checkReference = getReferenceChecker(references); + + if (COLLAPSERS.some(function (c) { + return tryUseCollapser(t, c, varDecl, topLevel, checkReference); + })) { + return; + } + } + } + }; +}; \ No newline at end of file diff --git a/node_modules/babel-preset-babili/node_modules/babel-plugin-transform-inline-consecutive-adds/lib/object-collapser.js b/node_modules/babel-plugin-transform-inline-consecutive-adds/lib/object-collapser.js similarity index 100% rename from node_modules/babel-preset-babili/node_modules/babel-plugin-transform-inline-consecutive-adds/lib/object-collapser.js rename to node_modules/babel-plugin-transform-inline-consecutive-adds/lib/object-collapser.js diff --git a/node_modules/babel-preset-babili/node_modules/babel-plugin-transform-inline-consecutive-adds/lib/set-collapser.js b/node_modules/babel-plugin-transform-inline-consecutive-adds/lib/set-collapser.js similarity index 98% rename from node_modules/babel-preset-babili/node_modules/babel-plugin-transform-inline-consecutive-adds/lib/set-collapser.js rename to node_modules/babel-plugin-transform-inline-consecutive-adds/lib/set-collapser.js index 9d520c98144..d2df7b43788 100644 --- a/node_modules/babel-preset-babili/node_modules/babel-plugin-transform-inline-consecutive-adds/lib/set-collapser.js +++ b/node_modules/babel-plugin-transform-inline-consecutive-adds/lib/set-collapser.js @@ -54,7 +54,7 @@ var SetCollapser = function (_Collapser) { if (args.length !== 1) { return false; } - if (checkReference(args)) { + if (checkReference(args[0])) { return false; } return true; diff --git a/node_modules/babel-plugin-transform-inline-consecutive-adds/package.json b/node_modules/babel-plugin-transform-inline-consecutive-adds/package.json new file mode 100644 index 00000000000..0646b298ae7 --- /dev/null +++ b/node_modules/babel-plugin-transform-inline-consecutive-adds/package.json @@ -0,0 +1,46 @@ +{ + "_from": "babel-plugin-transform-inline-consecutive-adds@^0.1.2", + "_id": "babel-plugin-transform-inline-consecutive-adds@0.1.2", + "_inBundle": false, + "_integrity": "sha1-VELp8cGceKeJn4pN7m/UgfYQAfU=", + "_location": "/babel-plugin-transform-inline-consecutive-adds", + "_phantomChildren": {}, + "_requested": { + "type": "range", + "registry": true, + "raw": "babel-plugin-transform-inline-consecutive-adds@^0.1.2", + "name": "babel-plugin-transform-inline-consecutive-adds", + "escapedName": "babel-plugin-transform-inline-consecutive-adds", + "rawSpec": "^0.1.2", + "saveSpec": null, + "fetchSpec": "^0.1.2" + }, + "_requiredBy": [ + "/node-titanium-sdk/babel-preset-babili" + ], + "_resolved": "https://registry.npmjs.org/babel-plugin-transform-inline-consecutive-adds/-/babel-plugin-transform-inline-consecutive-adds-0.1.2.tgz", + "_shasum": "5442e9f1c19c78a7899f8a4dee6fd481f61001f5", + "_spec": "babel-plugin-transform-inline-consecutive-adds@^0.1.2", + "_where": "/Users/chris/appc/titanium_mobile/node_modules/node-titanium-sdk/node_modules/babel-preset-babili", + "author": { + "name": "shinew" + }, + "bugs": { + "url": "https://github.com/babel/babili/issues" + }, + "bundleDependencies": false, + "deprecated": false, + "description": "This plugin inlines consecutive property assignments, array pushes, etc.", + "homepage": "https://github.com/babel/babili#readme", + "keywords": [ + "babel-plugin" + ], + "license": "MIT", + "main": "lib/index.js", + "name": "babel-plugin-transform-inline-consecutive-adds", + "repository": { + "type": "git", + "url": "https://github.com/babel/babili/tree/master/packages/babel-plugin-transform-inline-consecutive-adds" + }, + "version": "0.1.2" +} diff --git a/node_modules/babel-preset-babili/node_modules/babel-plugin-minify-simplify/node_modules/babel-helper-to-multiple-sequence-expressions/.npmignore b/node_modules/babel-plugin-transform-member-expression-literals/.npmignore similarity index 100% rename from node_modules/babel-preset-babili/node_modules/babel-plugin-minify-simplify/node_modules/babel-helper-to-multiple-sequence-expressions/.npmignore rename to node_modules/babel-plugin-transform-member-expression-literals/.npmignore diff --git a/node_modules/babel-preset-babili/node_modules/babel-plugin-transform-member-expression-literals/README.md b/node_modules/babel-plugin-transform-member-expression-literals/README.md similarity index 100% rename from node_modules/babel-preset-babili/node_modules/babel-plugin-transform-member-expression-literals/README.md rename to node_modules/babel-plugin-transform-member-expression-literals/README.md diff --git a/node_modules/babel-plugin-transform-member-expression-literals/lib/index.js b/node_modules/babel-plugin-transform-member-expression-literals/lib/index.js new file mode 100644 index 00000000000..a3133fec810 --- /dev/null +++ b/node_modules/babel-plugin-transform-member-expression-literals/lib/index.js @@ -0,0 +1,33 @@ +"use strict"; + +module.exports = function (_ref) { + var t = _ref.types; + + return { + name: "transform-member-expression-literals", + visitor: { + // foo['bar'] -> foo.bar + MemberExpression: { + exit(_ref2) { + var node = _ref2.node; + + var prop = node.property; + if (!node.computed || !t.isStringLiteral(prop)) { + return; + } + + if (prop.value.match(/^\d+$/)) { + var newProp = parseInt(prop.value, 10); + if (newProp.toString() === prop.value) { + node.property = t.numericLiteral(newProp); + node.computed = false; + } + } else if (t.isValidIdentifier(prop.value)) { + node.property = t.identifier(prop.value); + node.computed = false; + } + } + } + } + }; +}; \ No newline at end of file diff --git a/node_modules/babel-plugin-transform-member-expression-literals/package.json b/node_modules/babel-plugin-transform-member-expression-literals/package.json new file mode 100644 index 00000000000..55dc592d70b --- /dev/null +++ b/node_modules/babel-plugin-transform-member-expression-literals/package.json @@ -0,0 +1,46 @@ +{ + "_from": "babel-plugin-transform-member-expression-literals@^6.8.4", + "_id": "babel-plugin-transform-member-expression-literals@6.8.4", + "_inBundle": false, + "_integrity": "sha1-BWebxAWWuRKTQBlZqhYgqxsr5Dc=", + "_location": "/babel-plugin-transform-member-expression-literals", + "_phantomChildren": {}, + "_requested": { + "type": "range", + "registry": true, + "raw": "babel-plugin-transform-member-expression-literals@^6.8.4", + "name": "babel-plugin-transform-member-expression-literals", + "escapedName": "babel-plugin-transform-member-expression-literals", + "rawSpec": "^6.8.4", + "saveSpec": null, + "fetchSpec": "^6.8.4" + }, + "_requiredBy": [ + "/node-titanium-sdk/babel-preset-babili" + ], + "_resolved": "https://registry.npmjs.org/babel-plugin-transform-member-expression-literals/-/babel-plugin-transform-member-expression-literals-6.8.4.tgz", + "_shasum": "05679bc40596b91293401959aa1620ab1b2be437", + "_spec": "babel-plugin-transform-member-expression-literals@^6.8.4", + "_where": "/Users/chris/appc/titanium_mobile/node_modules/node-titanium-sdk/node_modules/babel-preset-babili", + "author": { + "name": "amasad" + }, + "bugs": { + "url": "https://github.com/babel/babili/issues" + }, + "bundleDependencies": false, + "deprecated": false, + "description": "Turn valid member expression property literals into plain identifiers", + "homepage": "https://github.com/babel/babili#readme", + "keywords": [ + "babel-plugin" + ], + "license": "MIT", + "main": "lib/index.js", + "name": "babel-plugin-transform-member-expression-literals", + "repository": { + "type": "git", + "url": "https://github.com/babel/babili/tree/master/packages/babel-plugin-transform-member-expression-literals" + }, + "version": "6.8.4" +} diff --git a/node_modules/babel-preset-babili/node_modules/babel-plugin-minify-type-constructors/.npmignore b/node_modules/babel-plugin-transform-merge-sibling-variables/.npmignore similarity index 100% rename from node_modules/babel-preset-babili/node_modules/babel-plugin-minify-type-constructors/.npmignore rename to node_modules/babel-plugin-transform-merge-sibling-variables/.npmignore diff --git a/node_modules/babel-preset-babili/node_modules/babel-plugin-transform-merge-sibling-variables/README.md b/node_modules/babel-plugin-transform-merge-sibling-variables/README.md similarity index 100% rename from node_modules/babel-preset-babili/node_modules/babel-plugin-transform-merge-sibling-variables/README.md rename to node_modules/babel-plugin-transform-merge-sibling-variables/README.md diff --git a/node_modules/babel-plugin-transform-merge-sibling-variables/lib/index.js b/node_modules/babel-plugin-transform-merge-sibling-variables/lib/index.js new file mode 100644 index 00000000000..45164b691a9 --- /dev/null +++ b/node_modules/babel-plugin-transform-merge-sibling-variables/lib/index.js @@ -0,0 +1,95 @@ +"use strict"; + +module.exports = function (_ref) { + var t = _ref.types; + + function liftDeclaration(path, body, kind) { + if (body[0] && body[0].isVariableDeclaration({ kind: kind })) { + if (body[0].node.declarations.length > 1) { + return; + } + + if (body[1] && body[1].isVariableDeclaration({ kind: kind })) { + return; + } + + var firstNode = body[0].node.declarations[0]; + + if (!t.isIdentifier(firstNode.id) || !firstNode.init) { + return; + } + + var init = path.get("init"); + if (!init.isVariableDeclaration({ kind: kind })) { + return; + } + + init.pushContainer("declarations", t.variableDeclarator(firstNode.id)); + + body[0].replaceWith(t.assignmentExpression("=", t.clone(firstNode.id), t.clone(firstNode.init))); + } + } + + return { + name: "transform-merge-sibling-variables", + visitor: { + ForStatement(path) { + // Lift declarations to the loop initializer + var body = path.get("body"); + body = body.isBlockStatement() ? body.get("body") : [body]; + + liftDeclaration(path, body, "var"); + liftDeclaration(path, body, "let"); + }, + VariableDeclaration: { + enter: [ + // concat variables of the same kind with their siblings + function (path) { + if (!path.inList) { + return; + } + + var node = path.node; + + + var sibling = path.getSibling(path.key + 1); + + while (sibling.isVariableDeclaration({ kind: node.kind })) { + node.declarations = node.declarations.concat(sibling.node.declarations); + sibling.remove(); + + sibling = path.getSibling(path.key + 1); + } + }, + + // concat `var` declarations next to for loops with it's initialisers. + // block-scoped `let` and `const` are not moved because the for loop + // is a different block scope. + function (path) { + if (!path.inList) { + return; + } + + var node = path.node; + + if (node.kind !== "var") { + return; + } + + var next = path.getSibling(path.key + 1); + if (!next.isForStatement()) { + return; + } + + var init = next.get("init"); + if (!init.isVariableDeclaration({ kind: node.kind })) { + return; + } + + init.node.declarations = node.declarations.concat(init.node.declarations); + path.remove(); + }] + } + } + }; +}; \ No newline at end of file diff --git a/node_modules/babel-plugin-transform-merge-sibling-variables/package.json b/node_modules/babel-plugin-transform-merge-sibling-variables/package.json new file mode 100644 index 00000000000..c26ea37f253 --- /dev/null +++ b/node_modules/babel-plugin-transform-merge-sibling-variables/package.json @@ -0,0 +1,46 @@ +{ + "_from": "babel-plugin-transform-merge-sibling-variables@^6.8.5", + "_id": "babel-plugin-transform-merge-sibling-variables@6.8.5", + "_inBundle": false, + "_integrity": "sha1-A6vfEHxhJBkT6yaN3t5tW8VBhiw=", + "_location": "/babel-plugin-transform-merge-sibling-variables", + "_phantomChildren": {}, + "_requested": { + "type": "range", + "registry": true, + "raw": "babel-plugin-transform-merge-sibling-variables@^6.8.5", + "name": "babel-plugin-transform-merge-sibling-variables", + "escapedName": "babel-plugin-transform-merge-sibling-variables", + "rawSpec": "^6.8.5", + "saveSpec": null, + "fetchSpec": "^6.8.5" + }, + "_requiredBy": [ + "/node-titanium-sdk/babel-preset-babili" + ], + "_resolved": "https://registry.npmjs.org/babel-plugin-transform-merge-sibling-variables/-/babel-plugin-transform-merge-sibling-variables-6.8.5.tgz", + "_shasum": "03abdf107c61241913eb268ddede6d5bc541862c", + "_spec": "babel-plugin-transform-merge-sibling-variables@^6.8.5", + "_where": "/Users/chris/appc/titanium_mobile/node_modules/node-titanium-sdk/node_modules/babel-preset-babili", + "author": { + "name": "amasad" + }, + "bugs": { + "url": "https://github.com/babel/babili/issues" + }, + "bundleDependencies": false, + "deprecated": false, + "description": "Merge sibling variables into one.", + "homepage": "https://github.com/babel/babili#readme", + "keywords": [ + "babel-plugin" + ], + "license": "MIT", + "main": "lib/index.js", + "name": "babel-plugin-transform-merge-sibling-variables", + "repository": { + "type": "git", + "url": "https://github.com/babel/babili/tree/master/packages/babel-plugin-transform-merge-sibling-variables" + }, + "version": "6.8.5" +} diff --git a/node_modules/babel-preset-babili/node_modules/babel-plugin-minify-type-constructors/node_modules/babel-helper-is-void-0/.npmignore b/node_modules/babel-plugin-transform-minify-booleans/.npmignore similarity index 100% rename from node_modules/babel-preset-babili/node_modules/babel-plugin-minify-type-constructors/node_modules/babel-helper-is-void-0/.npmignore rename to node_modules/babel-plugin-transform-minify-booleans/.npmignore diff --git a/node_modules/babel-plugin-transform-minify-booleans/README.md b/node_modules/babel-plugin-transform-minify-booleans/README.md new file mode 100644 index 00000000000..4345893e001 --- /dev/null +++ b/node_modules/babel-plugin-transform-minify-booleans/README.md @@ -0,0 +1,51 @@ +# babel-plugin-transform-minify-booleans + +This plugin allows Babel to transform boolean literals into `!0` for `true` and `!1` for `false`. + +## Example + +**In** + +```javascript +true; +false; +``` + +**Out** + +```javascript +!0; +!1; +``` + +## Installation + +```sh +npm install babel-plugin-transform-minify-booleans +``` + +## Usage + +### Via `.babelrc` (Recommended) + +**.babelrc** + +```json +{ + "plugins": ["transform-minify-booleans"] +} +``` + +### Via CLI + +```sh +babel --plugins transform-minify-booleans script.js +``` + +### Via Node API + +```javascript +require("babel-core").transform("code", { + plugins: ["transform-minify-booleans"] +}); +``` diff --git a/node_modules/babel-plugin-transform-minify-booleans/lib/index.js b/node_modules/babel-plugin-transform-minify-booleans/lib/index.js new file mode 100644 index 00000000000..ae00914168b --- /dev/null +++ b/node_modules/babel-plugin-transform-minify-booleans/lib/index.js @@ -0,0 +1,20 @@ +"use strict"; + +module.exports = function (_ref) { + var t = _ref.types; + + var TRUE = t.unaryExpression("!", t.numericLiteral(0), true); + var FALSE = t.unaryExpression("!", t.numericLiteral(1), true); + + return { + name: "transform-minify-booleans", + visitor: { + // shorten booleans to a negation + // true -> !0 + // false -> !1 + BooleanLiteral(path) { + path.replaceWith(path.node.value ? TRUE : FALSE); + } + } + }; +}; \ No newline at end of file diff --git a/node_modules/babel-plugin-transform-minify-booleans/package.json b/node_modules/babel-plugin-transform-minify-booleans/package.json new file mode 100644 index 00000000000..e65521ba5bc --- /dev/null +++ b/node_modules/babel-plugin-transform-minify-booleans/package.json @@ -0,0 +1,48 @@ +{ + "_from": "babel-plugin-transform-minify-booleans@^6.8.2", + "_id": "babel-plugin-transform-minify-booleans@6.8.2", + "_inBundle": false, + "_integrity": "sha1-hFFXn3BucCweGrJ1beXI6jac8Hw=", + "_location": "/babel-plugin-transform-minify-booleans", + "_phantomChildren": {}, + "_requested": { + "type": "range", + "registry": true, + "raw": "babel-plugin-transform-minify-booleans@^6.8.2", + "name": "babel-plugin-transform-minify-booleans", + "escapedName": "babel-plugin-transform-minify-booleans", + "rawSpec": "^6.8.2", + "saveSpec": null, + "fetchSpec": "^6.8.2" + }, + "_requiredBy": [ + "/node-titanium-sdk/babel-preset-babili" + ], + "_resolved": "https://registry.npmjs.org/babel-plugin-transform-minify-booleans/-/babel-plugin-transform-minify-booleans-6.8.2.tgz", + "_shasum": "8451579f706e702c1e1ab2756de5c8ea369cf07c", + "_spec": "babel-plugin-transform-minify-booleans@^6.8.2", + "_where": "/Users/chris/appc/titanium_mobile/node_modules/node-titanium-sdk/node_modules/babel-preset-babili", + "author": { + "name": "amasad" + }, + "bugs": { + "url": "https://github.com/babel/babili/issues" + }, + "bundleDependencies": false, + "dependencies": {}, + "deprecated": false, + "description": "Turn boolean literals into !0 for true and !1 for false.", + "devDependencies": {}, + "homepage": "https://github.com/babel/babili#readme", + "keywords": [ + "babel-plugin" + ], + "license": "MIT", + "main": "lib/index.js", + "name": "babel-plugin-transform-minify-booleans", + "repository": { + "type": "git", + "url": "https://github.com/babel/babili/tree/master/packages/babel-plugin-transform-minify-booleans" + }, + "version": "6.8.2" +} diff --git a/node_modules/babel-preset-babili/node_modules/babel-plugin-transform-inline-consecutive-adds/.npmignore b/node_modules/babel-plugin-transform-property-literals/.npmignore similarity index 100% rename from node_modules/babel-preset-babili/node_modules/babel-plugin-transform-inline-consecutive-adds/.npmignore rename to node_modules/babel-plugin-transform-property-literals/.npmignore diff --git a/node_modules/babel-preset-babili/node_modules/babel-plugin-transform-property-literals/README.md b/node_modules/babel-plugin-transform-property-literals/README.md similarity index 100% rename from node_modules/babel-preset-babili/node_modules/babel-plugin-transform-property-literals/README.md rename to node_modules/babel-plugin-transform-property-literals/README.md diff --git a/node_modules/babel-plugin-transform-property-literals/lib/escape-string-literal.js b/node_modules/babel-plugin-transform-property-literals/lib/escape-string-literal.js new file mode 100644 index 00000000000..370af2fd96f --- /dev/null +++ b/node_modules/babel-plugin-transform-property-literals/lib/escape-string-literal.js @@ -0,0 +1,69 @@ +"use strict"; + +/** + * Original Source: + * https://github.com/shapesecurity/shift-codegen-js/blob/0d09bd8a/src/coderep.js#L122 + * + * The following function is an exact copy of the original implementation + * + * LICENSE + +Copyright 2014 Shape Security, Inc. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + + */ + +module.exports = function escapeStringLiteral(stringValue) { + var result = ""; + var nSingle = 0, + nDouble = 0; + for (var i = 0, l = stringValue.length; i < l; ++i) { + var ch = stringValue[i]; + if (ch === '"') { + ++nDouble; + } else if (ch === "'") { + ++nSingle; + } + } + var delim = nDouble > nSingle ? "'" : '"'; + result += delim; + for (var _i = 0; _i < stringValue.length; _i++) { + var _ch = stringValue.charAt(_i); + switch (_ch) { + case delim: + result += "\\" + delim; + break; + case "\n": + result += "\\n"; + break; + case "\r": + result += "\\r"; + break; + case "\\": + result += "\\\\"; + break; + case "\u2028": + result += "\\u2028"; + break; + case "\u2029": + result += "\\u2029"; + break; + default: + result += _ch; + break; + } + } + result += delim; + return result; +}; \ No newline at end of file diff --git a/node_modules/babel-plugin-transform-property-literals/lib/index.js b/node_modules/babel-plugin-transform-property-literals/lib/index.js new file mode 100644 index 00000000000..e3720543d8b --- /dev/null +++ b/node_modules/babel-plugin-transform-property-literals/lib/index.js @@ -0,0 +1,29 @@ +"use strict"; + +var _require = require("./property-name"), + reduceStaticPropertyNameES5 = _require.reduceStaticPropertyNameES5; + +module.exports = function (_ref) { + var t = _ref.types; + + return { + name: "transform-property-literals", + visitor: { + // { 'foo': 'bar' } -> { foo: 'bar' } + ObjectProperty: { + exit(path) { + var key = path.get("key"); + if (!key.isStringLiteral()) { + return; + } + + var newNode = t.clone(path.node); + newNode.key = reduceStaticPropertyNameES5(t, key.node); + newNode.computed = false; + + path.replaceWith(newNode); + } + } + } + }; +}; \ No newline at end of file diff --git a/node_modules/babel-plugin-transform-property-literals/lib/property-name.js b/node_modules/babel-plugin-transform-property-literals/lib/property-name.js new file mode 100644 index 00000000000..9c6e8941fc6 --- /dev/null +++ b/node_modules/babel-plugin-transform-property-literals/lib/property-name.js @@ -0,0 +1,47 @@ +"use strict"; + +var _require = require("esutils"), + keyword = _require.keyword; + +var escapeStringLiteral = require("./escape-string-literal"); + +module.exports = { + reduceStaticPropertyNameES5 +}; + +/** + * + * Original Source: + * https://github.com/shapesecurity/shift-codegen-js/blob/0d09bd8a/src/minimal-codegen.js#L635 + * + * This implementation modifies the original source in the following ways + * + Check for ES5 Identifier name instead of ES6 Identifier name + * + Use Babel-Types & Babel's AST instead of ShiftAST + * + * LICENSE + +Copyright 2014 Shape Security, Inc. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + + */ +function reduceStaticPropertyNameES5(t, node) { + if (keyword.isIdentifierNameES5(node.value)) { + return t.Identifier(node.value); + } + var n = parseFloat(node.value); + if (n >= 0 && n.toString() === node.value) { + return t.NumericLiteral(n); + } + return t.Identifier(escapeStringLiteral(node.value)); +} \ No newline at end of file diff --git a/node_modules/babel-plugin-transform-property-literals/package.json b/node_modules/babel-plugin-transform-property-literals/package.json new file mode 100644 index 00000000000..323d789bd84 --- /dev/null +++ b/node_modules/babel-plugin-transform-property-literals/package.json @@ -0,0 +1,49 @@ +{ + "_from": "babel-plugin-transform-property-literals@^6.8.4", + "_id": "babel-plugin-transform-property-literals@6.8.4", + "_inBundle": false, + "_integrity": "sha1-atMREQuAoZKlbvtd30/jym96Ydo=", + "_location": "/babel-plugin-transform-property-literals", + "_phantomChildren": {}, + "_requested": { + "type": "range", + "registry": true, + "raw": "babel-plugin-transform-property-literals@^6.8.4", + "name": "babel-plugin-transform-property-literals", + "escapedName": "babel-plugin-transform-property-literals", + "rawSpec": "^6.8.4", + "saveSpec": null, + "fetchSpec": "^6.8.4" + }, + "_requiredBy": [ + "/node-titanium-sdk/babel-preset-babili" + ], + "_resolved": "https://registry.npmjs.org/babel-plugin-transform-property-literals/-/babel-plugin-transform-property-literals-6.8.4.tgz", + "_shasum": "6ad311110b80a192a56efb5ddf4fe3ca6f7a61da", + "_spec": "babel-plugin-transform-property-literals@^6.8.4", + "_where": "/Users/chris/appc/titanium_mobile/node_modules/node-titanium-sdk/node_modules/babel-preset-babili", + "author": { + "name": "amasad" + }, + "bugs": { + "url": "https://github.com/babel/babili/issues" + }, + "bundleDependencies": false, + "dependencies": { + "esutils": "^2.0.2" + }, + "deprecated": false, + "description": "Turn valid property key literals to plain identifiers", + "homepage": "https://github.com/babel/babili#readme", + "keywords": [ + "babel-plugin" + ], + "license": "MIT", + "main": "lib/index.js", + "name": "babel-plugin-transform-property-literals", + "repository": { + "type": "git", + "url": "https://github.com/babel/babili/tree/master/packages/babel-plugin-transform-property-literals" + }, + "version": "6.8.4" +} diff --git a/node_modules/babel-preset-babili/node_modules/babel-plugin-transform-member-expression-literals/.npmignore b/node_modules/babel-plugin-transform-regexp-constructors/.npmignore similarity index 100% rename from node_modules/babel-preset-babili/node_modules/babel-plugin-transform-member-expression-literals/.npmignore rename to node_modules/babel-plugin-transform-regexp-constructors/.npmignore diff --git a/node_modules/babel-preset-babili/node_modules/babel-plugin-transform-regexp-constructors/README.md b/node_modules/babel-plugin-transform-regexp-constructors/README.md similarity index 100% rename from node_modules/babel-preset-babili/node_modules/babel-plugin-transform-regexp-constructors/README.md rename to node_modules/babel-plugin-transform-regexp-constructors/README.md diff --git a/node_modules/babel-preset-babili/node_modules/babel-plugin-transform-regexp-constructors/lib/index.js b/node_modules/babel-plugin-transform-regexp-constructors/lib/index.js similarity index 100% rename from node_modules/babel-preset-babili/node_modules/babel-plugin-transform-regexp-constructors/lib/index.js rename to node_modules/babel-plugin-transform-regexp-constructors/lib/index.js diff --git a/node_modules/babel-plugin-transform-regexp-constructors/package.json b/node_modules/babel-plugin-transform-regexp-constructors/package.json new file mode 100644 index 00000000000..f233c2046b0 --- /dev/null +++ b/node_modules/babel-plugin-transform-regexp-constructors/package.json @@ -0,0 +1,48 @@ +{ + "_from": "babel-plugin-transform-regexp-constructors@^0.1.1", + "_id": "babel-plugin-transform-regexp-constructors@0.1.1", + "_inBundle": false, + "_integrity": "sha1-MSq3SHzIihxi7iXqG2CH6JuHeZw=", + "_location": "/babel-plugin-transform-regexp-constructors", + "_phantomChildren": {}, + "_requested": { + "type": "range", + "registry": true, + "raw": "babel-plugin-transform-regexp-constructors@^0.1.1", + "name": "babel-plugin-transform-regexp-constructors", + "escapedName": "babel-plugin-transform-regexp-constructors", + "rawSpec": "^0.1.1", + "saveSpec": null, + "fetchSpec": "^0.1.1" + }, + "_requiredBy": [ + "/node-titanium-sdk/babel-preset-babili" + ], + "_resolved": "https://registry.npmjs.org/babel-plugin-transform-regexp-constructors/-/babel-plugin-transform-regexp-constructors-0.1.1.tgz", + "_shasum": "312ab7487cc88a1c62ee25ea1b6087e89b87799c", + "_spec": "babel-plugin-transform-regexp-constructors@^0.1.1", + "_where": "/Users/chris/appc/titanium_mobile/node_modules/node-titanium-sdk/node_modules/babel-preset-babili", + "author": { + "name": "shinew" + }, + "bugs": { + "url": "https://github.com/babel/babili/issues" + }, + "bundleDependencies": false, + "dependencies": {}, + "deprecated": false, + "description": "This changes RegExp constructors into literals if the RegExp arguments are strings.", + "devDependencies": {}, + "homepage": "https://github.com/babel/babili#readme", + "keywords": [ + "babel-plugin" + ], + "license": "MIT", + "main": "lib/index.js", + "name": "babel-plugin-transform-regexp-constructors", + "repository": { + "type": "git", + "url": "https://github.com/babel/babili/tree/master/packages/babel-plugin-transform-regexp-constructors" + }, + "version": "0.1.1" +} diff --git a/node_modules/babel-preset-babili/node_modules/babel-plugin-transform-merge-sibling-variables/.npmignore b/node_modules/babel-plugin-transform-remove-console/.npmignore similarity index 100% rename from node_modules/babel-preset-babili/node_modules/babel-plugin-transform-merge-sibling-variables/.npmignore rename to node_modules/babel-plugin-transform-remove-console/.npmignore diff --git a/node_modules/babel-preset-babili/node_modules/babel-plugin-transform-remove-console/README.md b/node_modules/babel-plugin-transform-remove-console/README.md similarity index 100% rename from node_modules/babel-preset-babili/node_modules/babel-plugin-transform-remove-console/README.md rename to node_modules/babel-plugin-transform-remove-console/README.md diff --git a/node_modules/babel-preset-babili/node_modules/babel-plugin-transform-remove-console/lib/index.js b/node_modules/babel-plugin-transform-remove-console/lib/index.js similarity index 100% rename from node_modules/babel-preset-babili/node_modules/babel-plugin-transform-remove-console/lib/index.js rename to node_modules/babel-plugin-transform-remove-console/lib/index.js diff --git a/node_modules/babel-plugin-transform-remove-console/package.json b/node_modules/babel-plugin-transform-remove-console/package.json new file mode 100644 index 00000000000..ded2370cf94 --- /dev/null +++ b/node_modules/babel-plugin-transform-remove-console/package.json @@ -0,0 +1,46 @@ +{ + "_from": "babel-plugin-transform-remove-console@^6.8.4", + "_id": "babel-plugin-transform-remove-console@6.8.4", + "_inBundle": false, + "_integrity": "sha1-Qf3awZpymkw91+8pZOrAewlvmo8=", + "_location": "/babel-plugin-transform-remove-console", + "_phantomChildren": {}, + "_requested": { + "type": "range", + "registry": true, + "raw": "babel-plugin-transform-remove-console@^6.8.4", + "name": "babel-plugin-transform-remove-console", + "escapedName": "babel-plugin-transform-remove-console", + "rawSpec": "^6.8.4", + "saveSpec": null, + "fetchSpec": "^6.8.4" + }, + "_requiredBy": [ + "/node-titanium-sdk/babel-preset-babili" + ], + "_resolved": "https://registry.npmjs.org/babel-plugin-transform-remove-console/-/babel-plugin-transform-remove-console-6.8.4.tgz", + "_shasum": "41fddac19a729a4c3dd7ef2964eac07b096f9a8f", + "_spec": "babel-plugin-transform-remove-console@^6.8.4", + "_where": "/Users/chris/appc/titanium_mobile/node_modules/node-titanium-sdk/node_modules/babel-preset-babili", + "author": { + "name": "amasad" + }, + "bugs": { + "url": "https://github.com/babel/babili/issues" + }, + "bundleDependencies": false, + "deprecated": false, + "description": "Remove all console.* calls.", + "homepage": "https://github.com/babel/babili#readme", + "keywords": [ + "babel-plugin" + ], + "license": "MIT", + "main": "lib/index.js", + "name": "babel-plugin-transform-remove-console", + "repository": { + "type": "git", + "url": "https://github.com/babel/babili/tree/master/packages/babel-plugin-transform-remove-console" + }, + "version": "6.8.4" +} diff --git a/node_modules/babel-preset-babili/node_modules/babel-plugin-transform-property-literals/.npmignore b/node_modules/babel-plugin-transform-remove-debugger/.npmignore similarity index 100% rename from node_modules/babel-preset-babili/node_modules/babel-plugin-transform-property-literals/.npmignore rename to node_modules/babel-plugin-transform-remove-debugger/.npmignore diff --git a/node_modules/babel-preset-babili/node_modules/babel-plugin-transform-remove-debugger/README.md b/node_modules/babel-plugin-transform-remove-debugger/README.md similarity index 100% rename from node_modules/babel-preset-babili/node_modules/babel-plugin-transform-remove-debugger/README.md rename to node_modules/babel-plugin-transform-remove-debugger/README.md diff --git a/node_modules/babel-preset-babili/node_modules/babel-plugin-transform-remove-debugger/lib/index.js b/node_modules/babel-plugin-transform-remove-debugger/lib/index.js similarity index 100% rename from node_modules/babel-preset-babili/node_modules/babel-plugin-transform-remove-debugger/lib/index.js rename to node_modules/babel-plugin-transform-remove-debugger/lib/index.js diff --git a/node_modules/babel-plugin-transform-remove-debugger/package.json b/node_modules/babel-plugin-transform-remove-debugger/package.json new file mode 100644 index 00000000000..2a56a72e586 --- /dev/null +++ b/node_modules/babel-plugin-transform-remove-debugger/package.json @@ -0,0 +1,46 @@ +{ + "_from": "babel-plugin-transform-remove-debugger@^6.8.4", + "_id": "babel-plugin-transform-remove-debugger@6.8.4", + "_inBundle": false, + "_integrity": "sha1-+FcEoIrapxtV13AFtblOm53yH24=", + "_location": "/babel-plugin-transform-remove-debugger", + "_phantomChildren": {}, + "_requested": { + "type": "range", + "registry": true, + "raw": "babel-plugin-transform-remove-debugger@^6.8.4", + "name": "babel-plugin-transform-remove-debugger", + "escapedName": "babel-plugin-transform-remove-debugger", + "rawSpec": "^6.8.4", + "saveSpec": null, + "fetchSpec": "^6.8.4" + }, + "_requiredBy": [ + "/node-titanium-sdk/babel-preset-babili" + ], + "_resolved": "https://registry.npmjs.org/babel-plugin-transform-remove-debugger/-/babel-plugin-transform-remove-debugger-6.8.4.tgz", + "_shasum": "f85704a08adaa71b55d77005b5b94e9b9df21f6e", + "_spec": "babel-plugin-transform-remove-debugger@^6.8.4", + "_where": "/Users/chris/appc/titanium_mobile/node_modules/node-titanium-sdk/node_modules/babel-preset-babili", + "author": { + "name": "amasad" + }, + "bugs": { + "url": "https://github.com/babel/babili/issues" + }, + "bundleDependencies": false, + "deprecated": false, + "description": "Remove debugger statements", + "homepage": "https://github.com/babel/babili#readme", + "keywords": [ + "babel-plugin" + ], + "license": "MIT", + "main": "lib/index.js", + "name": "babel-plugin-transform-remove-debugger", + "repository": { + "type": "git", + "url": "https://github.com/babel/babili/tree/master/packages/babel-plugin-transform-remove-debugger" + }, + "version": "6.8.4" +} diff --git a/node_modules/babel-preset-babili/node_modules/babel-plugin-transform-regexp-constructors/.npmignore b/node_modules/babel-plugin-transform-remove-undefined/.npmignore similarity index 100% rename from node_modules/babel-preset-babili/node_modules/babel-plugin-transform-regexp-constructors/.npmignore rename to node_modules/babel-plugin-transform-remove-undefined/.npmignore diff --git a/node_modules/babel-preset-babili/node_modules/babel-plugin-transform-remove-undefined/README.md b/node_modules/babel-plugin-transform-remove-undefined/README.md similarity index 100% rename from node_modules/babel-preset-babili/node_modules/babel-plugin-transform-remove-undefined/README.md rename to node_modules/babel-plugin-transform-remove-undefined/README.md diff --git a/node_modules/babel-plugin-transform-remove-undefined/lib/index.js b/node_modules/babel-plugin-transform-remove-undefined/lib/index.js new file mode 100644 index 00000000000..f5a2cf71471 --- /dev/null +++ b/node_modules/babel-plugin-transform-remove-undefined/lib/index.js @@ -0,0 +1,216 @@ +"use strict"; + +function isPureAndUndefined(rval) { + var scope = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : { hasBinding: function hasBinding() { + return false; + } }; + + if (rval.isIdentifier() && rval.node.name === "undefined") { + // deopt right away if undefined is a local binding + if (scope.hasBinding(rval.node.name, true /* no globals */)) { + return false; + } + return true; + } + + if (!rval.isPure()) { + return false; + } + var evaluation = rval.evaluate(); + return evaluation.confident === true && evaluation.value === undefined; +} + +function getLoopParent(path, scopeParent) { + var parent = path.findParent(function (p) { + return p.isLoop() || p === scopeParent; + }); + // don't traverse higher than the function the var is defined in. + return parent === scopeParent ? null : parent; +} + +function getFunctionParent(path, scopeParent) { + var parent = path.findParent(function (p) { + return p.isFunction(); + }); + // don't traverse higher than the function the var is defined in. + return parent === scopeParent ? null : parent; +} + +function getFunctionReferences(path, scopeParent) { + var references = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : new Set(); + + for (var func = getFunctionParent(path, scopeParent); func; func = getFunctionParent(func, scopeParent)) { + var id = func.node.id; + var binding = id && func.scope.getBinding(id.name); + + if (!binding) { + continue; + } + + binding.referencePaths.forEach(function (path) { + if (!references.has(path)) { + references.add(path); + getFunctionReferences(path, scopeParent, references); + } + }); + } + return references; +} + +function hasViolation(declarator, scope, start) { + var binding = scope.getBinding(declarator.node.id.name); + if (!binding) { + return true; + } + + var scopeParent = declarator.getFunctionParent(); + + var violation = binding.constantViolations.some(function (v) { + // return 'true' if we cannot guarantee the violation references + // the initialized identifier after + var violationStart = v.node.start; + if (violationStart === undefined || violationStart < start) { + return true; + } + + var references = getFunctionReferences(v, scopeParent); + var _iteratorNormalCompletion = true; + var _didIteratorError = false; + var _iteratorError = undefined; + + try { + for (var _iterator = references[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { + var ref = _step.value; + + if (ref.node.start === undefined || ref.node.start < start) { + return true; + } + } + } catch (err) { + _didIteratorError = true; + _iteratorError = err; + } finally { + try { + if (!_iteratorNormalCompletion && _iterator.return) { + _iterator.return(); + } + } finally { + if (_didIteratorError) { + throw _iteratorError; + } + } + } + + for (var loop = getLoopParent(declarator, scopeParent); loop; loop = getLoopParent(loop, scopeParent)) { + if (loop.node.end === undefined || loop.node.end > violationStart) { + return true; + } + } + }); + + return violation; +} + +module.exports = function () { + return { + name: "transform-remove-undefined", + visitor: { + SequenceExpression(path) { + var expressions = path.get("expressions"); + + for (var i = 0; i < expressions.length; i++) { + var expr = expressions[i]; + if (!isPureAndUndefined(expr, path.scope)) continue; + + // last value + if (i === expressions.length - 1) { + if (path.parentPath.isExpressionStatement()) { + expr.remove(); + } + } else { + expr.remove(); + } + } + }, + + ReturnStatement(path) { + if (path.node.argument !== null) { + if (isPureAndUndefined(path.get("argument"), path.scope)) { + path.node.argument = null; + } + } + }, + + VariableDeclaration(path) { + switch (path.node.kind) { + case "const": + break; + case "let": + var _iteratorNormalCompletion2 = true; + var _didIteratorError2 = false; + var _iteratorError2 = undefined; + + try { + for (var _iterator2 = path.get("declarations")[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) { + var declarator = _step2.value; + + if (isPureAndUndefined(declarator.get("init"))) { + declarator.node.init = null; + } + } + } catch (err) { + _didIteratorError2 = true; + _iteratorError2 = err; + } finally { + try { + if (!_iteratorNormalCompletion2 && _iterator2.return) { + _iterator2.return(); + } + } finally { + if (_didIteratorError2) { + throw _iteratorError2; + } + } + } + + break; + case "var": + var start = path.node.start; + if (start === undefined) { + // This is common for plugin-generated nodes + break; + } + var scope = path.scope; + var _iteratorNormalCompletion3 = true; + var _didIteratorError3 = false; + var _iteratorError3 = undefined; + + try { + for (var _iterator3 = path.get("declarations")[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) { + var _declarator = _step3.value; + + if (isPureAndUndefined(_declarator.get("init")) && !hasViolation(_declarator, scope, start)) { + _declarator.node.init = null; + } + } + } catch (err) { + _didIteratorError3 = true; + _iteratorError3 = err; + } finally { + try { + if (!_iteratorNormalCompletion3 && _iterator3.return) { + _iterator3.return(); + } + } finally { + if (_didIteratorError3) { + throw _iteratorError3; + } + } + } + + break; + } + } + } + }; +}; \ No newline at end of file diff --git a/node_modules/babel-plugin-transform-remove-undefined/package.json b/node_modules/babel-plugin-transform-remove-undefined/package.json new file mode 100644 index 00000000000..d094bb3c2bf --- /dev/null +++ b/node_modules/babel-plugin-transform-remove-undefined/package.json @@ -0,0 +1,46 @@ +{ + "_from": "babel-plugin-transform-remove-undefined@^0.1.2", + "_id": "babel-plugin-transform-remove-undefined@0.1.2", + "_inBundle": false, + "_integrity": "sha1-4ev1ERD2seBmXyg4Lvc/leUCNlI=", + "_location": "/babel-plugin-transform-remove-undefined", + "_phantomChildren": {}, + "_requested": { + "type": "range", + "registry": true, + "raw": "babel-plugin-transform-remove-undefined@^0.1.2", + "name": "babel-plugin-transform-remove-undefined", + "escapedName": "babel-plugin-transform-remove-undefined", + "rawSpec": "^0.1.2", + "saveSpec": null, + "fetchSpec": "^0.1.2" + }, + "_requiredBy": [ + "/node-titanium-sdk/babel-preset-babili" + ], + "_resolved": "https://registry.npmjs.org/babel-plugin-transform-remove-undefined/-/babel-plugin-transform-remove-undefined-0.1.2.tgz", + "_shasum": "e1ebf51110f6b1e0665f28382ef73f95e5023652", + "_spec": "babel-plugin-transform-remove-undefined@^0.1.2", + "_where": "/Users/chris/appc/titanium_mobile/node_modules/node-titanium-sdk/node_modules/babel-preset-babili", + "author": { + "name": "shinew" + }, + "bugs": { + "url": "https://github.com/babel/babili/issues" + }, + "bundleDependencies": false, + "deprecated": false, + "description": "This removes rvals that are equivalent to undefined wherever possible", + "homepage": "https://github.com/babel/babili#readme", + "keywords": [ + "babel-plugin" + ], + "license": "MIT", + "main": "lib/index.js", + "name": "babel-plugin-transform-remove-undefined", + "repository": { + "type": "git", + "url": "https://github.com/babel/babili/tree/master/packages/babel-plugin-transform-remove-undefined" + }, + "version": "0.1.2" +} diff --git a/node_modules/babel-preset-babili/node_modules/babel-plugin-transform-remove-console/.npmignore b/node_modules/babel-plugin-transform-simplify-comparison-operators/.npmignore similarity index 100% rename from node_modules/babel-preset-babili/node_modules/babel-plugin-transform-remove-console/.npmignore rename to node_modules/babel-plugin-transform-simplify-comparison-operators/.npmignore diff --git a/node_modules/babel-preset-babili/node_modules/babel-plugin-transform-simplify-comparison-operators/README.md b/node_modules/babel-plugin-transform-simplify-comparison-operators/README.md similarity index 100% rename from node_modules/babel-preset-babili/node_modules/babel-plugin-transform-simplify-comparison-operators/README.md rename to node_modules/babel-plugin-transform-simplify-comparison-operators/README.md diff --git a/node_modules/babel-preset-babili/node_modules/babel-plugin-transform-simplify-comparison-operators/lib/index.js b/node_modules/babel-plugin-transform-simplify-comparison-operators/lib/index.js similarity index 100% rename from node_modules/babel-preset-babili/node_modules/babel-plugin-transform-simplify-comparison-operators/lib/index.js rename to node_modules/babel-plugin-transform-simplify-comparison-operators/lib/index.js diff --git a/node_modules/babel-plugin-transform-simplify-comparison-operators/package.json b/node_modules/babel-plugin-transform-simplify-comparison-operators/package.json new file mode 100644 index 00000000000..080b406df4a --- /dev/null +++ b/node_modules/babel-plugin-transform-simplify-comparison-operators/package.json @@ -0,0 +1,46 @@ +{ + "_from": "babel-plugin-transform-simplify-comparison-operators@^6.8.4", + "_id": "babel-plugin-transform-simplify-comparison-operators@6.8.4", + "_inBundle": false, + "_integrity": "sha1-KqJKJi1mTIyz4SWjBseY16LeCNU=", + "_location": "/babel-plugin-transform-simplify-comparison-operators", + "_phantomChildren": {}, + "_requested": { + "type": "range", + "registry": true, + "raw": "babel-plugin-transform-simplify-comparison-operators@^6.8.4", + "name": "babel-plugin-transform-simplify-comparison-operators", + "escapedName": "babel-plugin-transform-simplify-comparison-operators", + "rawSpec": "^6.8.4", + "saveSpec": null, + "fetchSpec": "^6.8.4" + }, + "_requiredBy": [ + "/node-titanium-sdk/babel-preset-babili" + ], + "_resolved": "https://registry.npmjs.org/babel-plugin-transform-simplify-comparison-operators/-/babel-plugin-transform-simplify-comparison-operators-6.8.4.tgz", + "_shasum": "2aa24a262d664c8cb3e125a306c798d7a2de08d5", + "_spec": "babel-plugin-transform-simplify-comparison-operators@^6.8.4", + "_where": "/Users/chris/appc/titanium_mobile/node_modules/node-titanium-sdk/node_modules/babel-preset-babili", + "author": { + "name": "amasad" + }, + "bugs": { + "url": "https://github.com/babel/babili/issues" + }, + "bundleDependencies": false, + "deprecated": false, + "description": "Convert === and !== to == and != if their types are inferred to be the same.", + "homepage": "https://github.com/babel/babili#readme", + "keywords": [ + "babel-plugin" + ], + "license": "MIT", + "main": "lib/index.js", + "name": "babel-plugin-transform-simplify-comparison-operators", + "repository": { + "type": "git", + "url": "https://github.com/babel/babili/tree/master/packages/babel-plugin-transform-simplify-comparison-operators" + }, + "version": "6.8.4" +} diff --git a/node_modules/babel-preset-babili/node_modules/babel-plugin-transform-remove-debugger/.npmignore b/node_modules/babel-plugin-transform-undefined-to-void/.npmignore similarity index 100% rename from node_modules/babel-preset-babili/node_modules/babel-plugin-transform-remove-debugger/.npmignore rename to node_modules/babel-plugin-transform-undefined-to-void/.npmignore diff --git a/node_modules/babel-plugin-transform-undefined-to-void/README.md b/node_modules/babel-plugin-transform-undefined-to-void/README.md new file mode 100644 index 00000000000..3eff783e291 --- /dev/null +++ b/node_modules/babel-plugin-transform-undefined-to-void/README.md @@ -0,0 +1,51 @@ +# babel-plugin-transform-undefined-to-void + +Some JavaScript implementations allow undefined to be overwritten, this may lead to peculiar bugs that are extremely hard to track down. + +This plugin transforms `undefined` into `void 0` which returns undefined regardless of if it's been reassigned. + +## Example + +**In** + +```javascript +foo === undefined; +``` + +**Out** + +```javascript +foo === void 0; +``` + +## Installation + +```sh +npm install babel-plugin-transform-undefined-to-void +``` + +## Usage + +### Via `.babelrc` (Recommended) + +**.babelrc** + +```json +{ + "plugins": ["transform-undefined-to-void"] +} +``` + +### Via CLI + +```sh +babel --plugins transform-undefined-to-void script.js +``` + +### Via Node API + +```javascript +require("babel-core").transform("code", { + plugins: ["transform-undefined-to-void"] +}); +``` diff --git a/node_modules/babel-plugin-transform-undefined-to-void/lib/index.js b/node_modules/babel-plugin-transform-undefined-to-void/lib/index.js new file mode 100644 index 00000000000..711275ad611 --- /dev/null +++ b/node_modules/babel-plugin-transform-undefined-to-void/lib/index.js @@ -0,0 +1,18 @@ +"use strict"; + +module.exports = function (_ref) { + var t = _ref.types; + + var VOID_0 = t.unaryExpression("void", t.numericLiteral(0), true); + + return { + name: "transform-undefined-to-void", + visitor: { + ReferencedIdentifier(path) { + if (path.node.name === "undefined") { + path.replaceWith(VOID_0); + } + } + } + }; +}; \ No newline at end of file diff --git a/node_modules/babel-plugin-transform-undefined-to-void/package.json b/node_modules/babel-plugin-transform-undefined-to-void/package.json new file mode 100644 index 00000000000..f18e94bdcd9 --- /dev/null +++ b/node_modules/babel-plugin-transform-undefined-to-void/package.json @@ -0,0 +1,48 @@ +{ + "_from": "babel-plugin-transform-undefined-to-void@^6.8.2", + "_id": "babel-plugin-transform-undefined-to-void@6.8.2", + "_inBundle": false, + "_integrity": "sha1-/isdKU6wXodSTrk3JN6m4sPWb6E=", + "_location": "/babel-plugin-transform-undefined-to-void", + "_phantomChildren": {}, + "_requested": { + "type": "range", + "registry": true, + "raw": "babel-plugin-transform-undefined-to-void@^6.8.2", + "name": "babel-plugin-transform-undefined-to-void", + "escapedName": "babel-plugin-transform-undefined-to-void", + "rawSpec": "^6.8.2", + "saveSpec": null, + "fetchSpec": "^6.8.2" + }, + "_requiredBy": [ + "/node-titanium-sdk/babel-preset-babili" + ], + "_resolved": "https://registry.npmjs.org/babel-plugin-transform-undefined-to-void/-/babel-plugin-transform-undefined-to-void-6.8.2.tgz", + "_shasum": "fe2b1d294eb05e87524eb93724dea6e2c3d66fa1", + "_spec": "babel-plugin-transform-undefined-to-void@^6.8.2", + "_where": "/Users/chris/appc/titanium_mobile/node_modules/node-titanium-sdk/node_modules/babel-preset-babili", + "author": { + "name": "amasad" + }, + "bugs": { + "url": "https://github.com/babel/babili/issues" + }, + "bundleDependencies": false, + "dependencies": {}, + "deprecated": false, + "description": "Replace references to `undefined` with `void 0`", + "devDependencies": {}, + "homepage": "https://github.com/babel/babili#readme", + "keywords": [ + "babel-plugin" + ], + "license": "MIT", + "main": "lib/index.js", + "name": "babel-plugin-transform-undefined-to-void", + "repository": { + "type": "git", + "url": "https://github.com/babel/babili/tree/master/packages/babel-plugin-transform-undefined-to-void" + }, + "version": "6.8.2" +} diff --git a/node_modules/babel-preset-babili/README.md b/node_modules/babel-preset-babili/README.md deleted file mode 100644 index b9987b00adc..00000000000 --- a/node_modules/babel-preset-babili/README.md +++ /dev/null @@ -1,181 +0,0 @@ -# babel-preset-babili - -Babel preset for all minify plugins. - -+ [Install](#install) -+ [Usage](#usage) -+ [Options](#options) - -## Install - -```sh -npm install --save-dev babel-preset-babili -``` - -## Usage - -### Via `.babelrc` (Recommended) - -**.babelrc** - -```json -{ - "presets": ["babili"] -} -``` - -or pass in options - - -```json -{ - "presets": [["babili", { - "mangle": { - "blacklist": ["MyCustomError"] - }, - "unsafe": { - "typeConstructors": false - }, - "keepFnName": true - }]] -} -``` - -### Via CLI - -```sh -babel script.js --presets babili -``` - -### Via Node API - -```javascript -require("babel-core").transform("code", { - presets: ["babili"] -}); -``` - -## Options - -All options are **enabled** by default **except** the ones with an explicit mention - `(Default: false)` - -Three types of options: - -### 1-1 mapping with plugin - -+ `false` to disable the plugin -+ `true` to enable the plugin with default plugin specific options -+ `{ ...pluginOpts }` to enable the plugin with custom plugin options - -The following options have 1-1 mapping with a plugin, -+ `evaluate` - [babel-plugin-minify-constant-folding](../../packages/babel-plugin-minify-constant-folding) -+ `deadcode` - [babel-plugin-minify-dead-code-elimination](../../packages/babel-plugin-minify-dead-code-elimination) -+ `infinity` - [babel-plugin-minify-infinity](../../packages/babel-plugin-minify-infinity) -+ `mangle` - [babel-plugin-minify-mangle-names](../../packages/babel-plugin-minify-mangle-names) -+ `numericLiterals` - [babel-plugin-minify-numeric-literals](../../packages/babel-plugin-minify-numeric-literals) -+ `replace` - [babel-plugin-minify-replace](../../packages/babel-plugin-minify-replace) -+ `simplify` - [babel-plugin-minify-simplify](../../packages/babel-plugin-minify-simplify) -+ `mergeVars` - [babel-plugin-transform-merge-sibling-variables](../../packages/babel-plugin-transform-merge-sibling-variables) -+ `booleans` - [babel-plugin-transform-minify-booleans](../../packages/babel-plugin-transform-minify-booleans) -+ `regexpConstructors` - [babel-plugin-transform-regexp-constructors](../../packages/babel-plugin-transform-regexp-constructors) -+ `removeConsole` - `(Default: false)` - [babel-plugin-transform-remove-console](../../packages/babel-plugin-transform-remove-console) -+ `removeDebugger` - `(Default: false)` - [babel-plugin-transform-remove-debugger](../../packages/babel-plugin-transform-remove-debugger) -+ `removeUndefined` - [babel-plugin-transform-remove-undefined](../../packages/babel-plugin-transform-remove-undefined) -+ `undefinedToVoid` - [babel-plugin-transform-undefined-to-void](../../packages/babel-plugin-transform-undefined-to-void) - -**Examples** - -```json -{ - "presets": [["babili", { - "evaluate": false, - "mangle": true - }]] -} -``` - -```json -{ - "presets": [["babili", { - "mangle": { - "blacklist": { - "ParserError": true, - "NetworkError": false - } - } - }]] -} -``` - -### Option groups - -+ `false` to disable the entire group -+ `true` to enable every plugin in the group -+ `{ pluginKey: <1-1 mapping> }` - enable/disable a particular plugin in a group (or) pass options to that plugin - -The following are groups of plugins - - -+ `unsafe` - + `flipComparisons` - [babel-plugin-minify-flip-comparisons](../../packages/babel-plugin-minify-flip-comparisons) - + `simplifyComparisons` - [babel-plugin-transform-simplify-comparison-operators](../../babel-plugin-transform-simplify-comparison-operators) - + `guards` - [babel-plugin-minify-guarded-expressions](../../packages/babel-plugin-minify-guarded-expressions) - + `typeConstructors` - [babel-plugin-minify-type-constructors](../../packages/babel-plugin-minify-type-constructors) -+ `properties` - + `memberExpressions` - [babel-plugin-transform-member-expression-literals](../../packages/babel-plugin-transform-member-expression-literals) - + `propertyLiterals` - [babel-plugin-transform-property-literals](../../packages/babel-plugin-transform-property-literals) - -**Examples** - -Disables all unsafe plugins: - -```json -{ - "presets": [["babili", { - "unsafe": false - }]] -} -``` - -Disables only minify-guarded-expressions, and enable all other unsafe plugins: - -```json -{ - "presets": [["babili", { - "unsafe": { - "guards": false - } - }]] -} -``` - -### Passing same plugin options to multiple plugins - -In babili, multiple plugins require the same set of options and it is easier to mention it in one place instead of two. - -+ `keepFnName` - This will be passed to `mangle` and `deadcode` and will NOT be overriden if the same option exists under either mangle or deadcode. - -**Examples** - -```json -{ - "presets": [["babili", { - "keepFnName": true - }]] -} -``` - -is the same as, - -Plugins applied: - -```json -{ - "presets": [["babili", { - "mangle": { - "keepFnName": true - }, - "deadcode": { - "keepFnName": true - } - }]] -} -``` diff --git a/node_modules/babel-preset-babili/lib/index.js b/node_modules/babel-preset-babili/lib/index.js deleted file mode 100644 index 592a48ffcd7..00000000000 --- a/node_modules/babel-preset-babili/lib/index.js +++ /dev/null @@ -1,60 +0,0 @@ -"use strict"; - -var isPlainObject = require("lodash.isplainobject"); - -var _require = require("./options-manager"), - group = _require.group, - option = _require.option, - proxy = _require.proxy, - generate = _require.generate; - -// the flat plugin map -// This is to prevent dynamic requires - require('babel-plugin-' + name); -// as it suffers during bundling of this code with webpack/browserify - - -var PLUGINS = [["booleans", require("babel-plugin-transform-minify-booleans"), true], ["consecutiveAdds", require("babel-plugin-transform-inline-consecutive-adds"), true], ["deadcode", require("babel-plugin-minify-dead-code-elimination"), true], ["evaluate", require("babel-plugin-minify-constant-folding"), true], ["flipComparisons", require("babel-plugin-minify-flip-comparisons"), true], ["guards", require("babel-plugin-minify-guarded-expressions"), true], ["infinity", require("babel-plugin-minify-infinity"), true], ["mangle", require("babel-plugin-minify-mangle-names"), true], ["memberExpressions", require("babel-plugin-transform-member-expression-literals"), true], ["mergeVars", require("babel-plugin-transform-merge-sibling-variables"), true], ["numericLiterals", require("babel-plugin-minify-numeric-literals"), true], ["propertyLiterals", require("babel-plugin-transform-property-literals"), true], ["regexpConstructors", require("babel-plugin-transform-regexp-constructors"), true], ["removeConsole", require("babel-plugin-transform-remove-console"), false], ["removeDebugger", require("babel-plugin-transform-remove-debugger"), false], ["removeUndefined", require("babel-plugin-transform-remove-undefined"), true], ["replace", require("babel-plugin-minify-replace"), true], ["simplify", require("babel-plugin-minify-simplify"), true], ["simplifyComparisons", require("babel-plugin-transform-simplify-comparison-operators"), true], ["typeConstructors", require("babel-plugin-minify-type-constructors"), true], ["undefinedToVoid", require("babel-plugin-transform-undefined-to-void"), true], ["builtIns", require("babel-plugin-minify-builtins"), true]]; - -module.exports = preset; - -function preset(context) { - var _opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; - - var opts = isPlainObject(_opts) ? _opts : {}; - - // to track every plugin is used - var usedPlugins = new Set(); - - var optionsMap = PLUGINS.map(function (plugin) { - return option(plugin[0], plugin[1], plugin[2]); - }).reduce(function (acc, cur) { - Object.defineProperty(acc, cur.name, { - get() { - usedPlugins.add(cur.name); - return cur; - } - }); - return acc; - }, {}); - - var optionsTree = group("options", [optionsMap.evaluate, optionsMap.deadcode, group("unsafe", [optionsMap.flipComparisons, optionsMap.simplifyComparisons, optionsMap.guards, optionsMap.typeConstructors]), optionsMap.infinity, optionsMap.mangle, optionsMap.numericLiterals, optionsMap.replace, optionsMap.simplify, optionsMap.builtIns, group("properties", [optionsMap.consecutiveAdds, optionsMap.memberExpressions, optionsMap.propertyLiterals]), optionsMap.mergeVars, optionsMap.booleans, optionsMap.undefinedToVoid, optionsMap.regexpConstructors, optionsMap.removeConsole, optionsMap.removeDebugger, optionsMap.removeUndefined, proxy("keepFnName", [optionsMap.mangle, optionsMap.deadcode]), proxy("keepClassName", [optionsMap.mangle, optionsMap.deadcode])], "some"); - - // verify all plugins are used - if (usedPlugins.size !== PLUGINS.length) { - var unusedPlugins = PLUGINS.filter(function (plugin) { - return !usedPlugins.has(plugin[0]); - }).map(function (plugin) { - return plugin[0]; - }); - throw new Error("Some imported plugins unused\n" + unusedPlugins); - } - - var plugins = generate(optionsTree, opts); - - return { - minified: true, - comments: false, - presets: [{ plugins }], - passPerPreset: true - }; -} \ No newline at end of file diff --git a/node_modules/babel-preset-babili/node_modules/babel-plugin-minify-builtins/lib/index.js b/node_modules/babel-preset-babili/node_modules/babel-plugin-minify-builtins/lib/index.js deleted file mode 100644 index d53dfbf9c5d..00000000000 --- a/node_modules/babel-preset-babili/node_modules/babel-plugin-minify-builtins/lib/index.js +++ /dev/null @@ -1,226 +0,0 @@ -"use strict"; - -var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }(); - -var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); - -function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } - -var evaluate = require("babel-helper-evaluate-path"); -// Assuming all the static methods from below array are side effect free evaluation -// except Math.random -var VALID_CALLEES = ["String", "Number", "Math"]; -var INVALID_METHODS = ["random"]; - -module.exports = function (_ref) { - var t = _ref.types; - - var BuiltInReplacer = function () { - function BuiltInReplacer(program) { - _classCallCheck(this, BuiltInReplacer); - - this.program = program; - this.pathsToUpdate = new Map(); - } - - _createClass(BuiltInReplacer, [{ - key: "run", - value: function run() { - this.collect(); - this.replace(); - } - }, { - key: "collect", - value: function collect() { - var context = this; - - var collectVisitor = { - MemberExpression(path) { - if (path.parentPath.isCallExpression()) { - return; - } - - if (!isComputed(path) && isBuiltin(path)) { - var expName = memberToString(path.node); - - if (!context.pathsToUpdate.has(expName)) { - context.pathsToUpdate.set(expName, []); - } - context.pathsToUpdate.get(expName).push(path); - } - }, - - CallExpression: { - exit(path) { - var callee = path.get("callee"); - if (!callee.isMemberExpression()) { - return; - } - - // computed property should be not optimized - // Math[max]() -> Math.max() - if (!isComputed(callee) && isBuiltin(callee)) { - var result = evaluate(path); - // deopt when we have side effecty evaluate-able arguments - // Math.max(foo(), 1) --> untouched - // Math.floor(1) --> 1 - if (result.confident && hasPureArgs(path)) { - path.replaceWith(t.valueToNode(result.value)); - } else { - var expName = memberToString(callee.node); - - if (!context.pathsToUpdate.has(expName)) { - context.pathsToUpdate.set(expName, []); - } - context.pathsToUpdate.get(expName).push(callee); - } - } - } - } - }; - - this.program.traverse(collectVisitor); - } - }, { - key: "replace", - value: function replace() { - var _iteratorNormalCompletion = true; - var _didIteratorError = false; - var _iteratorError = undefined; - - try { - for (var _iterator = this.pathsToUpdate[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { - var _ref2 = _step.value; - - var _ref3 = _slicedToArray(_ref2, 2); - - var expName = _ref3[0]; - var paths = _ref3[1]; - - // Should only transform if there is more than 1 occurence - if (paths.length > 1) { - var uniqueIdentifier = this.program.scope.generateUidIdentifier(expName); - var newNode = t.variableDeclaration("var", [t.variableDeclarator(uniqueIdentifier, paths[0].node)]); - - var _iteratorNormalCompletion2 = true; - var _didIteratorError2 = false; - var _iteratorError2 = undefined; - - try { - for (var _iterator2 = paths[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) { - var path = _step2.value; - - path.replaceWith(uniqueIdentifier); - } - // hoist the created var to top of the program - } catch (err) { - _didIteratorError2 = true; - _iteratorError2 = err; - } finally { - try { - if (!_iteratorNormalCompletion2 && _iterator2.return) { - _iterator2.return(); - } - } finally { - if (_didIteratorError2) { - throw _iteratorError2; - } - } - } - - this.program.unshiftContainer("body", newNode); - } - } - } catch (err) { - _didIteratorError = true; - _iteratorError = err; - } finally { - try { - if (!_iteratorNormalCompletion && _iterator.return) { - _iterator.return(); - } - } finally { - if (_didIteratorError) { - throw _iteratorError; - } - } - } - } - }]); - - return BuiltInReplacer; - }(); - - return { - name: "minify-builtins", - visitor: { - Program(path) { - var builtInReplacer = new BuiltInReplacer(path); - builtInReplacer.run(); - } - } - }; - - function memberToString(memberExpr) { - var object = memberExpr.object, - property = memberExpr.property; - - var result = ""; - - if (t.isIdentifier(object)) result += object.name; - if (t.isMemberExpression(object)) result += memberToString(object); - if (t.isIdentifier(property)) result += property.name; - - return result; - } - - function isBuiltin(memberExpr) { - var _memberExpr$node = memberExpr.node, - object = _memberExpr$node.object, - property = _memberExpr$node.property; - - - if (t.isIdentifier(object) && t.isIdentifier(property) && VALID_CALLEES.indexOf(object.name) >= 0 && INVALID_METHODS.indexOf(property.name) < 0) { - return true; - } - return false; - } -}; - -function hasPureArgs(path) { - var args = path.get("arguments"); - var _iteratorNormalCompletion3 = true; - var _didIteratorError3 = false; - var _iteratorError3 = undefined; - - try { - for (var _iterator3 = args[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) { - var arg = _step3.value; - - if (!arg.isPure()) { - return false; - } - } - } catch (err) { - _didIteratorError3 = true; - _iteratorError3 = err; - } finally { - try { - if (!_iteratorNormalCompletion3 && _iterator3.return) { - _iterator3.return(); - } - } finally { - if (_didIteratorError3) { - throw _iteratorError3; - } - } - } - - return true; -} - -function isComputed(path) { - var node = path.node; - - return node.computed; -} \ No newline at end of file diff --git a/node_modules/babel-preset-babili/node_modules/babel-plugin-minify-builtins/node_modules/babel-helper-evaluate-path/README.md b/node_modules/babel-preset-babili/node_modules/babel-plugin-minify-builtins/node_modules/babel-helper-evaluate-path/README.md deleted file mode 100644 index 4d1cef9ca31..00000000000 --- a/node_modules/babel-preset-babili/node_modules/babel-plugin-minify-builtins/node_modules/babel-helper-evaluate-path/README.md +++ /dev/null @@ -1,9 +0,0 @@ -# # babel-helper-evaluate-path - -`path.evaluate` wrapped in a try catch - -## Installation - -```sh -$ npm install babel-helper-evaluate-path -``` diff --git a/node_modules/babel-preset-babili/node_modules/babel-plugin-minify-builtins/node_modules/babel-helper-evaluate-path/package.json b/node_modules/babel-preset-babili/node_modules/babel-plugin-minify-builtins/node_modules/babel-helper-evaluate-path/package.json deleted file mode 100644 index cace51e77aa..00000000000 --- a/node_modules/babel-preset-babili/node_modules/babel-plugin-minify-builtins/node_modules/babel-helper-evaluate-path/package.json +++ /dev/null @@ -1,62 +0,0 @@ -{ - "name": "babel-helper-evaluate-path", - "version": "0.0.3", - "description": "path.evaluate wrapped in a try catch", - "homepage": "https://github.com/babel/babili#readme", - "repository": { - "type": "git", - "url": "https://github.com/babel/babili/tree/master/packages/babel-helper-evaluate-path" - }, - "bugs": { - "url": "https://github.com/babel/babili/issues" - }, - "author": { - "name": "boopathi" - }, - "license": "MIT", - "main": "lib/index.js", - "keywords": [ - "babel-plugin", - "babili" - ], - "dependencies": {}, - "devDependencies": {}, - "_id": "babel-helper-evaluate-path@0.0.3", - "scripts": {}, - "_shasum": "1d103ac9d4a59e5d431842212f151785f7ac547b", - "_from": "babel-helper-evaluate-path@>=0.0.3 <0.0.4", - "_npmVersion": "3.10.3", - "_nodeVersion": "6.3.1", - "_npmUser": { - "name": "kangax", - "email": "kangax@gmail.com" - }, - "dist": { - "shasum": "1d103ac9d4a59e5d431842212f151785f7ac547b", - "tarball": "https://registry.npmjs.org/babel-helper-evaluate-path/-/babel-helper-evaluate-path-0.0.3.tgz" - }, - "maintainers": [ - { - "name": "amasad", - "email": "amjad.masad@gmail.com" - }, - { - "name": "boopathi", - "email": "me@boopathi.in" - }, - { - "name": "hzoo", - "email": "hi@henryzoo.com" - }, - { - "name": "kangax", - "email": "kangax@gmail.com" - } - ], - "_npmOperationalInternal": { - "host": "packages-18-east.internal.npmjs.com", - "tmp": "tmp/babel-helper-evaluate-path-0.0.3.tgz_1479508976223_0.06866875709965825" - }, - "directories": {}, - "_resolved": "https://registry.npmjs.org/babel-helper-evaluate-path/-/babel-helper-evaluate-path-0.0.3.tgz" -} diff --git a/node_modules/babel-preset-babili/node_modules/babel-plugin-minify-builtins/package.json b/node_modules/babel-preset-babili/node_modules/babel-plugin-minify-builtins/package.json deleted file mode 100644 index 459470f00fd..00000000000 --- a/node_modules/babel-preset-babili/node_modules/babel-plugin-minify-builtins/package.json +++ /dev/null @@ -1,70 +0,0 @@ -{ - "name": "babel-plugin-minify-builtins", - "version": "0.0.2", - "description": "Minify Standard built-in Objects", - "homepage": "https://github.com/babel/babili#readme", - "repository": { - "type": "git", - "url": "https://github.com/babel/babili/tree/master/packages/babel-plugin-minify-builtins" - }, - "main": "lib/index.js", - "bugs": { - "url": "https://github.com/babel/babili/issues" - }, - "keywords": [ - "babel-plugin", - "transform-built-ins" - ], - "author": { - "name": "Vignesh Shanmugam", - "email": "vignesh.shanmugam22@gmail.com", - "url": "https://vigneshh.in" - }, - "license": "MIT", - "dependencies": { - "babel-helper-evaluate-path": "^0.0.3" - }, - "devDependencies": {}, - "_id": "babel-plugin-minify-builtins@0.0.2", - "scripts": {}, - "_shasum": "f3be6121763c0c518d5ef82067cef4b615c9498c", - "_from": "babel-plugin-minify-builtins@>=0.0.2 <0.0.3", - "_npmVersion": "4.0.5", - "_nodeVersion": "7.4.0", - "_npmUser": { - "name": "boopathi", - "email": "me@boopathi.in" - }, - "dist": { - "shasum": "f3be6121763c0c518d5ef82067cef4b615c9498c", - "tarball": "https://registry.npmjs.org/babel-plugin-minify-builtins/-/babel-plugin-minify-builtins-0.0.2.tgz" - }, - "maintainers": [ - { - "name": "amasad", - "email": "amjad.masad@gmail.com" - }, - { - "name": "boopathi", - "email": "me@boopathi.in" - }, - { - "name": "hzoo", - "email": "hi@henryzoo.com" - }, - { - "name": "kangax", - "email": "kangax@gmail.com" - }, - { - "name": "vignesh.shanmugam", - "email": "vignesh.shanmugam22@gmail.com" - } - ], - "_npmOperationalInternal": { - "host": "packages-12-west.internal.npmjs.com", - "tmp": "tmp/babel-plugin-minify-builtins-0.0.2.tgz_1488563258095_0.23415788495913148" - }, - "directories": {}, - "_resolved": "https://registry.npmjs.org/babel-plugin-minify-builtins/-/babel-plugin-minify-builtins-0.0.2.tgz" -} diff --git a/node_modules/babel-preset-babili/node_modules/babel-plugin-minify-constant-folding/README.md b/node_modules/babel-preset-babili/node_modules/babel-plugin-minify-constant-folding/README.md deleted file mode 100644 index 71468ccabb7..00000000000 --- a/node_modules/babel-preset-babili/node_modules/babel-plugin-minify-constant-folding/README.md +++ /dev/null @@ -1,55 +0,0 @@ -# babel-plugin-minify-constant-folding - -Tries to evaluate expressions and inline the result. For now only deals with numbers and strings. - -## Example - -**In** - -```javascript -"a" + "b" -2 * 3; -4 | 3; -"b" + a + "c" + "d" + g + z + "f" + "h" + "z" -``` - -**Out** - -```javascript -"ab"; -6; -7; -"b" + a + "cd" + g + z + "fhz"; -``` - -## Installation - -```sh -npm install babel-plugin-minify-constant-folding -``` - -## Usage - -### Via `.babelrc` (Recommended) - -**.babelrc** - -```json -{ - "plugins": ["minify-constant-folding"] -} -``` - -### Via CLI - -```sh -babel --plugins minify-constant-folding script.js -``` - -### Via Node API - -```javascript -require("babel-core").transform("code", { - plugins: ["minify-constant-folding"] -}); -``` diff --git a/node_modules/babel-preset-babili/node_modules/babel-plugin-minify-constant-folding/lib/index.js b/node_modules/babel-preset-babili/node_modules/babel-plugin-minify-constant-folding/lib/index.js deleted file mode 100644 index e4ab380ebad..00000000000 --- a/node_modules/babel-preset-babili/node_modules/babel-plugin-minify-constant-folding/lib/index.js +++ /dev/null @@ -1,131 +0,0 @@ -"use strict"; - -var evaluate = require("babel-helper-evaluate-path"); -var jsesc = require("jsesc"); - -module.exports = function (_ref) { - var t = _ref.types, - traverse = _ref.traverse; - - var seen = Symbol("seen"); - - return { - name: "minify-constant-folding", - visitor: { - - // Evaluate string expressions that are next to each other - // but are not actually a binary expression. - // "a" + b + "c" + "d" -> "a" + b + "cd" - BinaryExpression(path) { - var literal = void 0, - bin = void 0; - if (path.get("right").isStringLiteral()) { - literal = path.get("right"); - if (path.get("left").isBinaryExpression({ operator: "+" })) { - bin = path.get("left"); - } else { - return; - } - } else if (path.get("left").isStringLiteral()) { - literal = path.get("left"); - if (path.get("right").isBinaryExpression({ operator: "+" })) { - bin = path.get("right"); - } else { - return; - } - } else { - return; - } - - var relevant = getLeaf(bin, literal.key); - - if (!relevant) { - return; - } - - var value = literal.key === "right" ? relevant.node.value + literal.node.value : literal.node.value + relevant.node.value; - - relevant.replaceWith(t.stringLiteral(value)); - path.replaceWith(bin.node); - - function getLeaf(path, direction) { - if (path.isStringLiteral()) { - return path; - } else if (path.isBinaryExpression({ operator: "+" })) { - return getLeaf(path.get(direction), direction); - } - } - }, - - // TODO: look into evaluating binding too (could result in more code, but gzip?) - Expression(path) { - var node = path.node; - - - if (node[seen]) { - return; - } - - if (path.isLiteral()) { - return; - } - - if (!path.isPure()) { - return; - } - - if (traverse.hasType(node, path.scope, "Identifier", t.FUNCTION_TYPES)) { - return; - } - - // -0 maybe compared via dividing and then checking against -Infinity - // Also -X will always be -X. - if (t.isUnaryExpression(node, { operator: "-" }) && t.isNumericLiteral(node.argument)) { - return; - } - - // We have a transform that converts true/false to !0/!1 - if (t.isUnaryExpression(node, { operator: "!" }) && t.isNumericLiteral(node.argument)) { - if (node.argument.value === 0 || node.argument.value === 1) { - return; - } - } - - // void 0 is used for undefined. - if (t.isUnaryExpression(node, { operator: "void" }) && t.isNumericLiteral(node.argument, { value: 0 })) { - return; - } - - var res = evaluate(path); - if (res.confident) { - // Avoid fractions because they can be longer than the original expression. - // There is also issues with number percision? - if (typeof res.value === "number" && !Number.isInteger(res.value)) { - return; - } - - // Preserve -0 - if (typeof res.value === "number" && res.value === 0) { - if (1 / res.value === -Infinity) { - var _node2 = t.unaryExpression("-", t.numericLiteral(0), true); - _node2[seen] = true; - path.replaceWith(_node2); - return; - } - } - - // https://github.com/babel/babili/issues/382 - if (typeof res.value === "string") { - res.value = jsesc(res.value, { - isScriptContext: true - }); - } - - var _node = t.valueToNode(res.value); - _node[seen] = true; - path.replaceWith(_node); - } - } - } - }; -}; \ No newline at end of file diff --git a/node_modules/babel-preset-babili/node_modules/babel-plugin-minify-constant-folding/node_modules/.bin/jsesc b/node_modules/babel-preset-babili/node_modules/babel-plugin-minify-constant-folding/node_modules/.bin/jsesc deleted file mode 120000 index 7237604c357..00000000000 --- a/node_modules/babel-preset-babili/node_modules/babel-plugin-minify-constant-folding/node_modules/.bin/jsesc +++ /dev/null @@ -1 +0,0 @@ -../jsesc/bin/jsesc \ No newline at end of file diff --git a/node_modules/babel-preset-babili/node_modules/babel-plugin-minify-constant-folding/node_modules/babel-helper-evaluate-path/README.md b/node_modules/babel-preset-babili/node_modules/babel-plugin-minify-constant-folding/node_modules/babel-helper-evaluate-path/README.md deleted file mode 100644 index 4d1cef9ca31..00000000000 --- a/node_modules/babel-preset-babili/node_modules/babel-plugin-minify-constant-folding/node_modules/babel-helper-evaluate-path/README.md +++ /dev/null @@ -1,9 +0,0 @@ -# # babel-helper-evaluate-path - -`path.evaluate` wrapped in a try catch - -## Installation - -```sh -$ npm install babel-helper-evaluate-path -``` diff --git a/node_modules/babel-preset-babili/node_modules/babel-plugin-minify-constant-folding/node_modules/babel-helper-evaluate-path/lib/index.js b/node_modules/babel-preset-babili/node_modules/babel-plugin-minify-constant-folding/node_modules/babel-helper-evaluate-path/lib/index.js deleted file mode 100644 index 8dd551d69e8..00000000000 --- a/node_modules/babel-preset-babili/node_modules/babel-plugin-minify-constant-folding/node_modules/babel-helper-evaluate-path/lib/index.js +++ /dev/null @@ -1,12 +0,0 @@ -"use strict"; - -module.exports = function evaluate(path) { - try { - return path.evaluate(); - } catch (e) { - return { - confident: false, - error: e - }; - } -}; \ No newline at end of file diff --git a/node_modules/babel-preset-babili/node_modules/babel-plugin-minify-constant-folding/node_modules/babel-helper-evaluate-path/package.json b/node_modules/babel-preset-babili/node_modules/babel-plugin-minify-constant-folding/node_modules/babel-helper-evaluate-path/package.json deleted file mode 100644 index cace51e77aa..00000000000 --- a/node_modules/babel-preset-babili/node_modules/babel-plugin-minify-constant-folding/node_modules/babel-helper-evaluate-path/package.json +++ /dev/null @@ -1,62 +0,0 @@ -{ - "name": "babel-helper-evaluate-path", - "version": "0.0.3", - "description": "path.evaluate wrapped in a try catch", - "homepage": "https://github.com/babel/babili#readme", - "repository": { - "type": "git", - "url": "https://github.com/babel/babili/tree/master/packages/babel-helper-evaluate-path" - }, - "bugs": { - "url": "https://github.com/babel/babili/issues" - }, - "author": { - "name": "boopathi" - }, - "license": "MIT", - "main": "lib/index.js", - "keywords": [ - "babel-plugin", - "babili" - ], - "dependencies": {}, - "devDependencies": {}, - "_id": "babel-helper-evaluate-path@0.0.3", - "scripts": {}, - "_shasum": "1d103ac9d4a59e5d431842212f151785f7ac547b", - "_from": "babel-helper-evaluate-path@>=0.0.3 <0.0.4", - "_npmVersion": "3.10.3", - "_nodeVersion": "6.3.1", - "_npmUser": { - "name": "kangax", - "email": "kangax@gmail.com" - }, - "dist": { - "shasum": "1d103ac9d4a59e5d431842212f151785f7ac547b", - "tarball": "https://registry.npmjs.org/babel-helper-evaluate-path/-/babel-helper-evaluate-path-0.0.3.tgz" - }, - "maintainers": [ - { - "name": "amasad", - "email": "amjad.masad@gmail.com" - }, - { - "name": "boopathi", - "email": "me@boopathi.in" - }, - { - "name": "hzoo", - "email": "hi@henryzoo.com" - }, - { - "name": "kangax", - "email": "kangax@gmail.com" - } - ], - "_npmOperationalInternal": { - "host": "packages-18-east.internal.npmjs.com", - "tmp": "tmp/babel-helper-evaluate-path-0.0.3.tgz_1479508976223_0.06866875709965825" - }, - "directories": {}, - "_resolved": "https://registry.npmjs.org/babel-helper-evaluate-path/-/babel-helper-evaluate-path-0.0.3.tgz" -} diff --git a/node_modules/babel-preset-babili/node_modules/babel-plugin-minify-constant-folding/node_modules/jsesc/LICENSE-MIT.txt b/node_modules/babel-preset-babili/node_modules/babel-plugin-minify-constant-folding/node_modules/jsesc/LICENSE-MIT.txt deleted file mode 100644 index a41e0a7ef97..00000000000 --- a/node_modules/babel-preset-babili/node_modules/babel-plugin-minify-constant-folding/node_modules/jsesc/LICENSE-MIT.txt +++ /dev/null @@ -1,20 +0,0 @@ -Copyright Mathias Bynens - -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. diff --git a/node_modules/babel-preset-babili/node_modules/babel-plugin-minify-constant-folding/node_modules/jsesc/README.md b/node_modules/babel-preset-babili/node_modules/babel-plugin-minify-constant-folding/node_modules/jsesc/README.md deleted file mode 100644 index aae2b13a19b..00000000000 --- a/node_modules/babel-preset-babili/node_modules/babel-plugin-minify-constant-folding/node_modules/jsesc/README.md +++ /dev/null @@ -1,421 +0,0 @@ -# jsesc [![Build status](https://travis-ci.org/mathiasbynens/jsesc.svg?branch=master)](https://travis-ci.org/mathiasbynens/jsesc) [![Code coverage status](https://coveralls.io/repos/mathiasbynens/jsesc/badge.svg)](https://coveralls.io/r/mathiasbynens/jsesc) [![Dependency status](https://gemnasium.com/mathiasbynens/jsesc.svg)](https://gemnasium.com/mathiasbynens/jsesc) - -Given some data, _jsesc_ returns a stringified representation of that data. jsesc is similar to `JSON.stringify()` except: - -1. it outputs JavaScript instead of JSON [by default](#json), enabling support for data structures like ES6 maps and sets; -2. it offers [many options](#api) to customize the output; -3. its output is ASCII-safe [by default](#minimal), thanks to its use of [escape sequences](https://mathiasbynens.be/notes/javascript-escapes) where needed. - -For any input, jsesc generates the shortest possible valid printable-ASCII-only output. [Here’s an online demo.](https://mothereff.in/js-escapes) - -jsesc’s output can be used instead of `JSON.stringify`’s to avoid [mojibake](https://en.wikipedia.org/wiki/Mojibake) and other encoding issues, or even to [avoid errors](https://twitter.com/annevk/status/380000829643571200) when passing JSON-formatted data (which may contain U+2028 LINE SEPARATOR, U+2029 PARAGRAPH SEPARATOR, or [lone surrogates](https://esdiscuss.org/topic/code-points-vs-unicode-scalar-values#content-14)) to a JavaScript parser or an UTF-8 encoder. - -## Installation - -Via [npm](https://www.npmjs.com/): - -```bash -npm install jsesc -``` - -In [Node.js](https://nodejs.org/): - -```js -const jsesc = require('jsesc'); -``` - -## API - -### `jsesc(value, options)` - -This function takes a value and returns an escaped version of the value where any characters that are not printable ASCII symbols are escaped using the shortest possible (but valid) [escape sequences for use in JavaScript strings](https://mathiasbynens.be/notes/javascript-escapes). The first supported value type is strings: - -```js -jsesc('Ich ♥ Bücher'); -// → 'Ich \\u2665 B\\xFCcher' - -jsesc('foo 𝌆 bar'); -// → 'foo \\uD834\\uDF06 bar' -``` - -Instead of a string, the `value` can also be an array, an object, a map, a set, or a buffer. In such cases, `jsesc` returns a stringified version of the value where any characters that are not printable ASCII symbols are escaped in the same way. - -```js -// Escaping an array -jsesc([ - 'Ich ♥ Bücher', 'foo 𝌆 bar' -]); -// → '[\'Ich \\u2665 B\\xFCcher\',\'foo \\uD834\\uDF06 bar\']' - -// Escaping an object -jsesc({ - 'Ich ♥ Bücher': 'foo 𝌆 bar' -}); -// → '{\'Ich \\u2665 B\\xFCcher\':\'foo \\uD834\\uDF06 bar\'}' -``` - -The optional `options` argument accepts an object with the following options: - -#### `quotes` - -The default value for the `quotes` option is `'single'`. This means that any occurrences of `'` in the input string are escaped as `\'`, so that the output can be used in a string literal wrapped in single quotes. - -```js -jsesc('`Lorem` ipsum "dolor" sit \'amet\' etc.'); -// → 'Lorem ipsum "dolor" sit \\\'amet\\\' etc.' - -jsesc('`Lorem` ipsum "dolor" sit \'amet\' etc.', { - 'quotes': 'single' -}); -// → '`Lorem` ipsum "dolor" sit \\\'amet\\\' etc.' -// → "`Lorem` ipsum \"dolor\" sit \\'amet\\' etc." -``` - -If you want to use the output as part of a string literal wrapped in double quotes, set the `quotes` option to `'double'`. - -```js -jsesc('`Lorem` ipsum "dolor" sit \'amet\' etc.', { - 'quotes': 'double' -}); -// → '`Lorem` ipsum \\"dolor\\" sit \'amet\' etc.' -// → "`Lorem` ipsum \\\"dolor\\\" sit 'amet' etc." -``` - -If you want to use the output as part of a template literal (i.e. wrapped in backticks), set the `quotes` option to `'backtick'`. - -```js -jsesc('`Lorem` ipsum "dolor" sit \'amet\' etc.', { - 'quotes': 'backtick' -}); -// → '\\`Lorem\\` ipsum "dolor" sit \'amet\' etc.' -// → "\\`Lorem\\` ipsum \"dolor\" sit 'amet' etc." -// → `\\\`Lorem\\\` ipsum "dolor" sit 'amet' etc.` -``` - -This setting also affects the output for arrays and objects: - -```js -jsesc({ 'Ich ♥ Bücher': 'foo 𝌆 bar' }, { - 'quotes': 'double' -}); -// → '{"Ich \\u2665 B\\xFCcher":"foo \\uD834\\uDF06 bar"}' - -jsesc([ 'Ich ♥ Bücher', 'foo 𝌆 bar' ], { - 'quotes': 'double' -}); -// → '["Ich \\u2665 B\\xFCcher","foo \\uD834\\uDF06 bar"]' -``` - -#### `numbers` - -The default value for the `numbers` option is `'decimal'`. This means that any numeric values are represented using decimal integer literals. Other valid options are `binary`, `octal`, and `hexadecimal`, which result in binary integer literals, octal integer literals, and hexadecimal integer literals, respectively. - -```js -jsesc(42, { - 'numbers': 'binary' -}); -// → '0b101010' - -jsesc(42, { - 'numbers': 'octal' -}); -// → '0o52' - -jsesc(42, { - 'numbers': 'decimal' -}); -// → '42' - -jsesc(42, { - 'numbers': 'hexadecimal' -}); -// → '0x2A' -``` - -#### `wrap` - -The `wrap` option takes a boolean value (`true` or `false`), and defaults to `false` (disabled). When enabled, the output is a valid JavaScript string literal wrapped in quotes. The type of quotes can be specified through the `quotes` setting. - -```js -jsesc('Lorem ipsum "dolor" sit \'amet\' etc.', { - 'quotes': 'single', - 'wrap': true -}); -// → '\'Lorem ipsum "dolor" sit \\\'amet\\\' etc.\'' -// → "\'Lorem ipsum \"dolor\" sit \\\'amet\\\' etc.\'" - -jsesc('Lorem ipsum "dolor" sit \'amet\' etc.', { - 'quotes': 'double', - 'wrap': true -}); -// → '"Lorem ipsum \\"dolor\\" sit \'amet\' etc."' -// → "\"Lorem ipsum \\\"dolor\\\" sit \'amet\' etc.\"" -``` - -#### `es6` - -The `es6` option takes a boolean value (`true` or `false`), and defaults to `false` (disabled). When enabled, any astral Unicode symbols in the input are escaped using [ECMAScript 6 Unicode code point escape sequences](https://mathiasbynens.be/notes/javascript-escapes#unicode-code-point) instead of using separate escape sequences for each surrogate half. If backwards compatibility with ES5 environments is a concern, don’t enable this setting. If the `json` setting is enabled, the value for the `es6` setting is ignored (as if it was `false`). - -```js -// By default, the `es6` option is disabled: -jsesc('foo 𝌆 bar 💩 baz'); -// → 'foo \\uD834\\uDF06 bar \\uD83D\\uDCA9 baz' - -// To explicitly disable it: -jsesc('foo 𝌆 bar 💩 baz', { - 'es6': false -}); -// → 'foo \\uD834\\uDF06 bar \\uD83D\\uDCA9 baz' - -// To enable it: -jsesc('foo 𝌆 bar 💩 baz', { - 'es6': true -}); -// → 'foo \\u{1D306} bar \\u{1F4A9} baz' -``` - -#### `escapeEverything` - -The `escapeEverything` option takes a boolean value (`true` or `false`), and defaults to `false` (disabled). When enabled, all the symbols in the output are escaped — even printable ASCII symbols. - -```js -jsesc('lolwat"foo\'bar', { - 'escapeEverything': true -}); -// → '\\x6C\\x6F\\x6C\\x77\\x61\\x74\\"\\x66\\x6F\\x6F\\\'\\x62\\x61\\x72' -// → "\\x6C\\x6F\\x6C\\x77\\x61\\x74\\\"\\x66\\x6F\\x6F\\'\\x62\\x61\\x72" -``` - -This setting also affects the output for string literals within arrays and objects. - -#### `minimal` - -The `minimal` option takes a boolean value (`true` or `false`), and defaults to `false` (disabled). When enabled, only a limited set of symbols in the output are escaped: - -* U+0000 `\0` -* U+0008 `\b` -* U+0009 `\t` -* U+000A `\n` -* U+000C `\f` -* U+000D `\r` -* U+005C `\\` -* U+2028 `\u2028` -* U+2029 `\u2029` -* whatever symbol is being used for wrapping string literals (based on [the `quotes` option](#quotes)) - -Note: with this option enabled, jsesc output is no longer guaranteed to be ASCII-safe. - -```js -jsesc('foo\u2029bar\nbaz©qux𝌆flops', { - 'minimal': false -}); -// → 'foo\\u2029bar\\nbaz©qux𝌆flops' -``` - -#### `isScriptContext` - -The `isScriptContext` option takes a boolean value (`true` or `false`), and defaults to `false` (disabled). When enabled, occurrences of [`` or `