Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup compiler pipeline #2657

Closed
bartlomieju opened this issue Jul 18, 2019 · 0 comments · Fixed by #2686
Closed

Cleanup compiler pipeline #2657

bartlomieju opened this issue Jul 18, 2019 · 0 comments · Fixed by #2686

Comments

@bartlomieju
Copy link
Member

I think we should return CompiledModule from fetch_source_file_and_maybe_compile_async:

struct CompiledModule {
   name: String,
   code: String,
}

It'd be made from:

  • original source file for JS and Unknown media types
  • original source file wrapped in export for JSON media type
  • output code of compiled JS file for TypeScript media type

Originally posted by @bartlomieju in https://github.com/_render_node/MDExOlB1bGxSZXF1ZXN0Mjk2NzUxMTk3/timeline/more_items

Additionally:
#2636 (comment)

With refactored DenoDir flow for obtaining compiled modules looks much better but still it's not perfect.

Namely: for all modules TsCompiler.compile_async is called and it short-circuits for non-TS files. Additionally there's SourceFile.js_source() function that shouldn't exist on SourceFile.

Solution proposal:

  1. change return type of TsCompiler.compile_async to CompiledModule returning only URL and compiled code
  2. introduce JsCompiler and JsonCompiler structs. First one would be pass-through and second one would wrap JSON file source code into default export (see:

    deno/cli/deno_dir.rs

    Lines 43 to 62 in ac98bd8

    impl SourceFile {
    // TODO(bartlomieju): this method should be implemented on new `CompiledSourceFile`
    // trait and should be handled by "compiler pipeline"
    pub fn js_source(&self) -> String {
    if self.media_type == msg::MediaType::TypeScript {
    panic!("TypeScript module has no JS source, did you forget to run it through compiler?");
    }
    // TODO: this should be done by compiler and JS module should be returned
    if self.media_type == msg::MediaType::Json {
    return format!(
    "export default {};",
    str::from_utf8(&self.source_code).unwrap()
    );
    }
    // it's either JS or Unknown media type
    str::from_utf8(&self.source_code).unwrap().to_string()
    }
    }
    )
  3. each compiler registers what file extensions/content type it can compile - NOTE: in case of JS files we might use either JsCompiler or TsCompiler depending on the settings (this will be referenced in separate issue)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant