Skip to content

Commit

Permalink
swc fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
andrieshiemstra committed Jun 22, 2023
1 parent 67b26f5 commit e31ba6d
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 21 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# 0.11.2

* pin swc versions
* stacktrace fixer/parser no longer fails on empty lines

# 0.11.1

* if stack parsing fails, log as error but just return original stack
Expand Down
63 changes: 57 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "quickjs_runtime"
version = "0.11.1"
version = "0.11.2"
authors = ["Andries Hiemstra <info@hirofa.com>"]
edition = "2018"
description = "Wrapper API and utils for the QuickJS JavaScript engine with support for Promise, Modules, Async/await"
Expand All @@ -19,7 +19,7 @@ console = []
settimeout = []
setinterval = []
setimmediate = []
typescript = ["swc", "swc_ecma_parser", "swc_common", "swc_ecma_minifier"]
typescript = ["swc", "swc_atoms", "swc_cached", "swc_common", "swc_macros_common", "swc_eq_ignore_macros", "swc_visit", "swc_visit_macros", "swc_config", "swc_config_macro", "swc_ecma_codegen", "swc_ecma_ast", "swc_ecma_codegen_macros", "swc_ecma_ext_transforms", "swc_ecma_utils", "swc_ecma_visit", "swc_ecma_lints", "swc_ecma_loader", "swc_ecma_minifier", "swc_ecma_parser", "swc_error_reporters", "swc_fast_graph", "swc_ecma_usage_analyzer", "swc_timer", "swc_ecma_preset_env", "swc_ecma_transforms", "swc_ecma_transforms_base", "swc_ecma_transforms_compat", "swc_ecma_transforms_classes", "swc_ecma_transforms_module", "swc_ecma_transforms_optimization", "swc_ecma_transforms_proposal", "swc_ecma_transforms_macros", "swc_ecma_transforms_react", "swc_ecma_transforms_typescript", "swc_node_comments", "swc_trace_macro"]

[dependencies]
hirofa_utils = "0.7"
Expand All @@ -40,10 +40,61 @@ serde_json = "1.0"
serde = {version="1.0", features=["derive"]}
string_cache = "0.8"

swc = {version="0.236", optional = true}
swc_ecma_parser = {version = "0.123", optional = true}
swc_common = {version = "0.29", features = ["tty-emitter"], optional = true}
swc_ecma_minifier = {version = "0.160", optional = true}
#swc
# like the good people at denoland said
# swc's version bumping is very buggy and there will often be patch versions
# published that break our build, so we pin all swc versions to prevent
# pulling in new versions of swc crates

# before we can use a newer swc with stable rust we wait for swc_ecma_lint to no longer use box patterns
# see https://github.com/swc-project/swc/blob/main/crates/swc_ecma_lints/src/lib.rs
# could be a while a srust has no plans to stabilize box_patterns
# i gues thats one of the reaons deno does not use the swc dep as it allways loads swc_ecma_linter
# deno does not...
# see https://github.com/denoland/deno_ast/blob/main/Cargo.toml
# nb, just using the swc dep now gives us a lot of errors in macro's since swc upgraded to using syn v2 on june-21-2023
swc = {version="=0.236.21", optional=true}
swc_atoms = {version="=0.4.43", optional=true}
swc_cached = {version="=0.3.15", optional=true}
swc_common = {version="=0.29.40", optional=true, features = ["tty-emitter"]}
swc_macros_common = {version="=0.3.7", optional=true}
swc_eq_ignore_macros = {version="=0.1.1", optional=true}
swc_visit = {version="=0.5.6", optional=true}
swc_visit_macros = {version="=0.5.7", optional=true}
swc_config = {version="=0.1.5", optional=true}
swc_config_macro = {version="=0.1.1", optional=true}
swc_ecma_codegen = {version="=0.128.18", optional=true}
swc_ecma_ast = {version="=0.95.11", optional=true}
swc_ecma_codegen_macros = {version="=0.7.2", optional=true}
swc_ecma_ext_transforms = {version="=0.92.19", optional=true}
swc_ecma_utils = {version="=0.106.18", optional=true}
swc_ecma_visit = {version="=0.81.11", optional=true}
swc_ecma_lints = {version="=0.67.24", optional=true}
swc_ecma_loader = {version="=0.41.42", optional=true}
swc_ecma_minifier = {version="=0.160.38", optional=true}
swc_ecma_parser = {version="=0.123.16", optional=true}
swc_error_reporters = {version="=0.13.41", optional=true}
swc_fast_graph = {version="=0.17.42", optional=true}
swc_ecma_usage_analyzer = {version="=0.1.13", optional=true}
swc_timer = {version="=0.17.43", optional=true}
swc_ecma_preset_env = {version="=0.175.23", optional=true}
swc_ecma_transforms = {version="=0.199.27", optional=true}
swc_ecma_transforms_base = {version="=0.112.24", optional=true}
swc_ecma_transforms_compat = {version="=0.137.25", optional=true}
swc_ecma_transforms_classes = {version="=0.101.24", optional=true}
swc_ecma_transforms_module = {version="=0.154.25", optional=true}
swc_ecma_transforms_optimization = {version="=0.168.27", optional=true}
swc_ecma_transforms_proposal = {version="=0.145.25", optional=true}
swc_ecma_transforms_macros = {version="=0.5.1", optional=true}
swc_ecma_transforms_react = {version="=0.156.26", optional=true}
swc_ecma_transforms_typescript = {version="=0.160.27", optional=true}
swc_node_comments = {version="=0.16.40", optional=true}
swc_trace_macro = {version="=0.1.2", optional=true}


