Skip to content

@decorators on class are still being placed on separate line #5360

@desbrowne

Description

@desbrowne

Prettier 1.15.1
Playground link

--parser typescript

Input:

import { action, observable } from 'mobx';
import { observer } from 'mobx-react';
import * as React from 'react';
import { RouteComponentProps } from 'react-router';

interface CountHandlerProps extends RouteComponentProps<{}> { }
@observer export class CountHandler extends React.Component<CountHandlerProps> {
	@observable count = 0;
	render() {
      const { data } = this;
      return (
        <div>
          Count: {this.count}
          <button onClick={this.handleIncreaseClick}>Increase</button>
          <button onClick={handleResetClick}>Reset</button>
      	</div>
      );
	}
	@action handleIncreaseClick = () => this.count++;
	@action handleResetClick = () => {
      this.count = 0;
    }
}

Output:

import { action, observable } from "mobx";
import { observer } from "mobx-react";
import * as React from "react";
import { RouteComponentProps } from "react-router";

interface CountHandlerProps extends RouteComponentProps<{}> {}
@observer
export class CountHandler extends React.Component<CountHandlerProps> {
  @observable count = 0;
  render() {
    const { data } = this;
    return (
      <div>
        Count: {this.count}
        <button onClick={this.handleIncreaseClick}>Increase</button>
        <button onClick={handleResetClick}>Reset</button>
      </div>
    );
  }
  @action handleIncreaseClick = () => this.count++;
  @action
  handleResetClick = () => {
    this.count = 0;
  };
}

Expected behavior:
I would expect the @observer decorator and the second @action decorator(fixed in 1.15.2) to stay inline as discussed in #4924.

Metadata

Metadata

Assignees

No one assigned

    Labels

    lang:javascriptIssues affecting JSlang:typescriptIssues affecting TypeScript-specific constructs (not general JS issues)locked-due-to-inactivityPlease open a new issue and fill out the template instead of commenting.status:wontfixThis will not be worked on

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions