File tree Expand file tree Collapse file tree 4 files changed +25
-0
lines changed
tests/migrate/samples/self-closing-elements Expand file tree Collapse file tree 4 files changed +25
-0
lines changed Original file line number Diff line number Diff line change 1+ ---
2+ ' svelte ' : patch
3+ ---
4+
5+ feat: support migration of self closing tags
Original file line number Diff line number Diff line change @@ -14,6 +14,7 @@ import { extract_identifiers } from '../utils/ast.js';
1414import { migrate_svelte_ignore } from '../utils/extract_svelte_ignore.js' ;
1515import { determine_slot } from '../utils/slot.js' ;
1616import { validate_component_options } from '../validate-options.js' ;
17+ import { is_svg , is_void } from '../../utils.js' ;
1718
1819const regex_style_tags = / ( < s t y l e [ ^ > ] + > ) ( [ \S \s ] * ?) ( < \/ s t y l e > ) / g;
1920const style_placeholder = '/*$$__STYLE_CONTENT__$$*/' ;
@@ -580,6 +581,15 @@ const template = {
580581 } ,
581582 RegularElement ( node , { state, next } ) {
582583 handle_events ( node , state ) ;
584+ // Strip off any namespace from the beginning of the node name.
585+ const node_name = node . name . replace ( / [ a - z A - Z - ] * : / g, '' ) ;
586+
587+ if ( state . analysis . source [ node . end - 2 ] === '/' && ! is_void ( node_name ) && ! is_svg ( node_name ) ) {
588+ let trimmed_position = node . end - 2 ;
589+ while ( state . str . original . charAt ( trimmed_position - 1 ) === ' ' ) trimmed_position -- ;
590+ state . str . remove ( trimmed_position , node . end - 1 ) ;
591+ state . str . appendRight ( node . end , `</${ node . name } >` ) ;
592+ }
583593 next ( ) ;
584594 } ,
585595 SvelteElement ( node , { state, next } ) {
Original file line number Diff line number Diff line change 1+ <div />
2+ <div title =" preserve" />
3+ <input type =" text" />
4+ <hr />
5+ <f:table />
Original file line number Diff line number Diff line change 1+ <div ></div >
2+ <div title =" preserve" ></div >
3+ <input type =" text" />
4+ <hr />
5+ <f:table ></f:table >
You can’t perform that action at this time.
0 commit comments