1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-22 07:14:47 -05:00

fix(cli): fix panic in Deno.emit (#9302)

This commit is contained in:
Yoshiya Hinosawa 2021-01-29 10:33:58 +09:00 committed by GitHub
parent 6ecc86cf2a
commit fc162162a1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 3 deletions

View file

@ -10,6 +10,7 @@ use crate::specifier_handler::MemoryHandler;
use crate::specifier_handler::SpecifierHandler;
use deno_core::error::generic_error;
use deno_core::error::type_error;
use deno_core::error::AnyError;
use deno_core::error::Context;
use deno_core::serde_json;
@ -55,6 +56,7 @@ async fn op_emit(
) -> Result<Value, AnyError> {
deno_runtime::ops::check_unstable2(&state, "Deno.emit");
let args: EmitArgs = serde_json::from_value(args)?;
let root_specifier = args.root_specifier;
let program_state = state.borrow().borrow::<Arc<ProgramState>>().clone();
let runtime_permissions = {
let state = state.borrow();
@ -92,9 +94,16 @@ async fn op_emit(
None
};
let mut builder = GraphBuilder::new(handler, maybe_import_map, None);
let root_specifier =
ModuleSpecifier::resolve_url_or_path(&args.root_specifier)?;
builder.add(&root_specifier, is_dynamic).await?;
let root_specifier = ModuleSpecifier::resolve_url_or_path(&root_specifier)?;
builder
.add(&root_specifier, is_dynamic)
.await
.map_err(|_| {
type_error(format!(
"Unable to handle the given specifier: {}",
&root_specifier
))
})?;
let bundle_type = match args.bundle {
Some(RuntimeBundleType::Esm) => BundleType::Esm,
_ => BundleType::None,

View file

@ -292,3 +292,16 @@ Deno.test({
assert(diagnostics[0].messageText.includes("This import is never used"));
},
});
Deno.test({
name: "Deno.emit() - Unknown media type does not panic",
async fn() {
await assertThrowsAsync(async () => {
await Deno.emit("https://example.com/foo", {
sources: {
"https://example.com/foo": `let foo: string = "foo";`,
},
});
});
},
});