Skip to content

Commit d6d9f0c

Browse files
committed
fix
1 parent a466021 commit d6d9f0c

File tree

6 files changed

+31
-10
lines changed

6 files changed

+31
-10
lines changed

packages/svelte/src/compiler/phases/1-parse/state/element.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -500,7 +500,10 @@ function read_attribute(parser) {
500500
type: 'AttachTag',
501501
start,
502502
end: parser.index,
503-
expression
503+
expression,
504+
metadata: {
505+
expression: create_expression_metadata()
506+
}
504507
};
505508

506509
return attachment;

packages/svelte/src/compiler/phases/2-analyze/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import { extract_svelte_ignore } from '../../utils/extract_svelte_ignore.js';
1818
import { ignore_map, ignore_stack, pop_ignore, push_ignore } from '../../state.js';
1919
import { ArrowFunctionExpression } from './visitors/ArrowFunctionExpression.js';
2020
import { AssignmentExpression } from './visitors/AssignmentExpression.js';
21+
import { AttachTag } from './visitors/AttachTag.js';
2122
import { Attribute } from './visitors/Attribute.js';
2223
import { AwaitBlock } from './visitors/AwaitBlock.js';
2324
import { BindDirective } from './visitors/BindDirective.js';
@@ -131,6 +132,7 @@ const visitors = {
131132
},
132133
ArrowFunctionExpression,
133134
AssignmentExpression,
135+
AttachTag,
134136
Attribute,
135137
AwaitBlock,
136138
BindDirective,
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/** @import { AST } from '#compiler' */
2+
/** @import { Context } from '../types' */
3+
4+
import { mark_subtree_dynamic } from './shared/fragment.js';
5+
6+
/**
7+
* @param {AST.AttachTag} node
8+
* @param {Context} context
9+
*/
10+
export function AttachTag(node, context) {
11+
mark_subtree_dynamic(context.path);
12+
context.next({ ...context.state, expression: node.metadata.expression });
13+
}

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

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -262,15 +262,13 @@ export function build_component(node, component_name, context, anchor = context.
262262
}
263263
}
264264
} else if (attribute.type === 'AttachTag') {
265-
// TODO do we need to create a derived here?
266-
push_prop(
267-
b.prop(
268-
'get',
269-
b.call('Symbol'),
270-
/** @type {Expression} */ (context.visit(attribute.expression)),
271-
true
272-
)
273-
);
265+
let expression = /** @type {Expression} */ (context.visit(attribute.expression));
266+
267+
if (attribute.metadata.expression.has_state) {
268+
expression = b.arrow([b.id('node')], b.call(expression, b.id('node')));
269+
}
270+
271+
push_prop(b.prop('get', b.call('$.attachment'), expression, true));
274272
}
275273
}
276274

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,10 @@ export namespace AST {
178178
export interface AttachTag extends BaseNode {
179179
type: 'AttachTag';
180180
expression: Expression;
181+
/** @internal */
182+
metadata: {
183+
expression: ExpressionMetadata;
184+
};
181185
}
182186

183187
/** An `animate:` directive */

packages/svelte/src/internal/client/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
export { createAttachmentKey as attachment } from '../../attachments/index.js';
12
export { FILENAME, HMR, NAMESPACE_SVG } from '../../constants.js';
23
export { assign, assign_and, assign_or, assign_nullish } from './dev/assign.js';
34
export { cleanup_styles } from './dev/css.js';

0 commit comments

Comments
 (0)