remove format options but move compact option to main options
This commit is contained in:
parent
b03a806d7c
commit
1effa72a33
@ -15,6 +15,7 @@ commander.option("-r, --external-helpers", "Replace helpers with references to a
|
|||||||
commander.option("-e, --experimental", "Enable experimental support for proposed ES7 features");
|
commander.option("-e, --experimental", "Enable experimental support for proposed ES7 features");
|
||||||
commander.option("-p, --playground", "Enable playground support");
|
commander.option("-p, --playground", "Enable playground support");
|
||||||
|
|
||||||
|
commander.option("-c, --compact [mode]", "When set to \"auto\" compact is `true` when the input size exceeds 100KB. (auto|true|false)", "auto");
|
||||||
commander.option("-m, --modules [modules]", "Module formatter type to use [common]", "common");
|
commander.option("-m, --modules [modules]", "Module formatter type to use [common]", "common");
|
||||||
commander.option("-l, --whitelist [whitelist]", "Whitelist of transformers to ONLY use", util.list);
|
commander.option("-l, --whitelist [whitelist]", "Whitelist of transformers to ONLY use", util.list);
|
||||||
commander.option("-b, --blacklist [blacklist]", "Blacklist of transformers to NOT use", util.list);
|
commander.option("-b, --blacklist [blacklist]", "Blacklist of transformers to NOT use", util.list);
|
||||||
@ -113,6 +114,7 @@ exports.opts = {
|
|||||||
optional: commander.optional,
|
optional: commander.optional,
|
||||||
comments: !commander.removeComments,
|
comments: !commander.removeComments,
|
||||||
modules: commander.modules,
|
modules: commander.modules,
|
||||||
|
compact: commander.compact,
|
||||||
loose: commander.loose
|
loose: commander.loose
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -5,11 +5,10 @@ module.exports = Buffer;
|
|||||||
var repeating = require("repeating");
|
var repeating = require("repeating");
|
||||||
var trimRight = require("trim-right");
|
var trimRight = require("trim-right");
|
||||||
var isBoolean = require("lodash/lang/isBoolean");
|
var isBoolean = require("lodash/lang/isBoolean");
|
||||||
var messages = require("../messages");
|
|
||||||
var includes = require("lodash/collection/includes");
|
var includes = require("lodash/collection/includes");
|
||||||
var isNumber = require("lodash/lang/isNumber");
|
var isNumber = require("lodash/lang/isNumber");
|
||||||
|
|
||||||
function Buffer(position, format, opts, code) {
|
function Buffer(position, format) {
|
||||||
this.position = position;
|
this.position = position;
|
||||||
this._indent = format.indent.base;
|
this._indent = format.indent.base;
|
||||||
this.format = format;
|
this.format = format;
|
||||||
|
|||||||
@ -46,11 +46,9 @@ exports.ConditionalExpression = function (node, print) {
|
|||||||
exports.NewExpression = function (node, print) {
|
exports.NewExpression = function (node, print) {
|
||||||
this.push("new ");
|
this.push("new ");
|
||||||
print(node.callee);
|
print(node.callee);
|
||||||
if (node.arguments.length || this.format.parentheses) {
|
this.push("(");
|
||||||
this.push("(");
|
print.list(node.arguments);
|
||||||
print.list(node.arguments);
|
this.push(")");
|
||||||
this.push(")");
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.SequenceExpression = function (node, print) {
|
exports.SequenceExpression = function (node, print) {
|
||||||
|
|||||||
@ -159,7 +159,7 @@ exports.SwitchStatement = function (node, print) {
|
|||||||
this.push("}");
|
this.push("}");
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.SwitchCase = function (node, print, parent) {
|
exports.SwitchCase = function (node, print) {
|
||||||
if (node.test) {
|
if (node.test) {
|
||||||
this.push("case ");
|
this.push("case ");
|
||||||
print(node.test);
|
print(node.test);
|
||||||
|
|||||||
@ -12,6 +12,7 @@ var Whitespace = require("./whitespace");
|
|||||||
var repeating = require("repeating");
|
var repeating = require("repeating");
|
||||||
var SourceMap = require("./source-map");
|
var SourceMap = require("./source-map");
|
||||||
var Position = require("./position");
|
var Position = require("./position");
|
||||||
|
var messages = require("../messages");
|
||||||
var Buffer = require("./buffer");
|
var Buffer = require("./buffer");
|
||||||
var extend = require("lodash/object/extend");
|
var extend = require("lodash/object/extend");
|
||||||
var merge = require("lodash/object/merge");
|
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.whitespace = new Whitespace(this.tokens, this.comments, this.format);
|
||||||
this.position = new Position;
|
this.position = new Position;
|
||||||
this.map = new SourceMap(this.position, opts, code);
|
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) {
|
each(Buffer.prototype, function (fn, key) {
|
||||||
@ -47,23 +48,20 @@ CodeGenerator.normalizeOptions = function (code, opts) {
|
|||||||
if (indent && indent !== " ") style = indent;
|
if (indent && indent !== " ") style = indent;
|
||||||
}
|
}
|
||||||
|
|
||||||
var format = merge({
|
var format = {
|
||||||
parentheses: true,
|
|
||||||
comments: opts.comments == null || opts.comments,
|
comments: opts.comments == null || opts.comments,
|
||||||
concise: false,
|
compact: opts.compact,
|
||||||
compact: "auto",
|
|
||||||
indent: {
|
indent: {
|
||||||
adjustMultilineComment: true,
|
adjustMultilineComment: true,
|
||||||
style: style,
|
style: style,
|
||||||
base: 0
|
base: 0
|
||||||
}
|
}
|
||||||
}, opts.format || {});
|
};
|
||||||
|
|
||||||
if (format.compact === "auto") {
|
if (format.compact === "auto") {
|
||||||
format.compact = code.length > 100000; // 100KB
|
format.compact = code.length > 100000; // 100KB
|
||||||
|
|
||||||
if (format.compact) {
|
if (format.compact) {
|
||||||
format.compact = true;
|
|
||||||
console.error(messages.get("codeGeneratorDeopt", opts.filename, "100KB"));
|
console.error(messages.get("codeGeneratorDeopt", opts.filename, "100KB"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -83,15 +83,18 @@ File.validOptions = [
|
|||||||
"keepModuleIdExtensions",
|
"keepModuleIdExtensions",
|
||||||
"code",
|
"code",
|
||||||
"ast",
|
"ast",
|
||||||
"format",
|
|
||||||
"playground",
|
"playground",
|
||||||
"experimental",
|
"experimental",
|
||||||
"externalHelpers",
|
"externalHelpers",
|
||||||
"auxiliaryComment",
|
"auxiliaryComment",
|
||||||
|
"compact",
|
||||||
|
|
||||||
"resolveModuleSource",
|
"resolveModuleSource",
|
||||||
"getModuleName",
|
"getModuleName",
|
||||||
|
|
||||||
|
// legacy
|
||||||
|
"format",
|
||||||
|
|
||||||
// these are used by plugins
|
// these are used by plugins
|
||||||
"ignore",
|
"ignore",
|
||||||
"only",
|
"only",
|
||||||
@ -124,6 +127,7 @@ File.prototype.normalizeOptions = function (opts) {
|
|||||||
comments: true,
|
comments: true,
|
||||||
filename: "unknown",
|
filename: "unknown",
|
||||||
modules: "common",
|
modules: "common",
|
||||||
|
compact: "auto",
|
||||||
loose: [],
|
loose: [],
|
||||||
code: true,
|
code: true,
|
||||||
ast: true
|
ast: true
|
||||||
@ -140,6 +144,7 @@ File.prototype.normalizeOptions = function (opts) {
|
|||||||
opts.blacklist = util.arrayify(opts.blacklist);
|
opts.blacklist = util.arrayify(opts.blacklist);
|
||||||
opts.whitelist = util.arrayify(opts.whitelist);
|
opts.whitelist = util.arrayify(opts.whitelist);
|
||||||
opts.optional = util.arrayify(opts.optional);
|
opts.optional = util.arrayify(opts.optional);
|
||||||
|
opts.compact = util.booleanify(opts.compact);
|
||||||
opts.loose = util.arrayify(opts.loose);
|
opts.loose = util.arrayify(opts.loose);
|
||||||
|
|
||||||
if (includes(opts.loose, "all") || includes(opts.loose, true)) {
|
if (includes(opts.loose, "all") || includes(opts.loose, true)) {
|
||||||
@ -178,8 +183,7 @@ File.prototype.normalizeOptions = function (opts) {
|
|||||||
|
|
||||||
if (opts.reactCompat) {
|
if (opts.reactCompat) {
|
||||||
opts.optional.push("reactCompat");
|
opts.optional.push("reactCompat");
|
||||||
console.error("The reactCompat option has been moved into the optional transformer " +
|
console.error("The reactCompat option has been moved into the optional transformer `reactCompat`");
|
||||||
"`reactCompat` - backwards compatibility will be removed in v4.0.0");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var ensureEnabled = function (key) {
|
var ensureEnabled = function (key) {
|
||||||
|
|||||||
@ -56,6 +56,12 @@ exports.arrayify = function (val) {
|
|||||||
throw new TypeError("illegal type for arrayify");
|
throw new TypeError("illegal type for arrayify");
|
||||||
};
|
};
|
||||||
|
|
||||||
|
exports.booleanify = function (val) {
|
||||||
|
if (val === "true") return true;
|
||||||
|
if (val === "false") return false;
|
||||||
|
return val;
|
||||||
|
};
|
||||||
|
|
||||||
var templateVisitor = {
|
var templateVisitor = {
|
||||||
enter: function (node, parent, scope, nodes) {
|
enter: function (node, parent, scope, nodes) {
|
||||||
if (t.isExpressionStatement(node)) {
|
if (t.isExpressionStatement(node)) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user