fix readUntil infinite loop bug

pull/31/head
Rich-Harris 8 years ago
parent b233bbf404
commit 817d371826

@ -94,8 +94,19 @@ export default function parse ( template ) {
}, },
readUntil ( pattern ) { readUntil ( pattern ) {
const match = pattern.exec( this.template.slice( this.index ) ); if ( this.index >= this.template.length ) parser.error( 'Unexpected end of input' );
return this.template.slice( this.index, match ? ( this.index += match.index ) : this.template.length );
const start = this.index;
const match = pattern.exec( this.template.slice( start ) );
if ( match ) {
const start = this.index;
this.index = start + match.index;
return this.template.slice( start, this.index );
}
this.index = this.template.length;
return this.template.slice( start );
}, },
remaining () { remaining () {

@ -0,0 +1,8 @@
{
"message": "Unexpected end of input",
"loc": {
"line": 1,
"column": 2
},
"pos": 2
}

@ -0,0 +1,8 @@
{
"message": "Unexpected end of input",
"loc": {
"line": 1,
"column": 1
},
"pos": 1
}

@ -1,8 +1,8 @@
{ {
"message": "Unexpected end of input", "message": "Unexpected end of input",
"loc": { "loc": {
"line": 2, "line": 1,
"column": 0 "column": 5
}, },
"pos": 6 "pos": 5
} }

@ -32,7 +32,7 @@ describe( 'svelte', () => {
const solo = exists( `test/parser/${dir}/solo` ); const solo = exists( `test/parser/${dir}/solo` );
( solo ? it.only : it )( dir, () => { ( solo ? it.only : it )( dir, () => {
const input = fs.readFileSync( `test/parser/${dir}/input.html`, 'utf-8' ); const input = fs.readFileSync( `test/parser/${dir}/input.html`, 'utf-8' ).replace( /\s+$/, '' );
try { try {
const actual = parse( input ); const actual = parse( input );

Loading…
Cancel
Save