Compare commits

...

15 Commits

Author SHA1 Message Date
Sebastian McKenzie
781467d423 v2.1.0 2014-12-29 01:41:05 +11:00
Sebastian McKenzie
44f5b7d013 fix case statement newline in code generator test 2014-12-29 01:39:04 +11:00
Sebastian McKenzie
dcf7f0b70b fix newline in case statement test 2014-12-29 01:37:19 +11:00
Sebastian McKenzie
03efd69998 check if node exists before inheriting comments to it 2014-12-29 01:37:12 +11:00
Sebastian McKenzie
213003a007 fix new templates path in dotfiles 2014-12-29 01:34:49 +11:00
Sebastian McKenzie
b0503f2efe add 2.1.0 changelog 2014-12-29 01:33:58 +11:00
Sebastian McKenzie
c8cf7ff286 better blacklist tests and expose register cache - closes #344 2014-12-29 01:31:26 +11:00
Sebastian McKenzie
ceb32816d7 fix destructuring in switch/case statements - closes #346 2014-12-29 01:26:51 +11:00
Sebastian McKenzie
32b94899a6 update runtime script to runtime generator 2014-12-29 01:26:21 +11:00
Sebastian McKenzie
d951082b09 move replacement node comment inheritance to traverse replacement 2014-12-29 01:26:11 +11:00
Sebastian McKenzie
b49f6e33d6 fix newline on case statement 2014-12-29 01:25:56 +11:00
Sebastian McKenzie
c5fa6425a5 explicit canRun for hidden transformers 2014-12-29 01:25:15 +11:00
Sebastian McKenzie
70d896d609 rename runtime script to runtime-generator 2014-12-29 01:24:57 +11:00
Sebastian McKenzie
e00fa8c9b1 update core-js 2014-12-29 01:24:41 +11:00
Sebastian McKenzie
13933bc9b8 move templates folder into transformation folder 2014-12-29 01:24:35 +11:00
57 changed files with 63 additions and 37 deletions

View File

@@ -1,3 +1,3 @@
node_modules
test
lib/6to5/templates
lib/6to5/transformation/templates

View File

@@ -1,7 +1,7 @@
node_modules
*.log
*.cache
lib/6to5/templates
lib/6to5/transformation/templates
test
benchmark
Makefile

View File

@@ -2,6 +2,13 @@
Gaps between patch versions are faulty/broken releases.
## 2.1.0
* Add `cache` option to register hook.
* Update `core-js`.
* Fix starting newline not being added on case statements.
* Fix destructuring `VariableDeclaration`s not inside `BlockStatement`s and `Program`.
## 2.0.4
* Avoid being greedy when destructuring array iterables.

View File

@@ -1,4 +1,4 @@
#!/usr/bin/env node
var runtime = require("../lib/6to5/runtime");
var runtime = require("../lib/6to5/runtime-generator");
console.log(runtime(process.argv[2]));

View File

