Skip to content

Commit 9692532

Browse files
committed
rename modifier 'hidden' into 'this'
fix bug with in:/out: directive support for spreading with set_attributes()
1 parent b9e8677 commit 9692532

File tree

6 files changed

+33
-14
lines changed

6 files changed

+33
-14
lines changed

packages/svelte/src/compiler/phases/3-transform/client/visitors/TransitionDirective.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
/** @import { ComponentContext } from '../types' */
44
import {
55
TRANSITION_GLOBAL,
6-
TRANSITION_HIDDEN,
6+
TRANSITION_THIS,
77
TRANSITION_IN,
88
TRANSITION_OUT
99
} from '../../../../../constants.js';
@@ -18,8 +18,8 @@ export function TransitionDirective(node, context) {
1818
let flags = node.modifiers.includes('global') ? TRANSITION_GLOBAL : 0;
1919
if (node.intro) flags |= TRANSITION_IN;
2020
if (node.outro) flags |= TRANSITION_OUT;
21-
if (node.modifiers.includes('hidden')) {
22-
flags |= TRANSITION_HIDDEN;
21+
if (node.modifiers.includes('this')) {
22+
flags |= TRANSITION_THIS;
2323
}
2424

2525
const args = [

packages/svelte/src/compiler/types/template.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ export namespace AST {
251251
name: string;
252252
/** The 'y' in `transition:x={y}` */
253253
expression: null | Expression;
254-
modifiers: Array<'local' | 'global' | 'hidden'>;
254+
modifiers: Array<'local' | 'global' | 'this'>;
255255
/** True if this is a `transition:` or `in:` directive */
256256
intro: boolean;
257257
/** True if this is a `transition:` or `out:` directive */

packages/svelte/src/constants.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export const PROPS_IS_LAZY_INITIAL = 1 << 4;
1414
export const TRANSITION_IN = 1;
1515
export const TRANSITION_OUT = 1 << 1;
1616
export const TRANSITION_GLOBAL = 1 << 2;
17-
export const TRANSITION_HIDDEN = 1 << 3;
17+
export const TRANSITION_THIS = 1 << 3;
1818

1919
export const TEMPLATE_FRAGMENT = 1;
2020
export const TEMPLATE_USE_IMPORT_NODE = 1 << 1;

packages/svelte/src/internal/client/dom/elements/attributes.js

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ export function set_checked(element, checked) {
7575
}
7676

7777
/**
78-
* @param {Element & { hidden: boolean, __tm?: import('#client').TransitionManager}} element
78+
* @param {HTMLElement} element
7979
* @param {boolean} hidden
8080
*/
8181
export function set_hidden(element, hidden) {
@@ -84,12 +84,29 @@ export function set_hidden(element, hidden) {
8484

8585
if (attributes.hidden === (attributes.hidden = !!hidden)) return;
8686

87-
if (element.__tm) {
87+
/** @type {import('#client').TransitionManager[] | undefined} */
88+
// @ts-expect-error
89+
const tm = element.__tm;
90+
if (tm) {
8891
if (hidden) {
89-
element.__tm.out(() => (element.hidden = true));
92+
var remaining = tm.length;
93+
var check = () => {
94+
if (--remaining == 0) {
95+
// cleanup
96+
for (var transition of tm) {
97+
transition.stop();
98+
}
99+
element.hidden = true;
100+
}
101+
};
102+
for (var transition of tm) {
103+
transition.out(check);
104+
}
90105
} else {
91106
element.hidden = false;
92-
element.__tm.in();
107+
for (const transition of tm) {
108+
transition.in();
109+
}
93110
}
94111
} else {
95112
element.hidden = hidden;
@@ -292,6 +309,8 @@ export function set_attributes(
292309
} else if (key === '__value' || (key === 'value' && value != null)) {
293310
// @ts-ignore
294311
element.value = element[key] = element.__value = value;
312+
} else if (key === 'hidden') {
313+
set_hidden(/** @type {HTMLElement} */ (element), value);
295314
} else {
296315
var name = key;
297316
if (!preserve_attribute_case) {

packages/svelte/src/internal/client/dom/elements/transitions.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { should_intro } from '../../render.js';
77
import { current_each_item } from '../blocks/each.js';
88
import {
99
TRANSITION_GLOBAL,
10-
TRANSITION_HIDDEN,
10+
TRANSITION_THIS,
1111
TRANSITION_IN,
1212
TRANSITION_OUT
1313
} from '../../../../constants.js';
@@ -174,7 +174,7 @@ export function transition(flags, element, get_fn, get_params) {
174174
var is_outro = (flags & TRANSITION_OUT) !== 0;
175175
var is_both = is_intro && is_outro;
176176
var is_global = (flags & TRANSITION_GLOBAL) !== 0;
177-
var is_hidden = (flags & TRANSITION_HIDDEN) !== 0;
177+
var is_this = (flags & TRANSITION_THIS) !== 0;
178178

179179
/** @type {'in' | 'out' | 'both'} */
180180
var direction = is_both ? 'both' : is_intro ? 'in' : 'out';
@@ -249,9 +249,9 @@ export function transition(flags, element, get_fn, get_params) {
249249
}
250250
};
251251

252-
if (is_hidden) {
252+
if (is_this) {
253253
// @ts-expect-error
254-
element.__tm = transition;
254+
(element.__tm ??= []).push(transition);
255255
return;
256256
}
257257

packages/svelte/types/index.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1060,7 +1060,7 @@ declare module 'svelte/compiler' {
10601060
name: string;
10611061
/** The 'y' in `transition:x={y}` */
10621062
expression: null | Expression;
1063-
modifiers: Array<'local' | 'global' | 'hidden'>;
1063+
modifiers: Array<'local' | 'global' | 'this'>;
10641064
/** True if this is a `transition:` or `in:` directive */
10651065
intro: boolean;
10661066
/** True if this is a `transition:` or `out:` directive */

0 commit comments

Comments
 (0)