Type Literal and Binding Name formatting
This commit is contained in:
parent
b00aea5c7c
commit
d9b68e9213
|
@ -2602,7 +2602,8 @@ namespace ts {
|
||||||
context.inObjectTypeLiteral = true;
|
context.inObjectTypeLiteral = true;
|
||||||
const members = createTypeNodesFromResolvedType(resolved);
|
const members = createTypeNodesFromResolvedType(resolved);
|
||||||
context.inObjectTypeLiteral = saveInObjectTypeLiteral;
|
context.inObjectTypeLiteral = saveInObjectTypeLiteral;
|
||||||
return createTypeLiteralNode(members);
|
const typeLiteralNode = createTypeLiteralNode(members);
|
||||||
|
return setEmitFlags(typeLiteralNode, EmitFlags.ToStringFormatting);
|
||||||
}
|
}
|
||||||
|
|
||||||
function shouldAddParenthesisAroundFunctionType(callSignature: Signature, context: NodeBuilderContext) {
|
function shouldAddParenthesisAroundFunctionType(callSignature: Signature, context: NodeBuilderContext) {
|
||||||
|
@ -2811,8 +2812,14 @@ namespace ts {
|
||||||
const parameterDeclaration = <ParameterDeclaration>getDeclarationOfKind(parameterSymbol, SyntaxKind.Parameter);
|
const parameterDeclaration = <ParameterDeclaration>getDeclarationOfKind(parameterSymbol, SyntaxKind.Parameter);
|
||||||
const parameterType = getTypeOfSymbol(parameterSymbol);
|
const parameterType = getTypeOfSymbol(parameterSymbol);
|
||||||
const parameterTypeNode = typeToTypeNodeHelper(parameterType, context);
|
const parameterTypeNode = typeToTypeNodeHelper(parameterType, context);
|
||||||
const name = getDeepSynthesizedClone(parameterDeclaration.name);
|
let name: BindingName;
|
||||||
|
if (parameterDeclaration.name.kind === SyntaxKind.Identifier) {
|
||||||
|
name = getSynthesizedClone(parameterDeclaration.name);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
Debug.assert(parameterDeclaration.name.kind === SyntaxKind.ArrayBindingPattern || parameterDeclaration.name.kind === SyntaxKind.ObjectBindingPattern);
|
||||||
|
name = cloneBindingName(parameterDeclaration.name);
|
||||||
|
}
|
||||||
let questionToken: Token<SyntaxKind.QuestionToken> | undefined;
|
let questionToken: Token<SyntaxKind.QuestionToken> | undefined;
|
||||||
let initializer: Expression | undefined;
|
let initializer: Expression | undefined;
|
||||||
if (isOptionalParameter(parameterDeclaration)) {
|
if (isOptionalParameter(parameterDeclaration)) {
|
||||||
|
@ -2833,6 +2840,18 @@ namespace ts {
|
||||||
parameterTypeNode,
|
parameterTypeNode,
|
||||||
initializer);
|
initializer);
|
||||||
return parameterNode;
|
return parameterNode;
|
||||||
|
|
||||||
|
function cloneBindingName(node: BindingName): BindingName {
|
||||||
|
return <BindingName>elideInitializerAndSetEmitFlags(node);
|
||||||
|
function elideInitializerAndSetEmitFlags(node: Node): Node {
|
||||||
|
const visited = visitEachChild(node, elideInitializerAndSetEmitFlags, nullTransformationContext, /*nodesVisitor*/ undefined, elideInitializerAndSetEmitFlags);
|
||||||
|
const clone = nodeIsSynthesized(visited) ? visited : getSynthesizedClone(visited);
|
||||||
|
if (clone.kind === SyntaxKind.BindingElement) {
|
||||||
|
(<BindingElement>clone).initializer = undefined;
|
||||||
|
}
|
||||||
|
return setEmitFlags(clone, EmitFlags.ToStringFormatting);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: add meaning: SymbolFlags argument.
|
// TODO: add meaning: SymbolFlags argument.
|
||||||
|
|
|
@ -956,7 +956,7 @@ namespace ts {
|
||||||
function emitTypeLiteral(node: TypeLiteralNode) {
|
function emitTypeLiteral(node: TypeLiteralNode) {
|
||||||
write("{");
|
write("{");
|
||||||
if (node.members.length > 0) {
|
if (node.members.length > 0) {
|
||||||
emitList(node, node.members, ListFormat.SingleLineTypeLiteralMembers);
|
emitList(node, node.members, getEmitFlags(node) & EmitFlags.ToStringFormatting ? ListFormat.SingleLineTypeLiteralMembers : ListFormat.MultiLineTypeLiteralMembers);
|
||||||
}
|
}
|
||||||
write("}");
|
write("}");
|
||||||
}
|
}
|
||||||
|
@ -1037,7 +1037,7 @@ namespace ts {
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
write("{");
|
write("{");
|
||||||
emitList(node, elements, ListFormat.ObjectBindingPatternElements);
|
emitList(node, elements, getEmitFlags(node) & EmitFlags.ToStringFormatting ? ListFormat.ObjectBindingPatternElements : ListFormat.ObjectBindingPatternElementsWithSpaceBetweenBraces);
|
||||||
write("}");
|
write("}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2948,13 +2948,14 @@ namespace ts {
|
||||||
// Precomputed Formats
|
// Precomputed Formats
|
||||||
Modifiers = SingleLine | SpaceBetweenSiblings,
|
Modifiers = SingleLine | SpaceBetweenSiblings,
|
||||||
HeritageClauses = SingleLine | SpaceBetweenSiblings,
|
HeritageClauses = SingleLine | SpaceBetweenSiblings,
|
||||||
SingleLineTypeLiteralMembers = SingleLine | SpaceBetweenBraces | SpaceBetweenSiblings | Indented, // MultiLine | Indented,
|
SingleLineTypeLiteralMembers = SingleLine | SpaceBetweenBraces | SpaceBetweenSiblings | Indented,
|
||||||
MultiLineTypeLiteralMembers = MultiLine | Indented,
|
MultiLineTypeLiteralMembers = MultiLine | Indented,
|
||||||
|
|
||||||
TupleTypeElements = CommaDelimited | SpaceBetweenSiblings | SingleLine | Indented,
|
TupleTypeElements = CommaDelimited | SpaceBetweenSiblings | SingleLine | Indented,
|
||||||
UnionTypeConstituents = BarDelimited | SpaceBetweenSiblings | SingleLine,
|
UnionTypeConstituents = BarDelimited | SpaceBetweenSiblings | SingleLine,
|
||||||
IntersectionTypeConstituents = AmpersandDelimited | SpaceBetweenSiblings | SingleLine,
|
IntersectionTypeConstituents = AmpersandDelimited | SpaceBetweenSiblings | SingleLine,
|
||||||
ObjectBindingPatternElements = SingleLine | AllowTrailingComma | SpaceBetweenBraces | CommaDelimited | SpaceBetweenSiblings,
|
ObjectBindingPatternElements = SingleLine | AllowTrailingComma | CommaDelimited | SpaceBetweenSiblings,
|
||||||
|
ObjectBindingPatternElementsWithSpaceBetweenBraces = SingleLine | AllowTrailingComma | SpaceBetweenBraces | CommaDelimited | SpaceBetweenSiblings,
|
||||||
ArrayBindingPatternElements = SingleLine | AllowTrailingComma | CommaDelimited | SpaceBetweenSiblings,
|
ArrayBindingPatternElements = SingleLine | AllowTrailingComma | CommaDelimited | SpaceBetweenSiblings,
|
||||||
ObjectLiteralExpressionProperties = PreserveLines | CommaDelimited | SpaceBetweenSiblings | SpaceBetweenBraces | Indented | Braces,
|
ObjectLiteralExpressionProperties = PreserveLines | CommaDelimited | SpaceBetweenSiblings | SpaceBetweenBraces | Indented | Braces,
|
||||||
ArrayLiteralExpressionElements = PreserveLines | CommaDelimited | SpaceBetweenSiblings | AllowTrailingComma | Indented | SquareBrackets,
|
ArrayLiteralExpressionElements = PreserveLines | CommaDelimited | SpaceBetweenSiblings | AllowTrailingComma | Indented | SquareBrackets,
|
||||||
|
|
|
@ -3943,6 +3943,7 @@ namespace ts {
|
||||||
}
|
}
|
||||||
|
|
||||||
export const enum EmitFlags {
|
export const enum EmitFlags {
|
||||||
|
None = 0,
|
||||||
SingleLine = 1 << 0, // The contents of this node should be emitted on a single line.
|
SingleLine = 1 << 0, // The contents of this node should be emitted on a single line.
|
||||||
AdviseOnEmitNode = 1 << 1, // The printer should invoke the onEmitNode callback when printing this node.
|
AdviseOnEmitNode = 1 << 1, // The printer should invoke the onEmitNode callback when printing this node.
|
||||||
NoSubstitution = 1 << 2, // Disables further substitution of an expression.
|
NoSubstitution = 1 << 2, // Disables further substitution of an expression.
|
||||||
|
@ -3969,6 +3970,7 @@ namespace ts {
|
||||||
NoHoisting = 1 << 20, // Do not hoist this declaration in --module system
|
NoHoisting = 1 << 20, // Do not hoist this declaration in --module system
|
||||||
HasEndOfDeclarationMarker = 1 << 21, // Declaration has an associated NotEmittedStatement to mark the end of the declaration
|
HasEndOfDeclarationMarker = 1 << 21, // Declaration has an associated NotEmittedStatement to mark the end of the declaration
|
||||||
Iterator = 1 << 22, // The expression to a `yield*` should be treated as an Iterator when down-leveling, not an Iterable.
|
Iterator = 1 << 22, // The expression to a `yield*` should be treated as an Iterator when down-leveling, not an Iterable.
|
||||||
|
ToStringFormatting = 1 << 23
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface EmitHelper {
|
export interface EmitHelper {
|
||||||
|
|
Loading…
Reference in a new issue