Skip to content
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

chore: remove template expression inlining #14374

Merged
merged 13 commits into from
Nov 20, 2024
Prev Previous commit
Next Next commit
feedback
  • Loading branch information
trueadm committed Nov 20, 2024
commit 5ff9d2f164c01b4ce3a8fbb60611b3eb1b43ef18
28 changes: 28 additions & 0 deletions packages/svelte/src/internal/shared/attributes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { escape_html } from '../../escaping.js';

/**
* `<div translate={false}>` should be rendered as `<div translate="no">` and _not_
* `<div translate="false">`, which is equivalent to `<div translate="yes">`. There
* may be other odd cases that need to be added to this list in future
* @type {Record<string, Map<any, string>>}
*/
const replacements = {
translate: new Map([
[true, 'yes'],
[false, 'no']
])
};

/**
* @template V
* @param {string} name
* @param {V} value
* @param {boolean} [is_boolean]
* @returns {string}
*/
export function attr(name, value, is_boolean = false) {
if (value == null || (!value && is_boolean) || (value === '' && name === 'class')) return '';
const normalized = (name in replacements && replacements[name].get(value)) || value;
const assignment = is_boolean ? '' : `="${escape_html(normalized, true)}"`;
return ` ${name}${assignment}`;
}
Loading