Skip to content

Commit 03f2e44

Browse files
authored
chore: remove some todos (#16515)
* chore: remove some todos * fix * fix * doh * convert `TemplateComment` back to `Comment` * `Evaluation.has_unknown`
1 parent 5177144 commit 03f2e44

File tree

8 files changed

+45
-8
lines changed

8 files changed

+45
-8
lines changed

.changeset/happy-countries-dance.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'svelte': patch
3+
---
4+
5+
chore: remove some todos

packages/svelte/src/compiler/migrate/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1707,14 +1707,14 @@ function extract_type_and_comment(declarator, state, path) {
17071707
}
17081708

17091709
// Ensure modifiers are applied in the same order as Svelte 4
1710-
const modifier_order = [
1710+
const modifier_order = /** @type {const} */ ([
17111711
'preventDefault',
17121712
'stopPropagation',
17131713
'stopImmediatePropagation',
17141714
'self',
17151715
'trusted',
17161716
'once'
1717-
];
1717+
]);
17181718

17191719
/**
17201720
* @param {AST.RegularElement | AST.SvelteElement | AST.SvelteWindow | AST.SvelteDocument | AST.SvelteBody} element

packages/svelte/src/compiler/phases/1-parse/index.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
/** @import { AST } from '#compiler' */
2-
/** @import { Comment } from 'estree' */
32
// @ts-expect-error acorn type definitions are borked in the release we use
43
import { isIdentifierStart, isIdentifierChar } from 'acorn';
54
import fragment from './state/fragment.js';

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,9 @@ export function CallExpression(node, context) {
8282
['debug', 'dir', 'error', 'group', 'groupCollapsed', 'info', 'log', 'trace', 'warn'].includes(
8383
node.callee.property.name
8484
) &&
85-
node.arguments.some((arg) => arg.type !== 'Literal') // TODO more cases?
85+
node.arguments.some(
86+
(arg) => arg.type === 'SpreadElement' || context.state.scope.evaluate(arg).has_unknown
87+
)
8688
) {
8789
return b.call(
8890
node.callee,

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33
import * as b from '#compiler/builders';
44
import { build_event, build_event_handler } from './shared/events.js';
55

6-
const modifiers = [
6+
const modifiers = /** @type {const} */ ([
77
'stopPropagation',
88
'stopImmediatePropagation',
99
'preventDefault',
1010
'self',
1111
'trusted',
1212
'once'
13-
];
13+
]);
1414

1515
/**
1616
* @param {AST.OnDirective} node

packages/svelte/src/compiler/phases/scope.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,13 @@ class Evaluation {
180180
*/
181181
is_known = true;
182182

183+
/**
184+
* True if the possible values contains `UNKNOWN`
185+
* @readonly
186+
* @type {boolean}
187+
*/
188+
has_unknown = false;
189+
183190
/**
184191
* True if the value is known to not be null/undefined
185192
* @readonly
@@ -540,6 +547,10 @@ class Evaluation {
540547
if (value == null || value === UNKNOWN) {
541548
this.is_defined = false;
542549
}
550+
551+
if (value === UNKNOWN) {
552+
this.has_unknown = true;
553+
}
543554
}
544555

545556
if (this.values.size > 1 || typeof this.value === 'symbol') {

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,17 @@ export namespace AST {
247247
name: string;
248248
/** The 'y' in `on:x={y}` */
249249
expression: null | Expression;
250-
modifiers: string[]; // TODO specify
250+
modifiers: Array<
251+
| 'capture'
252+
| 'nonpassive'
253+
| 'once'
254+
| 'passive'
255+
| 'preventDefault'
256+
| 'self'
257+
| 'stopImmediatePropagation'
258+
| 'stopPropagation'
259+
| 'trusted'
260+
>;
251261
/** @internal */
252262
metadata: {
253263
expression: ExpressionMetadata;

packages/svelte/types/index.d.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1296,7 +1296,17 @@ declare module 'svelte/compiler' {
12961296
name: string;
12971297
/** The 'y' in `on:x={y}` */
12981298
expression: null | Expression;
1299-
modifiers: string[];
1299+
modifiers: Array<
1300+
| 'capture'
1301+
| 'nonpassive'
1302+
| 'once'
1303+
| 'passive'
1304+
| 'preventDefault'
1305+
| 'self'
1306+
| 'stopImmediatePropagation'
1307+
| 'stopPropagation'
1308+
| 'trusted'
1309+
>;
13001310
}
13011311

13021312
/** A `style:` directive */

0 commit comments

Comments
 (0)