Skip to content

Commit 654e354

Browse files
committed
fix
1 parent b5cff06 commit 654e354

File tree

4 files changed

+48
-25
lines changed

4 files changed

+48
-25
lines changed

rewriter/js/src/changes.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,8 @@ impl Ord for JsChange<'_, '_> {
209209
Ordering::Equal => match (&self.ty, &other.ty) {
210210
(Ty::ScramErrFn { .. }, _) => Ordering::Less,
211211
(_, Ty::ScramErrFn { .. }) => Ordering::Greater,
212+
(Ty::WrapFnRight { .. }, _) => Ordering::Less,
213+
(_, Ty::WrapFnRight { .. }) => Ordering::Greater,
212214
_ => Ordering::Equal,
213215
},
214216
x => x,

rewriter/js/src/rewrite.rs

Lines changed: 9 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,9 @@ impl<'alloc: 'data, 'data> RewriteType<'alloc, 'data> {
115115
($span1:ident $span2:ident end) => {
116116
Span::new($span1.end, $span2.end)
117117
};
118+
($span1:ident $span2:ident between) => {
119+
Span::new($span1.end, $span2.start)
120+
};
118121
}
119122

120123
match self {
@@ -128,12 +131,7 @@ impl<'alloc: 'data, 'data> RewriteType<'alloc, 'data> {
128131
enclose,
129132
} => smallvec![
130133
change!(span!(start), WrapGetLeft { ident, enclose }),
131-
change!(propspan, Delete),
132-
change!(Span::new(propspan.start - 1, propspan.start), Delete),
133-
change!(
134-
Span::new(propspan.end, propspan.end),
135-
WrapGetRight { enclose }
136-
),
134+
change!(propspan.expand_left(1), WrapGetRight { enclose }),
137135
],
138136
Self::WrapGetComputed {
139137
leftspan,
@@ -142,13 +140,10 @@ impl<'alloc: 'data, 'data> RewriteType<'alloc, 'data> {
142140
} => smallvec![
143141
change!(span!(start), WrapGetComputedLeft { enclose }),
144142
// replace the bracket with ,
145-
change!(
146-
Span::new(leftspan.end, propspan.start),
147-
Replace { text: "," }
148-
),
143+
change!(span!(leftspan propspan between), Replace { text: "," }),
149144
// replace the other bracket with )
150145
change!(
151-
Span::new(propspan.end, propspan.end + 1),
146+
propspan.expand_right(1),
152147
ClosingParen {
153148
semi: false,
154149
replace: true
@@ -163,10 +158,7 @@ impl<'alloc: 'data, 'data> RewriteType<'alloc, 'data> {
163158
} => smallvec![
164159
change!(span!(start), WrapSet { ident, propspan }),
165160
change!(propspan, Delete),
166-
change!(
167-
Span::new(leftspan.end, rightspan.start),
168-
Replace { text: "," }
169-
),
161+
change!(span!(leftspan rightspan between), Replace { text: "," }),
170162
change!(
171163
span!(end),
172164
ClosingParen {
@@ -182,15 +174,9 @@ impl<'alloc: 'data, 'data> RewriteType<'alloc, 'data> {
182174
} => smallvec![
183175
change!(span!(start), WrapSetComputed),
184176
// replace the bracket with ,
185-
change!(
186-
Span::new(leftspan.end, propspan.start),
187-
Replace { text: "," }
188-
),
177+
change!(span!(leftspan propspan between), Replace { text: "," }),
189178
// replace the other bracket with another ,
190-
change!(
191-
Span::new(propspan.end, rightspan.start),
192-
Replace { text: "," }
193-
),
179+
change!(span!(propspan rightspan between), Replace { text: "," }),
194180
change!(
195181
span!(end),
196182
ClosingParen {

rewriter/js/src/visitor.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ where
133133
it.span(),
134134
WrapGet {
135135
ident: s.property.name,
136-
propspan: Span::new(s.property.span.start, s.property.span.end),
136+
propspan: s.property.span,
137137
enclose: false,
138138
}
139139
));

rewriter/native/test.js

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,36 @@
1-
parent.location
1+
window.location.href = "http://example.com";
2+
3+
console.log(top.window.aaa);
4+
consle.log(globalThis["win" + "dow"]);
5+
6+
globalThis.eval("..");
7+
8+
let ref = { b: this.top.window, c: globalThis["win" + "dow"] };
9+
10+
11+
export default ref;
12+
13+
export { ref };
14+
15+
16+
export { ref as default };
17+
18+
export { S } from "module";
19+
export * from "module";
20+
import sd from "d"
21+
22+
location += "http://example.com";
23+
24+
function f() { return import("x") }
25+
26+
27+
let window = (1, window);
28+
29+
let x = new this.Abc();
30+
31+
try{}catch(e){this.a.log()};
32+
33+
await import("test")
34+
35+
36+
import{c as d,u as g,a as l,r as i,b,d as m,g as p,e as h,f as v,h as k}from"./1e3cB0WW.js";

0 commit comments

Comments
 (0)