Skip to content

Commit

Permalink
more linting and a few code style changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Ocean-OS committed Feb 23, 2025
1 parent 9f299f7 commit 57dc520
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@ import { is_ignored } from '../../../../../state.js';
import { is_event_attribute } from '../../../../../utils/ast.js';
import * as b from '../../../../../utils/builders.js';
import { build_getter } from '../../utils.js';
import { build_template_chunk, get_expression_id, DYNAMIC, evaluate_static_expression } from './utils.js';
import {
build_template_chunk,
get_expression_id,
DYNAMIC,
evaluate_static_expression
} from './utils.js';

/**
* @param {Array<AST.Attribute | AST.SpreadAttribute>} attributes
Expand Down Expand Up @@ -188,7 +193,7 @@ export function build_attribute_value(value, context, memoize = (value) => value
let expression = /** @type {Expression} */ (context.visit(chunk.expression));
let evaluated = evaluate_static_expression(expression, context.state);
if (evaluated !== DYNAMIC) {
return { value: b.literal(evaluated), has_state: false};
return { value: b.literal(evaluated), has_state: false };
}
return {
value: memoize(expression, chunk.metadata.expression),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,13 @@ function compare_expressions(a, b) {
export const DYNAMIC = Symbol('DYNAMIC');

/**
*
* @param {Expression | Node} node
* @param {ComponentClientTransformState} state
* @returns {any}
*/
export function evaluate_static_expression(node, state) {
if (node == undefined) return DYNAMIC;
/**
*
* @param {BinaryExpression | LogicalExpression} node
*/
function handle_left_right_node(node) {
Expand Down Expand Up @@ -146,15 +144,13 @@ export function evaluate_static_expression(node, state) {
}
}
/**
*
* @param {UnaryExpression} node
*/
function handle_unary_node(node) {
let argument = evaluate_static_expression(node?.argument, state);
if (argument === DYNAMIC) return DYNAMIC;
/**
*
* @param {Expression} argument
* @param {Expression} argument
*/
function handle_void(argument) {
//@ts-ignore
Expand Down Expand Up @@ -183,10 +179,13 @@ export function evaluate_static_expression(node, state) {
}
}
/**
* @param {SequenceExpression} node
* @param {SequenceExpression} node
*/
function handle_sequence(node) {
let is_static = node.expressions.reduce((a, b) => a && evaluate_static_expression(b, state) !== DYNAMIC, true);
let is_static = node.expressions.reduce(
(a, b) => a && evaluate_static_expression(b, state) !== DYNAMIC,
true
);
if (is_static) {
//@ts-ignore
return evaluate_static_expression(node.expressions.at(-1), state);
Expand All @@ -208,11 +207,14 @@ export function evaluate_static_expression(node, state) {
return DYNAMIC;
}
/**
* @param {TemplateLiteral} node
* @param {TemplateLiteral} node
*/
function handle_template(node) {
const expressions = node.expressions;
const is_static = expressions.reduce((a, b) => a && evaluate_static_expression(b, state) !== DYNAMIC, true);
const is_static = expressions.reduce(
(a, b) => a && evaluate_static_expression(b, state) !== DYNAMIC,
true
);
if (is_static) {
let res = '';
let quasis = node.quasis;
Expand Down

0 comments on commit 57dc520

Please sign in to comment.