Skip to content
This repository was archived by the owner on Jan 19, 2019. It is now read-only.

Chore: Wrap any parameter with modifers, not just in constructors #214

Merged

Conversation

Pajn
Copy link
Contributor

@Pajn Pajn commented Apr 5, 2017

As pretter reprints the code from the AST, anything not in it will be gone.
So while

interface I {
    new (public x);
}

is invalid TypeScript, it's no good if pretter prints that as

interface I {
    new (x)
}

If you have your editor set up to format on save, the modifier will just
be gone and you'll never see the error from TypeScript and will therfore
consider it a bug.
Note that the code does not explicitly support this, I just moved the code
that supports this in constructor parameters so that it applies to any parameter.

As the code parses correctly with just missing information in the AST there
are no good way to know that the printed file will be different from the original.
So while there is no intention to support invalid TS it's easier to do that in this
case than to error.

@eslintbot
Copy link

Thanks for the pull request, @Pajn! I took a look to make sure it's ready for merging and found some changes are needed:

  • Pull requests with code require an issue to be mentioned at the end of the commit summary, such as (fixes #1234). Please update the commit summary with an issue (file a new issue if one doesn't already exist).

Can you please update the pull request to address these?

(More information can be found in our pull request guide.)

Copy link
Member

@soda0289 soda0289 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@JamesHenry
Copy link
Member

I think this is a grey area but is probably ok.

The reason I think that is that this is is not actually "structurally invalid" TypeScript. We can parse that source with no TS parseDiagnostics issues, and it produces a full TS AST.

Clearly, other parts of TS will then tell you that this is semantically invalid, but I think that is a level of abstraction above what we are focused on here.

@JamesHenry JamesHenry merged commit a37d5ed into eslint:master Apr 9, 2017
@JamesHenry
Copy link
Member

P.S. @Pajn I changed this to a Fix, and fixed the typo in your commit ahead of merging.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants