Compare commits

...

15 Commits

Author SHA1 Message Date
Sebastian McKenzie
da8edecc09 v1.14.12 2014-12-05 10:57:27 +11:00
Sebastian McKenzie
cd6dea6480 fix version in changelog 2014-12-05 10:56:33 +11:00
Sebastian McKenzie
69d7ac0e0c 1.14.11 2014-12-05 10:54:25 +11:00
Sebastian McKenzie
dae46bfbfa DRY up isDynamic checks - add isDynamic check to spread - fixes #232 2014-12-05 10:53:46 +11:00
Sebastian McKenzie
b5b175c45a v1.14.11 2014-12-05 10:10:31 +11:00
Sebastian McKenzie
569c681c4f v1.14.10 2014-12-05 09:58:16 +11:00
Sebastian McKenzie
ed1e4a7820 fix changelog version 2014-12-05 09:57:14 +11:00
Sebastian McKenzie
b55f941dae v1.14.1 2014-12-05 09:56:36 +11:00
Sebastian McKenzie
a0219ef278 fix let scoping unneccesary override - fixes #245 2014-12-05 09:55:26 +11:00
Sebastian McKenzie
b9266b0c4c v1.14.10 2014-12-04 10:35:52 +11:00
Sebastian McKenzie
a1239e5f5a add ast return transform option 2014-12-04 10:34:52 +11:00
Sebastian McKenzie
2f279de7d1 v1.14.9 2014-12-04 10:31:08 +11:00
Sebastian McKenzie
c70b3586fb Remove roadrunner 2014-12-04 10:30:16 +11:00
Sebastian McKenzie
3928384c27 v1.14.8 2014-12-04 10:25:02 +11:00
Sebastian McKenzie
e469f7f589 fix require caching 2014-12-04 10:23:55 +11:00
9 changed files with 54 additions and 47 deletions

View File

@@ -1,3 +1,11 @@
# 1.14.12
* Fix duplicate dynamic expressions in call spread.
# 1.14.10
* Fix let scoping unneccesary override.
# 1.14.6
* Avoid ensuring a block on non-array node replacements.

View File

