mirror of
https://github.com/swc-project/swc.git
synced 2024-12-25 06:36:08 +03:00
fix(es/minifier): Abort eval on valueOf
or toString
(#8763)
**Related issue:** - Closes #8704 - Closes #8705
This commit is contained in:
parent
6fba5f7c97
commit
9f98a7026d
64
crates/swc/tests/fixture/issues-8xxx/8705/input/.swcrc
Normal file
64
crates/swc/tests/fixture/issues-8xxx/8705/input/.swcrc
Normal file
@ -0,0 +1,64 @@
|
||||
{
|
||||
"jsc": {
|
||||
"parser": {
|
||||
"syntax": "ecmascript",
|
||||
"jsx": false
|
||||
},
|
||||
"target": "es2022",
|
||||
"loose": false,
|
||||
"minify": {
|
||||
"compress": {
|
||||
"arguments": false,
|
||||
"arrows": true,
|
||||
"booleans": true,
|
||||
"booleans_as_integers": false,
|
||||
"collapse_vars": true,
|
||||
"comparisons": true,
|
||||
"computed_props": true,
|
||||
"conditionals": true,
|
||||
"dead_code": true,
|
||||
"directives": true,
|
||||
"drop_console": false,
|
||||
"drop_debugger": true,
|
||||
"evaluate": true,
|
||||
"expression": false,
|
||||
"hoist_funs": false,
|
||||
"hoist_props": true,
|
||||
"hoist_vars": false,
|
||||
"if_return": true,
|
||||
"join_vars": true,
|
||||
"keep_classnames": false,
|
||||
"keep_fargs": true,
|
||||
"keep_fnames": false,
|
||||
"keep_infinity": false,
|
||||
"loops": true,
|
||||
"negate_iife": true,
|
||||
"properties": true,
|
||||
"reduce_funcs": false,
|
||||
"reduce_vars": false,
|
||||
"side_effects": true,
|
||||
"switches": true,
|
||||
"typeofs": true,
|
||||
"unsafe": false,
|
||||
"unsafe_arrows": false,
|
||||
"unsafe_comps": false,
|
||||
"unsafe_Function": false,
|
||||
"unsafe_math": false,
|
||||
"unsafe_symbols": false,
|
||||
"unsafe_methods": false,
|
||||
"unsafe_proto": false,
|
||||
"unsafe_regexp": false,
|
||||
"unsafe_undefined": false,
|
||||
"unused": true,
|
||||
"const_to_let": true,
|
||||
"pristine_globals": true
|
||||
},
|
||||
"mangle": false
|
||||
}
|
||||
},
|
||||
"module": {
|
||||
"type": "es6"
|
||||
},
|
||||
"minify": false,
|
||||
"isModule": true
|
||||
}
|
1
crates/swc/tests/fixture/issues-8xxx/8705/input/1.js
Normal file
1
crates/swc/tests/fixture/issues-8xxx/8705/input/1.js
Normal file
@ -0,0 +1 @@
|
||||
console.log(Math.pow({ valueOf() { return 42 } }, 1))
|
3
crates/swc/tests/fixture/issues-8xxx/8705/output/1.js
Normal file
3
crates/swc/tests/fixture/issues-8xxx/8705/output/1.js
Normal file
@ -0,0 +1,3 @@
|
||||
console.log(Math.pow({
|
||||
valueOf: ()=>42
|
||||
}, 1));
|
@ -0,0 +1,47 @@
|
||||
{
|
||||
"defaults": true,
|
||||
"arguments": false,
|
||||
"arrows": true,
|
||||
"booleans": true,
|
||||
"booleans_as_integers": false,
|
||||
"collapse_vars": true,
|
||||
"comparisons": true,
|
||||
"computed_props": true,
|
||||
"conditionals": true,
|
||||
"dead_code": true,
|
||||
"directives": true,
|
||||
"drop_console": false,
|
||||
"drop_debugger": true,
|
||||
"evaluate": true,
|
||||
"expression": false,
|
||||
"hoist_funs": false,
|
||||
"hoist_props": true,
|
||||
"hoist_vars": false,
|
||||
"if_return": true,
|
||||
"join_vars": true,
|
||||
"keep_classnames": false,
|
||||
"keep_fargs": true,
|
||||
"keep_fnames": false,
|
||||
"keep_infinity": false,
|
||||
"loops": true,
|
||||
"negate_iife": true,
|
||||
"properties": true,
|
||||
"reduce_funcs": false,
|
||||
"reduce_vars": false,
|
||||
"side_effects": true,
|
||||
"switches": true,
|
||||
"typeofs": true,
|
||||
"unsafe": false,
|
||||
"unsafe_arrows": false,
|
||||
"unsafe_comps": false,
|
||||
"unsafe_Function": false,
|
||||
"unsafe_math": false,
|
||||
"unsafe_symbols": false,
|
||||
"unsafe_methods": false,
|
||||
"unsafe_proto": false,
|
||||
"unsafe_regexp": false,
|
||||
"unsafe_undefined": false,
|
||||
"unused": true,
|
||||
"const_to_let": true,
|
||||
"pristine_globals": true
|
||||
}
|
@ -0,0 +1 @@
|
||||
console.log({ toString() { return 'swc' } } + '')
|
@ -0,0 +1,3 @@
|
||||
console.log({
|
||||
toString: ()=>'swc'
|
||||
} + '');
|
@ -0,0 +1,47 @@
|
||||
{
|
||||
"defaults": true,
|
||||
"arguments": false,
|
||||
"arrows": true,
|
||||
"booleans": true,
|
||||
"booleans_as_integers": false,
|
||||
"collapse_vars": true,
|
||||
"comparisons": true,
|
||||
"computed_props": true,
|
||||
"conditionals": true,
|
||||
"dead_code": true,
|
||||
"directives": true,
|
||||
"drop_console": false,
|
||||
"drop_debugger": true,
|
||||
"evaluate": true,
|
||||
"expression": false,
|
||||
"hoist_funs": false,
|
||||
"hoist_props": true,
|
||||
"hoist_vars": false,
|
||||
"if_return": true,
|
||||
"join_vars": true,
|
||||
"keep_classnames": false,
|
||||
"keep_fargs": true,
|
||||
"keep_fnames": false,
|
||||
"keep_infinity": false,
|
||||
"loops": true,
|
||||
"negate_iife": true,
|
||||
"properties": true,
|
||||
"reduce_funcs": false,
|
||||
"reduce_vars": false,
|
||||
"side_effects": true,
|
||||
"switches": true,
|
||||
"typeofs": true,
|
||||
"unsafe": false,
|
||||
"unsafe_arrows": false,
|
||||
"unsafe_comps": false,
|
||||
"unsafe_Function": false,
|
||||
"unsafe_math": false,
|
||||
"unsafe_symbols": false,
|
||||
"unsafe_methods": false,
|
||||
"unsafe_proto": false,
|
||||
"unsafe_regexp": false,
|
||||
"unsafe_undefined": false,
|
||||
"unused": true,
|
||||
"const_to_let": true,
|
||||
"pristine_globals": true
|
||||
}
|
@ -0,0 +1 @@
|
||||
console.log(Math.pow({ valueOf() { return 42 } }, 1))
|
@ -0,0 +1,3 @@
|
||||
console.log(Math.pow({
|
||||
valueOf: ()=>42
|
||||
}, 1));
|
@ -661,10 +661,6 @@ fn test_folding_mix_types_early() {
|
||||
fn test_folding_add1() {
|
||||
fold("x = null + true", "x=1");
|
||||
fold_same("x = a + true");
|
||||
fold("x = '' + {}", "x = \"[object Object]\"");
|
||||
fold("x = [] + {}", "x = \"[object Object]\"");
|
||||
fold("x = {} + []", "x = \"[object Object]\"");
|
||||
fold("x = {} + ''", "x = \"[object Object]\"");
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -935,7 +935,7 @@ pub trait ExprExt {
|
||||
}
|
||||
}
|
||||
|
||||
Expr::Tpl(..) | Expr::Object(ObjectLit { .. }) | Expr::Array(ArrayLit { .. }) => {
|
||||
Expr::Tpl(..) => {
|
||||
return (
|
||||
Pure,
|
||||
num_from_str(&match self.as_pure_string(ctx) {
|
||||
@ -1058,7 +1058,6 @@ pub trait ExprExt {
|
||||
}
|
||||
Known(buf.into())
|
||||
}
|
||||
Expr::Object(ObjectLit { .. }) => Known(Cow::Borrowed("[object Object]")),
|
||||
_ => Unknown,
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user