diff --git a/rewriter/native/src/main.rs b/rewriter/native/src/main.rs index a8605de..5778dd8 100644 --- a/rewriter/native/src/main.rs +++ b/rewriter/native/src/main.rs @@ -29,7 +29,7 @@ fn dorewrite(data: &str) -> Result { capture_errors: true, do_sourcemaps: true, - scramitize: true, + scramitize: false, strict_rewrites: true, }, ) diff --git a/rewriter/native/test.js b/rewriter/native/test.js index 52f3f05..9196a12 100644 --- a/rewriter/native/test.js +++ b/rewriter/native/test.js @@ -27,3 +27,5 @@ function f() { return import("x") } let window = (1, window); let x = new this.Abc(); + +try{}catch(e){this.a.log()}; diff --git a/rewriter/rewriter/src/changes.rs b/rewriter/rewriter/src/changes.rs index 7c65554..b0aa696 100644 --- a/rewriter/rewriter/src/changes.rs +++ b/rewriter/rewriter/src/changes.rs @@ -35,6 +35,7 @@ pub(crate) enum Rewrite { /// `$scramerr(name)` ScramErr { span: Span, + ident: CompactStr, }, /// `$scramitize(span)` Scramitize { @@ -113,16 +114,11 @@ impl Rewrite { Self::ImportFn { span } => smallvec![JsChange::ImportFn { span }], Self::MetaFn { span } => smallvec![JsChange::MetaFn { span }], - Self::ScramErr { span, .. } => { - smallvec![ - JsChange::ScramErrFn { - span: Span::new(span.start, span.start) - }, - JsChange::ClosingParen { - span: Span::new(span.end, span.end), - semi: true - } - ] + Self::ScramErr { span, ident } => { + smallvec![JsChange::ScramErrFn { + span: Span::new(span.start, span.start), + ident, + },] } Self::Scramitize { span } => { smallvec![ @@ -180,8 +176,8 @@ enum JsChange { SetRealmFn { span: Span }, /// insert `${cfg.wrapthis}(` WrapThisFn { span: Span }, - /// insert `$scramerr(` - ScramErrFn { span: Span }, + /// insert `$scramerr(ident);` + ScramErrFn { span: Span, ident: CompactStr }, /// insert `$scramitize(` ScramitizeFn { span: Span }, /// insert `eval(${cfg.rewritefn}(` @@ -221,7 +217,7 @@ impl JsChange { Self::WrapFn { span, .. } | Self::SetRealmFn { span } | Self::WrapThisFn { span } - | Self::ScramErrFn { span } + | Self::ScramErrFn { span, .. } | Self::ScramitizeFn { span } | Self::EvalRewriteFn { span } | Self::ShorthandObj { span, .. } @@ -264,9 +260,9 @@ impl JsChange { loc: span.start, str: smallvec![cfg.wrapthisfn.as_str(), "("], }, - Self::ScramErrFn { span } => JsChangeInner::Insert { + Self::ScramErrFn { span, ident } => JsChangeInner::Insert { loc: span.start, - str: smallvec!["$scramerr("], + str: smallvec!["$scramerr(", ident.as_str(), ");"], }, Self::ScramitizeFn { span } => JsChangeInner::Insert { loc: span.start, diff --git a/rewriter/rewriter/src/visitor.rs b/rewriter/rewriter/src/visitor.rs index 22bf779..2ff47c4 100644 --- a/rewriter/rewriter/src/visitor.rs +++ b/rewriter/rewriter/src/visitor.rs @@ -231,9 +231,10 @@ where if self.config.capture_errors { if let Some(h) = &it.handler { if let Some(name) = &h.param { - if name.pattern.get_identifier().is_some() { + if let Some(ident) = name.pattern.get_identifier() { self.jschanges.add(Rewrite::ScramErr { span: Span::new(h.body.span.start + 1, h.body.span.start + 1), + ident: ident.to_compact_str(), }); } }