classify jsx text and jsx attribute values
This commit is contained in:
parent
5313928112
commit
946cf63a38
1 changed files with 11 additions and 6 deletions
|
@ -1640,7 +1640,9 @@ namespace ts {
|
||||||
jsxOpenTagName = 19,
|
jsxOpenTagName = 19,
|
||||||
jsxCloseTagName = 20,
|
jsxCloseTagName = 20,
|
||||||
jsxSelfClosingTagName = 21,
|
jsxSelfClosingTagName = 21,
|
||||||
jsxAttribute = 22
|
jsxAttribute = 22,
|
||||||
|
jsxText = 23,
|
||||||
|
jsxAttributeStringValue = 24,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Language Service
|
/// Language Service
|
||||||
|
@ -6783,12 +6785,12 @@ namespace ts {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function classifyToken(token: Node): void {
|
function classifyTokenOrJsxText(token: Node): void {
|
||||||
if (nodeIsMissing(token)) {
|
if (nodeIsMissing(token)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const tokenStart = classifyLeadingTriviaAndGetTokenStart(token);
|
const tokenStart = token.kind === SyntaxKind.JsxText ? token.pos : classifyLeadingTriviaAndGetTokenStart(token);
|
||||||
|
|
||||||
const tokenWidth = token.end - tokenStart;
|
const tokenWidth = token.end - tokenStart;
|
||||||
Debug.assert(tokenWidth >= 0);
|
Debug.assert(tokenWidth >= 0);
|
||||||
|
@ -6843,7 +6845,7 @@ namespace ts {
|
||||||
return ClassificationType.numericLiteral;
|
return ClassificationType.numericLiteral;
|
||||||
}
|
}
|
||||||
else if (tokenKind === SyntaxKind.StringLiteral || tokenKind === SyntaxKind.StringLiteralType) {
|
else if (tokenKind === SyntaxKind.StringLiteral || tokenKind === SyntaxKind.StringLiteralType) {
|
||||||
return ClassificationType.stringLiteral;
|
return token.parent.kind === SyntaxKind.JsxAttribute ? ClassificationType.jsxAttributeStringValue : ClassificationType.stringLiteral;
|
||||||
}
|
}
|
||||||
else if (tokenKind === SyntaxKind.RegularExpressionLiteral) {
|
else if (tokenKind === SyntaxKind.RegularExpressionLiteral) {
|
||||||
// TODO: we should get another classification type for these literals.
|
// TODO: we should get another classification type for these literals.
|
||||||
|
@ -6853,6 +6855,9 @@ namespace ts {
|
||||||
// TODO (drosen): we should *also* get another classification type for these literals.
|
// TODO (drosen): we should *also* get another classification type for these literals.
|
||||||
return ClassificationType.stringLiteral;
|
return ClassificationType.stringLiteral;
|
||||||
}
|
}
|
||||||
|
else if (tokenKind === SyntaxKind.JsxText) {
|
||||||
|
return ClassificationType.jsxText;
|
||||||
|
}
|
||||||
else if (tokenKind === SyntaxKind.Identifier) {
|
else if (tokenKind === SyntaxKind.Identifier) {
|
||||||
if (token) {
|
if (token) {
|
||||||
switch (token.parent.kind) {
|
switch (token.parent.kind) {
|
||||||
|
@ -6926,8 +6931,8 @@ namespace ts {
|
||||||
const children = element.getChildren(sourceFile);
|
const children = element.getChildren(sourceFile);
|
||||||
for (let i = 0, n = children.length; i < n; i++) {
|
for (let i = 0, n = children.length; i < n; i++) {
|
||||||
const child = children[i];
|
const child = children[i];
|
||||||
if (isToken(child)) {
|
if (isToken(child) || child.kind === SyntaxKind.JsxText) {
|
||||||
classifyToken(child);
|
classifyTokenOrJsxText(child);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// Recurse into our child nodes.
|
// Recurse into our child nodes.
|
||||||
|
|
Loading…
Reference in a new issue