Skip to content

Commit

Permalink
fix scramerr
Browse files Browse the repository at this point in the history
  • Loading branch information
r58Playz committed Dec 14, 2024
1 parent 4f7f633 commit 519c4e3
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 17 deletions.
2 changes: 1 addition & 1 deletion rewriter/native/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ fn dorewrite(data: &str) -> Result<RewriteResult> {

capture_errors: true,
do_sourcemaps: true,
scramitize: true,
scramitize: false,
strict_rewrites: true,
},
)
Expand Down
2 changes: 2 additions & 0 deletions rewriter/native/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,5 @@ function f() { return import("x") }
let window = (1, window);

let x = new this.Abc();

try{}catch(e){this.a.log()};
26 changes: 11 additions & 15 deletions rewriter/rewriter/src/changes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ pub(crate) enum Rewrite {
/// `$scramerr(name)`
ScramErr {
span: Span,
ident: CompactStr,
},
/// `$scramitize(span)`
Scramitize {
Expand Down Expand Up @@ -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![
Expand Down Expand Up @@ -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}(`
Expand Down Expand Up @@ -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, .. }
Expand Down Expand Up @@ -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,
Expand Down
3 changes: 2 additions & 1 deletion rewriter/rewriter/src/visitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
});
}
}
Expand Down

0 comments on commit 519c4e3

Please sign in to comment.