diff --git a/parse.ce b/parse.ce index b269666d..c0187a9e 100644 --- a/parse.ce +++ b/parse.ce @@ -6,4 +6,4 @@ var filename = args[0] var src = text(fd.slurp(filename)) var result = tokenize(src, filename) var ast = parse(result.tokens, src, filename, tokenize) -print(json.encode(ast)) +print(json.encode(ast, true)) diff --git a/source/runtime.c b/source/runtime.c index 2aba02e9..bf0f5f40 100644 --- a/source/runtime.c +++ b/source/runtime.c @@ -5762,8 +5762,7 @@ static int js_json_to_str (JSContext *ctx, JSONStringifyContext *jsc, JSValue ho if (ret) { if (js_get_length64 (ctx, &len, val_ref.val)) goto exception; /* Check if this is a leaf array for compact mode. - Leaf = no element is an array, and no element is an object - that has array-valued properties. */ + Leaf = every element is a primitive or string (no arrays or objects). */ BOOL was_compact = jsc->in_compact_array; if (jsc->compact_arrays && !jsc->in_compact_array && !JS_IsEmptyString (jsc->gap)) { BOOL is_leaf = TRUE; @@ -5773,23 +5772,7 @@ static int js_json_to_str (JSContext *ctx, JSONStringifyContext *jsc, JSValue ho if (JS_IsArray (v) > 0) { is_leaf = FALSE; } else if (mist_is_gc_object (v) && !JS_IsText (v)) { - /* Element is an object — check if any property is an array */ - v_ref.val = v; - prop_ref.val = JS_GetOwnPropertyNames (ctx, v_ref.val); - if (!JS_IsException (prop_ref.val)) { - int64_t nprops; - if (!js_get_length64 (ctx, &nprops, prop_ref.val)) { - for (int64_t j = 0; j < nprops && is_leaf; j++) { - JSValue key = JS_GetPropertyNumber (ctx, prop_ref.val, j); - if (!JS_IsException (key)) { - JSValue pval = JS_GetPropertyValue (ctx, v_ref.val, key); - if (JS_IsArray (pval) > 0) is_leaf = FALSE; - } - } - } - } - v_ref.val = JS_NULL; - prop_ref.val = JS_NULL; + is_leaf = FALSE; } } if (is_leaf) jsc->in_compact_array = TRUE; diff --git a/streamline.ce b/streamline.ce index 5fdf3c17..334a86e4 100644 --- a/streamline.ce +++ b/streamline.ce @@ -16,7 +16,4 @@ var ast = parse(result.tokens, src, filename, tokenize) var folded = fold(ast) var compiled = mcode(folded) var optimized = streamline(compiled) -print(json.encode(optimized, true, function(k,v) { - if (is_array(v)) return json.encode(v) - return v -})) +print(json.encode(optimized, true))