@@ -19,6 +19,7 @@ export class Parser {
19
19
readonly template : string ;
20
20
readonly filename ?: string ;
21
21
readonly customElement : boolean ;
22
+ private readonly isLooseParsing : boolean ;
22
23
23
24
index = 0 ;
24
25
stack : TemplateNode [ ] = [ ] ;
@@ -27,6 +28,7 @@ export class Parser {
27
28
css : Style [ ] = [ ] ;
28
29
js : Script [ ] = [ ] ;
29
30
meta_tags = { } ;
31
+ firstError ?: any ;
30
32
last_auto_closed_tag ?: LastAutoClosedTag ;
31
33
32
34
constructor ( template : string , options : ParserOptions ) {
@@ -37,6 +39,7 @@ export class Parser {
37
39
this . template = template . replace ( / \s + $ / , '' ) ;
38
40
this . filename = options . filename ;
39
41
this . customElement = options . customElement ;
42
+ this . isLooseParsing = options . errorMode === 'loose' ;
40
43
41
44
this . html = {
42
45
start : null ,
@@ -98,13 +101,18 @@ export class Parser {
98
101
}
99
102
100
103
error ( { code, message } : { code : string ; message : string } , index = this . index ) {
101
- error ( message , {
104
+ const errorProps = {
102
105
name : 'ParseError' ,
103
106
code,
104
107
source : this . template ,
105
108
start : index ,
106
109
filename : this . filename
107
- } ) ;
110
+ } ;
111
+ if ( this . isLooseParsing ) {
112
+ this . firstError = this . firstError = errorProps ;
113
+ } else {
114
+ error ( message , errorProps ) ;
115
+ }
108
116
}
109
117
110
118
eat ( str : string , required ?: boolean , error ?: { code : string , message : string } ) {
@@ -238,6 +246,7 @@ export default function parse(
238
246
html : parser . html ,
239
247
css : parser . css [ 0 ] ,
240
248
instance : instance_scripts [ 0 ] ,
241
- module : module_scripts [ 0 ]
249
+ module : module_scripts [ 0 ] ,
250
+ firstError : parser . firstError
242
251
} ;
243
252
}
0 commit comments