diff options
author | Kitson Kelly <me@kitsonkelly.com> | 2021-12-24 09:38:20 +1100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-12-24 09:38:20 +1100 |
commit | 37dbe5249c9b5c447da5577b5c787d7006a4c80f (patch) | |
tree | 3018d42a9b068170ce360f26f04a5e84fdd87b18 /cli/ast/mod.rs | |
parent | 86bddcc44a3b7356c7b0ccaa526dbaf72e3a9abf (diff) |
fix(cli): include JSON modules in bundle (#13188)
Fixes #13150
Diffstat (limited to 'cli/ast/mod.rs')
-rw-r--r-- | cli/ast/mod.rs | 16 |
1 files changed, 14 insertions, 2 deletions
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<SourceMap>, ) -> Result<(Rc<deno_ast::swc::common::SourceFile>, 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 |