|
|
@ -1,10 +1,16 @@
|
|
|
|
/** @import { BlockStatement, Expression, Pattern, Property, SequenceExpression, Statement } from 'estree' */
|
|
|
|
/** @import { BlockStatement, Expression, Pattern, Property, SequenceExpression, Statement } from 'estree' */
|
|
|
|
/** @import { AST } from '#compiler' */
|
|
|
|
/** @import { AST } from '#compiler' */
|
|
|
|
/** @import { ComponentContext } from '../../types.js' */
|
|
|
|
/** @import { ComponentContext } from '../../types.js' */
|
|
|
|
import { empty_comment, build_attribute_value, call_child_payload } from './utils.js';
|
|
|
|
import {
|
|
|
|
|
|
|
|
empty_comment,
|
|
|
|
|
|
|
|
build_attribute_value,
|
|
|
|
|
|
|
|
call_child_payload,
|
|
|
|
|
|
|
|
PromiseOptimiser
|
|
|
|
|
|
|
|
} from './utils.js';
|
|
|
|
import * as b from '#compiler/builders';
|
|
|
|
import * as b from '#compiler/builders';
|
|
|
|
import { is_element_node } from '../../../../nodes.js';
|
|
|
|
import { is_element_node } from '../../../../nodes.js';
|
|
|
|
import { dev } from '../../../../../state.js';
|
|
|
|
import { dev } from '../../../../../state.js';
|
|
|
|
|
|
|
|
import { get_attribute_chunks } from '../../../../../utils/ast.js';
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* @param {AST.Component | AST.SvelteComponent | AST.SvelteSelf} node
|
|
|
|
* @param {AST.Component | AST.SvelteComponent | AST.SvelteSelf} node
|
|
|
@ -72,16 +78,26 @@ export function build_inline_component(node, expression, context) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const optimiser = new PromiseOptimiser();
|
|
|
|
|
|
|
|
|
|
|
|
for (const attribute of node.attributes) {
|
|
|
|
for (const attribute of node.attributes) {
|
|
|
|
if (attribute.type === 'LetDirective') {
|
|
|
|
if (attribute.type === 'LetDirective') {
|
|
|
|
if (!slot_scope_applies_to_itself) {
|
|
|
|
if (!slot_scope_applies_to_itself) {
|
|
|
|
lets.default.push(attribute);
|
|
|
|
lets.default.push(attribute);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (attribute.type === 'SpreadAttribute') {
|
|
|
|
} else if (attribute.type === 'SpreadAttribute') {
|
|
|
|
props_and_spreads.push(/** @type {Expression} */ (context.visit(attribute)));
|
|
|
|
let expression = /** @type {Expression} */ (context.visit(attribute));
|
|
|
|
|
|
|
|
props_and_spreads.push(optimiser.transform(expression, attribute.metadata.expression));
|
|
|
|
} else if (attribute.type === 'Attribute') {
|
|
|
|
} else if (attribute.type === 'Attribute') {
|
|
|
|
|
|
|
|
const value = build_attribute_value(
|
|
|
|
|
|
|
|
attribute.value,
|
|
|
|
|
|
|
|
context,
|
|
|
|
|
|
|
|
false,
|
|
|
|
|
|
|
|
true,
|
|
|
|
|
|
|
|
optimiser.transform
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
if (attribute.name.startsWith('--')) {
|
|
|
|
if (attribute.name.startsWith('--')) {
|
|
|
|
const value = build_attribute_value(attribute.value, context, false, true);
|
|
|
|
|
|
|
|
custom_css_props.push(b.init(attribute.name, value));
|
|
|
|
custom_css_props.push(b.init(attribute.name, value));
|
|
|
|
continue;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -90,7 +106,6 @@ export function build_inline_component(node, expression, context) {
|
|
|
|
has_children_prop = true;
|
|
|
|
has_children_prop = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const value = build_attribute_value(attribute.value, context, false, true);
|
|
|
|
|
|
|
|
push_prop(b.prop('init', b.key(attribute.name), value));
|
|
|
|
push_prop(b.prop('init', b.key(attribute.name), value));
|
|
|
|
} else if (attribute.type === 'BindDirective' && attribute.name !== 'this') {
|
|
|
|
} else if (attribute.type === 'BindDirective' && attribute.name !== 'this') {
|
|
|
|
if (attribute.expression.type === 'SequenceExpression') {
|
|
|
|
if (attribute.expression.type === 'SequenceExpression') {
|
|
|
@ -298,27 +313,29 @@ export function build_inline_component(node, expression, context) {
|
|
|
|
node.type === 'SvelteComponent' || (node.type === 'Component' && node.metadata.dynamic);
|
|
|
|
node.type === 'SvelteComponent' || (node.type === 'Component' && node.metadata.dynamic);
|
|
|
|
|
|
|
|
|
|
|
|
if (custom_css_props.length > 0) {
|
|
|
|
if (custom_css_props.length > 0) {
|
|
|
|
context.state.template.push(
|
|
|
|
statement = b.stmt(
|
|
|
|
b.stmt(
|
|
|
|
b.call(
|
|
|
|
b.call(
|
|
|
|
'$.css_props',
|
|
|
|
'$.css_props',
|
|
|
|
b.id('$$payload'),
|
|
|
|
b.id('$$payload'),
|
|
|
|
b.literal(context.state.namespace === 'svg' ? false : true),
|
|
|
|
b.literal(context.state.namespace === 'svg' ? false : true),
|
|
|
|
b.object(custom_css_props),
|
|
|
|
b.object(custom_css_props),
|
|
|
|
b.thunk(b.block([statement])),
|
|
|
|
b.thunk(b.block([statement])),
|
|
|
|
dynamic && b.true
|
|
|
|
dynamic && b.true
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
}
|
|
|
|
if (dynamic) {
|
|
|
|
|
|
|
|
context.state.template.push(empty_comment);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
context.state.template.push(statement);
|
|
|
|
if (optimiser.expressions.length > 0) {
|
|
|
|
|
|
|
|
statement = call_child_payload(b.block([optimiser.apply(), statement]), true);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (!context.state.skip_hydration_boundaries) {
|
|
|
|
if (dynamic && custom_css_props.length === 0) {
|
|
|
|
context.state.template.push(empty_comment);
|
|
|
|
context.state.template.push(empty_comment);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
context.state.template.push(statement);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!context.state.skip_hydration_boundaries && custom_css_props.length === 0) {
|
|
|
|
|
|
|
|
context.state.template.push(empty_comment);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|