Microsoft/TypeScript

Feature Request: Line Breaks in Assignments in Compiled Javascript

Open

#7468 aperta il 10 mar 2016

Vedi su GitHub
 (2 commenti) (0 reazioni) (0 assegnatari)TypeScript (6726 fork)batch import
Help WantedSuggestion

Metriche repository

Star
 (48.455 star)
Metriche merge PR
 (Merge medio 6g 17h) (9 PR mergiate in 30 g)

Descrizione

One of typescript's key advantages over Babel (at least as far as I'm concerned), is the readability of its compiled javascript. It is so readable, in fact, that I often use typescript for non-typescript projects, and just submit the compiled javascript. One issue that often arises, however, is that the compiled javascript will not match style rules in these javascript projects. One style rule is to have each assignment on its own line. Typescript generally does this, except when destructuring. It would be extremely valuable to be able to specify a compiler option for assignmentsOnNewLine which would add line breaks after each assignment.

For example, the following typescript code:

const aVeryLargeObject = {
    firstValue: 1,
    secondValue: 2,
    thirdValue: 3,
    fourthValue: 4
};
const {firstValue, secondValue, thirdValue, fourthValue} = aVeryLargeObject;

Produces the following javascript:

var aVeryLargeObject = {
    firstValue: 1,
    secondValue: 2,
    thirdValue: 3,
    fourthValue: 4
};
var firstValue = aVeryLargeObject.firstValue, secondValue = aVeryLargeObject.secondValue, thirdValue = aVeryLargeObject.thirdValue, fourthValue = aVeryLargeObject.fourthValue;

If this feature was implemented it should produce the following javascript:

var aVeryLargeObject = {
    firstValue: 1,
    secondValue: 2,
    thirdValue: 3,
    fourthValue: 4
};
var firstValue = aVeryLargeObject.firstValue,
    secondValue = aVeryLargeObject.secondValue,
    thirdValue = aVeryLargeObject.thirdValue,
    fourthValue = aVeryLargeObject.fourthValue;

Guida contributor