#swc_ecma_parser = {version = "0.136.4", optional = true}
#swc_common = {version = "0.31.13", features = ["tty-emitter"], optional = true}
#swc_ecma_minifier = {version = "0.183.17", optional = true}

[dev-dependencies]
#green_copper_runtime = { git = 'https://github.com/HiRoFa/GreenCopperRuntime', branch="main", features = ["console"]}
Expand Down
13 changes: 0 additions & 13 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,19 +75,6 @@
extern crate lazy_static;
extern crate core;

#[macro_export]
macro_rules! es_args {
( $( $x:expr ),* ) => {
{
let mut temp_vec: Vec<$crate::esvalue::EsValueFacade> = Vec::new();
$(
temp_vec.push($crate::esvalue::EsValueConvertible::to_es_value_facade($x));
)*
temp_vec
}
};
}

pub mod builder;
pub mod facades;
#[cfg(any(
Expand Down
18 changes: 16 additions & 2 deletions src/typescript/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use crate::quickjs_utils::modules::detect_module;
use crate::quickjsruntimeadapter::QuickJsRuntimeAdapter;
use std::cell::RefCell;
use std::collections::HashMap;
use std::fmt::format;
use std::io;
use std::str::FromStr;
use std::sync::Arc;
Expand Down Expand Up @@ -285,6 +284,8 @@ impl FromStr for StackEntry {
fn parse_stack_trace(stack_trace: &str) -> Result<Vec<StackEntry>, String> {
let entries: Vec<StackEntry> = stack_trace
.lines()
.map(|line| line.trim())
.filter(|line| !line.is_empty())
.map(|line| line.parse::<StackEntry>())
.collect::<Result<Vec<_>, _>>()?;

Expand Down Expand Up @@ -357,6 +358,7 @@ pub fn fix_stack_trace(stack_trace: &str, maps: &HashMap<String, String>) -> Str
pub mod tests {
use crate::builder::QuickJsRuntimeBuilder;
use crate::jsutils::{JsValueType, Script};
use crate::typescript::{parse_stack_trace, StackEntry};

#[test]
fn test_ts() {
Expand Down Expand Up @@ -398,6 +400,18 @@ pub mod tests {
.expect("script passed.. which it shouldnt");
// far from perfect test, also line numbers don't yet realy match..
// check again after https://github.com/HiRoFa/quickjs_es_runtime/issues/77
assert!(res.get_stack().contains("t_ts (test.ts):8"));
assert!(res.get_stack().contains("t_ts (file:///test.ts):8"));
}
#[test]
fn test_stack_parse(){
let stack = r#"
at func (file.ts:88)
"#;
match parse_stack_trace(stack) {
Ok(_) => {}
Err(e) => {
panic!("{}", e);
}
}
}
}

0 comments on commit e31ba6d

Please sign in to comment.