Skip to content

Commit 319c8cf

Browse files
authored
(fix) shorthand transition and animation params (#816)
Fixes #785
1 parent a933bf0 commit 319c8cf

File tree

5 files changed

+10
-44
lines changed

5 files changed

+10
-44
lines changed

packages/svelte2tsx/src/htmlxtojsx/nodes/animation-directive.ts

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,7 @@ export function handleAnimateDirective(
2020
const nodeType = `__sveltets_mapElementTag('${parent.name}')`;
2121

2222
if (!attr.expression) {
23-
if (animationsThatNeedParam.has(attr.name)) {
24-
str.appendLeft(attr.end, `(${nodeType},__sveltets_AnimationMove,{}))}`);
25-
} else {
26-
str.appendLeft(attr.end, `(${nodeType},__sveltets_AnimationMove))}`);
27-
}
23+
str.appendLeft(attr.end, `(${nodeType},__sveltets_AnimationMove,{}))}`);
2824
return;
2925
}
3026
str.overwrite(
@@ -37,16 +33,3 @@ export function handleAnimateDirective(
3733
str.remove(attr.end - 1, attr.end);
3834
}
3935
}
40-
41-
/**
42-
* Up to Svelte version 3.32.0, the following built-in animate functions have
43-
* optional parameters, but according to its typings they were mandatory.
44-
* To not show unnecessary type errors to those users, `{}` should be added
45-
* as a fallback parameter if the user did not provide one.
46-
* It may be the case that someone has a custom animation with the same name
47-
* that expects different parameters, or that someone did an import alias fly as foo,
48-
* but those are very unlikely.
49-
*
50-
* Remove this "hack" some day.
51-
*/
52-
const animationsThatNeedParam = new Set(['flip']);

packages/svelte2tsx/src/htmlxtojsx/nodes/transition-directive.ts

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,7 @@ export function handleTransitionDirective(
2525
const nodeType = `__sveltets_mapElementTag('${parent.name}')`;
2626

2727
if (!attr.expression) {
28-
if (transitionsThatNeedParam.has(attr.name)) {
29-
str.appendLeft(attr.end, `(${nodeType},{}))}`);
30-
} else {
31-
str.appendLeft(attr.end, `(${nodeType}))}`);
32-
}
28+
str.appendLeft(attr.end, `(${nodeType},{}))}`);
3329
return;
3430
}
3531

@@ -43,16 +39,3 @@ export function handleTransitionDirective(
4339
str.remove(attr.end - 1, attr.end);
4440
}
4541
}
46-
47-
/**
48-
* Up to Svelte version 3.32.0, the following built-in transition functions have
49-
* optional parameters, but according to its typings they were mandatory.
50-
* To not show unnecessary type errors to those users, `{}` should be added
51-
* as a fallback parameter if the user did not provide one.
52-
* It may be the case that someone has a custom transition with the same name
53-
* that expects different parameters, or that someone did an import alias fly as foo,
54-
* but those are very unlikely.
55-
*
56-
* Remove this "hack" some day.
57-
*/
58-
const transitionsThatNeedParam = new Set(['blur', 'fade', 'fly', 'slide', 'scale', 'draw']);
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<><h1 {...__sveltets_ensureAnimation(blink(__sveltets_mapElementTag('h1'),__sveltets_AnimationMove))}>Hello</h1></>
1+
<><h1 {...__sveltets_ensureAnimation(blink(__sveltets_mapElementTag('h1'),__sveltets_AnimationMove,{}))}>Hello</h1></>

packages/svelte2tsx/test/htmlx2jsx/samples/transition-animate-fallbacks/expected.jsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
<h1 {...__sveltets_ensureAnimation(flip(__sveltets_mapElementTag('h1'),__sveltets_AnimationMove,{}))}>Hello</h1>
1313

14-
<h1 {...__sveltets_ensureTransition(foo(__sveltets_mapElementTag('h1')))}>Hello</h1>
15-
<h1 {...__sveltets_ensureTransition(foo(__sveltets_mapElementTag('h1')))}>Hello</h1>
16-
<h1 {...__sveltets_ensureTransition(foo(__sveltets_mapElementTag('h1')))}>Hello</h1>
17-
<h1 {...__sveltets_ensureAnimation(foo(__sveltets_mapElementTag('h1'),__sveltets_AnimationMove))}>Hello</h1></>
14+
<h1 {...__sveltets_ensureTransition(foo(__sveltets_mapElementTag('h1'),{}))}>Hello</h1>
15+
<h1 {...__sveltets_ensureTransition(foo(__sveltets_mapElementTag('h1'),{}))}>Hello</h1>
16+
<h1 {...__sveltets_ensureTransition(foo(__sveltets_mapElementTag('h1'),{}))}>Hello</h1>
17+
<h1 {...__sveltets_ensureAnimation(foo(__sveltets_mapElementTag('h1'),__sveltets_AnimationMove,{}))}>Hello</h1></>
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
<><h1 {...__sveltets_ensureTransition(blink(__sveltets_mapElementTag('h1')))}>Hello</h1>
2-
<h1 {...__sveltets_ensureTransition(blink(__sveltets_mapElementTag('h1')))}>Hello</h1>
3-
<h1 {...__sveltets_ensureTransition(blink(__sveltets_mapElementTag('h1')))}>Hello</h1></>
1+
<><h1 {...__sveltets_ensureTransition(blink(__sveltets_mapElementTag('h1'),{}))}>Hello</h1>
2+
<h1 {...__sveltets_ensureTransition(blink(__sveltets_mapElementTag('h1'),{}))}>Hello</h1>
3+
<h1 {...__sveltets_ensureTransition(blink(__sveltets_mapElementTag('h1'),{}))}>Hello</h1></>

0 commit comments

Comments
 (0)