Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 4d2aa9b

Browse filesBrowse files
author
Andy
authored
Fix formatting when keyword is parsed as part of a JSX identifier (e.g. module-layout) (microsoft#18598)
1 parent 7dec4ae commit 4d2aa9b
Copy full SHA for 4d2aa9b

2 files changed

+12-2Lines changed: 12 additions & 2 deletions

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎src/services/formatting/formattingScanner.ts‎

Copy file name to clipboardExpand all lines: src/services/formatting/formattingScanner.ts
+3-2Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,8 @@ namespace ts.formatting {
125125
case SyntaxKind.JsxOpeningElement:
126126
case SyntaxKind.JsxClosingElement:
127127
case SyntaxKind.JsxSelfClosingElement:
128-
return node.kind === SyntaxKind.Identifier;
128+
// May parse an identifier like `module-layout`; that will be scanned as a keyword at first, but we should parse the whole thing to get an identifier.
129+
return isKeyword(node.kind) || node.kind === SyntaxKind.Identifier;
129130
}
130131
}
131132

@@ -209,7 +210,7 @@ namespace ts.formatting {
209210
currentToken = scanner.reScanTemplateToken();
210211
lastScanAction = ScanAction.RescanTemplateToken;
211212
}
212-
else if (expectedScanAction === ScanAction.RescanJsxIdentifier && currentToken === SyntaxKind.Identifier) {
213+
else if (expectedScanAction === ScanAction.RescanJsxIdentifier) {
213214
currentToken = scanner.scanJsxIdentifier();
214215
lastScanAction = ScanAction.RescanJsxIdentifier;
215216
}
Collapse file
+9Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/// <reference path='fourslash.ts' />
2+
3+
// Test that we don't crash when encountering a keyword in a JSX identifier.
4+
5+
// @Filename: /a.tsx
6+
////<div module-layout=""></div>
7+
8+
format.document();
9+
verify.currentFileContentIs(`<div module-layout=""></div>`);

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.