diff --git a/Cargo.lock b/Cargo.lock index 43038f5..1b1f8b4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -17,6 +17,15 @@ version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" +[[package]] +name = "aho-corasick" +version = "0.7.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cc936419f96fa211c1b9166887b38e5e40b19958e5b895be7c1f93adec7071ac" +dependencies = [ + "memchr", +] + [[package]] name = "ansi_term" version = "0.11.0" @@ -519,12 +528,13 @@ dependencies = [ [[package]] name = "mtsc" -version = "4.7.3" +version = "4.9.4" dependencies = [ "backtrace", "clap", "html5ever", "panic-message", + "regex", "reqwest", "tokio", "v8", @@ -793,6 +803,23 @@ dependencies = [ "bitflags", ] +[[package]] +name = "regex" +version = "1.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e076559ef8e241f2ae3479e36f97bd5741c0330689e217ad51ce2c76808b868a" +dependencies = [ + "aho-corasick", + "memchr", + "regex-syntax", +] + +[[package]] +name = "regex-syntax" +version = "0.6.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "456c603be3e8d448b072f410900c09faf164fbce2d480456f50eea6e25f9c848" + [[package]] name = "remove_dir_all" version = "0.5.3" diff --git a/Cargo.toml b/Cargo.toml index f9333c8..5b55f86 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,8 +1,8 @@ [package] name = "mtsc" -version = "4.7.3" +version = "4.9.4" edition = "2018" -authors = ["S. Beeblebrox"] # +authors = ["Trin Wasinger"] # license = "MIT" [dependencies] @@ -11,6 +11,7 @@ clap = "2.33.3" html5ever = "0.26.0" panic-message = "0.3.0" backtrace = "0.3.64" +regex = "1.7.0" [build-dependencies] reqwest = "0.11.6" diff --git a/dependency-licenses/LICENSE-MIT b/dependency-licenses/LICENSE-MIT index 0ddfb8b..9ac3fdd 100644 --- a/dependency-licenses/LICENSE-MIT +++ b/dependency-licenses/LICENSE-MIT @@ -1,6 +1,6 @@ The MIT License (MIT) -Copyright (c) 2015-2016 Kevin B. Knapp (clap), 2018-2019 the Deno authors (Rust v8), 2016 Sean McArthur (reqwest), 2021 Tokio Contributors (Tokio), 2014 The html5ever Project Developers (html5ever), 2016 Jorge Aparicio (panic-message), 2014 Alex Crichton (backtrace-rs) +Copyright (c) 2015-2016 Kevin B. Knapp (clap), 2018-2019 The Deno Authors (Rust v8), 2016 Sean McArthur (reqwest), 2021 Tokio Contributors (Tokio), 2014 The html5ever Project Developers (html5ever), 2016 Jorge Aparicio (panic-message), 2014 Alex Crichton (backtrace-rs), 2014 The Rust Project Developers (regex) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/src/main.rs b/src/main.rs index d3173df..9eeab6d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,6 +1,7 @@ mod compilers; use compilers::{compile_typescript, compile_html, CompileOptions, minify_javascript, MinifyOptions}; +use regex::{Regex, Captures}; use clap::{Arg, App}; use backtrace::Backtrace; @@ -148,6 +149,11 @@ fn main() { jsx_fragment }; + let regex = Regex::new(r"//#\s*?include\s+?([^\r\n]+)").unwrap(); + let input_text = regex.replace_all(&input_text, |captures: &Captures| { + fs::read_to_string(captures[1].to_string()).expect(format!("Error resolving transform `{}`", captures[0].to_string()).as_str()) + }).to_string(); + let result = if html { compile_html(input_text.as_str(), options.clone()).expect("Error compiling HTML") } else { diff --git a/test.ts b/test.ts index 01de1b0..de065b9 100644 --- a/test.ts +++ b/test.ts @@ -16,4 +16,6 @@ let xx = { foo() { console.log(1+1) } -} \ No newline at end of file +} + +const bar = //#include test_include.ts \ No newline at end of file diff --git a/test_include.ts b/test_include.ts new file mode 100644 index 0000000..584c005 --- /dev/null +++ b/test_include.ts @@ -0,0 +1 @@ +class Bar {} \ No newline at end of file