From afcb94bc19f02c1389554ffc08b6b91b079b1b44 Mon Sep 17 00:00:00 2001 From: Leah Date: Wed, 8 Feb 2023 21:40:21 +0100 Subject: [PATCH 1/2] fix json parsing --- crates/turbopack-json/src/lib.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/crates/turbopack-json/src/lib.rs b/crates/turbopack-json/src/lib.rs index efd996c690b30..6a668c3530195 100644 --- a/crates/turbopack-json/src/lib.rs +++ b/crates/turbopack-json/src/lib.rs @@ -122,9 +122,10 @@ impl EcmascriptChunkItem for JsonChunkItem { let data = content.parse_json().await?; match &*data { FileJsonContent::Content(data) => { - let js_str_content = serde_json::to_string(data)?; + let js_str_content = serde_json::to_string(&data.to_string())?; let inner_code = format!("__turbopack_export_value__(JSON.parse({js_str_content}));"); + Ok(EcmascriptChunkItemContent { inner_code: inner_code.into(), ..Default::default() @@ -139,6 +140,7 @@ impl EcmascriptChunkItem for JsonChunkItem { } else { write!(message, "{}", e)?; } + Err(Error::msg(message)) } FileJsonContent::NotFound => { From b0d06218231f5c12163b532f2706b59fa0ec9b08 Mon Sep 17 00:00:00 2001 From: Leah Date: Wed, 8 Feb 2023 22:20:41 +0100 Subject: [PATCH 2/2] update snapshot --- ...ck-tests_tests_snapshot_imports_json_input_index_6aa119.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/turbopack-tests/tests/snapshot/imports/json/output/crates_turbopack-tests_tests_snapshot_imports_json_input_index_6aa119.js b/crates/turbopack-tests/tests/snapshot/imports/json/output/crates_turbopack-tests_tests_snapshot_imports_json_input_index_6aa119.js index f548a0fc47800..2d3a5d0aff1ca 100644 --- a/crates/turbopack-tests/tests/snapshot/imports/json/output/crates_turbopack-tests_tests_snapshot_imports_json_input_index_6aa119.js +++ b/crates/turbopack-tests/tests/snapshot/imports/json/output/crates_turbopack-tests_tests_snapshot_imports_json_input_index_6aa119.js @@ -13,7 +13,7 @@ console.log(__TURBOPACK__imported__module__$5b$project$5d2f$crates$2f$turbopack$ })()), "[project]/crates/turbopack-tests/tests/snapshot/imports/json/input/package.json (json)": (({ r: __turbopack_require__, x: __turbopack_external_require__, i: __turbopack_import__, s: __turbopack_esm__, v: __turbopack_export_value__, c: __turbopack_cache__, l: __turbopack_load__, j: __turbopack_cjs__, p: process, g: global, __dirname }) => (() => { -__turbopack_export_value__(JSON.parse({"name":"json-snapshot"})); +__turbopack_export_value__(JSON.parse("{\"name\":\"json-snapshot\"}")); })()), "[project]/crates/turbopack-tests/tests/snapshot/imports/json/input/invalid.json (json)": (() => {{ @@ -1071,4 +1071,4 @@ globalThis.TURBOPACK = { })(); -//# sourceMappingURL=crates_turbopack-tests_tests_snapshot_imports_json_input_index_6aa119.js.map \ No newline at end of file +//# sourceMappingURL=crates_turbopack-tests_tests_snapshot_imports_json_input_index_6aa119.js.map