@@ -40,8 +40,11 @@ static int js_parse_jsx_expr(JSParseState *s, int level)
4040 JSValue tag = JS_UNINITIALIZED ;
4141 JSAtom attr_name = JS_ATOM_NULL ;
4242 JSValue attr_value = JS_UNINITIALIZED ;
43+ int token_read = 0 ;
44+ int is_bodyless = 0 ;
4345
4446 const char * errmsg = "invalid JSX expression" ;
47+ char msg_buffer [512 ] = { 0 };
4548#if defined(CONFIG_JSX_SCITER ) // HTML shortcuts used by Sciter
4649 char class_buffer [512 ] = { 0 };
4750#endif
@@ -107,7 +110,9 @@ static int js_parse_jsx_expr(JSParseState *s, int level)
107110 errmsg = "expecting '>'" ;
108111 goto fail ;
109112 }
110- goto GENERATE_KIDS ;
113+ //goto GENERATE_KIDS;
114+ is_bodyless = 1 ;
115+ break ;
111116 }
112117#if defined(CONFIG_JSX_SCITER ) // HTML shortcuts used by Sciter
113118 if (s -> token .val == '#' ) { // <div #some> -> <div id="some">
@@ -192,16 +197,29 @@ static int js_parse_jsx_expr(JSParseState *s, int level)
192197 goto fail ;
193198 }
194199
195- if (js_parse_expect (s , '=' ))
200+ if (s -> token .val != '=' ) {
201+ token_read = 1 ;
202+ attr_value = JS_AtomToString (s -> ctx , JS_ATOM_empty_string );
203+ goto PUSH_ATTR_VALUE ;
204+ }
205+ else {
206+ token_read = 0 ;
207+ if (next_token (s )) // eat `=`
196208 goto fail ;
209+ }
197210
198211 if (s -> token .val == TOK_STRING ) {
199- attr_value = JS_DupValue (s -> ctx ,s -> token .u .str .str );
212+ attr_value = JS_DupValue (s -> ctx , s -> token .u .str .str );
200213 PUSH_ATTR_VALUE :
201214 if (emit_push_const (s , attr_value , 0 ))
202215 goto fail ;
203216 JS_FreeValue (s -> ctx , attr_value );
204217 }
218+ else if (s -> token .val == TOK_TEMPLATE ) {
219+ if (js_parse_template (s , 0 , NULL ))
220+ goto fail ;
221+ token_read = 1 ;
222+ }
205223 else if (s -> token .val == '{' )
206224 {
207225 if (next_token (s ))
@@ -213,15 +231,34 @@ static int js_parse_jsx_expr(JSParseState *s, int level)
213231 goto fail ;
214232 }
215233 }
234+ else if (s -> token .val == TOK_NUMBER ) {
235+ attr_value = JS_DupValue (s -> ctx ,s -> token .u .num .val );
236+ goto PUSH_ATTR_VALUE ;
237+ }
238+ else if (s -> token .val == TOK_FALSE ) {
239+ emit_op (s , OP_push_false );
240+ }
241+ else if (s -> token .val == TOK_TRUE ) {
242+ emit_op (s , OP_push_true );
243+ }
244+ else if (s -> token .val == TOK_NULL ) {
245+ emit_op (s , OP_null );
246+ }
247+ else {
248+ errmsg = "bad attribute value" ;
249+ goto fail ;
250+ }
216251
217252 set_object_name (s , attr_name );
218253 emit_op (s , OP_define_field );
219254 emit_atom (s , attr_name );
220255 JS_FreeAtom (s -> ctx , attr_name );
221256
257+ if (!token_read ) {
222258 if (next_web_token (s ))
223259 goto fail ;
224260 }
261+ }
225262
226263#if defined(CONFIG_JSX_SCITER ) // HTML shortcuts used by Sciter
227264 if (class_buffer [0 ]) { // add remaining classes
@@ -239,7 +276,8 @@ static int js_parse_jsx_expr(JSParseState *s, int level)
239276
240277 // parse content of the element
241278
242- for (;;) {
279+ while (!is_bodyless )
280+ {
243281 const uint8_t * p ;
244282 p = s -> last_ptr = s -> buf_ptr ;
245283 s -> last_line_num = s -> token .line_num ;
@@ -271,7 +309,12 @@ static int js_parse_jsx_expr(JSParseState *s, int level)
271309 goto fail ;
272310 if (token_is_ident (s -> token .val )) { /* keywords and reserved words have a valid atom */
273311 if (s -> token .u .ident .atom != tag_atom ) {
274- errmsg = "head and tail tags do not match" ;
312+ char atail [64 ];
313+ char ahead [64 ];
314+ snprintf (msg_buffer , countof (msg_buffer ), "head <%s> and tail </%s> tags do not match" ,
315+ JS_AtomGetStr (s -> ctx , ahead , countof (ahead ), tag_atom ),
316+ JS_AtomGetStr (s -> ctx , atail , countof (atail ), s -> token .u .ident .atom ));
317+ errmsg = msg_buffer ;
275318 goto fail ;
276319 }
277320 if (next_token (s ))
@@ -301,7 +344,7 @@ static int js_parse_jsx_expr(JSParseState *s, int level)
301344 }
302345 }
303346
304- GENERATE_KIDS :
347+ // GENERATE_KIDS:
305348 emit_op (s , OP_array_from );
306349 emit_u16 (s , kids_count );
307350
@@ -315,15 +358,11 @@ static int js_parse_jsx_expr(JSParseState *s, int level)
315358
316359 JS_FreeValue (s -> ctx , tag );
317360 JS_FreeAtom (s -> ctx , tag_atom );
318- //JS_FreeAtom(s->ctx, attr_name);
319- //JS_FreeValue(s->ctx, attr_value);
320361
321362 return 0 ;
322363fail :
323364 JS_FreeValue (s -> ctx , tag );
324365 JS_FreeAtom (s -> ctx , tag_atom );
325- JS_FreeAtom (s -> ctx , attr_name );
326- //JS_FreeValue(s->ctx, attr_value);
327366 return js_parse_error (s , errmsg );
328367}
329368
0 commit comments