Compare commits
16 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
078b09676f | ||
|
|
b719eaf6ab | ||
|
|
b63accca25 | ||
|
|
2d41b09c3b | ||
|
|
0b44137d1f | ||
|
|
8d8dd5fa37 | ||
|
|
16b7ff972c | ||
|
|
ca41612109 | ||
|
|
8fc7af5480 | ||
|
|
1c6cb7ce40 | ||
|
|
24d6c3f488 | ||
|
|
d877a04397 | ||
|
|
4844882f5e | ||
|
|
a80945cfb4 | ||
|
|
6a884c58a7 | ||
|
|
7c4701716c |
@@ -10,3 +10,4 @@ dist
|
||||
tests.json
|
||||
CHANGELOG.md
|
||||
.package.json
|
||||
coverage
|
||||
|
||||
13
CHANGELOG.md
13
CHANGELOG.md
@@ -11,6 +11,19 @@
|
||||
|
||||
_Note: Gaps between patch versions are faulty/broken releases._
|
||||
|
||||
## 2.13.2
|
||||
|
||||
* **Bug Fix**
|
||||
* Fix `super` inside of nested functions.
|
||||
* **Internal**
|
||||
* Move let scoping TDZ into a separate transformer until it's more solid.
|
||||
* Use `process.stdin.write` instead of `console.log` in `bin` to avoid sprintfification.
|
||||
|
||||
## 2.13.1
|
||||
|
||||
* **New Feature**
|
||||
* Temporal dead zone for block binding.
|
||||
|
||||
## 2.13.0
|
||||
|
||||
* **New Feature**
|
||||
|
||||
3
Makefile
3
Makefile
@@ -1,6 +1,7 @@
|
||||
BROWSERIFY_CMD = node_modules/browserify/bin/cmd.js
|
||||
ISTANBUL_CMD = node_modules/istanbul/lib/cli.js cover
|
||||
UGLIFY_CMD = node_modules/uglify-js/bin/uglifyjs --mangle sort
|
||||
UGLIFY_CMD = node_modules/uglify-js/bin/uglifyjs
|
||||
#UGLIFY_CMD = node_modules/uglify-js/bin/uglifyjs --mangle sort
|
||||
JSHINT_CMD = node_modules/jshint/bin/jshint
|
||||
MOCHA_CMD = node_modules/mocha/bin/_mocha
|
||||
|
||||
|
||||
1
NOTES.md
1
NOTES.md
@@ -11,3 +11,4 @@
|
||||
* Add autoindentation.
|
||||
* Move `super` transformation from classes into a separate transformer that also supports object expressions.
|
||||
* Remove fast transformer backwards compatibility.
|
||||
* Rename let scoping transformer to block scoping.
|
||||
|
||||
@@ -63,7 +63,7 @@ module.exports = function (commander, filenames) {
|
||||
|
||||
fs.writeFileSync(commander.outFile, result.code);
|
||||
} else {
|
||||
console.log(result.code);
|
||||
process.stdout.write(result.code + "\n");
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -34,13 +34,10 @@ commander.on("--help", function(){
|
||||
console.log(" " + title + ":");
|
||||
console.log();
|
||||
|
||||
var hasOptional = true;
|
||||
|
||||
_.each(_.keys(obj).sort(), function (key) {
|
||||
if (key[0] === "_") return;
|
||||
|
||||
if (obj[key].optional) {
|
||||
hasOptional = true;
|
||||
key = "[" + key + "]";
|
||||
}
|
||||
|
||||
|
||||
@@ -152,7 +152,7 @@ ReplaceSupers.prototype.getThisReference = function () {
|
||||
return this.topLevelThisReference;
|
||||
} else {
|
||||
var ref = this.topLevelThisReference = this.file.generateUidIdentifier("this");
|
||||
this.methodNode.body.body.unshift(t.variableDeclaration("var", [
|
||||
this.methodNode.value.body.body.unshift(t.variableDeclaration("var", [
|
||||
t.variableDeclarator(this.topLevelThisReference, t.thisExpression())
|
||||
]));
|
||||
return ref;
|
||||
|
||||
@@ -79,6 +79,7 @@ _.each({
|
||||
|
||||
constants: require("./transformers/es6-constants"),
|
||||
letScoping: require("./transformers/es6-let-scoping"),
|
||||
blockScopingTDZ: require("./transformers/optional-block-scoping-tdz"),
|
||||
|
||||
_blockHoist: require("./transformers/_block-hoist"),
|
||||
|
||||
|
||||
@@ -57,6 +57,7 @@ exports.Loop = function (node, parent, scope, context, file) {
|
||||
}
|
||||
};
|
||||
|
||||
exports.Program =
|
||||
exports.BlockStatement = function (block, parent, scope, context, file) {
|
||||
if (!t.isLoop(parent)) {
|
||||
var letScoping = new LetScoping(false, block, parent, scope, file);
|
||||
@@ -82,7 +83,8 @@ function LetScoping(loopParent, block, parent, scope, file) {
|
||||
this.file = file;
|
||||
|
||||
this.outsideLetReferences = {};
|
||||
this.letReferences = {};
|
||||
this.hasLetReferences = false;
|
||||
this.letReferences = block._letReferences = {};
|
||||
this.body = [];
|
||||
}
|
||||
|
||||
@@ -95,10 +97,14 @@ LetScoping.prototype.run = function () {
|
||||
if (block._letDone) return;
|
||||
block._letDone = true;
|
||||
|
||||
// this is a block within a `Function` so we can safely leave it be
|
||||
if (t.isFunction(this.parent)) return;
|
||||
|
||||
var needsClosure = this.getLetReferences();
|
||||
|
||||
// this is a block within a `Function/Program` so we can safely leave it be
|
||||
if (t.isFunction(this.parent) || t.isProgram(this.block)) return;
|
||||
|
||||
// we can skip everything
|
||||
if (!this.hasLetReferences) return;
|
||||
|
||||
if (needsClosure) {
|
||||
this.needsClosure();
|
||||
} else {
|
||||
@@ -130,7 +136,7 @@ LetScoping.prototype.remap = function () {
|
||||
var uid = file.generateUidIdentifier(ref.name, scope).name;
|
||||
ref.name = uid;
|
||||
|
||||
remaps[key] = {
|
||||
remaps[key] = remaps[uid] = {
|
||||
node: ref,
|
||||
uid: uid
|
||||
};
|
||||
@@ -239,8 +245,12 @@ LetScoping.prototype.getLetReferences = function () {
|
||||
declar = declarators[i];
|
||||
var keys = t.getIds(declar, true);
|
||||
_.extend(this.letReferences, keys);
|
||||
this.hasLetReferences = true;
|
||||
}
|
||||
|
||||
// no let references so we can just quit
|
||||
if (!this.hasLetReferences) return;
|
||||
|
||||
// set let references to plain var references
|
||||
standardiseLets(declarators);
|
||||
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
var traverse = require("../../traverse");
|
||||
var t = require("../../types");
|
||||
|
||||
exports.optional = true;
|
||||
|
||||
exports.Loop =
|
||||
exports.Program =
|
||||
exports.BlockStatement = function (node, parent, scope, context, file) {
|
||||
var letRefs = node._letReferences;
|
||||
if (!letRefs) return;
|
||||
|
||||
var state = {
|
||||
letRefs: letRefs,
|
||||
file: file
|
||||
};
|
||||
|
||||
traverse(node, {
|
||||
enter: function (node, parent, scope, context, state) {
|
||||
if (!t.isIdentifier(node)) return;
|
||||
if (!t.isReferenced(node, parent)) return;
|
||||
|
||||
var declared = state.letRefs[node.name];
|
||||
if (!declared) return;
|
||||
|
||||
// declared node is different in this scope
|
||||
if (scope.get(node.name, true) !== declared) return;
|
||||
|
||||
var declaredLoc = declared.loc;
|
||||
var referenceLoc = node.loc;
|
||||
|
||||
if (!declaredLoc || !referenceLoc) return;
|
||||
|
||||
// does this reference appear on a line before the declaration?
|
||||
var before = referenceLoc.start.line < declaredLoc.start.line;
|
||||
|
||||
if (referenceLoc.start.line === declaredLoc.start.line) {
|
||||
// this reference appears on the same line
|
||||
// check it appears before the declaration
|
||||
before = referenceLoc.start.col < declaredLoc.start.col;
|
||||
}
|
||||
|
||||
if (before) {
|
||||
throw state.file.errorWithNode(node, "Temporal dead zone - accessing a variable before it's initialized");
|
||||
}
|
||||
}
|
||||
}, scope, state);
|
||||
};
|
||||
@@ -7,6 +7,9 @@ exports.FunctionDeclaration = function (node, parent) {
|
||||
return;
|
||||
}
|
||||
|
||||
// this is to avoid triggering the TDZ detection
|
||||
node.id.loc = null;
|
||||
|
||||
var declar = t.variableDeclaration("let", [
|
||||
t.variableDeclarator(node.id, t.toExpression(node))
|
||||
]);
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "6to5",
|
||||
"description": "Turn ES6 code into readable vanilla ES5 with source maps",
|
||||
"version": "2.13.0",
|
||||
"version": "2.13.2",
|
||||
"author": "Sebastian McKenzie <sebmck@gmail.com>",
|
||||
"homepage": "https://6to5.org/",
|
||||
"repository": "6to5/6to5",
|
||||
|
||||
2
test/fixtures/transformation/es6-let-scoping/temporal-dead-zone/actual.js
vendored
Normal file
2
test/fixtures/transformation/es6-let-scoping/temporal-dead-zone/actual.js
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
qux;
|
||||
let qux = 456;
|
||||
4
test/fixtures/transformation/es6-let-scoping/temporal-dead-zone/options.json
vendored
Normal file
4
test/fixtures/transformation/es6-let-scoping/temporal-dead-zone/options.json
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"throws": "Temporal dead zone - accessing a variable before it's initialized",
|
||||
"optional": ["blockScopingTDZ"]
|
||||
}
|
||||
Reference in New Issue
Block a user