Sha256: bab8f552241c13a946dd118bd08fd1274a89f3af86838a3b8c35c9922e352bac

Contents?: true

Size: 1.19 KB

Versions: 25

Compression:

Stored size: 1.19 KB

Contents

"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = hoistVariables;
var _t = require("@babel/types");
const {
  assignmentExpression,
  expressionStatement,
  identifier
} = _t;
const visitor = {
  Scope(path, state) {
    if (state.kind === "let") path.skip();
  },
  FunctionParent(path) {
    path.skip();
  },
  VariableDeclaration(path, state) {
    if (state.kind && path.node.kind !== state.kind) return;
    const nodes = [];
    const declarations = path.get("declarations");
    let firstId;
    for (const declar of declarations) {
      firstId = declar.node.id;
      if (declar.node.init) {
        nodes.push(expressionStatement(assignmentExpression("=", declar.node.id, declar.node.init)));
      }
      for (const name of Object.keys(declar.getBindingIdentifiers())) {
        state.emit(identifier(name), name, declar.node.init !== null);
      }
    }
    if (path.parentPath.isFor({
      left: path.node
    })) {
      path.replaceWith(firstId);
    } else {
      path.replaceWithMultiple(nodes);
    }
  }
};
function hoistVariables(path, emit, kind = "var") {
  path.traverse(visitor, {
    kind,
    emit
  });
}

//# sourceMappingURL=index.js.map

Version data entries

25 entries across 25 versions & 3 rubygems

Version Path
immosquare-cleaner-0.1.60 node_modules/@babel/helper-hoist-variables/lib/index.js
immosquare-cleaner-0.1.59 node_modules/@babel/helper-hoist-variables/lib/index.js
immosquare-cleaner-0.1.58 node_modules/@babel/helper-hoist-variables/lib/index.js
immosquare-cleaner-0.1.57 node_modules/@babel/helper-hoist-variables/lib/index.js
immosquare-cleaner-0.1.56 node_modules/@babel/helper-hoist-variables/lib/index.js
immosquare-cleaner-0.1.55 node_modules/@babel/helper-hoist-variables/lib/index.js
immosquare-cleaner-0.1.54 node_modules/@babel/helper-hoist-variables/lib/index.js
immosquare-cleaner-0.1.53 node_modules/@babel/helper-hoist-variables/lib/index.js
immosquare-cleaner-0.1.52 node_modules/@babel/helper-hoist-variables/lib/index.js
trusty-cms-6.3.1 node_modules/@babel/helper-hoist-variables/lib/index.js
immosquare-cleaner-0.1.51 node_modules/@babel/helper-hoist-variables/lib/index.js
immosquare-cleaner-0.1.50 node_modules/@babel/helper-hoist-variables/lib/index.js
immosquare-cleaner-0.1.49 node_modules/@babel/helper-hoist-variables/lib/index.js
immosquare-cleaner-0.1.48 node_modules/@babel/helper-hoist-variables/lib/index.js
immosquare-cleaner-0.1.47 node_modules/@babel/helper-hoist-variables/lib/index.js
immosquare-cleaner-0.1.46 node_modules/@babel/helper-hoist-variables/lib/index.js
immosquare-cleaner-0.1.45 node_modules/@babel/helper-hoist-variables/lib/index.js
immosquare-cleaner-0.1.44 node_modules/@babel/helper-hoist-variables/lib/index.js
immosquare-cleaner-0.1.43 node_modules/@babel/helper-hoist-variables/lib/index.js
immosquare-cleaner-0.1.42 node_modules/@babel/helper-hoist-variables/lib/index.js