Compare commits

...

8 Commits

Author SHA1 Message Date
Sebastian McKenzie
6bd67ca660 v1.11.13 2014-11-11 14:31:06 +11:00
Sebastian McKenzie
4722c0ce56 add support for escodegen-style format options 2014-11-11 14:30:06 +11:00
Sebastian McKenzie
25a5caa0fc update regenerator-6to5 2014-11-11 14:29:32 +11:00
Sebastian McKenzie
6f05466cf5 normalise windows path separators to unix 2014-11-11 13:36:59 +11:00
Sebastian McKenzie
1ad9edb57c tests/bin: normalise stdout path separators 2014-11-11 13:33:50 +11:00
Sebastian McKenzie
c6ae33c5a2 tests: change all windows line endings to unix ones 2014-11-11 13:30:19 +11:00
Sebastian McKenzie
e0d620b1d5 remove browser-polyfill.js instead of polyfill.js 2014-11-11 13:29:50 +11:00
Sebastian McKenzie
5588bf56eb add CHANGELOG 2014-11-11 13:29:37 +11:00
8 changed files with 60 additions and 40 deletions

4
CHANGELOG.md Normal file
View File

@@ -0,0 +1,4 @@
# 1.11.13
* Update regenerator-6to5
* Add support for most escodegen formatting options

View File

@@ -78,4 +78,4 @@ publish:
git push --follow-tags
rm -rf templates.json browser.js runtime.js polyfill.js
rm -rf templates.json browser.js runtime.js browser-polyfill.js

View File

