fix(36140): handle quotesPreference option in interface implementation (#36398)

This commit is contained in:
Alexander T
2020-01-27 12:25:31 -08:00
committed by Sheetal Nandi
parent 20e8eba143
commit c239626f23
6 changed files with 34 additions and 5 deletions
+1 -1
View File
@@ -3956,7 +3956,7 @@ namespace ts {
}
if (type.flags & TypeFlags.StringLiteral) {
context.approximateLength += ((<StringLiteralType>type).value.length + 2);
return createLiteralTypeNode(setEmitFlags(createLiteral((<StringLiteralType>type).value), EmitFlags.NoAsciiEscaping));
return createLiteralTypeNode(setEmitFlags(createLiteral((<StringLiteralType>type).value, !!(context.flags & NodeBuilderFlags.UseSingleQuotesForStringLiteralType)), EmitFlags.NoAsciiEscaping));
}
if (type.flags & TypeFlags.NumberLiteral) {
const value = (<NumberLiteralType>type).value;
+4 -1
View File
@@ -3630,6 +3630,7 @@ namespace ts {
UseTypeOfFunction = 1 << 12, // Build using typeof instead of function type literal
OmitParameterModifiers = 1 << 13, // Omit modifiers on parameters
UseAliasDefinedOutsideCurrentScope = 1 << 14, // Allow non-visible aliases
UseSingleQuotesForStringLiteralType = 1 << 28, // Use single quotes for string literal type
// Error handling
AllowThisInObjectLiteral = 1 << 15,
@@ -3672,6 +3673,7 @@ namespace ts {
OmitParameterModifiers = 1 << 13, // Omit modifiers on parameters
UseAliasDefinedOutsideCurrentScope = 1 << 14, // For a `type T = ... ` defined in a different file, write `T` instead of its value, even though `T` can't be accessed in the current scope.
UseSingleQuotesForStringLiteralType = 1 << 28, // Use single quotes for string literal type
// Error Handling
AllowUniqueESSymbolType = 1 << 20, // This is bit 20 to align with the same bit in `NodeBuilderFlags`
@@ -3690,7 +3692,8 @@ namespace ts {
NodeBuilderFlagsMask = NoTruncation | WriteArrayAsGenericType | UseStructuralFallback | WriteTypeArgumentsOfSignature |
UseFullyQualifiedType | SuppressAnyReturnType | MultilineObjectLiterals | WriteClassExpressionAsTypeLiteral |
UseTypeOfFunction | OmitParameterModifiers | UseAliasDefinedOutsideCurrentScope | AllowUniqueESSymbolType | InTypeAlias,
UseTypeOfFunction | OmitParameterModifiers | UseAliasDefinedOutsideCurrentScope | AllowUniqueESSymbolType | InTypeAlias |
UseSingleQuotesForStringLiteralType,
}
export const enum SymbolFormatFlags {
+2 -1
View File
@@ -60,7 +60,8 @@ namespace ts.codefix {
switch (declaration.kind) {
case SyntaxKind.PropertySignature:
case SyntaxKind.PropertyDeclaration:
const typeNode = checker.typeToTypeNode(type, enclosingDeclaration, /*flags*/ undefined, getNoopSymbolTrackerWithResolver(context));
const flags = preferences.quotePreference === "single" ? NodeBuilderFlags.UseSingleQuotesForStringLiteralType : undefined;
const typeNode = checker.typeToTypeNode(type, enclosingDeclaration, flags, getNoopSymbolTrackerWithResolver(context));
out(createProperty(
/*decorators*/undefined,
modifiers,
+3 -1
View File
@@ -2118,6 +2118,7 @@ declare namespace ts {
UseTypeOfFunction = 4096,
OmitParameterModifiers = 8192,
UseAliasDefinedOutsideCurrentScope = 16384,
UseSingleQuotesForStringLiteralType = 268435456,
AllowThisInObjectLiteral = 32768,
AllowQualifedNameInPlaceOfIdentifier = 65536,
AllowAnonymousIdentifier = 131072,
@@ -2145,6 +2146,7 @@ declare namespace ts {
UseTypeOfFunction = 4096,
OmitParameterModifiers = 8192,
UseAliasDefinedOutsideCurrentScope = 16384,
UseSingleQuotesForStringLiteralType = 268435456,
AllowUniqueESSymbolType = 1048576,
AddUndefined = 131072,
WriteArrowStyleSignature = 262144,
@@ -2153,7 +2155,7 @@ declare namespace ts {
InFirstTypeArgument = 4194304,
InTypeAlias = 8388608,
/** @deprecated */ WriteOwnNameForAnyLike = 0,
NodeBuilderFlagsMask = 9469291
NodeBuilderFlagsMask = 277904747
}
export enum SymbolFormatFlags {
None = 0,
+3 -1
View File
@@ -2118,6 +2118,7 @@ declare namespace ts {
UseTypeOfFunction = 4096,
OmitParameterModifiers = 8192,
UseAliasDefinedOutsideCurrentScope = 16384,
UseSingleQuotesForStringLiteralType = 268435456,
AllowThisInObjectLiteral = 32768,
AllowQualifedNameInPlaceOfIdentifier = 65536,
AllowAnonymousIdentifier = 131072,
@@ -2145,6 +2146,7 @@ declare namespace ts {
UseTypeOfFunction = 4096,
OmitParameterModifiers = 8192,
UseAliasDefinedOutsideCurrentScope = 16384,
UseSingleQuotesForStringLiteralType = 268435456,
AllowUniqueESSymbolType = 1048576,
AddUndefined = 131072,
WriteArrowStyleSignature = 262144,
@@ -2153,7 +2155,7 @@ declare namespace ts {
InFirstTypeArgument = 4194304,
InTypeAlias = 8388608,
/** @deprecated */ WriteOwnNameForAnyLike = 0,
NodeBuilderFlagsMask = 9469291
NodeBuilderFlagsMask = 277904747
}
export enum SymbolFormatFlags {
None = 0,
@@ -0,0 +1,21 @@
/// <reference path='fourslash.ts' />
////interface IFoo {
//// a: 'string';
//// c: { d: 'string'; };
////}
////class Foo implements IFoo {}
verify.codeFix({
description: [ts.Diagnostics.Implement_interface_0.message, "IFoo"],
newFileContent:
`interface IFoo {
a: 'string';
c: { d: 'string'; };
}
class Foo implements IFoo {
a: 'string';
c: { d: 'string'; };
}`,
preferences: { quotePreference: "single" }
});