File tree Expand file tree Collapse file tree 1 file changed +28
-0
lines changed
packages/svelte/src/internal/shared Expand file tree Collapse file tree 1 file changed +28
-0
lines changed Original file line number Diff line number Diff line change 1+ import { escape_html } from '../../escaping.js' ;
2+
3+ /**
4+ * `<div translate={false}>` should be rendered as `<div translate="no">` and _not_
5+ * `<div translate="false">`, which is equivalent to `<div translate="yes">`. There
6+ * may be other odd cases that need to be added to this list in future
7+ * @type {Record<string, Map<any, string>> }
8+ */
9+ const replacements = {
10+ translate : new Map ( [
11+ [ true , 'yes' ] ,
12+ [ false , 'no' ]
13+ ] )
14+ } ;
15+
16+ /**
17+ * @template V
18+ * @param {string } name
19+ * @param {V } value
20+ * @param {boolean } [is_boolean]
21+ * @returns {string }
22+ */
23+ export function attr ( name , value , is_boolean = false ) {
24+ if ( value == null || ( ! value && is_boolean ) || ( value === '' && name === 'class' ) ) return '' ;
25+ const normalized = ( name in replacements && replacements [ name ] . get ( value ) ) || value ;
26+ const assignment = is_boolean ? '' : `="${ escape_html ( normalized , true ) } "` ;
27+ return ` ${ name } ${ assignment } ` ;
28+ }
You can’t perform that action at this time.
0 commit comments