@@ -40,14 +40,9 @@ import {
40
40
} from '../../../../internal/server/hydration.js' ;
41
41
import { filename , locator } from '../../../state.js' ;
42
42
43
- export const block_open = string ( BLOCK_OPEN ) ;
44
- export const block_close = string ( BLOCK_CLOSE ) ;
45
- export const block_anchor = string ( BLOCK_ANCHOR ) ;
46
-
47
- /** @param {string } value */
48
- function string ( value ) {
49
- return b . literal ( sanitize_template_string ( value ) ) ;
50
- }
43
+ export const block_open = b . literal ( BLOCK_OPEN ) ;
44
+ export const block_close = b . literal ( BLOCK_CLOSE ) ;
45
+ export const block_anchor = b . literal ( BLOCK_ANCHOR ) ;
51
46
52
47
/**
53
48
* @param {import('estree').Node } node
@@ -93,7 +88,8 @@ function serialize_template(template, out = b.id('$$payload.out'), operator = '+
93
88
if ( ! last ) quasis . push ( ( last = b . quasi ( '' , false ) ) ) ;
94
89
95
90
if ( node . type === 'Literal' ) {
96
- last . value . raw += node . value ;
91
+ last . value . raw +=
92
+ typeof node . value === 'string' ? sanitize_template_string ( node . value ) : node . value ;
97
93
} else if ( node . type === 'TemplateLiteral' ) {
98
94
last . value . raw += node . quasis [ 0 ] . value . raw ;
99
95
quasis . push ( ...node . quasis . slice ( 1 ) ) ;
@@ -1203,14 +1199,14 @@ const template_visitors = {
1203
1199
throw new Error ( 'Node should have been handled elsewhere' ) ;
1204
1200
} ,
1205
1201
RegularElement ( node , context ) {
1206
- context . state . template . push ( string ( `<${ node . name } ` ) ) ;
1202
+ context . state . template . push ( b . literal ( `<${ node . name } ` ) ) ;
1207
1203
const body = serialize_element_attributes ( node , context ) ;
1208
- context . state . template . push ( string ( '>' ) ) ;
1204
+ context . state . template . push ( b . literal ( '>' ) ) ;
1209
1205
1210
1206
if ( ( node . name === 'script' || node . name === 'style' ) && node . fragment . nodes . length === 1 ) {
1211
1207
context . state . template . push (
1212
- string ( /** @type {import('#compiler').Text } */ ( node . fragment . nodes [ 0 ] ) . data ) ,
1213
- string ( `</${ node . name } >` )
1208
+ b . literal ( /** @type {import('#compiler').Text } */ ( node . fragment . nodes [ 0 ] ) . data ) ,
1209
+ b . literal ( `</${ node . name } >` )
1214
1210
) ;
1215
1211
1216
1212
return ;
@@ -1285,7 +1281,7 @@ const template_visitors = {
1285
1281
}
1286
1282
1287
1283
if ( ! VoidElements . includes ( node . name ) && namespace !== 'foreign' ) {
1288
- state . template . push ( string ( `</${ node . name } >` ) ) ;
1284
+ state . template . push ( b . literal ( `</${ node . name } >` ) ) ;
1289
1285
}
1290
1286
1291
1287
if ( state . options . dev ) {
@@ -1524,9 +1520,9 @@ const template_visitors = {
1524
1520
} ,
1525
1521
TitleElement ( node , context ) {
1526
1522
// title is guaranteed to contain only text/expression tag children
1527
- const template = [ string ( '<title>' ) ] ;
1523
+ const template = [ b . literal ( '<title>' ) ] ;
1528
1524
process_children ( node . fragment . nodes , { ...context , state : { ...context . state , template } } ) ;
1529
- template . push ( string ( '</title>' ) ) ;
1525
+ template . push ( b . literal ( '</title>' ) ) ;
1530
1526
1531
1527
context . state . init . push ( ...serialize_template ( template , b . id ( '$$payload.title' ) , '=' ) ) ;
1532
1528
} ,
@@ -1802,7 +1798,7 @@ function serialize_element_attributes(node, context) {
1802
1798
) . value ;
1803
1799
if ( name !== 'class' || literal_value ) {
1804
1800
context . state . template . push (
1805
- string (
1801
+ b . literal (
1806
1802
` ${ attribute . name } ${
1807
1803
DOMBooleanAttributes . includes ( name ) && literal_value === true
1808
1804
? ''
@@ -1830,7 +1826,7 @@ function serialize_element_attributes(node, context) {
1830
1826
1831
1827
if ( events_to_capture . size !== 0 ) {
1832
1828
for ( const event of events_to_capture ) {
1833
- context . state . template . push ( string ( ` ${ event } ="this.__e=event"` ) ) ;
1829
+ context . state . template . push ( b . literal ( ` ${ event } ="this.__e=event"` ) ) ;
1834
1830
}
1835
1831
}
1836
1832
0 commit comments