/*jshint node:true */
|
/*
|
|
The MIT License (MIT)
|
|
Copyright (c) 2007-2018 Einar Lielmanis, Liam Newman, and contributors.
|
|
Permission is hereby granted, free of charge, to any person
|
obtaining a copy of this software and associated documentation files
|
(the "Software"), to deal in the Software without restriction,
|
including without limitation the rights to use, copy, modify, merge,
|
publish, distribute, sublicense, and/or sell copies of the Software,
|
and to permit persons to whom the Software is furnished to do so,
|
subject to the following conditions:
|
|
The above copyright notice and this permission notice shall be
|
included in all copies or substantial portions of the Software.
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
|
BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
SOFTWARE.
|
*/
|
|
'use strict';
|
|
var BaseOptions = require('../core/options').Options;
|
|
var validPositionValues = ['before-newline', 'after-newline', 'preserve-newline'];
|
|
function Options(options) {
|
BaseOptions.call(this, options, 'js');
|
|
// compatibility, re
|
var raw_brace_style = this.raw_options.brace_style || null;
|
if (raw_brace_style === "expand-strict") { //graceful handling of deprecated option
|
this.raw_options.brace_style = "expand";
|
} else if (raw_brace_style === "collapse-preserve-inline") { //graceful handling of deprecated option
|
this.raw_options.brace_style = "collapse,preserve-inline";
|
} else if (this.raw_options.braces_on_own_line !== undefined) { //graceful handling of deprecated option
|
this.raw_options.brace_style = this.raw_options.braces_on_own_line ? "expand" : "collapse";
|
// } else if (!raw_brace_style) { //Nothing exists to set it
|
// raw_brace_style = "collapse";
|
}
|
|
//preserve-inline in delimited string will trigger brace_preserve_inline, everything
|
//else is considered a brace_style and the last one only will have an effect
|
|
var brace_style_split = this._get_selection_list('brace_style', ['collapse', 'expand', 'end-expand', 'none', 'preserve-inline']);
|
|
this.brace_preserve_inline = false; //Defaults in case one or other was not specified in meta-option
|
this.brace_style = "collapse";
|
|
for (var bs = 0; bs < brace_style_split.length; bs++) {
|
if (brace_style_split[bs] === "preserve-inline") {
|
this.brace_preserve_inline = true;
|
} else {
|
this.brace_style = brace_style_split[bs];
|
}
|
}
|
|
this.unindent_chained_methods = this._get_boolean('unindent_chained_methods');
|
this.break_chained_methods = this._get_boolean('break_chained_methods');
|
this.space_in_paren = this._get_boolean('space_in_paren');
|
this.space_in_empty_paren = this._get_boolean('space_in_empty_paren');
|
this.jslint_happy = this._get_boolean('jslint_happy');
|
this.space_after_anon_function = this._get_boolean('space_after_anon_function');
|
this.space_after_named_function = this._get_boolean('space_after_named_function');
|
this.keep_array_indentation = this._get_boolean('keep_array_indentation');
|
this.space_before_conditional = this._get_boolean('space_before_conditional', true);
|
this.unescape_strings = this._get_boolean('unescape_strings');
|
this.e4x = this._get_boolean('e4x');
|
this.comma_first = this._get_boolean('comma_first');
|
this.operator_position = this._get_selection('operator_position', validPositionValues);
|
|
// For testing of beautify preserve:start directive
|
this.test_output_raw = this._get_boolean('test_output_raw');
|
|
// force this._options.space_after_anon_function to true if this._options.jslint_happy
|
if (this.jslint_happy) {
|
this.space_after_anon_function = true;
|
}
|
|
}
|
Options.prototype = new BaseOptions();
|
|
|
|
module.exports.Options = Options;
|