Deno.bundle supports targets < ES2017 (#6346)

This commit provides a "system_loader_es5.js" bundle loader which will be added
to the bundle when the target is < ES2017, which is the minimum target syntax
required for "system_loader.js".

Supports #5913 (via Deno.bundle()) with a couple caveats:

* Allowing "deno bundle" to take a different target is not supported, as we
specifically ignore "target" when passed in a TypeScript config file. This is
because deno bundle is really intended to generate bundles that work in Deno.
It is an unintentional side effect that some bundles are loadable in browsers.

* While a target of "es3" will be accepted, the module loader will still only be
compatible with ES5 or later. Realistically no one should be expecting bundles
generated by Deno to be used on IE8 and prior, and there is just too much
"baggage" to support that at this point.

This is a minor variation of 75bb9d, which exposed some sort of internal V8 bug.
Ref #6358

This is 100% authored by Kitson Kelly. Github might change the author when landing
so I'm leaving this in:
Co-authored-by: Kitson Kelly <me@kitsonkelly.com>
This commit is contained in:
Ryan Dahl 2020-06-18 09:06:48 -04:00 committed by GitHub
parent 940f8e8433
commit a2969ecd27
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 420 additions and 171 deletions

View file

@ -208,7 +208,7 @@ pub fn mksnapshot_bundle(
js_check(
isolate.execute(&bundle_filename.to_string_lossy(), bundle_source_code),
);
let script = &format!("__instantiate(\"{}\");", main_module_name);
let script = &format!("__instantiate(\"{}\", false);", main_module_name);
js_check(isolate.execute("anon", script));
write_snapshot(isolate, snapshot_filename)?;
Ok(())
@ -252,6 +252,7 @@ pub fn get_asset(name: &str) -> Option<&'static str> {
}
match name {
"system_loader.js" => Some(include_str!("system_loader.js")),
"system_loader_es5.js" => Some(include_str!("system_loader_es5.js")),
"bootstrap.ts" => Some("console.log(\"hello deno\");"),
"typescript.d.ts" => inc!("typescript.d.ts"),
"lib.dom.d.ts" => inc!("lib.dom.d.ts"),