diff options
Diffstat (limited to 'node_modules/babel-helper-to-multiple-sequence-expressions')
4 files changed, 182 insertions, 0 deletions
diff --git a/node_modules/babel-helper-to-multiple-sequence-expressions/LICENSE b/node_modules/babel-helper-to-multiple-sequence-expressions/LICENSE new file mode 100644 index 00000000..f9f0a7f3 --- /dev/null +++ b/node_modules/babel-helper-to-multiple-sequence-expressions/LICENSE @@ -0,0 +1,22 @@ +Copyright (c) 2015-2016 Amjad Masad <amjad.masad@gmail.com> + +MIT License + +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-helper-to-multiple-sequence-expressions/README.md b/node_modules/babel-helper-to-multiple-sequence-expressions/README.md new file mode 100644 index 00000000..63db981c --- /dev/null +++ b/node_modules/babel-helper-to-multiple-sequence-expressions/README.md @@ -0,0 +1,7 @@ +# babel-helper-to-multiple-sequence-expressions + +## Installation + +```sh +npm install babel-helper-to-multiple-sequence-expressions --save-dev +``` diff --git a/node_modules/babel-helper-to-multiple-sequence-expressions/lib/index.js b/node_modules/babel-helper-to-multiple-sequence-expressions/lib/index.js new file mode 100644 index 00000000..01572d48 --- /dev/null +++ b/node_modules/babel-helper-to-multiple-sequence-expressions/lib/index.js @@ -0,0 +1,138 @@ +"use strict"; + +module.exports = function (t) { + return function toMultipleSequenceExpressions(statements) { + const retStatements = []; + let bailed; + + do { + const res = convert(statements); + bailed = res.bailed; + const seq = res.seq, + bailedAtIndex = res.bailedAtIndex; + + if (seq) { + retStatements.push(t.expressionStatement(seq)); + } + + if (bailed && statements[bailedAtIndex]) { + retStatements.push(statements[bailedAtIndex]); + } + + if (bailed) { + statements = statements.slice(bailedAtIndex + 1); + + if (!statements.length) { + bailed = false; + } + } + } while (bailed); + + return retStatements; + + function convert(nodes) { + const exprs = []; + const comments = []; + + for (let i = 0; i < nodes.length; i++) { + const bail = () => { + let seq; + + if (exprs.length === 1) { + seq = exprs[0]; + } else if (exprs.length) { + seq = t.sequenceExpression(exprs); + } + + return { + seq, + bailed: true, + bailedAtIndex: i + }; + }; + + const node = nodes[i]; + + if (t.isExpression(node)) { + exprs.push(node); + } else if (t.isExpressionStatement(node)) { + if (node.leadingComments) { + comments.push(...node.leadingComments); + } + + if (node.expression) exprs.push(node.expression); + } else if (t.isIfStatement(node)) { + let consequent; + + if (node.consequent) { + const res = convert([node.consequent]); + + if (res.bailed) { + return bail(); + } + + consequent = res.seq; + } + + let alternate; + + if (node.alternate) { + const res = convert([node.alternate]); + + if (res.bailed) { + return bail(); + } + + alternate = res.seq; + } + + if (!alternate && !consequent) { + exprs.push(node.test); + } else if (!alternate) { + exprs.push(t.logicalExpression("&&", node.test, consequent)); + } else if (!consequent) { + exprs.push(t.logicalExpression("||", node.test, alternate)); + } else { + exprs.push(t.conditionalExpression(node.test, consequent, alternate)); + } + } else if (t.isBlockStatement(node)) { + const res = convert(node.body); + + if (res.bailed) { + return bail(); + } + + if (res.seq) { + exprs.push(res.seq); + } + } else { + return bail(); + } + } + + let seq; + + if (exprs.length === 1) { + seq = exprs[0]; + } else if (exprs.length) { + seq = t.sequenceExpression(exprs); + } + /** + * collect all the comment ast nodes that are before expression + * statments and add it to the new generated node + */ + + + if (seq) { + seq.leadingComments = comments; + } + /* eslint-disable no-self-assign */ + + + seq = seq; + return { + seq + }; + } + }; +};
\ No newline at end of file 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 00000000..33ce230e --- /dev/null +++ b/node_modules/babel-helper-to-multiple-sequence-expressions/package.json @@ -0,0 +1,15 @@ +{ + "name": "babel-helper-to-multiple-sequence-expressions", + "version": "0.5.0", + "description": "", + "keywords": [ + "babel-plugin" + ], + "homepage": "https://github.com/babel/minify#readme", + "bugs": "https://github.com/babel/minify/issues", + "license": "MIT", + "author": "amasad", + "main": "lib/index.js", + "repository": "https://github.com/babel/minify/tree/master/packages/babel-helper-to-multiple-sequence-expressions", + "gitHead": "4de390008da4a486b37819109d2021a0957ad405" +} |
