| | |
| | | in_case_statement: false, // switch(..){ INSIDE HERE } |
| | | in_case: false, // we're on the exact line with "case 0:" |
| | | case_body: false, // the indented case-action block |
| | | case_block: false, // the indented case-action block is wrapped with {} |
| | | indentation_level: next_indent_level, |
| | | alignment: 0, |
| | | line_indent_level: flags_base ? flags_base.line_indent_level : next_indent_level, |
| | |
| | | )) { |
| | | // We don't support TypeScript,but we didn't break it for a very long time. |
| | | // We'll try to keep not breaking it. |
| | | if (!in_array(this._last_last_text, ['class', 'interface'])) { |
| | | this.set_mode(MODE.ObjectLiteral); |
| | | } else { |
| | | if (in_array(this._last_last_text, ['class', 'interface']) && !in_array(second_token.text, [':', ','])) { |
| | | this.set_mode(MODE.BlockStatement); |
| | | } else { |
| | | this.set_mode(MODE.ObjectLiteral); |
| | | } |
| | | } else if (this._flags.last_token.type === TOKEN.OPERATOR && this._flags.last_token.text === '=>') { |
| | | // arrow function: (param1, paramN) => { statements } |
| | |
| | | if (current_token.type === TOKEN.RESERVED) { |
| | | if (in_array(current_token.text, ['set', 'get']) && this._flags.mode !== MODE.ObjectLiteral) { |
| | | current_token.type = TOKEN.WORD; |
| | | } else if (current_token.text === 'import' && this._tokens.peek().text === '(') { |
| | | } else if (current_token.text === 'import' && in_array(this._tokens.peek().text, ['(', '.'])) { |
| | | current_token.type = TOKEN.WORD; |
| | | } else if (in_array(current_token.text, ['as', 'from']) && !this._flags.import_block) { |
| | | current_token.type = TOKEN.WORD; |
| | |
| | | |
| | | if (this._flags.in_case_statement && reserved_array(current_token, ['case', 'default'])) { |
| | | this.print_newline(); |
| | | if (this._flags.last_token.type !== TOKEN.END_BLOCK && (this._flags.case_body || this._options.jslint_happy)) { |
| | | if (!this._flags.case_block && (this._flags.case_body || this._options.jslint_happy)) { |
| | | // switch cases following one another |
| | | this.deindent(); |
| | | } |
| | |
| | | if (this._tokens.peek().type !== TOKEN.START_BLOCK) { |
| | | this.indent(); |
| | | this.print_newline(); |
| | | this._flags.case_block = false; |
| | | } else { |
| | | this._flags.case_block = true; |
| | | this._output.space_before_token = true; |
| | | } |
| | | return; |
| | |
| | | |
| | | // http://www.ecma-international.org/ecma-262/5.1/#sec-7.9.1 |
| | | // if there is a newline between -- or ++ and anything else we should preserve it. |
| | | if (current_token.newlines && (current_token.text === '--' || current_token.text === '++')) { |
| | | if (current_token.newlines && (current_token.text === '--' || current_token.text === '++' || current_token.text === '~')) { |
| | | this.print_newline(false, true); |
| | | } |
| | | |