Skip to content

Commit

Permalink
fix(language-core): avoid unchecked index access when parsing `define…
Browse files Browse the repository at this point in the history
…Emits` (#5028)
  • Loading branch information
KazariEX authored Dec 5, 2024
1 parent 31d1484 commit 21fa760
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
14 changes: 9 additions & 5 deletions packages/language-core/lib/parsers/scriptSetupRanges.ts
Original file line number Diff line number Diff line change
Expand Up @@ -306,11 +306,14 @@ export function parseScriptSetupRanges(
if (ts.isVariableDeclaration(parent)) {
emits.name = getNodeText(ts, parent.name, ast);
}
if (node.typeArguments?.length && ts.isTypeLiteralNode(node.typeArguments[0]) && node.typeArguments[0].members.at(0)) {
if (node.typeArguments?.length && ts.isTypeLiteralNode(node.typeArguments[0])) {
for (const member of node.typeArguments[0].members) {
if (ts.isCallSignatureDeclaration(member) && member.parameters[0].type && ts.isUnionTypeNode(member.parameters[0].type)) {
emits.define.hasUnionTypeArg = true;
return;
if (ts.isCallSignatureDeclaration(member)) {
const type = member.parameters[0]?.type;
if (type && ts.isUnionTypeNode(type)) {
emits.define.hasUnionTypeArg = true;
break;
}
}
}
}
Expand Down Expand Up @@ -377,7 +380,8 @@ export function parseScriptSetupRanges(
}
}
}
} else if (vueCompilerOptions.composibles.useTemplateRef.includes(callText) && node.arguments.length && !node.typeArguments?.length) {
}
else if (vueCompilerOptions.composibles.useTemplateRef.includes(callText) && node.arguments.length && !node.typeArguments?.length) {
const define = parseDefineFunction(node);
let name;
if (ts.isVariableDeclaration(parent)) {
Expand Down
4 changes: 4 additions & 0 deletions test-workspace/tsc/passedFixtures/vue3/#5027/main.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<script setup lang="ts">
// @ts-expect-error
defineEmits<{()}>();
</script>

0 comments on commit 21fa760

Please sign in to comment.