remove format options but move compact option to main options

This commit is contained in:
Sebastian McKenzie
2015-02-21 12:41:03 +11:00
parent b03a806d7c
commit 1effa72a33
7 changed files with 25 additions and 18 deletions

View File

@@ -5,11 +5,10 @@ module.exports = Buffer;
var repeating = require("repeating");
var trimRight = require("trim-right");
var isBoolean = require("lodash/lang/isBoolean");
var messages = require("../messages");
var includes = require("lodash/collection/includes");
var isNumber = require("lodash/lang/isNumber");
function Buffer(position, format, opts, code) {
function Buffer(position, format) {
this.position = position;
this._indent = format.indent.base;
this.format = format;

View File

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

View File

@@ -159,7 +159,7 @@ exports.SwitchStatement = function (node, print) {
this.push("}");
};
exports.SwitchCase = function (node, print, parent) {
exports.SwitchCase = function (node, print) {
if (node.test) {
this.push("case ");
print(node.test);

View File

@@ -12,6 +12,7 @@ var Whitespace = require("./whitespace");
var repeating = require("repeating");
var SourceMap = require("./source-map");
var Position = require("./position");
var messages = require("../messages");
var Buffer = require("./buffer");
var extend = require("lodash/object/extend");
var merge = require("lodash/object/merge");
@@ -31,7 +32,7 @@ function CodeGenerator(ast, opts, code) {
this.whitespace = new Whitespace(this.tokens, this.comments, this.format);
this.position = new Position;
this.map = new SourceMap(this.position, opts, code);
this.buffer = new Buffer(this.position, this.format, opts, code);
this.buffer = new Buffer(this.position, this.format);
}
each(Buffer.prototype, function (fn, key) {
@@ -47,23 +48,20 @@ CodeGenerator.normalizeOptions = function (code, opts) {
if (indent && indent !== " ") style = indent;
}
var format = merge({
parentheses: true,
var format = {
comments: opts.comments == null || opts.comments,
concise: false,
compact: "auto",
compact: opts.compact,
indent: {
adjustMultilineComment: true,
style: style,
base: 0
}
}, opts.format || {});
};
if (format.compact === "auto") {
format.compact = code.length > 100000; // 100KB
if (format.compact) {
format.compact = true;
console.error(messages.get("codeGeneratorDeopt", opts.filename, "100KB"));
}
}