@@ -19,6 +19,7 @@ export class Parser {
1919 readonly template : string ;
2020 readonly filename ?: string ;
2121 readonly customElement : boolean ;
22+ private readonly isLooseParsing : boolean ;
2223
2324 index = 0 ;
2425 stack : TemplateNode [ ] = [ ] ;
@@ -27,6 +28,7 @@ export class Parser {
2728 css : Style [ ] = [ ] ;
2829 js : Script [ ] = [ ] ;
2930 meta_tags = { } ;
31+ firstError ?: any ;
3032 last_auto_closed_tag ?: LastAutoClosedTag ;
3133
3234 constructor ( template : string , options : ParserOptions ) {
@@ -37,6 +39,7 @@ export class Parser {
3739 this . template = template . replace ( / \s + $ / , '' ) ;
3840 this . filename = options . filename ;
3941 this . customElement = options . customElement ;
42+ this . isLooseParsing = options . errorMode === 'loose' ;
4043
4144 this . html = {
4245 start : null ,
@@ -98,13 +101,18 @@ export class Parser {
98101 }
99102
100103 error ( { code, message } : { code : string ; message : string } , index = this . index ) {
101- error ( message , {
104+ const errorProps = {
102105 name : 'ParseError' ,
103106 code,
104107 source : this . template ,
105108 start : index ,
106109 filename : this . filename
107- } ) ;
110+ } ;
111+ if ( this . isLooseParsing ) {
112+ this . firstError = this . firstError || errorProps ;
113+ } else {
114+ error ( message , errorProps ) ;
115+ }
108116 }
109117
110118 eat ( str : string , required ?: boolean , error ?: { code : string , message : string } ) {
@@ -238,6 +246,7 @@ export default function parse(
238246 html : parser . html ,
239247 css : parser . css [ 0 ] ,
240248 instance : instance_scripts [ 0 ] ,
241- module : module_scripts [ 0 ]
249+ module : module_scripts [ 0 ] ,
250+ firstError : parser . firstError
242251 } ;
243252}
0 commit comments