Merge branch 'newsyn' into mach

This commit is contained in:
2026-02-06 03:54:38 -06:00
4 changed files with 26 additions and 8 deletions

View File

@@ -9432,7 +9432,8 @@ static int js_parse_expect (JSParseState *s, int tok) {
static int js_parse_expect_semi (JSParseState *s) {
if (s->token.val != ';') {
/* automatic insertion of ';' */
if (s->token.val == TOK_EOF || s->token.val == '}' || s->got_lf) {
if (s->token.val == TOK_EOF || s->token.val == '}' || s->got_lf
|| s->token.val == TOK_ELSE) {
return 0;
}
return js_parse_error (s, "expecting '%c'", ';');
@@ -29498,7 +29499,8 @@ static cJSON *ast_parse_arrow_function (ASTParseState *s) {
static void ast_expect_semi (ASTParseState *s) {
if (s->token_val == ';') { ast_next_token (s); return; }
if (s->token_val == TOK_EOF || s->token_val == '}' || s->got_lf) return;
if (s->token_val == TOK_EOF || s->token_val == '}' || s->got_lf
|| s->token_val == TOK_ELSE) return;
ast_error (s, s->token_ptr, "expecting ';'");
}
@@ -29549,7 +29551,9 @@ static cJSON *ast_parse_statement (ASTParseState *s) {
return NULL;
}
/* Can have multiple declarations */
/* Can have multiple declarations: var x = 1, y = 2 */
cJSON *decls = cJSON_CreateArray ();
int decl_count = 0;
while (s->token_val == TOK_IDENT) {
const uint8_t *var_ptr = s->token_ptr;
node = ast_node (s, kind_name, start);
@@ -29562,7 +29566,7 @@ static cJSON *ast_parse_statement (ASTParseState *s) {
if (s->token_val == '=') {
ast_next_token (s);
cJSON *right = ast_parse_expr (s);
cJSON *right = ast_parse_assign_expr (s);
cJSON_AddItemToObject (node, "right", right);
const char *right_kind = cJSON_GetStringValue (cJSON_GetObjectItem (right, "kind"));
if (right_kind && strcmp (right_kind, "[") == 0 && !cJSON_GetObjectItem (right, "right"))
@@ -29573,15 +29577,24 @@ static cJSON *ast_parse_statement (ASTParseState *s) {
}
JS_FreeCString (s->ctx, str);
ast_node_end (s, node, s->buf_ptr);
cJSON_AddItemToArray (decls, node);
decl_count++;
if (s->token_val == ',') {
ast_next_token (s);
/* For multiple vars, we'd need to return an array - simplified here */
} else {
break;
}
}
ast_expect_semi (s);
if (decl_count == 1) {
node = cJSON_DetachItemFromArray (decls, 0);
cJSON_Delete (decls);
} else {
node = ast_node (s, "var_list", start);
cJSON_AddItemToObject (node, "list", decls);
ast_node_end (s, node, s->buf_ptr);
}
} break;
case TOK_IF: {
@@ -30221,6 +30234,14 @@ static void ast_sem_check_stmt (ASTSemState *st, ASTSemScope *scope, cJSON *stmt
const char *kind = cJSON_GetStringValue (cJSON_GetObjectItem (stmt, "kind"));
if (!kind) return;
if (strcmp (kind, "var_list") == 0) {
cJSON *item;
cJSON_ArrayForEach (item, cJSON_GetObjectItem (stmt, "list")) {
ast_sem_check_stmt (st, scope, item);
}
return;
}
if (strcmp (kind, "var") == 0) {
/* Register variable */
cJSON *left = cJSON_GetObjectItem (stmt, "left");