Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(fix) ignore error about transition third argument #2139

Merged
merged 1 commit into from
Aug 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 }} />