@@ -250,6 +250,10 @@ require("6to5/register")({
// This will remove the currently hooked extensions of .es6 and .js so you'll
// have to add them back if you want them to be used again.
extensions: [".js", ".es6"]
extensions: [".js", ".es6"],
// Enables `roadrunner` cache that will save to a `.roadrunner.json` file in your cwd
// Do not check this into git as it's user-specific
cache: true
});
```

View File

@@ -146,7 +146,7 @@ exports.SwitchCase = function (node, print) {
this.push("default:");
}
this.space();
this.newline();
print.sequence(node.consequent, { indent: true });
};

View File

@@ -7,7 +7,7 @@ exports.Transformer = require("./transformation/transformer");
exports.types = require("./types");
exports.runtime = require("./runtime");
exports.runtime = require("./runtime-generator");
exports.register = function (opts) {
var register = require("./register");

View File

@@ -1,6 +1,7 @@
require("./polyfill");
var sourceMapSupport = require("source-map-support");
var roadrunner = require("roadrunner");
var util = require("./util");
var to5 = require("./index");
var fs = require("fs");
@@ -38,15 +39,22 @@ var blacklistTest = function (transformer, code) {
};
blacklistTest("arrayComprehension", "var foo = [for (foo of bar) foo * foo];");
//blacklistTest("generatorComprehension", "");
blacklistTest("generatorComprehension", "var foo = (for (foo of bar) foo * foo)");
blacklistTest("arrowFunctions", "var foo = x => x * x;");
blacklistTest("classes", "class Foo {}");
blacklistTest("computedPropertyNames", "var foo = { [foo]: bar };");
//blacklistTest("constants", "const foo = 0;");
blacklistTest("constants", function () {
try {
new Function("const foo = 'foo';\nfoo = 'wow';");
} catch (err) {
return; // constants are supported
}
throw new SyntaxError;
});
blacklistTest("defaultParamaters", "var foo = function (bar = 0) {};");
blacklistTest("destructuring", "var { x, y } = { x: 0, y: 0 };");
blacklistTest("forOf", "for (var foo of bar) {}");
blacklistTest("generators", "function* foo() {}");
blacklistTest("generators", "function* foo() {}\nasync function bar() {}"); // generators/async functions delegated to same transformer
blacklistTest("letScoping", "let foo = 0;");
blacklistTest("modules", 'import foo from "from";');
blacklistTest("propertyMethodAssignment", "{ get foo() {} }");
@@ -130,6 +138,11 @@ module.exports = function (opts) {
if (opts.cache) cache = opts.cache;
if (opts.cache === false) cache = null;
if (opts.cache === true) {
roadrunner.load();
roadrunner.setup();
cache = roadrunner.get("6to5");
}
_.extend(transformOpts, opts);
};

View File

@@ -72,14 +72,13 @@ Transformer.prototype.transform = function (file) {
Transformer.prototype.canRun = function (file) {
var opts = file.opts;
var key = this.key;
if (key[0] === "_") return true;
var blacklist = opts.blacklist;
if (blacklist.length && _.contains(blacklist, key)) return false;
if (key[0] !== "_") {
var whitelist = opts.whitelist;
if (whitelist.length && !_.contains(whitelist, key)) return false;
}
var whitelist = opts.whitelist;
if (whitelist.length && !_.contains(whitelist, key)) return false;
return true;
};

View File

@@ -268,6 +268,7 @@ exports.VariableDeclaration = function (node, parent, file, scope) {
}
if (!t.isProgram(parent) && !t.isBlockStatement(parent)) {
declar = null;
for (i in nodes) {
node = nodes[i];

View File

@@ -1,26 +1,16 @@
var t = require("../../types");
var inheritsComments = function (node, nodes) {
if (nodes.length) {
t.inheritsComments(nodes[0], node);
}
};
exports.ImportDeclaration = function (node, parent, file) {
var nodes = [];
if (node.specifiers.length) {
if (!file.moduleFormatter.importSpecifier) return;
for (var i in node.specifiers) {
file.moduleFormatter.importSpecifier(node.specifiers[i], node, nodes, parent);
}
} else {
if (!file.moduleFormatter.importDeclaration) return;
file.moduleFormatter.importDeclaration(node, nodes, parent);
}
inheritsComments(node, nodes);
return nodes;
};
@@ -35,16 +25,12 @@ exports.ExportDeclaration = function (node, parent, file) {
declar.init = declar.init || t.identifier("undefined");
}
if (!file.moduleFormatter.exportDeclaration) return;
file.moduleFormatter.exportDeclaration(node, nodes, parent);
} else {
if (!file.moduleFormatter.exportSpecifier) return;
for (var i in node.specifiers) {
file.moduleFormatter.exportSpecifier(node.specifiers[i], node, nodes, parent);
}
}
inheritsComments(node, nodes);
return nodes;
};

View File

@@ -42,9 +42,20 @@ function traverse(parent, opts, scope) {
if (result != null) {
updated = true;
var isArray = _.isArray(result);
// inherit comments from original node to the first replacement node
var inheritTo = result;
if (isArray) inheritTo = result[0];
if (inheritTo) t.inheritsComments(inheritTo, node);
// replace the node
node = obj[key] = result;
if (_.isArray(result) && _.contains(t.STATEMENT_OR_BLOCK_KEYS, key) && !t.isBlockStatement(obj)) {
// we're replacing a statement or block node with an array of statements so we better
// ensure that it's a block
if (isArray && _.contains(t.STATEMENT_OR_BLOCK_KEYS, key) && !t.isBlockStatement(obj)) {
t.ensureBlock(obj, key);
}
}

View File

@@ -268,7 +268,7 @@ exports.parseTemplate = function (loc, code) {
var loadTemplates = function () {
var templates = {};
var templatesLoc = __dirname + "/templates";
var templatesLoc = __dirname + "/transformation/templates";
if (!fs.existsSync(templatesLoc)) {
throw new Error("no templates directory - this is most likely the " +
"result of a broken `npm publish`. Please report to " +

View File

@@ -1,7 +1,7 @@
{
"name": "6to5",
"description": "Turn ES6 code into readable vanilla ES5 with source maps",
"version": "2.0.4",
"version": "2.1.0",
"author": "Sebastian McKenzie <sebmck@gmail.com>",
"homepage": "https://github.com/6to5/6to5",
"repository": {
@@ -39,7 +39,7 @@
"ast-types": "~0.6.1",
"chokidar": "0.11.1",
"commander": "2.5.0",
"core-js": "^0.3.2",
"core-js": "^0.3.3",
"estraverse": "1.8.0",
"esutils": "1.1.6",
"fs-readdir-recursive": "0.1.0",

View File

@@ -33,7 +33,10 @@ switch (foo) {
}
switch (foo) {
case "foo": foo();
case "bar": bar();
default: yay();
case "foo":
foo();
case "bar":
bar();
default:
yay();
}

View File

@@ -17,8 +17,10 @@ _loop: for (var i in nums) {
})(i);
switch (_ret) {
case "break": break _loop;
case "continue": continue _loop;
case "break":
break _loop;
case "continue":
continue _loop;
default:
if (typeof _ret === "object") return _ret.v;
}

View File

@@ -1,4 +1,4 @@
var runtime = require("../lib/6to5/runtime");
var runtime = require("../lib/6to5/runtime-generator");
var assert = require("assert");
suite("runtime", function () {