From 88809467e8761e71483e2f4948ef411d8e447188 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Burzy=C5=84ski?= Date: Fri, 20 Sep 2024 00:59:36 +0200 Subject: [PATCH] Fixed a crash when trying to find references on `NoSubstitutionTemplateLiteral` with `LiteralType` parent (#59889) --- src/compiler/utilities.ts | 4 +++- ...tionTemplateLiteralNoCrash1.baseline.jsonc | 23 +++++++++++++++++++ ...fsNoSubstitutionTemplateLiteralNoCrash1.ts | 5 ++++ 3 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 tests/baselines/reference/findAllRefsNoSubstitutionTemplateLiteralNoCrash1.baseline.jsonc create mode 100644 tests/cases/fourslash/findAllRefsNoSubstitutionTemplateLiteralNoCrash1.ts diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index c7ade289737ca..285d3156106a5 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -4227,7 +4227,9 @@ export function tryGetImportFromModuleSpecifier(node: StringLiteralLike): AnyVal case SyntaxKind.CallExpression: return isImportCall(node.parent) || isRequireCall(node.parent, /*requireStringLiteralLikeArgument*/ false) ? node.parent as RequireOrImportCall : undefined; case SyntaxKind.LiteralType: - Debug.assert(isStringLiteral(node)); + if (!isStringLiteral(node)) { + break; + } return tryCast(node.parent.parent, isImportTypeNode) as ValidImportTypeNode | undefined; default: return undefined; diff --git a/tests/baselines/reference/findAllRefsNoSubstitutionTemplateLiteralNoCrash1.baseline.jsonc b/tests/baselines/reference/findAllRefsNoSubstitutionTemplateLiteralNoCrash1.baseline.jsonc new file mode 100644 index 0000000000000..170a75d22a350 --- /dev/null +++ b/tests/baselines/reference/findAllRefsNoSubstitutionTemplateLiteralNoCrash1.baseline.jsonc @@ -0,0 +1,23 @@ +// === findAllReferences === +// === /tests/cases/fourslash/findAllRefsNoSubstitutionTemplateLiteralNoCrash1.ts === +// type Test = `[|{| isInString: true |}T|]/*FIND ALL REFS*/`; + + // === Definitions === + // === /tests/cases/fourslash/findAllRefsNoSubstitutionTemplateLiteralNoCrash1.ts === + // type Test = `[|T|]/*FIND ALL REFS*/`; + + // === Details === + [ + { + "containerKind": "", + "containerName": "", + "kind": "var", + "name": "T", + "displayParts": [ + { + "text": "`T`", + "kind": "stringLiteral" + } + ] + } + ] \ No newline at end of file diff --git a/tests/cases/fourslash/findAllRefsNoSubstitutionTemplateLiteralNoCrash1.ts b/tests/cases/fourslash/findAllRefsNoSubstitutionTemplateLiteralNoCrash1.ts new file mode 100644 index 0000000000000..e56f41ab80510 --- /dev/null +++ b/tests/cases/fourslash/findAllRefsNoSubstitutionTemplateLiteralNoCrash1.ts @@ -0,0 +1,5 @@ +/// + +//// type Test = `T/*1*/`; + +verify.baselineFindAllReferences('1');