Compare commits
9 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ff6677a4b7 | ||
|
|
ac5e0ad392 | ||
|
|
0a25618c34 | ||
|
|
984c048591 | ||
|
|
5867e24886 | ||
|
|
02d7cdc701 | ||
|
|
d3b3febfeb | ||
|
|
7fccf98c10 | ||
|
|
4a1c393bdb |
@@ -1,3 +1,11 @@
|
||||
# 1.12.24
|
||||
|
||||
* Collect references that haven't been declared in scope.
|
||||
|
||||
# 1.12.23
|
||||
|
||||
* Fix generator function export hoisting.
|
||||
|
||||
# 1.12.22
|
||||
|
||||
* Update `fs-readdir-recursive` and `chokidar`.
|
||||
|
||||
@@ -133,13 +133,31 @@ for (var i of [1, 2, 3]) {
|
||||
## Generators
|
||||
|
||||
```javascript
|
||||
function* fibonacci() {
|
||||
var pre = 0, cur = 1;
|
||||
for (;;) {
|
||||
var temp = pre;
|
||||
pre = cur;
|
||||
cur += temp;
|
||||
yield cur;
|
||||
}
|
||||
}
|
||||
|
||||
for (var n of fibonacci()) {
|
||||
// truncate the sequence at 1000
|
||||
if (n > 1000) break;
|
||||
console.log(n);
|
||||
}
|
||||
```
|
||||
|
||||
## Generator comprehension
|
||||
|
||||
```javascript
|
||||
|
||||
var nums = [1, 2, 3, 4, 5, 6];
|
||||
var multiples = (for (i of nums) if (i % 2) i * i);
|
||||
assert.equal(multiples.next().value, 1);
|
||||
assert.equal(multiples.next().value, 9);
|
||||
assert.equal(multiples.next().value, 25);
|
||||
```
|
||||
|
||||
## Let scoping
|
||||
@@ -153,7 +171,17 @@ for (let i in arr) {
|
||||
## Modules
|
||||
|
||||
```javascript
|
||||
import "foo";
|
||||
import foo from "foo";
|
||||
import * as foo from "foo";
|
||||
import {bar} from "foo";
|
||||
import {foo as bar} from "foo";
|
||||
|
||||
export { test };
|
||||
export var test = 5;
|
||||
export function test() {}
|
||||
|
||||
export default test;
|
||||
```
|
||||
|
||||
## Numeric literals
|
||||
|
||||
@@ -22,8 +22,7 @@ CommonJSInteropFormatter.prototype.importSpecifier = function (specifier, node,
|
||||
})])
|
||||
)
|
||||
]));
|
||||
return;
|
||||
} else {
|
||||
CommonJSFormatter.prototype.importSpecifier.apply(this, arguments);
|
||||
}
|
||||
|
||||
CommonJSFormatter.prototype.importSpecifier.apply(this, arguments);
|
||||
};
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
var t = require("../../types");
|
||||
var _ = require("lodash");
|
||||
|
||||
module.exports = function (ast, file) {
|
||||
var body = ast.program.body;
|
||||
|
||||
_.each(file.declarations, function (declar) {
|
||||
for (var i in file.declarations) {
|
||||
var declar = file.declarations[i];
|
||||
body.unshift(t.variableDeclaration("var", [
|
||||
t.variableDeclarator(declar.uid, declar.node)
|
||||
]));
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
@@ -156,12 +156,12 @@ var visitor = types.PathVisitor.fromMethodsObject({
|
||||
)
|
||||
]);
|
||||
|
||||
if (node.comments) {
|
||||
// Copy any comments preceding the function declaration to the
|
||||
// variable declaration, to avoid weird formatting consequences.
|
||||
varDecl.comments = node.comments;
|
||||
node.comments = null;
|
||||
}
|
||||
// Copy any comments preceding the function declaration to the
|
||||
// variable declaration, to avoid weird formatting consequences.
|
||||
t.inheritsComments(varDecl, node);
|
||||
t.removeComments(node);
|
||||
|
||||
varDecl._blockHoist = true;
|
||||
|
||||
var bodyPath = pp.get("body");
|
||||
var bodyLen = bodyPath.value.length;
|
||||
@@ -175,7 +175,6 @@ var visitor = types.PathVisitor.fromMethodsObject({
|
||||
}
|
||||
|
||||
bodyPath.push(varDecl);
|
||||
|
||||
} else {
|
||||
t.assertFunctionExpression(node);
|
||||
return t.callExpression(runtimeMarkMethod, [node]);
|
||||
|
||||
@@ -22,9 +22,7 @@ exports.TaggedTemplateExpression = function (node, parent, file) {
|
||||
t.arrayExpression(raw)
|
||||
]));
|
||||
|
||||
_.each(quasi.expressions, function (expr) {
|
||||
args.push(expr);
|
||||
});
|
||||
args = args.concat(quasi.expressions);
|
||||
|
||||
return t.callExpression(node.tag, args);
|
||||
};
|
||||
|
||||
@@ -6,25 +6,30 @@ var _ = require("lodash");
|
||||
|
||||
var FOR_KEYS = ["left", "init"];
|
||||
|
||||
/**
|
||||
* This searches the current "scope" and collects all references/declarations
|
||||
* within.
|
||||
*
|
||||
* @param {Scope} [parent]
|
||||
* @param {Node} block
|
||||
*/
|
||||
|
||||
function Scope(parent, block) {
|
||||
this.parent = parent;
|
||||
this.block = block;
|
||||
|
||||
this.info = this.getInfo();
|
||||
this.declarations = this.info.declarations;
|
||||
this.references = this.getReferences();
|
||||
}
|
||||
|
||||
Scope.prototype.getInfo = function () {
|
||||
Scope.prototype.getReferences = function () {
|
||||
var block = this.block;
|
||||
if (block._scope) return block._scope;
|
||||
|
||||
var self = this;
|
||||
var info = block._scope = {
|
||||
declarations: {}
|
||||
};
|
||||
var self = this;
|
||||
var references = block._scope = {};
|
||||
|
||||
var add = function (node) {
|
||||
self.addDeclaration(node, info.declarations);
|
||||
self.add(node, references);
|
||||
};
|
||||
|
||||
// ForStatement - left, init
|
||||
@@ -56,7 +61,7 @@ Scope.prototype.getInfo = function () {
|
||||
// Program, Function - var variables
|
||||
|
||||
if (t.isProgram(block) || t.isFunction(block)) {
|
||||
traverse(block, function (node) {
|
||||
traverse(block, function (node, parent, scope) {
|
||||
if (t.isFor(node)) {
|
||||
_.each(FOR_KEYS, function (key) {
|
||||
var declar = node[key];
|
||||
@@ -68,12 +73,16 @@ Scope.prototype.getInfo = function () {
|
||||
// declared within are accessible
|
||||
if (t.isFunction(node)) return false;
|
||||
|
||||
if (t.isIdentifier(node) && t.isReferenced(node, parent) && !scope.has(node.name)) {
|
||||
add(node);
|
||||
}
|
||||
|
||||
// we've ran into a declaration!
|
||||
// we'll let the BlockStatement scope deal with `let` declarations
|
||||
if (t.isDeclaration(node) && !t.isLet(node)) {
|
||||
add(node);
|
||||
}
|
||||
});
|
||||
}, { scope: this });
|
||||
}
|
||||
|
||||
// Function - params, rest
|
||||
@@ -85,12 +94,12 @@ Scope.prototype.getInfo = function () {
|
||||
});
|
||||
}
|
||||
|
||||
return info;
|
||||
return references;
|
||||
};
|
||||
|
||||
Scope.prototype.addDeclaration = function (node, declarations) {
|
||||
Scope.prototype.add = function (node, references) {
|
||||
if (!node) return;
|
||||
_.merge(declarations || this.declarations, t.getIds(node, true));
|
||||
_.merge(references || this.references, t.getIds(node, true));
|
||||
};
|
||||
|
||||
Scope.prototype.get = function (id) {
|
||||
@@ -98,7 +107,7 @@ Scope.prototype.get = function (id) {
|
||||
};
|
||||
|
||||
Scope.prototype.getOwn = function (id) {
|
||||
return _.has(this.declarations, id) && this.declarations[id];
|
||||
return _.has(this.references, id) && this.references[id];
|
||||
};
|
||||
|
||||
Scope.prototype.parentGet = function (id) {
|
||||
|
||||
@@ -250,6 +250,11 @@ t.inheritsComments = function (child, parent) {
|
||||
return child;
|
||||
};
|
||||
|
||||
t.removeComments = function (node) {
|
||||
delete node.leadingComments;
|
||||
delete node.trailingComments;
|
||||
};
|
||||
|
||||
t.inherits = function (child, parent) {
|
||||
child.loc = parent.loc;
|
||||
child.end = parent.end;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "6to5",
|
||||
"description": "Turn ES6 code into readable vanilla ES5 with source maps",
|
||||
"version": "1.12.22",
|
||||
"version": "1.12.24",
|
||||
"author": "Sebastian McKenzie <sebmck@gmail.com>",
|
||||
"homepage": "https://github.com/6to5/6to5",
|
||||
"repository": {
|
||||
|
||||
Reference in New Issue
Block a user