Compare commits

...

14 Commits

Author SHA1 Message Date
Sebastian McKenzie
833e8b091b v1.11.4 2014-11-10 13:02:04 +11:00
Sebastian McKenzie
23ebb23944 add missing util declaration to let scoping transformer 2014-11-10 13:00:52 +11:00
Sebastian McKenzie
778cab33d5 move canCompile method to util 2014-11-10 12:59:24 +11:00
Sebastian McKenzie
5849c6af17 add canCompile method to node api 2014-11-10 12:58:44 +11:00
Sebastian McKenzie
bb0655d8f6 move transformer assignment to new Transformer 2014-11-10 08:21:35 +11:00
Sebastian McKenzie
9977a5f614 change gitter travis hook to always 2014-11-10 08:20:18 +11:00
Sebastian McKenzie
9318d63b5c add let-scoping-return template to let scoping transformer 2014-11-10 08:16:47 +11:00
Sebastian McKenzie
b2ab0dbedc add self-global template to runtime generation 2014-11-10 08:16:38 +11:00
Sebastian McKenzie
e0d3e18865 add allowReturnOutsideFunction to util.parse and make nodes optional in util.template 2014-11-10 08:16:22 +11:00
Sebastian McKenzie
3a3ad4775b add gitter webhook to travis 2014-11-10 08:16:00 +11:00
Sebastian McKenzie
40fdd2a828 dry up types.getIds 2014-11-10 00:51:46 +11:00
Sebastian McKenzie
12f66e852a v1.11.3 2014-11-10 00:22:09 +11:00
Sebastian McKenzie
c61c9aab56 remove invalid ObjectPattern assignment 2014-11-10 00:19:37 +11:00
Sebastian McKenzie
7adc919bb6 remove invalid ObjectPattern destructuring assignment 2014-11-10 00:18:01 +11:00
15 changed files with 84 additions and 89 deletions

View File

@@ -9,3 +9,11 @@ branches:
before_script: "npm install -g codeclimate-test-reporter"
script: "make test-travis"
notifications:
webhooks:
urls:
- https://webhooks.gitter.im/e/acf1870e9d223c65e8d5
on_success: always
on_failure: always
on_start: false

View File

