diff --git a/tsc/internal/format/indent.go b/tsc/internal/format/indent.go index f440423b64397..b98fd95ff21d0 100644 --- a/tsc/internal/format/indent.go +++ b/tsc/internal/format/indent.go @@ -486,7 +486,7 @@ func findFirstNonWhitespaceCharacterAndColumn(startPos int, endPos int, sourceFi if ch == '\t' { if options.TabSize > 0 { - column += options.TabSize + (column % options.TabSize) + column += options.TabSize - (column % options.TabSize) } } else { column++ diff --git a/tsc/internal/format/span.go b/tsc/internal/format/span.go index df9d11119b2cb..d5b37160d4d49 100644 --- a/tsc/internal/format/span.go +++ b/tsc/internal/format/span.go @@ -1227,7 +1227,7 @@ func getFirstNonDecoratorTokenOfNode(node *ast.Node) ast.Kind { case ast.KindFunctionDeclaration: return ast.KindFunctionKeyword case ast.KindEnumDeclaration: - return ast.KindEnumDeclaration + return ast.KindEnumKeyword case ast.KindGetAccessor: return ast.KindGetKeyword case ast.KindSetAccessor: diff --git a/tsc/internal/fourslash/tests/formattingDecorators_test.go b/tsc/internal/fourslash/tests/formattingDecorators_test.go index f7e3839fa08d4..0155373b71f9c 100644 --- a/tsc/internal/fourslash/tests/formattingDecorators_test.go +++ b/tsc/internal/fourslash/tests/formattingDecorators_test.go @@ -7,6 +7,20 @@ import ( "github.com/microsoft/TypeScript/tsc/internal/testutil" ) +func TestFormattingDecoratedEnum(t *testing.T) { + t.Parallel() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + // Preserve alignment while editing an enum with an invalid decorator. + const content = `@decorator +enum E { + A +}` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.FormatDocument(t, "") + f.VerifyCurrentFileContent(t, content) +} + func TestFormattingDecorators(t *testing.T) { t.Parallel() defer testutil.RecoverAndFail(t, "Panic on fourslash test") diff --git a/tsc/internal/fourslash/tests/formattingMultilineCommentsWithTabs1_test.go b/tsc/internal/fourslash/tests/formattingMultilineCommentsWithTabs1_test.go index 18ce87bf55b90..c391282c4c193 100644 --- a/tsc/internal/fourslash/tests/formattingMultilineCommentsWithTabs1_test.go +++ b/tsc/internal/fourslash/tests/formattingMultilineCommentsWithTabs1_test.go @@ -7,6 +7,16 @@ import ( "github.com/microsoft/TypeScript/tsc/internal/testutil" ) +func TestFormattingMultilineCommentWithMixedIndentation(t *testing.T) { + t.Parallel() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = "function f() {\n \t/* comment\n * continuation\n */\n}" + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.FormatDocument(t, "") + f.VerifyCurrentFileContent(t, "function f() {\n /* comment\n * continuation\n */\n}") +} + func TestFormattingMultilineCommentsWithTabs1(t *testing.T) { t.Parallel() defer testutil.RecoverAndFail(t, "Panic on fourslash test")