Skip to content

Commit

Permalink
chore: bump magic-string (#2476)
Browse files Browse the repository at this point in the history
requires adjustments of mapping tests and a fix in the InlayHintProvider, because more things are mappable now
  • Loading branch information
dummdidumm authored Aug 27, 2024
1 parent 6a05963 commit ec5fef4
Show file tree
Hide file tree
Showing 16 changed files with 503 additions and 179 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import ts from 'typescript';
import ts, { ArrowFunction } from 'typescript';
import { CancellationToken } from 'vscode-languageserver';
import {
Position,
Expand Down Expand Up @@ -69,6 +69,7 @@ export class InlayHintProviderImpl implements InlayHintProvider {
inlayHint.position !== renderFunctionReturnTypeLocation &&
!this.isSvelte2tsxFunctionHints(sourceFile, inlayHint) &&
!this.isGeneratedVariableTypeHint(sourceFile, inlayHint) &&
!this.isGeneratedAsyncFunctionReturnType(sourceFile, inlayHint) &&
!this.isGeneratedFunctionReturnType(sourceFile, inlayHint)
)
.map(async (inlayHint) => ({
Expand Down Expand Up @@ -254,6 +255,29 @@ export class InlayHintProviderImpl implements InlayHintProvider {
);
}

/** `true` if is one of the `async () => {...}` functions svelte2tsx generates */
private isGeneratedAsyncFunctionReturnType(sourceFile: ts.SourceFile, inlayHint: ts.InlayHint) {
if (inlayHint.kind !== ts.InlayHintKind.Type) {
return false;
}

const expression = findContainingNode(
sourceFile,
{ start: inlayHint.position, length: 0 },
(node): node is ArrowFunction => ts.isArrowFunction(node)
);

if (
!expression?.modifiers?.some((m) => m.kind === ts.SyntaxKind.AsyncKeyword) ||
!expression.parent?.parent ||
!ts.isBlock(expression.parent.parent)
) {
return false;
}

return this.getTypeAnnotationPosition(expression) === inlayHint.position;
}

private isGeneratedFunctionReturnType(sourceFile: ts.SourceFile, inlayHint: ts.InlayHint) {
if (inlayHint.kind !== ts.InlayHintKind.Type) {
return false;
Expand Down
2 changes: 1 addition & 1 deletion packages/svelte2tsx/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"@types/vfile": "^3.0.2",
"builtin-modules": "^3.3.0",
"estree-walker": "^2.0.1",
"magic-string": "^0.27.0",
"magic-string": "^0.30.11",
"mocha": "^9.2.0",
"periscopic": "^2.0.2",
"rollup": "3.7.5",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@ async•()•=>•{•{const•$$action_0•=•__sveltets_2_ensureAction(action
< action/ element su ↲
#================================================================== # Order-breaking mappings
<element us action/ ↲
<element•use:action/>↲ [original] line 1
<element•use:action/>↲ [original] line 1 (rest generated at line 4)
------------------------------------------------------------------------------------------------------------------------------------------------------ */}
{/**
↲ [generated] line 4
<element•use:action/>↲ [original] line 1 (rest generated at line 3)
------------------------------------------------------------------------------------------------------------------------------------------------------ */}
{const $$action_0 = __sveltets_2_ensureAction(action(svelteHTML.mapElementTag('element')));{ svelteHTML.createElement("element", __sveltets_2_union($$action_0), { });}}{/**
•{const•$$action_0•=•__sveltets_2_ensureAction(action(svelteHTML.mapElementTag('element')));{•svelteHTML.createElement("element",•__sveltets_2_union($$action_0),•{••});}}↲ [generated] line 5
Expand All @@ -30,27 +32,31 @@ async•()•=>•{•{const•$$action_0•=•__sveltets_2_ensureAction(action
• ↲ [generated] subset
/ ↲
/ ↲
/>↲ [original] line 5
/>↲ [original] line 5 (rest generated at line 6)
------------------------------------------------------------------------------------------------------------------------------------------------------ */}
{/**
↲ [generated] line 6
/>↲ [original] line 5 (rest generated at line 5)
------------------------------------------------------------------------------------------------------------------------------------------------------ */}
{const $$action_0 = __sveltets_2_ensureAction(action.nested.method(svelteHTML.mapElementTag('element'),(foo)));{ svelteHTML.createElement("element", __sveltets_2_union($$action_0), { });}}{/**
••{const•$$action_0•=•__sveltets_2_ensureAction(action.nested.method(svelteHTML.mapElementTag('element'),(foo)));{•svelteHTML.createElement("element",•__sveltets_2_union($$action_0),•{••});}}↲ [generated] line 7
<> action.nested.method= foo} element s{u ↲
#============================================== #=============================== # Order-breaking mappings
<element us action.nested.method={foo} >↲
<element•use:action.nested.method={foo}/>↲ [original] line 7
<element•use:action.nested.method={foo}/>↲ [original] line 7 (rest generated at line 8)
------------------------------------------------------------------------------------------------------------------------------------------------------ */}
{/**
↲ [generated] line 8
<element•use:action.nested.method={foo}/>↲ [original] line 7 (rest generated at line 7)
------------------------------------------------------------------------------------------------------------------------------------------------------ */}
{const $$action_0 = __sveltets_2_ensureAction(action(svelteHTML.mapElementTag('element'),($foo)));{ svelteHTML.createElement("element", __sveltets_2_union($$action_0), { });}}{/**
•{const•$$action_0•=•__sveltets_2_ensureAction(action(svelteHTML.mapElementTag('element'),($foo)));{•svelteHTML.createElement("element",•__sveltets_2_union($$action_0),•{•••});}}↲ [generated] line 9
• ↲ [generated] subset
/ ↲
/ ↲
/>↲ [original] line 11
/>↲ [original] line 11 (rest generated at line 10)
•{const•$$action_0•=•__sveltets_2_ensureAction(action(svelteHTML.mapElementTag('element'),($foo)));{•svelteHTML.createElement("element",•__sveltets_2_union($$action_0),•{•••});}}↲ [generated] line 9
•{const•$$action_0•=•__sveltets_2_ensureAction( element",•__sveltets_2_union($$action_0),•{ });}} [generated] subset
Expand All @@ -66,7 +72,9 @@ async•()•=>•{•{const•$$action_0•=•__sveltets_2_ensureAction(action
╚use:action={$foo}↲ [original] line 10
------------------------------------------------------------------------------------------------------------------------------------------------------ */}
{/**
↲ [generated] line 10
/>↲ [original] line 11 (rest generated at line 9)
------------------------------------------------------------------------------------------------------------------------------------------------------ */}
{const $$action_0 = __sveltets_2_ensureAction(action(svelteHTML.mapElementTag('element'),({ foo })));{ svelteHTML.createElement("element", __sveltets_2_union($$action_0), { });}}{/**
•{const•$$action_0•=•__sveltets_2_ensureAction(action(svelteHTML.mapElementTag('element'),({•foo•})));{•svelteHTML.createElement("element",•__sveltets_2_union($$action_0),•{•••});}}↲ [generated] line 11
Expand All @@ -86,10 +94,12 @@ async•()•=>•{•{const•$$action_0•=•__sveltets_2_ensureAction(action
• ↲ [generated] subset
/ ↲
/ ↲
/>↲ [original] line 15
/>↲ [original] line 15 (rest generated at line 12)
------------------------------------------------------------------------------------------------------------------------------------------------------ */}
{/**
↲ [generated] line 12
/>↲ [original] line 15 (rest generated at line 11)
------------------------------------------------------------------------------------------------------------------------------------------------------ */}
{const $$action_0 = __sveltets_2_ensureAction(action(svelteHTML.mapElementTag('element'),({ {/**
•{const•$$action_0•=•__sveltets_2_ensureAction(action(svelteHTML.mapElementTag('element'),({•↲ [generated] line 13
Expand Down
Loading

0 comments on commit ec5fef4

Please sign in to comment.