|
1 | 1 | /** @import { VariableDeclaration, VariableDeclarator, Expression, CallExpression, Pattern, Identifier } from 'estree' */
|
2 | 2 | /** @import { Binding } from '#compiler' */
|
3 | 3 | /** @import { Context } from '../types.js' */
|
| 4 | +/** @import { ComponentAnalysis } from '../../../types.js' */ |
4 | 5 | /** @import { Scope } from '../../../scope.js' */
|
5 | 6 | import { build_fallback, extract_paths } from '../../../../utils/ast.js';
|
6 | 7 | import * as b from '#compiler/builders';
|
@@ -50,20 +51,26 @@ export function VariableDeclaration(node, context) {
|
50 | 51 | }
|
51 | 52 | }
|
52 | 53 | });
|
| 54 | + |
| 55 | + // if `$$slots` is declared separately, deconflict |
| 56 | + const slots_name = /** @type {ComponentAnalysis} */ (context.state.analysis).uses_slots |
| 57 | + ? b.id('$$slots_') |
| 58 | + : b.id('$$slots'); |
| 59 | + |
53 | 60 | if (id.type === 'ObjectPattern' && has_rest) {
|
54 | 61 | // If a rest pattern is used within an object pattern, we need to ensure we don't expose $$slots or $$events
|
55 | 62 | id.properties.splice(
|
56 | 63 | id.properties.length - 1,
|
57 | 64 | 0,
|
58 | 65 | // @ts-ignore
|
59 |
| - b.prop('init', b.id('$$slots'), b.id('$$slots')), |
| 66 | + b.prop('init', b.id('$$slots'), slots_name), |
60 | 67 | b.prop('init', b.id('$$events'), b.id('$$events'))
|
61 | 68 | );
|
62 | 69 | } else if (id.type === 'Identifier') {
|
63 | 70 | // If $props is referenced as an identifier, we need to ensure we don't expose $$slots or $$events as properties
|
64 | 71 | // on the identifier reference
|
65 | 72 | id = b.object_pattern([
|
66 |
| - b.prop('init', b.id('$$slots'), b.id('$$slots')), |
| 73 | + b.prop('init', b.id('$$slots'), slots_name), |
67 | 74 | b.prop('init', b.id('$$events'), b.id('$$events')),
|
68 | 75 | b.rest(b.id(id.name))
|
69 | 76 | ]);
|
|
0 commit comments