Compare commits

...

26 Commits

Author SHA1 Message Date
Sebastian McKenzie
7b8a50509a v1.11.7 2014-11-11 01:07:20 +11:00
Sebastian McKenzie
1400dee0c1 delegate code and opts assurance to File 2014-11-11 01:06:29 +11:00
Sebastian McKenzie
9e2fc6db9c clone options - sindresorhus/grunt-6to5#7 2014-11-11 01:04:39 +11:00
Sebastian McKenzie
aef5b89492 fix appveyor badge 2014-11-10 21:12:30 +11:00
Sebastian McKenzie
e0bf6f698e add appveyor badge to readme 2014-11-10 21:09:09 +11:00
Sebastian McKenzie
1ac459a05d better appveyor make test 2014-11-10 21:09:04 +11:00
Sebastian McKenzie
1b49835b27 v1.11.6 2014-11-10 16:46:40 +11:00
Sebastian McKenzie
db7b6a4972 fix canCompile in readdirFilter in bin/6to5 util 2014-11-10 16:45:30 +11:00
Sebastian McKenzie
79045e15c5 remove second canCompile declaration 2014-11-10 16:42:04 +11:00
Sebastian McKenzie
b7e6d8f998 add appveyor.yml 2014-11-10 16:31:32 +11:00
Sebastian McKenzie
88c6ce4e48 v1.11.5 2014-11-10 13:10:39 +11:00
Sebastian McKenzie
8c97f1d92e allow constant properties to be modified - fixes #131 2014-11-10 13:09:45 +11:00
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
21 changed files with 131 additions and 106 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

@@ -6,7 +6,7 @@ MOCHA_CMD = node_modules/mocha/bin/_mocha
export NODE_ENV = test
.PHONY: clean test test-cov test-travis test-browser publish bench build
.PHONY: clean test test-cov tlint est-travis test-appveyor test-browser publish bench build
clean:
rm -rf coverage templates.json test/tmp dist
@@ -15,16 +15,22 @@ bench:
npm install es6-transpiler traceur esnext es6now jstransform
node node_modules/matcha/bin/_matcha
test:
lint:
$(JSHINT_CMD) lib bin benchmark/index.js
test:
make lint
$(MOCHA_CMD)
test-cov:
rm -rf coverage
node $(ISTANBUL_CMD) $(MOCHA_CMD) --
test-travis:
test-appveyor:
node $(ISTANBUL_CMD) $(MOCHA_CMD) -- --reporter spec
test-travis:
make test-appveyor
if test -n "$$CODECLIMATE_REPO_TOKEN"; then codeclimate < coverage/lcov.info; fi
test-browser:

View File

@@ -7,6 +7,10 @@
<img alt="Travis Status" src="http://img.shields.io/travis/6to5/6to5.svg?branch=master&amp;style=flat&amp;label=travis">
</a>
<a href="https://ci.appveyor.com/project/sebmck/6to5">
<img alt="Appveyor Status" src="http://img.shields.io/appveyor/ci/sebmck/6to5.svg?style=flat&amp;label=appveyor">
</a>
<a href="https://codeclimate.com/github/6to5/6to5">
<img alt="Code Climate Score" src="http://img.shields.io/codeclimate/github/6to5/6to5.svg?style=flat">
</a>

17
appveyor.yml Normal file
View File

@@ -0,0 +1,17 @@
environment:
matrix:
- nodejs_version: "0.10"
- nodejs_version: "0.11"
install:
- "npm install"
- "cinst make"
test_script:
- "node --version"
- "npm --version"
- "make test-appveyor"
build: "off"
version: "{build}"

View File

@@ -6,7 +6,9 @@ var fs = require("fs");
var _ = require("lodash");
exports.readdirFilter = function (filename) {
return readdir(filename).filter(util.canCompile);
return readdir(filename).filter(function (filename) {
return util.canCompile(filename);
});
};
exports.transform = function (filename, code, opts) {

View File

@@ -11,7 +11,7 @@ var _ = require("lodash");
function File(opts) {
this.opts = File.normaliseOptions(opts);
this.moduleFormatter = this.getModuleFormatter(opts.modules);
this.moduleFormatter = this.getModuleFormatter(this.opts.modules);
this.declarations = {};
this.uids = {};
@@ -21,7 +21,7 @@ function File(opts) {
File.declarations = ["extends", "class-props", "slice"];
File.normaliseOptions = function (opts) {
opts = opts || {};
opts = _.cloneDeep(opts || {});
_.defaults(opts, {
whitespace: true,
@@ -110,6 +110,8 @@ File.prototype.errorWithNode = function (node, msg, Error) {
};
File.prototype.parse = function (code) {
code = (code || "") + "";
var self = this;
this.code = code;

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

@@ -5,9 +5,6 @@ var File = require("../file");
var _ = require("lodash");
function transform(code, opts) {
opts = opts || {};
code = (code || "") + "";
var file = new File(opts);
return file.parse(code);
}
@@ -20,7 +17,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 +59,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

@@ -17,10 +17,14 @@ exports.ForStatement = function (node, parent, file) {
});
};
var getIds = function (node) {
return t.getIds(node, false, ["MemberExpression"]);
};
_.each(node.body, function (child) {
if (child && t.isVariableDeclaration(child, { kind: "const" })) {
_.each(child.declarations, function (declar) {
_.each(t.getIds(declar), function (name) {
_.each(getIds(declar), function (name) {
check(declar, [name]);
constants.push(name);
});
@@ -39,7 +43,7 @@ exports.ForStatement = function (node, parent, file) {
if (child._ignoreConstant) return;
if (t.isVariableDeclarator(child) || t.isDeclaration(child) || t.isAssignmentExpression(child)) {
check(child, t.getIds(child));
check(child, getIds(child));
}
});
};

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

@@ -156,37 +156,26 @@ t.toBlock = function (node, parent) {
return t.blockStatement(node);
};
t.getIds = function (node, map) {
t.getIds = function (node, map, ignoreTypes) {
ignoreTypes = ignoreTypes || [];
var search = [node];
var ids = {};
while (search.length) {
var id = search.shift();
if (!id) continue;
if (_.contains(ignoreTypes, id.type)) 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 +183,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);
@@ -46,11 +52,6 @@ exports.isAbsolute = function (loc) {
return false;
};
exports.canCompile = function (filename) {
var ext = path.extname(filename);
return _.contains([".js", ".es6"], ext);
};
exports.sourceMapToComment = function (map) {
var json = JSON.stringify(map);
var base64 = new Buffer(json).toString("base64");
@@ -111,6 +112,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 +198,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.7",
"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;