pull/16255/head
Simon Holthausen 3 months ago
parent d387f7958e
commit 3e3d20cc1d

@ -5,7 +5,7 @@ import { extract_identifiers } from '../../../../utils/ast.js';
import * as b from '#compiler/builders'; import * as b from '#compiler/builders';
import { create_derived } from '../utils.js'; import { create_derived } from '../utils.js';
import { get_value } from './shared/declarations.js'; import { get_value } from './shared/declarations.js';
import { build_expression, with_dev_stack } from './shared/utils.js'; import { build_expression, add_svelte_meta } from './shared/utils.js';
/** /**
* @param {AST.AwaitBlock} node * @param {AST.AwaitBlock} node
@ -54,7 +54,7 @@ export function AwaitBlock(node, context) {
} }
context.state.init.push( context.state.init.push(
with_dev_stack( add_svelte_meta(
b.call( b.call(
'$.await', '$.await',
context.state.node, context.state.node,

@ -13,7 +13,7 @@ import { dev } from '../../../../state.js';
import { extract_paths, object } from '../../../../utils/ast.js'; import { extract_paths, object } from '../../../../utils/ast.js';
import * as b from '#compiler/builders'; import * as b from '#compiler/builders';
import { get_value } from './shared/declarations.js'; import { get_value } from './shared/declarations.js';
import { build_expression, with_dev_stack } from './shared/utils.js'; import { build_expression, add_svelte_meta } from './shared/utils.js';
/** /**
* @param {AST.EachBlock} node * @param {AST.EachBlock} node
@ -337,7 +337,7 @@ export function EachBlock(node, context) {
); );
} }
context.state.init.push(with_dev_stack(b.call('$.each', ...args), node, 'each')); context.state.init.push(add_svelte_meta(b.call('$.each', ...args), node, 'each'));
} }
/** /**

@ -2,7 +2,7 @@
/** @import { AST } from '#compiler' */ /** @import { AST } from '#compiler' */
/** @import { ComponentContext } from '../types' */ /** @import { ComponentContext } from '../types' */
import * as b from '#compiler/builders'; import * as b from '#compiler/builders';
import { build_expression, with_dev_stack } from './shared/utils.js'; import { build_expression, add_svelte_meta } from './shared/utils.js';
/** /**
* @param {AST.IfBlock} node * @param {AST.IfBlock} node
@ -74,7 +74,7 @@ export function IfBlock(node, context) {
args.push(b.id('$$elseif')); args.push(b.id('$$elseif'));
} }
statements.push(with_dev_stack(b.call('$.if', ...args), node, 'if')); statements.push(add_svelte_meta(b.call('$.if', ...args), node, 'if'));
context.state.init.push(b.block(statements)); context.state.init.push(b.block(statements));
} }

@ -2,7 +2,7 @@
/** @import { AST } from '#compiler' */ /** @import { AST } from '#compiler' */
/** @import { ComponentContext } from '../types' */ /** @import { ComponentContext } from '../types' */
import * as b from '#compiler/builders'; import * as b from '#compiler/builders';
import { build_expression, with_dev_stack } from './shared/utils.js'; import { build_expression, add_svelte_meta } from './shared/utils.js';
/** /**
* @param {AST.KeyBlock} node * @param {AST.KeyBlock} node
@ -15,7 +15,7 @@ export function KeyBlock(node, context) {
const body = /** @type {Expression} */ (context.visit(node.fragment)); const body = /** @type {Expression} */ (context.visit(node.fragment));
context.state.init.push( context.state.init.push(
with_dev_stack( add_svelte_meta(
b.call('$.key', context.state.node, b.thunk(key), b.arrow([b.id('$$anchor')], body)), b.call('$.key', context.state.node, b.thunk(key), b.arrow([b.id('$$anchor')], body)),
node, node,
'key' 'key'

@ -8,7 +8,7 @@ import {
build_bind_this, build_bind_this,
memoize_expression, memoize_expression,
validate_binding, validate_binding,
with_dev_stack add_svelte_meta
} from '../shared/utils.js'; } from '../shared/utils.js';
import { build_attribute_value } from '../shared/element.js'; import { build_attribute_value } from '../shared/element.js';
import { build_event_handler } from './events.js'; import { build_event_handler } from './events.js';
@ -490,7 +490,7 @@ export function build_component(node, component_name, context) {
context.state.template.push_comment(); context.state.template.push_comment();
statements.push( statements.push(
with_dev_stack(fn(anchor), node, 'component', { componentTag: component_name }) add_svelte_meta(fn(anchor), node, 'component', { componentTag: component_name })
); );
} }

@ -7,7 +7,7 @@ import * as b from '#compiler/builders';
import { sanitize_template_string } from '../../../../../utils/sanitize_template_string.js'; import { sanitize_template_string } from '../../../../../utils/sanitize_template_string.js';
import { regex_is_valid_identifier } from '../../../../patterns.js'; import { regex_is_valid_identifier } from '../../../../patterns.js';
import is_reference from 'is-reference'; import is_reference from 'is-reference';
import { dev, is_ignored, locator, filename } from '../../../../../state.js'; import { dev, is_ignored, locator, component_name } from '../../../../../state.js';
import { build_getter, create_derived } from '../../utils.js'; import { build_getter, create_derived } from '../../utils.js';
/** /**
@ -403,7 +403,7 @@ export function build_expression(context, expression, metadata, state = context.
* @param {Record<string, number | string>} [additional] - Any additional properties to add to the dev stack entry * @param {Record<string, number | string>} [additional] - Any additional properties to add to the dev stack entry
* @returns {Statement} - Statement with or without dev stack wrapping * @returns {Statement} - Statement with or without dev stack wrapping
*/ */
export function with_dev_stack(call_expression, node, type, additional) { export function add_svelte_meta(call_expression, node, type, additional) {
if (!dev) { if (!dev) {
return b.stmt(call_expression); return b.stmt(call_expression);
} }
@ -415,10 +415,10 @@ export function with_dev_stack(call_expression, node, type, additional) {
return b.stmt( return b.stmt(
b.call( b.call(
'$.with_dev_stack', '$.add_svelte_meta',
b.arrow([], call_expression), b.arrow([], call_expression),
b.literal(type), b.literal(type),
b.literal(filename), b.id(component_name),
b.literal(location.line), b.literal(location.line),
b.literal(location.column), b.literal(location.column),
additional && b.object(Object.entries(additional).map(([k, v]) => b.init(k, b.literal(v)))) additional && b.object(Object.entries(additional).map(([k, v]) => b.init(k, b.literal(v))))

@ -16,6 +16,9 @@ export let warnings = [];
*/ */
export let filename; export let filename;
/**
* The name of the component that is used in the `export default function ...` statement.
*/
export let component_name = '<unknown>'; export let component_name = '<unknown>';
/** /**

@ -11,6 +11,7 @@ import {
} from './runtime.js'; } from './runtime.js';
import { effect, teardown } from './reactivity/effects.js'; import { effect, teardown } from './reactivity/effects.js';
import { legacy_mode_flag } from '../flags/index.js'; import { legacy_mode_flag } from '../flags/index.js';
import { FILENAME } from '../../constants.js';
/** @type {ComponentContext | null} */ /** @type {ComponentContext | null} */
export let component_context = null; export let component_context = null;
@ -32,18 +33,18 @@ export function set_dev_stack(stack) {
* Execute a callback with a new dev stack entry * Execute a callback with a new dev stack entry
* @param {() => any} callback - Function to execute * @param {() => any} callback - Function to execute
* @param {DevStackEntry['type']} type - Type of block/component * @param {DevStackEntry['type']} type - Type of block/component
* @param {string} file - Source file * @param {any} component - Component function
* @param {number} line - Line number * @param {number} line - Line number
* @param {number} column - Column number * @param {number} column - Column number
* @param {Record<string, any>} [additional] - Any additional properties to add to the dev stack entry * @param {Record<string, any>} [additional] - Any additional properties to add to the dev stack entry
* @returns {any} * @returns {any}
*/ */
export function with_dev_stack(callback, type, file, line, column, additional) { export function add_svelte_meta(callback, type, component, line, column, additional) {
const parent = dev_stack; const parent = dev_stack;
dev_stack = { dev_stack = {
type, type,
file, file: component[FILENAME],
line, line,
column, column,
parent, parent,

@ -1,6 +1,6 @@
export { createAttachmentKey as attachment } from '../../attachments/index.js'; export { createAttachmentKey as attachment } from '../../attachments/index.js';
export { FILENAME, HMR, NAMESPACE_SVG } from '../../constants.js'; export { FILENAME, HMR, NAMESPACE_SVG } from '../../constants.js';
export { push, pop, with_dev_stack } from './context.js'; export { push, pop, add_svelte_meta } from './context.js';
export { assign, assign_and, assign_or, assign_nullish } from './dev/assign.js'; export { assign, assign_and, assign_or, assign_nullish } from './dev/assign.js';
export { cleanup_styles } from './dev/css.js'; export { cleanup_styles } from './dev/css.js';
export { add_locations } from './dev/elements.js'; export { add_locations } from './dev/elements.js';

Loading…
Cancel
Save