summaryrefslogtreecommitdiff
path: root/src/deno_dir.rs
diff options
context:
space:
mode:
authorRyan Dahl <ry@tinyclouds.org>2019-01-09 12:59:46 -0500
committerGitHub <noreply@github.com>2019-01-09 12:59:46 -0500
commit0ceb554343ff3d311a19f027b7aa8f0806bbb162 (patch)
tree24603f165b7da831c2b68ad9472e26fabf72134c /src/deno_dir.rs
parent3afdae165d3bc9acb5e5a4749334d2673f2566af (diff)
Native ES modules (#1460)
* Native ES modules This is a major refactor of internal compiler. Before: JS and TS both were sent through the typescript compiler where their imports were parsed and handled. Both compiled to AMD JS and finally sent to V8 Now: JS is sent directly into V8. TS is sent through the typescript compiler, but tsc generates ES modules now instead of AMD. This generated JS is then dumped into V8. This should much faster for pure JS code. It may improve TS compilation speed. In the future this allows us to separate TS out of the runtime heap and into its own dedicated snapshot. This will result in a smaller runtime heap, and thus should be faster. Some tests were unfortunately disabled to ease landing this patch: 1. compiler_tests.ts which I intend to bring back in later commits. 2. Some text_encoding_test.ts tests which made the file invalid utf8. See PR for a discussion. Also worth noting that this is necessary to support WASM
Diffstat (limited to 'src/deno_dir.rs')
-rw-r--r--src/deno_dir.rs24
1 files changed, 5 insertions, 19 deletions
diff --git a/src/deno_dir.rs b/src/deno_dir.rs
index d3d67d195..3b35035d6 100644
--- a/src/deno_dir.rs
+++ b/src/deno_dir.rs
@@ -1,4 +1,5 @@
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
+use compiler::CodeFetchOutput;
use dirs;
use errors;
use errors::DenoError;
@@ -19,25 +20,6 @@ use std::result::Result;
use url;
use url::Url;
-#[derive(Debug)]
-pub struct CodeFetchOutput {
- pub module_name: String,
- pub filename: String,
- pub media_type: msg::MediaType,
- pub source_code: String,
- pub maybe_output_code: Option<String>,
- pub maybe_source_map: Option<String>,
-}
-
-impl CodeFetchOutput {
- pub fn js_source<'a>(&'a self) -> &'a String {
- match self.maybe_output_code {
- None => &self.source_code,
- Some(ref output_code) => output_code,
- }
- }
-}
-
/// Gets corresponding MediaType given extension
fn extmap(ext: &str) -> msg::MediaType {
match ext {
@@ -319,6 +301,10 @@ impl DenoDir {
out.source_code = filter_shebang(out.source_code);
+ if out.media_type != msg::MediaType::TypeScript {
+ return Ok(out);
+ }
+
let result =
self.load_cache(out.filename.as_str(), out.source_code.as_str());
match result {