mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-12-11 09:24:19 -06:00
Use jsx language variant for jsx file scanning in getChildren (#61928)
This commit is contained in:
parent
f3a6d3165f
commit
02672d281c
@ -4288,6 +4288,7 @@ export interface SourceFileLike {
|
||||
lineMap?: readonly number[];
|
||||
/** @internal */
|
||||
getPositionOfLineAndCharacter?(line: number, character: number, allowEdits?: true): number;
|
||||
languageVariant?: LanguageVariant;
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
|
||||
@ -1595,7 +1595,7 @@ function getJsxClosingTagCompletion(location: Node | undefined, sourceFile: Sour
|
||||
switch (node.kind) {
|
||||
case SyntaxKind.JsxClosingElement:
|
||||
return true;
|
||||
case SyntaxKind.SlashToken:
|
||||
case SyntaxKind.LessThanSlashToken:
|
||||
case SyntaxKind.GreaterThanToken:
|
||||
case SyntaxKind.Identifier:
|
||||
case SyntaxKind.PropertyAccessExpression:
|
||||
@ -3508,7 +3508,7 @@ function getCompletionData(
|
||||
}
|
||||
break;
|
||||
|
||||
case SyntaxKind.SlashToken:
|
||||
case SyntaxKind.LessThanSlashToken:
|
||||
if (currentToken.parent.kind === SyntaxKind.JsxSelfClosingElement) {
|
||||
location = currentToken;
|
||||
}
|
||||
@ -3518,7 +3518,7 @@ function getCompletionData(
|
||||
|
||||
switch (parent.kind) {
|
||||
case SyntaxKind.JsxClosingElement:
|
||||
if (contextToken.kind === SyntaxKind.SlashToken) {
|
||||
if (contextToken.kind === SyntaxKind.LessThanSlashToken) {
|
||||
isStartingCloseTag = true;
|
||||
location = contextToken;
|
||||
}
|
||||
@ -5805,7 +5805,7 @@ function isValidTrigger(sourceFile: SourceFile, triggerCharacter: CompletionsTri
|
||||
case "/":
|
||||
return !!contextToken && (isStringLiteralLike(contextToken)
|
||||
? !!tryGetImportFromModuleSpecifier(contextToken)
|
||||
: contextToken.kind === SyntaxKind.SlashToken && isJsxClosingElement(contextToken.parent));
|
||||
: contextToken.kind === SyntaxKind.LessThanSlashToken && isJsxClosingElement(contextToken.parent));
|
||||
case " ":
|
||||
return !!contextToken && isImportKeyword(contextToken) && contextToken.parent.kind === SyntaxKind.SourceFile;
|
||||
default:
|
||||
|
||||
@ -504,8 +504,9 @@ function createChildren(node: Node, sourceFile: SourceFileLike | undefined): rea
|
||||
});
|
||||
return children;
|
||||
}
|
||||
|
||||
const languageVariant = sourceFile?.languageVariant ?? LanguageVariant.Standard;
|
||||
scanner.setText((sourceFile || node.getSourceFile()).text);
|
||||
scanner.setLanguageVariant(languageVariant);
|
||||
let pos = node.pos;
|
||||
const processNode = (child: Node) => {
|
||||
addSyntheticNodes(children, pos, child.pos, node);
|
||||
@ -526,6 +527,7 @@ function createChildren(node: Node, sourceFile: SourceFileLike | undefined): rea
|
||||
node.forEachChild(processNode, processNodes);
|
||||
addSyntheticNodes(children, pos, node.end, node);
|
||||
scanner.setText(undefined);
|
||||
scanner.setLanguageVariant(LanguageVariant.Standard);
|
||||
return children;
|
||||
}
|
||||
|
||||
|
||||
@ -1889,7 +1889,7 @@ export function isInsideJsxElementOrAttribute(sourceFile: SourceFile, position:
|
||||
}
|
||||
|
||||
// <div>|</div>
|
||||
if (token.kind === SyntaxKind.LessThanToken && token.parent.kind === SyntaxKind.JsxClosingElement) {
|
||||
if (token.kind === SyntaxKind.LessThanSlashToken && token.parent.kind === SyntaxKind.JsxClosingElement) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -1934,6 +1934,7 @@ export function isInsideJsxElement(sourceFile: SourceFile, position: number): bo
|
||||
|| node.kind === SyntaxKind.CloseBraceToken
|
||||
|| node.kind === SyntaxKind.OpenBraceToken
|
||||
|| node.kind === SyntaxKind.SlashToken
|
||||
|| node.kind === SyntaxKind.LessThanSlashToken
|
||||
) {
|
||||
node = node.parent;
|
||||
}
|
||||
|
||||
@ -5907,6 +5907,7 @@ declare namespace ts {
|
||||
*/
|
||||
interface SourceFileLike {
|
||||
readonly text: string;
|
||||
languageVariant?: LanguageVariant;
|
||||
}
|
||||
interface SourceFileLike {
|
||||
getLineAndCharacterOfPosition(pos: number): LineAndCharacter;
|
||||
|
||||
@ -18,7 +18,7 @@ verify.syntacticClassificationsAre(
|
||||
c.jsxText(`
|
||||
some jsx text
|
||||
`),
|
||||
c.punctuation("<"), c.punctuation("/"), c.jsxCloseTagName("div"), c.punctuation(">"), c.punctuation(";"),
|
||||
c.punctuation("</"), c.jsxCloseTagName("div"), c.punctuation(">"), c.punctuation(";"),
|
||||
c.keyword("let"), c.identifier("y"), c.operator("="),
|
||||
c.punctuation("<"),
|
||||
c.jsxSelfClosingTagName("element"),
|
||||
@ -26,8 +26,8 @@ verify.syntacticClassificationsAre(
|
||||
c.punctuation("/"), c.punctuation(">")
|
||||
)
|
||||
|
||||
const c2 = classification("2020");
|
||||
verify.semanticClassificationsAre("2020",
|
||||
c2.semanticToken("variable.declaration", "x"),
|
||||
c2.semanticToken("variable.declaration", "y"),
|
||||
const c2 = classification("2020");
|
||||
verify.semanticClassificationsAre("2020",
|
||||
c2.semanticToken("variable.declaration", "x"),
|
||||
c2.semanticToken("variable.declaration", "y"),
|
||||
);
|
||||
|
||||
@ -18,7 +18,7 @@ verify.syntacticClassificationsAre(
|
||||
c.jsxText(`
|
||||
some jsx text
|
||||
`),
|
||||
c.punctuation("<"), c.punctuation("/"), c.jsxCloseTagName("div.name"), c.punctuation(">"), c.punctuation(";"),
|
||||
c.punctuation("</"), c.jsxCloseTagName("div.name"), c.punctuation(">"), c.punctuation(";"),
|
||||
c.keyword("let"), c.identifier("y"), c.operator("="),
|
||||
c.punctuation("<"),
|
||||
c.jsxSelfClosingTagName("element.name"),
|
||||
@ -26,8 +26,8 @@ verify.syntacticClassificationsAre(
|
||||
c.punctuation("/"), c.punctuation(">")
|
||||
)
|
||||
|
||||
const c2 = classification("2020");
|
||||
verify.semanticClassificationsAre("2020",
|
||||
c2.semanticToken("variable.declaration", "x"),
|
||||
c2.semanticToken("variable.declaration", "y"),
|
||||
const c2 = classification("2020");
|
||||
verify.semanticClassificationsAre("2020",
|
||||
c2.semanticToken("variable.declaration", "x"),
|
||||
c2.semanticToken("variable.declaration", "y"),
|
||||
);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user