shithub: libmujs

Download patch

ref: 380be8129fadeb358e5475cba08005a08ded9c29
parent: 659e55976532f9b390541139b486441f28f56b7e
author: Tor Andersson <[email protected]>
date: Thu Jan 9 20:45:28 EST 2014

Parse labelled statements.

--- a/js-parse.c
+++ b/js-parse.c
@@ -735,7 +735,20 @@
 		return STM2(SWITCH, a, b);
 	}
 
-	if (J->lookahead != TK_FUNCTION) {
+	/* LabelledStatement : Identifier ':' Statement */
+	/* ExpressionStatement : Expression ';' */
+	if (J->lookahead == TK_IDENTIFIER) {
+		a = expression(J, 0);
+		if (a->type == AST_IDENTIFIER && accept(J, ':')) {
+			b = statement(J);
+			return STM2(LABEL, a, b);
+		}
+		semicolon(J);
+		return a;
+	}
+
+	/* ExpressionStatement : [lookahead not 'function' or '{'] Expression ';' */
+	if (J->lookahead != TK_FUNCTION && J->lookahead != '{') {
 		a = expression(J, 0);
 		semicolon(J);
 		return a;