rename stuff

pull/15538/head
Rich Harris 4 months ago
parent 19fae2023d
commit 408955dae6

@ -31,7 +31,7 @@ export class Template {
* @param {string} name * @param {string} name
* @param {number} start * @param {number} start
*/ */
create_element(name, start) { push_element(name, start) {
this.#element = { this.#element = {
type: 'element', type: 'element',
name, name,
@ -47,12 +47,12 @@ export class Template {
} }
/** @param {string} [data] */ /** @param {string} [data] */
create_anchor(data) { push_comment(data) {
this.#fragment.push({ type: 'anchor', data }); this.#fragment.push({ type: 'comment', data });
} }
/** @param {AST.Text[]} nodes */ /** @param {AST.Text[]} nodes */
create_text(nodes) { push_text(nodes) {
this.#fragment.push({ type: 'text', nodes }); this.#fragment.push({ type: 'text', nodes });
} }
@ -75,8 +75,8 @@ export class Template {
as_objects() { as_objects() {
// if the first item is a comment we need to add another comment for effect.start // if the first item is a comment we need to add another comment for effect.start
if (this.nodes[0].type === 'anchor') { if (this.nodes[0].type === 'comment') {
this.nodes.unshift({ type: 'anchor', data: undefined }); this.nodes.unshift({ type: 'comment', data: undefined });
} }
return b.array(this.nodes.map(objectify)); return b.array(this.nodes.map(objectify));
@ -91,7 +91,7 @@ function stringify(item) {
return item.nodes.map((node) => node.raw).join(''); return item.nodes.map((node) => node.raw).join('');
} }
if (item.type === 'anchor') { if (item.type === 'comment') {
return item.data ? `<!--${item.data}-->` : '<!>'; return item.data ? `<!--${item.data}-->` : '<!>';
} }
@ -120,7 +120,7 @@ function objectify(item) {
return b.literal(item.nodes.map((node) => node.data).join('')); return b.literal(item.nodes.map((node) => node.data).join(''));
} }
if (item.type === 'anchor') { if (item.type === 'comment') {
return item.data ? b.array([b.literal(`// ${item.data}`)]) : null; return item.data ? b.array([b.literal(`// ${item.data}`)]) : null;
} }

@ -14,9 +14,9 @@ export interface Text {
nodes: AST.Text[]; nodes: AST.Text[];
} }
export interface Anchor { export interface Comment {
type: 'anchor'; type: 'comment';
data: string | undefined; data: string | undefined;
} }
export type Node = Element | Text | Anchor; export type Node = Element | Text | Comment;

@ -11,7 +11,7 @@ import { get_value } from './shared/declarations.js';
* @param {ComponentContext} context * @param {ComponentContext} context
*/ */
export function AwaitBlock(node, context) { export function AwaitBlock(node, context) {
context.state.template.create_anchor(); context.state.template.push_comment();
// Visit {#await <expression>} first to ensure that scopes are in the correct order // Visit {#await <expression>} first to ensure that scopes are in the correct order
const expression = b.thunk(/** @type {Expression} */ (context.visit(node.expression))); const expression = b.thunk(/** @type {Expression} */ (context.visit(node.expression)));

@ -7,5 +7,5 @@
*/ */
export function Comment(node, context) { export function Comment(node, context) {
// We'll only get here if comments are not filtered out, which they are unless preserveComments is true // We'll only get here if comments are not filtered out, which they are unless preserveComments is true
context.state.template.create_anchor(node.data); context.state.template.push_comment(node.data);
} }

@ -32,7 +32,7 @@ export function EachBlock(node, context) {
); );
if (!each_node_meta.is_controlled) { if (!each_node_meta.is_controlled) {
context.state.template.create_anchor(); context.state.template.push_comment();
} }
let flags = 0; let flags = 0;

@ -140,7 +140,7 @@ export function Fragment(node, context) {
flags |= TEMPLATE_USE_IMPORT_NODE; flags |= TEMPLATE_USE_IMPORT_NODE;
} }
if (state.template.nodes.length === 1 && state.template.nodes[0].type === 'anchor') { if (state.template.nodes.length === 1 && state.template.nodes[0].type === 'comment') {
// special case — we can use `$.comment` instead of creating a unique template // special case — we can use `$.comment` instead of creating a unique template
body.push(b.var(id, b.call('$.comment'))); body.push(b.var(id, b.call('$.comment')));
} else { } else {

@ -9,7 +9,7 @@ import * as b from '#compiler/builders';
* @param {ComponentContext} context * @param {ComponentContext} context
*/ */
export function HtmlTag(node, context) { export function HtmlTag(node, context) {
context.state.template.create_anchor(); context.state.template.push_comment();
const expression = /** @type {Expression} */ (context.visit(node.expression)); const expression = /** @type {Expression} */ (context.visit(node.expression));

@ -8,7 +8,7 @@ import * as b from '#compiler/builders';
* @param {ComponentContext} context * @param {ComponentContext} context
*/ */
export function IfBlock(node, context) { export function IfBlock(node, context) {
context.state.template.create_anchor(); context.state.template.push_comment();
const statements = []; const statements = [];
const consequent = /** @type {BlockStatement} */ (context.visit(node.consequent)); const consequent = /** @type {BlockStatement} */ (context.visit(node.consequent));

@ -8,7 +8,7 @@ import * as b from '#compiler/builders';
* @param {ComponentContext} context * @param {ComponentContext} context
*/ */
export function KeyBlock(node, context) { export function KeyBlock(node, context) {
context.state.template.create_anchor(); context.state.template.push_comment();
const key = /** @type {Expression} */ (context.visit(node.expression)); const key = /** @type {Expression} */ (context.visit(node.expression));
const body = /** @type {Expression} */ (context.visit(node.fragment)); const body = /** @type {Expression} */ (context.visit(node.fragment));

@ -36,7 +36,7 @@ import { visit_event_attribute } from './shared/events.js';
* @param {ComponentContext} context * @param {ComponentContext} context
*/ */
export function RegularElement(node, context) { export function RegularElement(node, context) {
context.state.template.create_element(node.name, node.start); context.state.template.push_element(node.name, node.start);
if (node.name === 'noscript') { if (node.name === 'noscript') {
context.state.template.pop_element(); context.state.template.pop_element();

@ -9,7 +9,7 @@ import * as b from '#compiler/builders';
* @param {ComponentContext} context * @param {ComponentContext} context
*/ */
export function RenderTag(node, context) { export function RenderTag(node, context) {
context.state.template.create_anchor(); context.state.template.push_comment();
const expression = unwrap_optional(node.expression); const expression = unwrap_optional(node.expression);

@ -11,7 +11,7 @@ import { memoize_expression } from './shared/utils.js';
*/ */
export function SlotElement(node, context) { export function SlotElement(node, context) {
// <slot {a}>fallback</slot> --> $.slot($$slots.default, { get a() { .. } }, () => ...fallback); // <slot {a}>fallback</slot> --> $.slot($$slots.default, { get a() { .. } }, () => ...fallback);
context.state.template.create_anchor(); context.state.template.push_comment();
/** @type {Property[]} */ /** @type {Property[]} */
const props = []; const props = [];

@ -88,7 +88,7 @@ export function SvelteBoundary(node, context) {
b.call('$.boundary', context.state.node, props, b.arrow([b.id('$$anchor')], block)) b.call('$.boundary', context.state.node, props, b.arrow([b.id('$$anchor')], block))
); );
context.state.template.create_anchor(); context.state.template.push_comment();
context.state.init.push( context.state.init.push(
external_statements.length > 0 ? b.block([...external_statements, boundary]) : boundary external_statements.length > 0 ? b.block([...external_statements, boundary]) : boundary
); );

@ -13,7 +13,7 @@ import { build_render_statement } from './shared/utils.js';
* @param {ComponentContext} context * @param {ComponentContext} context
*/ */
export function SvelteElement(node, context) { export function SvelteElement(node, context) {
context.state.template.create_anchor(); context.state.template.push_comment();
/** @type {Array<AST.Attribute | AST.SpreadAttribute>} */ /** @type {Array<AST.Attribute | AST.SpreadAttribute>} */
const attributes = []; const attributes = [];

@ -442,14 +442,14 @@ export function build_component(node, component_name, context, anchor = context.
if (Object.keys(custom_css_props).length > 0) { if (Object.keys(custom_css_props).length > 0) {
if (context.state.metadata.namespace === 'svg') { if (context.state.metadata.namespace === 'svg') {
// this boils down to <g><!></g> // this boils down to <g><!></g>
context.state.template.create_element('g', node.start); context.state.template.push_element('g', node.start);
} else { } else {
// this boils down to <svelte-css-wrapper style='display: contents'><!></svelte-css-wrapper> // this boils down to <svelte-css-wrapper style='display: contents'><!></svelte-css-wrapper>
context.state.template.create_element('svelte-css-wrapper', node.start); context.state.template.push_element('svelte-css-wrapper', node.start);
context.state.template.set_prop('style', 'display: contents'); context.state.template.set_prop('style', 'display: contents');
} }
context.state.template.create_anchor(); context.state.template.push_comment();
context.state.template.pop_element(); context.state.template.pop_element();
statements.push( statements.push(
@ -458,7 +458,7 @@ export function build_component(node, component_name, context, anchor = context.
b.stmt(b.call('$.reset', anchor)) b.stmt(b.call('$.reset', anchor))
); );
} else { } else {
context.state.template.create_anchor(); context.state.template.push_comment();
statements.push(b.stmt(fn(anchor))); statements.push(b.stmt(fn(anchor)));
} }

@ -64,11 +64,11 @@ export function process_children(nodes, initial, is_element, { visit, state }) {
function flush_sequence(sequence) { function flush_sequence(sequence) {
if (sequence.every((node) => node.type === 'Text')) { if (sequence.every((node) => node.type === 'Text')) {
skipped += 1; skipped += 1;
state.template.create_text(sequence); state.template.push_text(sequence);
return; return;
} }
state.template.create_text([{ type: 'Text', data: ' ', raw: ' ', start: -1, end: -1 }]); state.template.push_text([{ type: 'Text', data: ' ', raw: ' ', start: -1, end: -1 }]);
const { has_state, value } = build_template_chunk(sequence, visit, state); const { has_state, value } = build_template_chunk(sequence, visit, state);

Loading…
Cancel
Save