diff options
author | Bartek IwaĆczuk <biwanczuk@gmail.com> | 2020-06-19 12:27:15 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-06-19 12:27:15 +0200 |
commit | 826a3135b41bdaeb8c8cd27a4652563971b04baa (patch) | |
tree | e8baaca1b5560e5825e19f5b0c6872d781d767a3 /cli/msg.rs | |
parent | 345a5b3dff3a333d156bf4aff9f7e2a355d59746 (diff) |
refactor(compiler): split code paths for compile and bundle (#6304)
* refactor "compile" and "runtimeCompile" in "compiler.ts" and factor out
separate methods for "compile" and "bundle" operations
* remove noisy debug output from "compiler.ts"
* provide "Serialize" implementations for enums in "msg.rs"
* rename "analyze_dependencies_and_references" to "pre_process_file" and
move it to "tsc.rs"
* refactor ModuleGraph to use more concrete types and properly annotate
locations where errors occur
* remove dead code from "file_fetcher.rs" - "SourceFile.types_url" is no
longer needed, as type reference parsing is done in "ModuleGraph"
* remove unneeded field "source_path" from ".meta" files stored for
compiled source file (towards #6080)
Diffstat (limited to 'cli/msg.rs')
-rw-r--r-- | cli/msg.rs | 47 |
1 files changed, 42 insertions, 5 deletions
diff --git a/cli/msg.rs b/cli/msg.rs index 186fde42c..3e5000296 100644 --- a/cli/msg.rs +++ b/cli/msg.rs @@ -3,10 +3,11 @@ // Warning! The values in this enum are duplicated in js/compiler.ts // Update carefully! use serde::Serialize; +use serde::Serializer; #[allow(non_camel_case_types)] -#[repr(i8)] -#[derive(Clone, Copy, PartialEq, Debug, Serialize)] +#[repr(i32)] +#[derive(Clone, Copy, PartialEq, Debug)] pub enum MediaType { JavaScript = 0, JSX = 1, @@ -17,6 +18,24 @@ pub enum MediaType { Unknown = 6, } +impl Serialize for MediaType { + fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> + where + S: Serializer, + { + let value: i32 = match self { + MediaType::JavaScript => 0 as i32, + MediaType::JSX => 1 as i32, + MediaType::TypeScript => 2 as i32, + MediaType::TSX => 3 as i32, + MediaType::Json => 4 as i32, + MediaType::Wasm => 5 as i32, + MediaType::Unknown => 6 as i32, + }; + Serialize::serialize(&value, serializer) + } +} + pub fn enum_name_media_type(mt: MediaType) -> &'static str { match mt { MediaType::JavaScript => "JavaScript", @@ -32,10 +51,28 @@ pub fn enum_name_media_type(mt: MediaType) -> &'static str { // Warning! The values in this enum are duplicated in js/compiler.ts // Update carefully! #[allow(non_camel_case_types)] -#[repr(i8)] +#[repr(i32)] #[derive(Clone, Copy, PartialEq, Debug)] pub enum CompilerRequestType { Compile = 0, - RuntimeCompile = 1, - RuntimeTranspile = 2, + Bundle = 1, + RuntimeCompile = 2, + RuntimeBundle = 3, + RuntimeTranspile = 4, +} + +impl Serialize for CompilerRequestType { + fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> + where + S: Serializer, + { + let value: i32 = match self { + CompilerRequestType::Compile => 0 as i32, + CompilerRequestType::Bundle => 1 as i32, + CompilerRequestType::RuntimeCompile => 2 as i32, + CompilerRequestType::RuntimeBundle => 3 as i32, + CompilerRequestType::RuntimeTranspile => 4 as i32, + }; + Serialize::serialize(&value, serializer) + } } |