-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(es/minifier): Fix detection of
this
(#9339)
**Related issue:** - Closes #9148
- Loading branch information
Showing
6 changed files
with
80 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
swc_ecma_minifier: patch | ||
--- | ||
|
||
fix(es/minifier): Fix detection of `this` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
crates/swc_ecma_minifier/tests/fixture/issues/9148/input.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
function foo() { | ||
const obj = { | ||
clear: function () { | ||
console.log('clear') | ||
}, | ||
start: function () { | ||
const _this = this; | ||
setTimeout(function () { | ||
_this.clear(); | ||
}); | ||
} | ||
}; | ||
return () => obj.start() | ||
}; | ||
|
||
export default foo() |
14 changes: 14 additions & 0 deletions
14
crates/swc_ecma_minifier/tests/fixture/issues/9148/output.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
export default (function() { | ||
const obj = { | ||
clear: function() { | ||
console.log('clear'); | ||
}, | ||
start: function() { | ||
const _this = this; | ||
setTimeout(function() { | ||
_this.clear(); | ||
}); | ||
} | ||
}; | ||
return ()=>obj.start(); | ||
})(); |
8 changes: 7 additions & 1 deletion
8
crates/swc_ecma_minifier/tests/terser/compress/hoist_props/contains_this_1/output.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,7 @@ | ||
console.log(1, 1); | ||
var o = { | ||
u: function() { | ||
return this === this; | ||
}, | ||
p: 1 | ||
}; | ||
console.log(o.p, o.p); |