relax restriction on label - no longer necessary with new design

pull/14290/head
Rich Harris 2 years ago
parent 7778e99510
commit 28e05ed058

@ -1,4 +1,4 @@
/** @import { ArrowFunctionExpression, CallExpression, FunctionDeclaration, FunctionExpression, Identifier, VariableDeclarator } from 'estree' */
/** @import { ArrowFunctionExpression, CallExpression, Expression, FunctionDeclaration, FunctionExpression, Identifier, VariableDeclarator } from 'estree' */
/** @import { AST } from '#compiler' */
/** @import { Context } from '../types' */
import { get_rune } from '../../scope.js';
@ -6,6 +6,7 @@ import * as e from '../../../errors.js';
import { get_parent, unwrap_optional } from '../../../utils/ast.js';
import { is_pure, is_safe_identifier } from './shared/utils.js';
import { dev, locate_node, source } from '../../../state.js';
import * as b from '../../../utils/builders.js';
/**
* @param {CallExpression} node
@ -141,13 +142,6 @@ export function CallExpression(node, context) {
e.rune_invalid_arguments_length(node, rune, 'zero or one arguments');
}
if (
node.arguments[0] &&
(node.arguments[0].type !== 'Literal' || typeof node.arguments[0].value !== 'string')
) {
e.trace_rune_invalid_argument(node);
}
const grand_parent = context.path.at(-2);
const fn = context.path.at(-3);
@ -166,12 +160,12 @@ export function CallExpression(node, context) {
if (dev) {
if (node.arguments[0]) {
context.state.scope.tracing = /** @type {string} */ (node.arguments[0].value);
context.state.scope.tracing = b.thunk(/** @type {Expression} */ (node.arguments[0]));
} else {
const label = get_function_label(context.path.slice(0, -2));
const loc = `(${locate_node(fn)})`;
context.state.scope.tracing = label ? label + ' ' + loc : loc;
context.state.scope.tracing = b.thunk(b.literal(label ? label + ' ' + loc : loc));
}
}

@ -1,4 +1,4 @@
/** @import { BlockStatement, Statement } from 'estree' */
/** @import { BlockStatement, Expression, Statement } from 'estree' */
/** @import { ComponentContext } from '../types' */
import { add_state_transformers } from './shared/declarations.js';
import * as b from '../../../../utils/builders.js';
@ -16,8 +16,8 @@ export function BlockStatement(node, context) {
b.return(
b.call(
'$.trace',
b.thunk(b.block(node.body.map((n) => /** @type {Statement} */ (context.visit(n))))),
b.literal(tracing)
/** @type {Expression} */ (context.visit(tracing)),
b.thunk(b.block(node.body.map((n) => /** @type {Statement} */ (context.visit(n)))))
)
)
]);

@ -60,7 +60,7 @@ export class Scope {
/**
* If tracing of reactive dependencies is enabled for this scope
* @type {null | string}
* @type {null | Expression}
*/
tracing = null;

@ -85,10 +85,10 @@ function log_entry(signal, entry) {
/**
* @template T
* @param {() => string} label
* @param {() => T} fn
* @param {string} label
*/
export function trace(fn, label) {
export function trace(label, fn) {
var previously_tracing_expressions = tracing_expressions;
try {
tracing_expressions = { entries: new Map(), reaction: active_reaction };
@ -99,10 +99,10 @@ export function trace(fn, label) {
if (tracing_expressions.entries.size === 0) {
// eslint-disable-next-line no-console
console.log(`${label} %cno reactive dependencies (${time}ms)`, 'color: grey');
console.log(`${label()} %cno reactive dependencies (${time}ms)`, 'color: grey');
} else {
// eslint-disable-next-line no-console
console.group(`${label} %c(${time}ms)`, 'color: grey');
console.group(`${label()} %c(${time}ms)`, 'color: grey');
var entries = tracing_expressions.entries;

Loading…
Cancel
Save