Skip to content

Commit

Permalink
(fix) ignore error about transition third argument (#2139)
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonlyu123 committed Aug 26, 2023
1 parent 2bbc673 commit c80a020
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ export enum DiagnosticCode {
MISSING_PROPS = 2739, // "Type '...' is missing the following properties from type '..': ..."
MISSING_PROP = 2741, // "Property '..' is missing in type '..' but required in type '..'."
NO_OVERLOAD_MATCHES_CALL = 2769, // "No overload matches this call"
CANNOT_FIND_NAME = 2304 // "Cannot find name 'xxx'"
CANNOT_FIND_NAME = 2304, // "Cannot find name 'xxx'"
EXPECTED_N_ARGUMENTS = 2554 // Expected {0} arguments, but got {1}.
}

export class DiagnosticsProviderImpl implements DiagnosticsProvider {
Expand Down Expand Up @@ -117,7 +118,11 @@ export class DiagnosticsProviderImpl implements DiagnosticsProvider {
}
diagnostics.push(...additionalStoreDiagnostics);

diagnostics = diagnostics.filter(notGenerated).filter(not(isUnusedReactiveStatementLabel));
diagnostics = diagnostics
.filter(notGenerated)
.filter(not(isUnusedReactiveStatementLabel))
.filter((diagnostics) => !expectedTransitionThirdArgument(diagnostics, tsDoc, lang));

diagnostics = resolveNoopsInReactiveStatements(lang, diagnostics);

return diagnostics
Expand Down Expand Up @@ -499,3 +504,35 @@ function movePropsErrorRangeBackIfNecessary(
});
}
}

function expectedTransitionThirdArgument(
diagnostic: ts.Diagnostic,
tsDoc: SvelteDocumentSnapshot,
lang: ts.LanguageService
) {
if (
diagnostic.code !== DiagnosticCode.EXPECTED_N_ARGUMENTS ||
!diagnostic.start ||
!tsDoc.getText(0, diagnostic.start).endsWith('__sveltets_2_ensureTransition(')
) {
return false;
}

const node = findDiagnosticNode(diagnostic);
if (!node) {
return false;
}

const callExpression = findNodeAtSpan(
node,
{ start: node.getStart(), length: node.getWidth() },
ts.isCallExpression
);
const signature =
callExpression && lang.getProgram()?.getTypeChecker().getResolvedSignature(callExpression);

return (
signature?.parameters.filter((parameter) => !(parameter.flags & ts.SymbolFlags.Optional))
.length === 3
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<script lang="ts">
function myTransition(
_node: HTMLElement,
_params: { delay: number },
_context: { direction: 'in' | 'out' | 'both' }
) {
return {};
}
</script>

<div in:myTransition={{ delay: 100 }} />

0 comments on commit c80a020

Please sign in to comment.