Skip to content

Commit 68bdeef

Browse files
committed
re-edited element.js to implement self closing tag acceptance
1 parent 1db0f1d commit 68bdeef

File tree

1 file changed

+12
-5
lines changed
  • packages/svelte/src/compiler/phases/1-parse/state

1 file changed

+12
-5
lines changed

packages/svelte/src/compiler/phases/1-parse/state/element.js

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ import { get_attribute_expression, is_expression_attribute } from '../../../util
1414
import { closing_tag_omitted } from '../../../../html-tree-validation.js';
1515
import { list } from '../../../utils/string.js';
1616

17-
const regex_invalid_unquoted_attribute_value = /^(\/>|[\s"'=<>`])/;
17+
const regex_invalid_unquoted_attribute_value_or_self_closing_tag = /^(\/>|[\s"'=<>`])/;
18+
const regex_invalid_unquoted_attribute_value = /^[\s"'=<>`]/;
1819
const regex_closing_textarea_tag = /^<\/textarea(\s[^>]*)?>/i;
1920
const regex_closing_comment = /-->/;
2021
const regex_whitespace_or_slash_or_closing_tag = /(\s|\/|>)/;
@@ -634,9 +635,15 @@ function read_attribute_value(parser) {
634635
try {
635636
value = read_sequence(
636637
parser,
637-
() => {
638+
/** @param {number} chunk_length */
639+
(chunk_length) => {
638640
// handle common case of quote marks existing outside of regex for performance reasons
639-
if (quote_mark) return parser.match(quote_mark);
641+
if (quote_mark) return !!parser.match(quote_mark);
642+
643+
// if chunk is not empty, handle possibility of self-closing tag
644+
if (chunk_length > 0) {
645+
return !!parser.match_regex(regex_invalid_unquoted_attribute_value_or_self_closing_tag);
646+
}
640647
return !!parser.match_regex(regex_invalid_unquoted_attribute_value);
641648
},
642649
'in attribute value'
@@ -670,7 +677,7 @@ function read_attribute_value(parser) {
670677

671678
/**
672679
* @param {Parser} parser
673-
* @param {() => boolean} done
680+
* @param {(value: number) => boolean} done
674681
* @param {string} location
675682
* @returns {any[]}
676683
*/
@@ -700,7 +707,7 @@ function read_sequence(parser, done, location) {
700707
while (parser.index < parser.template.length) {
701708
const index = parser.index;
702709

703-
if (done()) {
710+
if (done(current_chunk.raw.length)) {
704711
flush(parser.index);
705712
return chunks;
706713
} else if (parser.eat('{')) {

0 commit comments

Comments
 (0)