mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-06-10 18:04:18 -05:00
fix(19385): add space after brace in the multiline string template (#38742)
This commit is contained in:
@@ -279,9 +279,9 @@ namespace ts.formatting {
|
||||
rule("NoSpaceBetweenEmptyBraceBrackets", SyntaxKind.OpenBraceToken, SyntaxKind.CloseBraceToken, [isOptionDisabled("insertSpaceAfterOpeningAndBeforeClosingEmptyBraces"), isNonJsxSameLineTokenContext], RuleAction.DeleteSpace),
|
||||
|
||||
// Insert space after opening and before closing template string braces
|
||||
rule("SpaceAfterTemplateHeadAndMiddle", [SyntaxKind.TemplateHead, SyntaxKind.TemplateMiddle], anyToken, [isOptionEnabled("insertSpaceAfterOpeningAndBeforeClosingTemplateStringBraces"), isNonJsxSameLineTokenContext], RuleAction.InsertSpace),
|
||||
rule("SpaceAfterTemplateHeadAndMiddle", [SyntaxKind.TemplateHead, SyntaxKind.TemplateMiddle], anyToken, [isOptionEnabled("insertSpaceAfterOpeningAndBeforeClosingTemplateStringBraces"), isNonJsxTextContext], RuleAction.InsertSpace, RuleFlags.CanDeleteNewLines),
|
||||
rule("SpaceBeforeTemplateMiddleAndTail", anyToken, [SyntaxKind.TemplateMiddle, SyntaxKind.TemplateTail], [isOptionEnabled("insertSpaceAfterOpeningAndBeforeClosingTemplateStringBraces"), isNonJsxSameLineTokenContext], RuleAction.InsertSpace),
|
||||
rule("NoSpaceAfterTemplateHeadAndMiddle", [SyntaxKind.TemplateHead, SyntaxKind.TemplateMiddle], anyToken, [isOptionDisabledOrUndefined("insertSpaceAfterOpeningAndBeforeClosingTemplateStringBraces"), isNonJsxSameLineTokenContext], RuleAction.DeleteSpace),
|
||||
rule("NoSpaceAfterTemplateHeadAndMiddle", [SyntaxKind.TemplateHead, SyntaxKind.TemplateMiddle], anyToken, [isOptionDisabledOrUndefined("insertSpaceAfterOpeningAndBeforeClosingTemplateStringBraces"), isNonJsxTextContext], RuleAction.DeleteSpace, RuleFlags.CanDeleteNewLines),
|
||||
rule("NoSpaceBeforeTemplateMiddleAndTail", anyToken, [SyntaxKind.TemplateMiddle, SyntaxKind.TemplateTail], [isOptionDisabledOrUndefined("insertSpaceAfterOpeningAndBeforeClosingTemplateStringBraces"), isNonJsxSameLineTokenContext], RuleAction.DeleteSpace),
|
||||
|
||||
// No space after { and before } in JSX expression
|
||||
@@ -690,6 +690,10 @@ namespace ts.formatting {
|
||||
return context.TokensAreOnSameLine() && context.contextNode.kind !== SyntaxKind.JsxText;
|
||||
}
|
||||
|
||||
function isNonJsxTextContext(context: FormattingContext): boolean {
|
||||
return context.contextNode.kind !== SyntaxKind.JsxText;
|
||||
}
|
||||
|
||||
function isNonJsxElementOrFragmentContext(context: FormattingContext): boolean {
|
||||
return context.contextNode.kind !== SyntaxKind.JsxElement && context.contextNode.kind !== SyntaxKind.JsxFragment;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
////const a1 = `${ 1 }${ 1 }`;
|
||||
////const a2 = `
|
||||
//// ${ 1 }${ 1 }
|
||||
////`;
|
||||
////const a3 = `
|
||||
////
|
||||
////
|
||||
//// ${ 1 }${ 1 }
|
||||
////`;
|
||||
////const a4 = `
|
||||
////
|
||||
//// ${ 1 }${ 1 }
|
||||
////
|
||||
////`;
|
||||
////const a5 = `text ${ 1 } text ${ 1 } text`;
|
||||
////const a6 = `
|
||||
//// text ${ 1 }
|
||||
//// text ${ 1 }
|
||||
//// text
|
||||
////`;
|
||||
|
||||
format.setOption("insertSpaceAfterOpeningAndBeforeClosingTemplateStringBraces", false);
|
||||
format.document();
|
||||
verify.currentFileContentIs(
|
||||
"const a1 = `${1}${1}`;\n" +
|
||||
|
||||
"const a2 = `\n" +
|
||||
" ${1}${1}\n" +
|
||||
"`;\n" +
|
||||
|
||||
"const a3 = `\n" +
|
||||
"\n" +
|
||||
"\n" +
|
||||
" ${1}${1}\n" +
|
||||
"`;\n" +
|
||||
|
||||
"const a4 = `\n" +
|
||||
"\n" +
|
||||
" ${1}${1}\n" +
|
||||
"\n" +
|
||||
"`;\n" +
|
||||
|
||||
"const a5 = `text ${1} text ${1} text`;\n" +
|
||||
|
||||
"const a6 = `\n" +
|
||||
" text ${1}\n" +
|
||||
" text ${1}\n" +
|
||||
" text\n" +
|
||||
"`;"
|
||||
);
|
||||
@@ -0,0 +1,52 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
////const a1 = `${1}${1}`;
|
||||
////const a2 = `
|
||||
//// ${1}${1}
|
||||
////`;
|
||||
////const a3 = `
|
||||
////
|
||||
////
|
||||
//// ${1}${1}
|
||||
////`;
|
||||
////const a4 = `
|
||||
////
|
||||
//// ${1}${1}
|
||||
////
|
||||
////`;
|
||||
////const a5 = `text ${1} text ${1} text`;
|
||||
////const a6 = `
|
||||
//// text ${1}
|
||||
//// text ${1}
|
||||
//// text
|
||||
////`;
|
||||
|
||||
format.setOption("insertSpaceAfterOpeningAndBeforeClosingTemplateStringBraces", true);
|
||||
format.document();
|
||||
verify.currentFileContentIs(
|
||||
"const a1 = `${ 1 }${ 1 }`;\n" +
|
||||
|
||||
"const a2 = `\n" +
|
||||
" ${ 1 }${ 1 }\n" +
|
||||
"`;\n" +
|
||||
|
||||
"const a3 = `\n" +
|
||||
"\n" +
|
||||
"\n" +
|
||||
" ${ 1 }${ 1 }\n" +
|
||||
"`;\n" +
|
||||
|
||||
"const a4 = `\n" +
|
||||
"\n" +
|
||||
" ${ 1 }${ 1 }\n" +
|
||||
"\n" +
|
||||
"`;\n" +
|
||||
|
||||
"const a5 = `text ${ 1 } text ${ 1 } text`;\n" +
|
||||
|
||||
"const a6 = `\n" +
|
||||
" text ${ 1 }\n" +
|
||||
" text ${ 1 }\n" +
|
||||
" text\n" +
|
||||
"`;"
|
||||
);
|
||||
Reference in New Issue
Block a user