@@ -41,7 +41,8 @@ File.normaliseOptions = function (opts) {
filename: "unknown",
modules: "common",
runtime: false,
code: true
code: true,
ast: true
});
// normalise windows path separators to unix
@@ -186,15 +187,18 @@ File.prototype.generate = function () {
var opts = this.opts;
var ast = this.ast;
if (!opts.code) {
return {
code: "",
map: null,
ast: ast
};
}
var result = {
code: "",
map: null,
ast: null
};
var result = generate(ast, opts, this.code);
if (opts.ast) result.ast = ast;
if (!opts.code) return result;
var _result = generate(ast, opts, this.code);
result.code = _result.code;
result.map = _result.map;
if (this.shebang) {
// add back shebang
@@ -205,8 +209,6 @@ File.prototype.generate = function () {
result.code += "\n" + util.sourceMapToComment(result.map);
}
result.ast = result;
return result;
};

View File

@@ -1,7 +1,6 @@
require("./polyfill");
var sourceMapSupport = require("source-map-support");
var roadrunner = require('roadrunner');
var util = require("./util");
var to5 = require("./index");
var fs = require("fs");
@@ -79,15 +78,19 @@ var loader = function (m, filename) {
var result;
if (cache && cache[filename].mtime === mtime(filename)) {
result = cache[filename];
if (cache) {
var cached = cache[filename];
if (cached && cached.mtime === mtime(filename)) {
result = cached;
}
}
result = result || to5.transformFileSync(filename, _.extend({
whitelist: whitelist,
blacklist: blacklist,
sourceMap: true,
modules: "commonInterop"
modules: "commonInterop",
ast: false
}, transformOpts));
if (cache) {
@@ -126,7 +129,7 @@ module.exports = function (opts) {
if (opts.extensions) hookExtensions(util.arrayify(opts.extensions));
if (opts.cache) cache = roadrunner.get('6to5');
if (opts.cache) cache = opts.cache;
if (opts.cache === false) cache = null;
_.extend(transformOpts, opts);

View File

@@ -56,7 +56,7 @@ exports.ArrayExpression = function (node, parent, file) {
return t.callExpression(t.memberExpression(first, t.identifier("concat")), nodes);
};
exports.CallExpression = function (node, parent, file) {
exports.CallExpression = function (node, parent, file, scope) {
var args = node.arguments;
if (!hasSpread(args)) return;
@@ -79,10 +79,16 @@ exports.CallExpression = function (node, parent, file) {
}
var callee = node.callee;
var temp;
if (t.isMemberExpression(callee)) {
contextLiteral = callee.object;
if (t.isDynamic(contextLiteral)) {
temp = contextLiteral = scope.generateTemp(file);
callee.object = t.assignmentExpression("=", temp, callee.object);
}
if (callee.computed) {
callee.object = t.memberExpression(callee.object, callee.property, true);
callee.property = t.identifier("apply");

View File

@@ -30,12 +30,7 @@ exports.AssignmentExpression = function (node, parent, file, scope) {
if (!t.isExpressionStatement(parent)) {
// `node.right` isn't a simple identifier so we need to reference it
if (t.isDynamic(value)) {
var tempName = file.generateUid("temp");
temp = value = t.identifier(tempName);
scope.push({
key: tempName,
id: temp
});
temp = value = scope.generateTemp(file);
}
}
@@ -75,12 +70,7 @@ exports.CallExpression = function (node, parent, file, scope) {
var temp;
if (t.isDynamic(callee.object)) {
// we need to save `callee.object` so we can call it again
var tempName = file.generateUid("temp");
temp = t.identifier(tempName);
scope.push({
key: tempName,
id: temp
});
temp = scope.generateTemp(file);
}
var call = util.template("abstract-expression-call", {

View File

@@ -7,12 +7,7 @@ exports.BindMemberExpression = function (node, parent, file, scope) {
var temp;
if (t.isDynamic(object)) {
var tempName = file.generateUid("temp", scope);
temp = object = t.identifier(tempName);
scope.push({
key: tempName,
id: temp
});
temp = object = scope.generateTemp(file);
}
var call = t.callExpression(
@@ -39,17 +34,12 @@ exports.BindFunctionExpression = function (node, parent, file, scope) {
};
if (_.find(node.arguments, t.isDynamic)) {
var argsIdName = file.generateUid("args", scope);
var argsId = t.identifier(argsIdName);
scope.push({
key: argsIdName,
id: argsId
});
var temp = scope.generateTemp(file, "args");
return t.sequenceExpression([
t.assignmentExpression("=", argsId, t.arrayExpression(node.arguments)),
t.assignmentExpression("=", temp, t.arrayExpression(node.arguments)),
buildCall(node.arguments.map(function (node, i) {
return t.memberExpression(argsId, t.literal(i), true);
return t.memberExpression(temp, t.literal(i), true);
}))
]);
} else {

View File

@@ -23,7 +23,16 @@ function Scope(block, parent) {
Scope.add = function (node, references) {
if (!node) return;
_.merge(references, t.getIds(node, true));
_.defaults(references, t.getIds(node, true));
};
Scope.prototype.generateTemp = function (file, name) {
var id = file.generateUidIdentifier(name || "temp", this);
this.push({
key: id.name,
id: id
});
return id;
};
Scope.prototype.getReferences = function () {

View File

@@ -162,7 +162,7 @@ t.toIdentifier = function (name) {
return c ? c.toUpperCase() : "";
});
return name;
return name || '_';
};
t.isValidIdentifier = function (name) {

View File

@@ -1,7 +1,7 @@
{
"name": "6to5",
"description": "Turn ES6 code into readable vanilla ES5 with source maps",
"version": "1.14.7",
"version": "1.14.12",
"author": "Sebastian McKenzie <sebmck@gmail.com>",
"homepage": "https://github.com/6to5/6to5",
"repository": {
@@ -48,7 +48,6 @@
"mkdirp": "0.5.0",
"private": "0.1.6",
"regexpu": "0.3.0",
"roadrunner": "^1.0.4",
"source-map": "0.1.40",
"source-map-support": "0.2.8"
},