JSPM

ast-redeclare

1.0.4
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 70
  • Score
    100M100P100Q63110F
  • License Unlicensed

Hoist variable declarations to the top of scope.

Package Exports

  • ast-redeclare

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (ast-redeclare) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

ast-redeclare Build Status

Hoist and fold variable declarations within scopes, so that each variable has only one declaration per scope. Don’t touch functions. Useful to normalize code before analysis, like data-flow etc.

Usage

npm install ast-redeclare
var parse = require('esprima').parse;
var generate = require('escodegen').generate;
var redeclare = require('ast-redeclare');

var ast = parse(
    'var a = 1, b = 2; if (a > 1) { var c = b; } else {var c = 3;} var d = 4;'
);
ast = redeclare(ast);

generate(ast);
//var a, b, c, d; a = 1; b = 2; if (a > 1) { c = b; } else { c = 3; }; d = 4;

API

redeclare(Node) → Node

Analogs

NPM