Skip to content

Commit 28e05ed

Browse files
committed
relax restriction on label - no longer necessary with new design
1 parent 7778e99 commit 28e05ed

File tree

4 files changed

+12
-18
lines changed

4 files changed

+12
-18
lines changed

packages/svelte/src/compiler/phases/2-analyze/visitors/CallExpression.js

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
/** @import { ArrowFunctionExpression, CallExpression, FunctionDeclaration, FunctionExpression, Identifier, VariableDeclarator } from 'estree' */
1+
/** @import { ArrowFunctionExpression, CallExpression, Expression, FunctionDeclaration, FunctionExpression, Identifier, VariableDeclarator } from 'estree' */
22
/** @import { AST } from '#compiler' */
33
/** @import { Context } from '../types' */
44
import { get_rune } from '../../scope.js';
55
import * as e from '../../../errors.js';
66
import { get_parent, unwrap_optional } from '../../../utils/ast.js';
77
import { is_pure, is_safe_identifier } from './shared/utils.js';
88
import { dev, locate_node, source } from '../../../state.js';
9+
import * as b from '../../../utils/builders.js';
910

1011
/**
1112
* @param {CallExpression} node
@@ -141,13 +142,6 @@ export function CallExpression(node, context) {
141142
e.rune_invalid_arguments_length(node, rune, 'zero or one arguments');
142143
}
143144

144-
if (
145-
node.arguments[0] &&
146-
(node.arguments[0].type !== 'Literal' || typeof node.arguments[0].value !== 'string')
147-
) {
148-
e.trace_rune_invalid_argument(node);
149-
}
150-
151145
const grand_parent = context.path.at(-2);
152146
const fn = context.path.at(-3);
153147

@@ -166,12 +160,12 @@ export function CallExpression(node, context) {
166160

167161
if (dev) {
168162
if (node.arguments[0]) {
169-
context.state.scope.tracing = /** @type {string} */ (node.arguments[0].value);
163+
context.state.scope.tracing = b.thunk(/** @type {Expression} */ (node.arguments[0]));
170164
} else {
171165
const label = get_function_label(context.path.slice(0, -2));
172166
const loc = `(${locate_node(fn)})`;
173167

174-
context.state.scope.tracing = label ? label + ' ' + loc : loc;
168+
context.state.scope.tracing = b.thunk(b.literal(label ? label + ' ' + loc : loc));
175169
}
176170
}
177171

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/** @import { BlockStatement, Statement } from 'estree' */
1+
/** @import { BlockStatement, Expression, Statement } from 'estree' */
22
/** @import { ComponentContext } from '../types' */
33
import { add_state_transformers } from './shared/declarations.js';
44
import * as b from '../../../../utils/builders.js';
@@ -16,8 +16,8 @@ export function BlockStatement(node, context) {
1616
b.return(
1717
b.call(
1818
'$.trace',
19-
b.thunk(b.block(node.body.map((n) => /** @type {Statement} */ (context.visit(n))))),
20-
b.literal(tracing)
19+
/** @type {Expression} */ (context.visit(tracing)),
20+
b.thunk(b.block(node.body.map((n) => /** @type {Statement} */ (context.visit(n)))))
2121
)
2222
)
2323
]);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ export class Scope {
6060

6161
/**
6262
* If tracing of reactive dependencies is enabled for this scope
63-
* @type {null | string}
63+
* @type {null | Expression}
6464
*/
6565
tracing = null;
6666

packages/svelte/src/internal/client/dev/tracing.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,10 @@ function log_entry(signal, entry) {
8585

8686
/**
8787
* @template T
88+
* @param {() => string} label
8889
* @param {() => T} fn
89-
* @param {string} label
9090
*/
91-
export function trace(fn, label) {
91+
export function trace(label, fn) {
9292
var previously_tracing_expressions = tracing_expressions;
9393
try {
9494
tracing_expressions = { entries: new Map(), reaction: active_reaction };
@@ -99,10 +99,10 @@ export function trace(fn, label) {
9999

100100
if (tracing_expressions.entries.size === 0) {
101101
// eslint-disable-next-line no-console
102-
console.log(`${label} %cno reactive dependencies (${time}ms)`, 'color: grey');
102+
console.log(`${label()} %cno reactive dependencies (${time}ms)`, 'color: grey');
103103
} else {
104104
// eslint-disable-next-line no-console
105-
console.group(`${label} %c(${time}ms)`, 'color: grey');
105+
console.group(`${label()} %c(${time}ms)`, 'color: grey');
106106

107107
var entries = tracing_expressions.entries;
108108

0 commit comments

Comments
 (0)