@@ -1,4 +1,5 @@
var transform = require("./transformation/transform");
var util = require("./util");
var fs = require("fs");
var _ = require("lodash");
@@ -14,6 +15,8 @@ exports.polyfill = function () {
require("./polyfill");
};
exports.canCompile = util.canCompile;
exports.transform = transform;
exports.transformFile = function (filename, opts, callback) {

View File

@@ -11,16 +11,7 @@ module.exports = function (namespace) {
var container = t.functionExpression(null, [], t.blockStatement(body));
var tree = t.program([t.expressionStatement(t.callExpression(container, []))]);
body.push(t.variableDeclaration("var", [
t.variableDeclarator(t.identifier("self"), t.conditionalExpression(
t.binaryExpression("===",
t.unaryExpression("typeof", t.identifier("global"), true),
t.literal("undefined")
),
t.identifier("window"),
t.identifier("global"))
)
]));
body.push(util.template("self-global", true));
body.push(t.variableDeclaration("var", [
t.variableDeclarator(

View File

@@ -0,0 +1 @@
if (typeof RETURN === "object") return RETURN.v;

View File

@@ -0,0 +1 @@
var self = typeof global === "undefined" ? window : global;

View File

@@ -20,7 +20,16 @@ transform._ensureTransformerNames = function (type, keys) {
});
};
transform.transformers = {
transform.transformers = {};
transform.moduleFormatters = {
common: require("./modules/common"),
ignore: require("./modules/ignore"),
amd: require("./modules/amd"),
umd: require("./modules/umd")
};
_.each({
modules: require("./transformers/modules"),
propertyNameShorthand: require("./transformers/property-name-shorthand"),
constants: require("./transformers/constants"),
@@ -53,15 +62,6 @@ transform.transformers = {
useStrict: require("./transformers/use-strict"),
_moduleFormatter: require("./transformers/_module-formatter")
};
transform.moduleFormatters = {
common: require("./modules/common"),
ignore: require("./modules/ignore"),
amd: require("./modules/amd"),
umd: require("./modules/umd")
};
_.each(transform.transformers, function (transformer, key) {
}, function (transformer, key) {
transform.transformers[key] = new Transformer(key, transformer);
});

View File

@@ -11,21 +11,7 @@ var buildVariableAssign = function (kind, id, init) {
}
};
var normalise = function (node) {
if (t.isParenthesizedExpression(node)) {
return node.expression;
} else {
return node;
}
};
var isPattern = function (node) {
return t.isPattern(normalise(node));
};
var push = function (kind, nodes, elem, parentId) {
elem = normalise(elem);
if (t.isObjectPattern(elem)) {
pushObjectPattern(kind, nodes, elem, parentId);
} else if (t.isArrayPattern(elem)) {
@@ -42,7 +28,7 @@ var pushObjectPattern = function (kind, nodes, pattern, parentId) {
var pattern2 = prop.value;
var patternId2 = t.memberExpression(parentId, prop.key);
if (isPattern(pattern2)) {
if (t.isPattern(pattern2)) {
push(kind, nodes, pattern2, patternId2);
} else {
nodes.push(buildVariableAssign(kind, pattern2, patternId2));
@@ -94,7 +80,7 @@ exports.ForOfStatement = function (node, parent, file, scope) {
if (!t.isVariableDeclaration(declar)) return;
var pattern = declar.declarations[0].id;
if (!isPattern(pattern)) return;
if (!t.isPattern(pattern)) return;
var key = t.identifier(file.generateUid("ref", scope));
node.left = t.variableDeclaration(declar.kind, [
@@ -117,7 +103,7 @@ exports.Function = function (node, parent, file, scope) {
var hasDestructuring = false;
node.params = node.params.map(function (pattern) {
if (!isPattern(pattern)) return pattern;
if (!t.isPattern(pattern)) return pattern;
hasDestructuring = true;
var parentId = t.identifier(file.generateUid("ref", scope));
@@ -146,7 +132,7 @@ exports.ExpressionStatement = function (node, parent, file, scope) {
var expr = node.expression;
if (expr.type !== "AssignmentExpression") return;
if (!isPattern(expr.left)) return;
if (!t.isPattern(expr.left)) return;
var nodes = [];
@@ -167,7 +153,7 @@ exports.VariableDeclaration = function (node, parent, file, scope) {
var hasPattern = false;
_.each(node.declarations, function (declar) {
if (isPattern(declar.id)) {
if (t.isPattern(declar.id)) {
hasPattern = true;
return false;
}

View File

@@ -1,4 +1,5 @@
var traverse = require("../../traverse");
var util = require("../../util");
var t = require("../../types");
var _ = require("lodash");
@@ -287,10 +288,9 @@ var run = function (forParent, block, parent, file, scope) {
if (has.hasReturn) {
// typeof ret === "object"
retCheck = t.ifStatement(
t.binaryExpression("===", t.unaryExpression("typeof", ret, true), t.literal("object")),
t.returnStatement(t.memberExpression(ret, t.identifier("v")))
);
retCheck = util.template("let-scoping-return", {
RETURN: ret,
});
// there's no `break` or `continue` so we can just push in the `if`
if (!has.hasBreak && !has.hasContinue) {

View File

@@ -162,31 +162,17 @@ t.getIds = function (node, map) {
while (search.length) {
var id = search.shift();
if (!id) continue;
var nodeKey = t.getIds.nodes[id.type];
var arrKey = t.getIds.arrays[id.type];
if (t.isIdentifier(id)) {
ids[id.name] = id;
} else if (t.isArrayPattern(id)) {
_.each(id.elements, function (elem) {
search.push(elem);
});
} else if (t.isAssignmentExpression(id)) {
search.push(id.left);
} else if (t.isObjectPattern(id)) {
_.each(id.properties, function (prop) {
search.push(prop.value);
});
} else if (t.isVariableDeclaration(id)) {
search = search.concat(id.declarations);
} else if (t.isImportSpecifier(id) || t.isExportSpecifier(id) || t.isVariableDeclarator(id) || t.isFunctionDeclaration(id) || t.isClassDeclaration(id)) {
search.push(id.id);
} else if (t.isSpreadElement(id)) {
search.push(id.argument);
} else if (t.isExportDeclaration(id) || t.isImportDeclaration(id)) {
search = search.concat(id.specifiers);
} else if (t.isMemberExpression(id)) {
search.push(id.object);
} else if (t.isParenthesizedExpression(id)) {
search.push(id.expression);
} else if (nodeKey) {
if (id[nodeKey]) search.push(id[nodeKey]);
} else if (arrKey) {
search = search.concat(id[arrKey] || []);
}
}
@@ -194,6 +180,27 @@ t.getIds = function (node, map) {
return ids;
};
t.getIds.nodes = {
AssignmentExpression: "left",
ImportSpecifier: "id",
ExportSpecifier: "id",
VariableDeclarator: "id",
FunctionDeclaration: "id",
ClassDeclaration: "id",
ParenthesizedExpression: "expression",
MemeberExpression: "object",
SpreadElement: "argument",
Property: "value"
};
t.getIds.arrays = {
ExportDeclaration: "specifiers",
ImportDeclaration: "specifiers",
VariableDeclaration: "declarations",
ArrayPattern: "elements",
ObjectPattern: "properties"
};
t.inherits = function (child, parent) {
child.loc = parent.loc;
child.end = parent.end;

View File

@@ -11,6 +11,12 @@ var _ = require("lodash");
exports.inherits = util.inherits;
exports.canCompile = function (filename, altExts) {
var exts = altExts || [".js", ".jsx", ".es6"];
var ext = path.extname(filename);
return _.contains(exts, ext);
};
exports.resolve = function (loc) {
try {
return require.resolve(loc);
@@ -111,6 +117,11 @@ exports.template = function (name, nodes, keepExpression) {
var template = exports.templates[name];
if (!template) throw new ReferenceError("unknown template " + name);
if (nodes === true) {
keepExpression = true;
nodes = null;
}
template = _.cloneDeep(template);
var inherits = false;
@@ -192,13 +203,14 @@ exports.parse = function (opts, code, callback) {
var tokens = [];
var ast = acorn.parse(code, {
preserveParens: true,
ecmaVersion: Infinity,
strictMode: true,
onComment: comments,
locations: true,
onToken: tokens,
ranges: true
allowReturnOutsideFunction: true,
preserveParens: true,
ecmaVersion: Infinity,
strictMode: true,
onComment: comments,
locations: true,
onToken: tokens,
ranges: true
});
estraverse.attachComments(ast, comments, tokens);

View File

@@ -1,7 +1,7 @@
{
"name": "6to5",
"description": "Turn ES6 code into readable vanilla ES5 with source maps",
"version": "1.11.2",
"version": "1.11.4",
"author": "Sebastian McKenzie <sebmck@gmail.com>",
"homepage": "https://github.com/6to5/6to5",
"repository": {
@@ -48,7 +48,7 @@
"chokidar": "0.10.5",
"source-map-support": "0.2.8",
"esutils": "1.1.4",
"acorn-6to5": "https://github.com/6to5/acorn-6to5/archive/f5110383517eef0bea78c2da2a1fb01fbed74e4e.tar.gz",
"acorn-6to5": "https://github.com/6to5/acorn-6to5/archive/49e421660af161af0e75c2fa066ea356d6650e69.tar.gz",
"estraverse": "^1.7.0"
},
"devDependencies": {

View File

@@ -1,5 +0,0 @@
({ t: t }) = obj;
({
t: { C: C }
}) = obj;
({ a, b, c }) = obj;

View File

@@ -1,5 +0,0 @@
({ t: t }) = obj;
({
t: { C: C }
}) = obj;
({ a, b, c }) = obj;

View File

@@ -1,2 +1 @@
[a, b] = f();
({ x }) = e();

View File

@@ -4,6 +4,3 @@ var _ref = f();
a = _ref[0];
b = _ref[1];
var _ref2 = e();
x = _ref2.x;