Comparing version 0.2.0 to 0.2.1
@@ -14,2 +14,3 @@ "use strict"; | ||
const options = require("./options"); | ||
const Stats = require("./stats"); | ||
const jshint_vars = require("./jshint_globals/vars.js"); | ||
@@ -259,3 +260,3 @@ | ||
function varify(ast, src) { | ||
function varify(ast, stats) { | ||
const changes = []; | ||
@@ -279,2 +280,4 @@ | ||
stats.declarator(node.kind); | ||
// rename if | ||
@@ -291,3 +294,5 @@ // 1) name already exists in hoistScope, or | ||
if (newName !== name) { | ||
declarator.id.originalName = declarator.id.name; | ||
stats.rename(name, newName, getline(declarator)); | ||
declarator.id.originalName = name; | ||
declarator.id.name = newName; | ||
@@ -455,3 +460,4 @@ | ||
const changes = varify(ast, src); | ||
const stats = new Stats(); | ||
const changes = varify(ast, stats); | ||
@@ -462,2 +468,3 @@ if (options.ast) { | ||
exitcode: 0, | ||
stats: stats, | ||
ast: ast, | ||
@@ -469,2 +476,3 @@ }; | ||
exitcode: 0, | ||
stats: stats, | ||
src: transformedSrc, | ||
@@ -471,0 +479,0 @@ }; |
@@ -30,2 +30,6 @@ "use strict"; | ||
if (config.stats) { | ||
process.stdout.write(ret.stats.toString()); | ||
process.exit(0); | ||
} | ||
if (ret.ast) { | ||
@@ -32,0 +36,0 @@ process.stdout.write(JSON.stringify(ret.ast, null, 4)); |
{ | ||
"name": "defs", | ||
"version": "0.2.0", | ||
"version": "0.2.1", | ||
"description": "Static scope analysis and transpilation of ES6 block scoped const and let variables, to ES3.", | ||
@@ -5,0 +5,0 @@ "main": "defs-main.js", |
@@ -61,3 +61,6 @@ # defs.js | ||
`stats` (defaults to `false`) prints const/let statistics and renames | ||
(experimental). | ||
## Example | ||
@@ -97,5 +100,6 @@ | ||
## Compatibility | ||
`defs.js` strives to transpile your program as true to the ES6 block scope semantics as possible, | ||
while being as unintrusive as possible. The only textual differences you'll find between your | ||
original and transpiled program is that the latter uses `var` and occasional variable renames. | ||
`defs.js` strives to transpile your program as true to the ES6 block scope semantics as | ||
possible, while being as maximally non-intrusive as possible. The only textual | ||
differences you'll find between your original and transpiled program is that the latter | ||
uses `var` and occasional variable renames. | ||
@@ -113,3 +117,3 @@ ### Loop closures limitation | ||
With ES6 semantics `y` is bound fresh per loop iteration, so each closure captures a seperate | ||
With ES6 semantics `y` is bound fresh per loop iteration, so each closure captures a separate | ||
instance of `y`, unlike if `y` would have been a `var`. [Actually, even `x` is bound per | ||
@@ -119,4 +123,4 @@ iteration, but v8 (so node) has an | ||
To transpile this example, an IIFE or `try-catch` must be inserted, which isn't non-intrusive. | ||
`defs.js` will detect this case and spit out an error instead, like so: | ||
To transpile this example, an IIFE or `try-catch` must be inserted, which isn't maximally | ||
non-intrusive. `defs.js` will detect this case and spit out an error instead, like so: | ||
@@ -123,0 +127,0 @@ line 3: can't transform closure. y is defined outside closure, inside loop |
51212
52
1435
159