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("-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("-l, --whitelist [whitelist]", "Whitelist of transformers to ONLY 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,
|
||||
comments: !commander.removeComments,
|
||||
modules: commander.modules,
|
||||
compact: commander.compact,
|
||||
loose: commander.loose
|
||||
};
|
||||
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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) {
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -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"));
|
||||
}
|
||||
}
|
||||
|
||||
@ -83,15 +83,18 @@ File.validOptions = [
|
||||
"keepModuleIdExtensions",
|
||||
"code",
|
||||
"ast",
|
||||
"format",
|
||||
"playground",
|
||||
"experimental",
|
||||
"externalHelpers",
|
||||
"auxiliaryComment",
|
||||
"compact",
|
||||
|
||||
"resolveModuleSource",
|
||||
"getModuleName",
|
||||
|
||||
// legacy
|
||||
"format",
|
||||
|
||||
// these are used by plugins
|
||||
"ignore",
|
||||
"only",
|
||||
@ -124,6 +127,7 @@ File.prototype.normalizeOptions = function (opts) {
|
||||
comments: true,
|
||||
filename: "unknown",
|
||||
modules: "common",
|
||||
compact: "auto",
|
||||
loose: [],
|
||||
code: true,
|
||||
ast: true
|
||||
@ -140,6 +144,7 @@ File.prototype.normalizeOptions = function (opts) {
|
||||
opts.blacklist = util.arrayify(opts.blacklist);
|
||||
opts.whitelist = util.arrayify(opts.whitelist);
|
||||
opts.optional = util.arrayify(opts.optional);
|
||||
opts.compact = util.booleanify(opts.compact);
|
||||
opts.loose = util.arrayify(opts.loose);
|
||||
|
||||
if (includes(opts.loose, "all") || includes(opts.loose, true)) {
|
||||
@ -178,8 +183,7 @@ File.prototype.normalizeOptions = function (opts) {
|
||||
|
||||
if (opts.reactCompat) {
|
||||
opts.optional.push("reactCompat");
|
||||
console.error("The reactCompat option has been moved into the optional transformer " +
|
||||
"`reactCompat` - backwards compatibility will be removed in v4.0.0");
|
||||
console.error("The reactCompat option has been moved into the optional transformer `reactCompat`");
|
||||
}
|
||||
|
||||
var ensureEnabled = function (key) {
|
||||
|
||||
@ -56,6 +56,12 @@ exports.arrayify = function (val) {
|
||||
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 = {
|
||||
enter: function (node, parent, scope, nodes) {
|
||||
if (t.isExpressionStatement(node)) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user