Skip to content

chore: simplify SSR #11977

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 28 commits into from
Jun 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,6 @@ import { function_visitor, serialize_hoistable_params } from '../utils.js';

/** @type {import('../types.js').ComponentVisitors} */
export const javascript_visitors = {
Program(node, { visit }) {
return /** @type {import('estree').Program} */ ({
...node,
body: node.body.map((node) => /** @type {import('estree').Node} */ (visit(node)))
});
},
BlockStatement(node, { visit }) {
return /** @type {import('estree').BlockStatement} */ ({
...node,
body: node.body.map((node) => /** @type {import('estree').Node} */ (visit(node)))
});
},
FunctionExpression: function_visitor,
ArrowFunctionExpression: function_visitor,
FunctionDeclaration(node, context) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1435,37 +1435,29 @@ function get_node_id(expression, state, name) {
}

/**
* @param {true | Array<import('#compiler').Text | import('#compiler').ExpressionTag>} attribute_value
* @param {true | Array<import('#compiler').Text | import('#compiler').ExpressionTag>} value
* @param {import('../types').ComponentContext} context
* @returns {[boolean, import('estree').Expression]}
* @returns {[contains_call_expression: boolean, import('estree').Expression]}
*/
function serialize_attribute_value(attribute_value, context) {
let contains_call_expression = false;

if (attribute_value === true) {
return [contains_call_expression, b.literal(true)];
function serialize_attribute_value(value, context) {
if (value === true) {
return [false, b.literal(true)];
}

if (attribute_value.length === 0) {
return [contains_call_expression, b.literal('')]; // is this even possible?
}
if (value.length === 1) {
const chunk = value[0];

if (attribute_value.length === 1) {
const value = attribute_value[0];
if (value.type === 'Text') {
return [contains_call_expression, b.literal(value.data)];
} else {
if (value.type === 'ExpressionTag') {
contains_call_expression = value.metadata.contains_call_expression;
}
return [
contains_call_expression,
/** @type {import('estree').Expression} */ (context.visit(value.expression))
];
if (chunk.type === 'Text') {
return [false, b.literal(chunk.data)];
}

return [
chunk.metadata.contains_call_expression,
/** @type {import('estree').Expression} */ (context.visit(chunk.expression))
];
}

return serialize_template_literal(attribute_value, context.visit, context.state);
return serialize_template_literal(value, context.visit, context.state);
}

/**
Expand Down
Loading
Loading