From 37dbe5249c9b5c447da5577b5c787d7006a4c80f Mon Sep 17 00:00:00 2001 From: Kitson Kelly Date: Fri, 24 Dec 2021 09:38:20 +1100 Subject: fix(cli): include JSON modules in bundle (#13188) Fixes #13150 --- cli/ast/mod.rs | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'cli/ast/mod.rs') diff --git a/cli/ast/mod.rs b/cli/ast/mod.rs index 464c89257..80cbd5c4b 100644 --- a/cli/ast/mod.rs +++ b/cli/ast/mod.rs @@ -351,11 +351,23 @@ pub fn transpile_module( cm: Rc, ) -> Result<(Rc, Module), AnyError> { let source = strip_bom(source); + let source = if media_type == MediaType::Json { + format!( + "export default JSON.parse(`{}`);", + source.replace("${", "\\${").replace('`', "\\`") + ) + } else { + source.to_string() + }; let source_file = - cm.new_source_file(FileName::Url(specifier.clone()), source.to_string()); + cm.new_source_file(FileName::Url(specifier.clone()), source); let input = StringInput::from(&*source_file); let comments = SingleThreadedComments::default(); - let syntax = get_syntax(media_type); + let syntax = if media_type == MediaType::Json { + get_syntax(MediaType::JavaScript) + } else { + get_syntax(media_type) + }; let lexer = Lexer::new(syntax, deno_ast::ES_VERSION, input, Some(&comments)); let mut parser = deno_ast::swc::parser::Parser::new_from(lexer); let module = parser -- cgit v1.2.3