Skip to content

Commit 946cf63

Browse files
committed
classify jsx text and jsx attribute values
1 parent 5313928 commit 946cf63

1 file changed

Lines changed: 11 additions & 6 deletions

File tree

src/services/services.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1640,7 +1640,9 @@ namespace ts {
16401640
jsxOpenTagName = 19,
16411641
jsxCloseTagName = 20,
16421642
jsxSelfClosingTagName = 21,
1643-
jsxAttribute = 22
1643+
jsxAttribute = 22,
1644+
jsxText = 23,
1645+
jsxAttributeStringValue = 24,
16441646
}
16451647

16461648
/// Language Service
@@ -6783,12 +6785,12 @@ namespace ts {
67836785
}
67846786
}
67856787

6786-
function classifyToken(token: Node): void {
6788+
function classifyTokenOrJsxText(token: Node): void {
67876789
if (nodeIsMissing(token)) {
67886790
return;
67896791
}
67906792

6791-
const tokenStart = classifyLeadingTriviaAndGetTokenStart(token);
6793+
const tokenStart = token.kind === SyntaxKind.JsxText ? token.pos : classifyLeadingTriviaAndGetTokenStart(token);
67926794

67936795
const tokenWidth = token.end - tokenStart;
67946796
Debug.assert(tokenWidth >= 0);
@@ -6843,7 +6845,7 @@ namespace ts {
68436845
return ClassificationType.numericLiteral;
68446846
}
68456847
else if (tokenKind === SyntaxKind.StringLiteral || tokenKind === SyntaxKind.StringLiteralType) {
6846-
return ClassificationType.stringLiteral;
6848+
return token.parent.kind === SyntaxKind.JsxAttribute ? ClassificationType.jsxAttributeStringValue : ClassificationType.stringLiteral;
68476849
}
68486850
else if (tokenKind === SyntaxKind.RegularExpressionLiteral) {
68496851
// TODO: we should get another classification type for these literals.
@@ -6853,6 +6855,9 @@ namespace ts {
68536855
// TODO (drosen): we should *also* get another classification type for these literals.
68546856
return ClassificationType.stringLiteral;
68556857
}
6858+
else if (tokenKind === SyntaxKind.JsxText) {
6859+
return ClassificationType.jsxText;
6860+
}
68566861
else if (tokenKind === SyntaxKind.Identifier) {
68576862
if (token) {
68586863
switch (token.parent.kind) {
@@ -6926,8 +6931,8 @@ namespace ts {
69266931
const children = element.getChildren(sourceFile);
69276932
for (let i = 0, n = children.length; i < n; i++) {
69286933
const child = children[i];
6929-
if (isToken(child)) {
6930-
classifyToken(child);
6934+
if (isToken(child) || child.kind === SyntaxKind.JsxText) {
6935+
classifyTokenOrJsxText(child);
69316936
}
69326937
else {
69336938
// Recurse into our child nodes.

0 commit comments

Comments
 (0)