prettier / prettier/prettier

Flatten nested function decorators / higher-order functions

Open
#10,756 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

area:arrow functions area:function calls lang:javascript
Dominant language
JavaScript
Stars
52.3k
Forks
5k
Avg merge
19h 2m
Merged PRs (30d)
117

Description

Prettier 2.2.1
Playground link

--parser typescript

Input:

const Counter = decorator("foo")(decorator("bar")((props: {
  foo: Foo,
  bar: Bar,
}) => {
  return <Other foo={foo} bar={bar} />;
}));

Output:

const Counter = decorator("foo")(
  decorator("bar")((props: { foo: Foo; bar: Bar }) => {
    return <Other foo={foo} bar={bar} />;
  })
);

Expected behavior:

const Counter = 
  decorator("foo")(
  decorator("bar")(
  (props: {
    foo: Foo,
    bar: Bar,
  }) => {
    return <Other foo={foo} bar={bar} />;
  }));

Would likely build on https://github.com/prettier/prettier/pull/10714

Note that many people currently add a runtime abstraction just to avoid the current formatting, eg:

const Counter = compose(
  decorator("foo"),
  decorator("bar")
)((props: { foo; bar }) => {
  return <div />;
});

so cleaning this up could help make people's code faster and simpler.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Run the provided TypeScript playground example and compare the current output with the expected nested-decorator formatting. Read the referenced pull request #10714 for the proposed direction, then verify that the example produces the expected output without relying on a runtime compose abstraction.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, typescript
Domain
tooling
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.