Compare commits

...

6 Commits

Author SHA1 Message Date
Sebastian McKenzie
984c048591 v1.12.23 2014-11-20 16:03:53 +11:00
Sebastian McKenzie
5867e24886 remove unused variables 2014-11-20 16:02:56 +11:00
Sebastian McKenzie
02d7cdc701 changelog for 1.12.23 2014-11-20 16:02:15 +11:00
Sebastian McKenzie
d3b3febfeb finish missing code examples in features 2014-11-20 16:02:10 +11:00
Sebastian McKenzie
7fccf98c10 small performance improvements 2014-11-20 15:09:20 +11:00
Sebastian McKenzie
4a1c393bdb inherit generator comments and add block hoisting - fixes #196 2014-11-20 15:09:07 +11:00
8 changed files with 51 additions and 18 deletions

View File

@@ -1,3 +1,7 @@
# 1.12.23
* Fix generator function export hoisting.
# 1.12.22
* Update `fs-readdir-recursive` and `chokidar`.

View File

@@ -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

View File

@@ -22,8 +22,7 @@ CommonJSInteropFormatter.prototype.importSpecifier = function (specifier, node,
})])
)
]));
return;
} else {
CommonJSFormatter.prototype.importSpecifier.apply(this, arguments);
}
CommonJSFormatter.prototype.importSpecifier.apply(this, arguments);
};

View File

@@ -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)
]));
});
}
};

View File

@@ -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]);

View File

@@ -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);
};

View File

@@ -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;

View File

@@ -1,7 +1,7 @@
{
"name": "6to5",
"description": "Turn ES6 code into readable vanilla ES5 with source maps",
"version": "1.12.22",
"version": "1.12.23",
"author": "Sebastian McKenzie <sebmck@gmail.com>",
"homepage": "https://github.com/6to5/6to5",
"repository": {