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

@ -14,9 +14,9 @@ export interface Text {
nodes: AST.Text[];
}
export interface Anchor {
type: 'anchor';
export interface Comment {
type: 'comment';
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
*/
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
const expression = b.thunk(/** @type {Expression} */ (context.visit(node.expression)));

@ -7,5 +7,5 @@
*/
export function Comment(node, context) {
// 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) {
context.state.template.create_anchor();
context.state.template.push_comment();
}
let flags = 0;

@ -140,7 +140,7 @@ export function Fragment(node, context) {
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
body.push(b.var(id, b.call('$.comment')));
} else {

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

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

@ -8,7 +8,7 @@ import * as b from '#compiler/builders';
* @param {ComponentContext} 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 body = /** @type {Expression} */ (context.visit(node.fragment));

@ -36,7 +36,7 @@ import { visit_event_attribute } from './shared/events.js';
* @param {ComponentContext} 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') {
context.state.template.pop_element();

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

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

@ -88,7 +88,7 @@ export function SvelteBoundary(node, context) {
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(
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
*/
export function SvelteElement(node, context) {
context.state.template.create_anchor();
context.state.template.push_comment();
/** @type {Array<AST.Attribute | AST.SpreadAttribute>} */
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 (context.state.metadata.namespace === 'svg') {
// this boils down to <g><!></g>
context.state.template.create_element('g', node.start);
context.state.template.push_element('g', node.start);
} else {
// 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.create_anchor();
context.state.template.push_comment();
context.state.template.pop_element();
statements.push(
@ -458,7 +458,7 @@ export function build_component(node, component_name, context, anchor = context.
b.stmt(b.call('$.reset', anchor))
);
} else {
context.state.template.create_anchor();
context.state.template.push_comment();
statements.push(b.stmt(fn(anchor)));
}

@ -64,11 +64,11 @@ export function process_children(nodes, initial, is_element, { visit, state }) {
function flush_sequence(sequence) {
if (sequence.every((node) => node.type === 'Text')) {
skipped += 1;
state.template.create_text(sequence);
state.template.push_text(sequence);
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);

Loading…
Cancel
Save