From 286e5d0be9bb11a69d55f0eedd4a6678b0d48e7d Mon Sep 17 00:00:00 2001 From: Leo Kettmeir Date: Wed, 8 Feb 2023 22:40:18 +0100 Subject: refactor: internal runtime code TS support (#17672) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is a proof of concept for being able to snapshot TypeScript files. Currently only a single runtime file is authored in TypeScript - "runtime/js/01_version.ts". Not needed infrastructure was removed from "core/snapshot_util.rs". --------- Co-authored-by: Bartek IwaƄczuk --- core/extensions.rs | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) (limited to 'core/extensions.rs') diff --git a/core/extensions.rs b/core/extensions.rs index e08e8c566..16cca924d 100644 --- a/core/extensions.rs +++ b/core/extensions.rs @@ -6,6 +6,7 @@ use std::rc::Rc; use std::task::Context; use v8::fast_api::FastFunction; +#[derive(Clone, Debug)] pub struct ExtensionFileSource { pub specifier: String, pub code: &'static str, @@ -244,8 +245,9 @@ impl ExtensionBuilder { } } } -/// Helps embed JS files in an extension. Returns Vec<(&'static str, &'static str)> -/// representing the filename and source code. + +/// Helps embed JS files in an extension. Returns a vector of +/// `ExtensionFileSource`, that represent the filename and source code. /// /// Example: /// ```ignore @@ -265,3 +267,29 @@ macro_rules! include_js_files { ] }; } + +/// Helps embed JS files in an extension. Returns a vector of +/// `ExtensionFileSource`, that represent the filename and source code. +/// Additional "dir" option is required, that specifies which directory in the +/// crate root contains the listed files. "dir" option will be prepended to +/// each file name. +/// +/// Example: +/// ```ignore +/// include_js_files_dir!( +/// dir "example", +/// "01_hello.js", +/// "02_goodbye.js", +/// ) +/// ``` +#[macro_export] +macro_rules! include_js_files_dir { + (dir $dir:literal, $($file:literal,)+) => { + vec![ + $($crate::ExtensionFileSource { + specifier: concat!($dir, "/", $file).to_string(), + code: include_str!(concat!($dir, "/", $file)), + },)+ + ] + }; +} -- cgit v1.2.3