@@ -33,6 +33,9 @@ File.normaliseOptions = function (opts) {
runtime: false
});
// normalise windows path separators to unix
opts.filename = opts.filename.replace(/\\/g, "/");
_.defaults(opts, {
sourceFileName: opts.filename,
sourceMapName: opts.filename

View File

@@ -16,29 +16,38 @@ var _ = require("lodash");
function CodeGenerator(ast, opts, code) {
opts = opts || {};
this.style = {
semicolons: true,
comments: true,
compact: false,
indent: {
char: " ",
width: 2
}
};
this.comments = ast.comments || [];
this.tokens = ast.tokens || [];
this.opts = opts;
this.ast = ast;
this.buf = "";
this._indent = 0;
this.format = CodeGenerator.normaliseOptions(opts);
this._indent = this.format.indent.base;
this.whitespace = new Whitespace(this.tokens, this.comments);
this.position = new Position;
this.map = new SourceMap(this.position, opts, code);
}
CodeGenerator.normaliseOptions = function (opts) {
opts = opts.format || {};
opts = _.merge({
parentheses: true,
semicolons: true,
comments: true,
compact: false,
indent: {
adjustMultilineComment: true,
style: " ",
base: 0
}
}, opts);
return opts;
};
CodeGenerator.generators = {
arrayComprehensions: require("./generators/array-comprehensions"),
templateLiterals: require("./generators/template-literals"),
@@ -58,7 +67,7 @@ _.each(CodeGenerator.generators, function (generator) {
CodeGenerator.prototype.newline = function (i, removeLast) {
if (!this.buf) return;
if (this.style.compact) return;
if (this.format.compact) return;
if (this.endsWith("{\n")) return;
if (_.isBoolean(i)) {
@@ -89,7 +98,7 @@ CodeGenerator.prototype.removeLast = function (cha) {
};
CodeGenerator.prototype.semicolon = function () {
if (this.style.semicolons) this.push(";");
if (this.format.semicolons) this.push(";");
};
CodeGenerator.prototype.ensureSemicolon = function () {
@@ -145,15 +154,15 @@ CodeGenerator.prototype.isLast = function (cha, trimRight) {
};
CodeGenerator.prototype.getIndent = function () {
if (this.style.compact) {
if (this.format.compact) {
return "";
} else {
return util.repeat(this.indentSize(), this.style.indent.char);
return util.repeat(this._indent, this.format.indent.style);
}
};
CodeGenerator.prototype.indentSize = function () {
return this._indent * this.style.indent.width;
return this.getIndent().length;
};
CodeGenerator.prototype.indent = function () {
@@ -353,8 +362,8 @@ CodeGenerator.prototype._getComments = function (key, node) {
};
CodeGenerator.prototype._printComments = function (comments) {
if (this.style.compact) return;
if (!this.style.comments) return;
if (this.format.compact) return;
if (!this.format.comments) return;
if (!comments || !comments.length) return;
var self = this;
@@ -373,14 +382,16 @@ CodeGenerator.prototype._printComments = function (comments) {
//
var offset = comment.loc.start.column;
if (offset) {
var newlineRegex = new RegExp("\\n\\s{1," + offset + "}", "g");
val = val.replace(newlineRegex, "\n");
}
if (comment.type === "Block" && self.format.indent.adjustMultilineComment) {
var offset = comment.loc.start.column;
if (offset) {
var newlineRegex = new RegExp("\\n\\s{1," + offset + "}", "g");
val = val.replace(newlineRegex, "\n");
}
var indent = Math.max(self.indentSize(), column);
val = val.replace(/\n/g, "\n" + util.repeat(indent));
var indent = Math.max(self.indentSize(), column);
val = val.replace(/\n/g, "\n" + util.repeat(indent));
}
if (column === 0) {
val = self.getIndent() + val;

View File

@@ -44,9 +44,11 @@ exports.ConditionalExpression = function (node, print) {
exports.NewExpression = function (node, print) {
this.push("new ");
print(node.callee);
this.push("(");
print.join(node.arguments, { separator: ", " });
this.push(")");
if (node.arguments.length || this.format.parentheses) {
this.push("(");
print.join(node.arguments, { separator: ", " });
this.push(")");
}
};
exports.SequenceExpression = function (node, print) {

View File

@@ -1,7 +1,7 @@
{
"name": "6to5",
"description": "Turn ES6 code into readable vanilla ES5 with source maps",
"version": "1.11.12",
"version": "1.11.13",
"author": "Sebastian McKenzie <sebmck@gmail.com>",
"homepage": "https://github.com/6to5/6to5",
"repository": {
@@ -44,7 +44,7 @@
"es6-symbol": "0.1.1",
"regexpu": "0.3.0",
"source-map": "0.1.40",
"regenerator-6to5": "https://github.com/6to5/regenerator-6to5/archive/37798b2311c46975bc199ff595fe1b1f28bee94c.tar.gz",
"regenerator-6to5": "https://github.com/6to5/regenerator-6to5/archive/62d1bfcb331dcf0bbcdbbee8043da0c6408f09cf.tar.gz",
"chokidar": "0.10.5",
"source-map-support": "0.2.8",
"esutils": "1.1.4",

View File

@@ -5,9 +5,11 @@ var humanise = function (val) {
return val.replace(/-/g, " ");
};
var readFile = function (filename) {
var readFile = exports.readFile = function (filename) {
if (fs.existsSync(filename)) {
return fs.readFileSync(filename, "utf8").trim();
var file = fs.readFileSync(filename, "utf8").trim();
file = file.replace(/\r\n/g, "\n");
return file;
} else {
return "";
}

View File

@@ -1,4 +1,5 @@
var readdir = require("fs-readdir-recursive");
var helper = require("./_helper");
var assert = require("assert");
var rimraf = require("rimraf");
var mkdirp = require("mkdirp");
@@ -11,15 +12,11 @@ var _ = require("lodash");
var fixtureLoc = __dirname + "/fixtures/bin";
var tmpLoc = __dirname + "/tmp";
var readFile = function (filename) {
return fs.readFileSync(filename, "utf8").trim();
};
var readDir = function (loc) {
var files = {};
if (fs.existsSync(loc)) {
_.each(readdir(loc), function (filename) {
var contents = readFile(loc + "/" + filename);
var contents = helper.readFile(loc + "/" + filename);
files[filename] = contents;
});
}
@@ -51,6 +48,7 @@ var assertTest = function (stdout, stderr, opts) {
var expectStdout = opts.stdout.trim();
stdout = stdout.trim();
stdout = stdout.replace(/\\/g, "/");
if (opts.stdout) {
if (opts.stdoutContains) {
@@ -63,7 +61,7 @@ var assertTest = function (stdout, stderr, opts) {
}
_.each(opts.outFiles, function (expect, filename) {
var actual = readFile(filename);
var actual = helper.readFile(filename);
chai.expect(actual).to.equal(expect, "out-file " + filename);
});
};
@@ -138,7 +136,7 @@ _.each(fs.readdirSync(fixtureLoc), function (binName) {
_.each(["stdout", "stdin", "stderr"], function (key) {
var loc = testLoc + "/" + key + ".txt";
if (fs.existsSync(loc)) {
opts[key] = readFile(loc);
opts[key] = helper.readFile(loc);
} else {
opts[key] = opts[key] || "";
}