Update with working working version (#12)

* Fix workflow

* Trigger

* [auto] Update compiled version

* [auto] Commit modules

* Push Windows changes

* Fix

* [auto] Update compiled version

* Try removing cwd

* [auto] Update compiled version

* Try with path module

* [auto] Update compiled version

* Fix path

* [auto] Update compiled version

* Use raw path

* [auto] Update compiled version

* Other path

* [auto] Update compiled version

* Avoid @action/exec

* [auto] Update compiled version

* test

* [auto] Update compiled version

* test

* [auto] Update compiled version

* test

* [auto] Update compiled version

* test

* [auto] Update compiled version

* Try with shelljs

* [auto] Update compiled version

* Fix my stupidity

* Copy scripts to local dir

* [auto] Update compiled version

* Still use path

* [auto] Update compiled version

* Delete entrypoint.sh

* [auto] Update compiled version

* Make file executable

* [auto] Update compiled version

* Try using bash

* [auto] Update compiled version
This commit is contained in:
Federico Grandi
2019-12-14 21:47:13 +01:00
committed by GitHub
parent d81e04e96c
commit f118062594
4276 changed files with 1075004 additions and 40 deletions

View File

@@ -0,0 +1,60 @@
# babel-plugin-transform-merge-sibling-variables
Merge sibling variables into one.
## Example
**In**
```javascript
// merge into a single VariableDeclaration
var foo = "bar";
var bar = "foo";
foobar();
// merge into the next for loop
var i = 0;
for (var x = 0; x < 10; x++) {}
```
**Out**
```javascript
var foo = "bar",
bar = "foo";
foobar();
for (var i = 0, x = 0; x < 10; x++) {}
```
## Installation
```sh
npm install babel-plugin-transform-merge-sibling-variables --save-dev
```
## Usage
### Via `.babelrc` (Recommended)
**.babelrc**
```json
{
"plugins": ["transform-merge-sibling-variables"]
}
```
### Via CLI
```sh
babel --plugins transform-merge-sibling-variables script.js
```
### Via Node API
```javascript
require("@babel/core").transform("code", {
plugins: ["transform-merge-sibling-variables"]
});
```

View File

@@ -0,0 +1,109 @@
"use strict";
module.exports = function ({
types: t
}) {
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;
}
const firstNode = body[0].node.declarations[0];
if (!t.isIdentifier(firstNode.id) || !firstNode.init) {
return;
}
const 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
let 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;
}
const node = path.node;
let sibling = path.getSibling(path.key + 1);
let declarations = [];
while (sibling.isVariableDeclaration({
kind: node.kind
})) {
declarations = declarations.concat(sibling.node.declarations);
sibling.remove();
sibling = path.getSibling(path.key + 1);
}
if (declarations.length > 0) {
path.replaceWith(t.variableDeclaration(node.kind, [...node.declarations, ...declarations]));
}
}, // 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;
}
const node = path.node;
if (node.kind !== "var") {
return;
}
const next = path.getSibling(path.key + 1);
if (!next.isForStatement()) {
return;
}
const init = next.get("init");
if (!init.isVariableDeclaration({
kind: node.kind
})) {
return;
}
const declarations = node.declarations.concat(init.node.declarations); // temporary workaround to forces babel recalculate scope,
// references and binding until babel/babel#4818 resolved
path.remove();
init.replaceWith(t.variableDeclaration("var", declarations));
}]
}
}
};
};

View File

@@ -0,0 +1,50 @@
{
"_args": [
[
"babel-plugin-transform-merge-sibling-variables@6.9.4",
"/home/runner/work/add-and-commit/add-and-commit"
]
],
"_development": true,
"_from": "babel-plugin-transform-merge-sibling-variables@6.9.4",
"_id": "babel-plugin-transform-merge-sibling-variables@6.9.4",
"_inBundle": false,
"_integrity": "sha1-hbQi/DN3tEnJ0c3kQIcgNTJAHa4=",
"_location": "/babel-plugin-transform-merge-sibling-variables",
"_phantomChildren": {},
"_requested": {
"type": "version",
"registry": true,
"raw": "babel-plugin-transform-merge-sibling-variables@6.9.4",
"name": "babel-plugin-transform-merge-sibling-variables",
"escapedName": "babel-plugin-transform-merge-sibling-variables",
"rawSpec": "6.9.4",
"saveSpec": null,
"fetchSpec": "6.9.4"
},
"_requiredBy": [
"/babel-preset-minify"
],
"_resolved": "https://registry.npmjs.org/babel-plugin-transform-merge-sibling-variables/-/babel-plugin-transform-merge-sibling-variables-6.9.4.tgz",
"_spec": "6.9.4",
"_where": "/home/runner/work/add-and-commit/add-and-commit",
"author": {
"name": "amasad"
},
"bugs": {
"url": "https://github.com/babel/minify/issues"
},
"description": "Merge sibling variables into one.",
"homepage": "https://github.com/babel/minify#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/minify/tree/master/packages/babel-plugin-transform-merge-sibling-variables"
},
"version": "6.9.4"
}