mirror of
https://github.com/swc-project/swc.git
synced 2024-11-28 11:13:43 +03:00
fix(es/minifier): Fix handling of .toFixed
call without an argument (#5868)
This commit is contained in:
parent
9f182c555c
commit
90d311c042
@ -282,7 +282,12 @@ impl Pure<'_> {
|
||||
}
|
||||
|
||||
if &*method.sym == "toFixed" {
|
||||
if let Some(precision) = eval_as_number(&self.expr_ctx, &args[0].expr) {
|
||||
if let Some(precision) = args
|
||||
.first()
|
||||
// https://tc39.es/ecma262/multipage/numbers-and-dates.html#sec-number.prototype.tofixed
|
||||
// 3. Assert: If fractionDigits is undefined, then f is 0.
|
||||
.map_or(Some(0f64), |arg| eval_as_number(&self.expr_ctx, &arg.expr))
|
||||
{
|
||||
let precision = precision.floor() as usize;
|
||||
let value = num_to_fixed(num.value, precision + 1);
|
||||
|
||||
|
@ -0,0 +1,42 @@
|
||||
TestSnapshot {
|
||||
vars: [
|
||||
(
|
||||
(
|
||||
Atom('foo' type=inline),
|
||||
#1,
|
||||
),
|
||||
VarUsageInfo {
|
||||
inline_prevented: false,
|
||||
ref_count: 1,
|
||||
cond_init: false,
|
||||
declared: false,
|
||||
declared_count: 0,
|
||||
declared_as_fn_param: false,
|
||||
declared_as_fn_expr: false,
|
||||
assign_count: 0,
|
||||
mutation_by_call_count: 0,
|
||||
usage_count: 0,
|
||||
reassigned_with_assignment: false,
|
||||
reassigned_with_var_decl: false,
|
||||
mutated: true,
|
||||
has_property_access: false,
|
||||
has_property_mutation: false,
|
||||
accessed_props: {},
|
||||
exported: false,
|
||||
used_above_decl: true,
|
||||
is_fn_local: true,
|
||||
used_by_nested_fn: false,
|
||||
executed_multiple_time: false,
|
||||
used_in_cond: false,
|
||||
var_kind: None,
|
||||
var_initialized: true,
|
||||
declared_as_catch_param: false,
|
||||
no_side_effect_for_member_access: false,
|
||||
used_as_callee: false,
|
||||
used_as_arg: false,
|
||||
pure_fn: false,
|
||||
infects: [],
|
||||
},
|
||||
),
|
||||
],
|
||||
}
|
@ -0,0 +1,46 @@
|
||||
{
|
||||
"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,3 @@
|
||||
foo = {
|
||||
v: (0).toFixed(),
|
||||
};
|
@ -0,0 +1,3 @@
|
||||
foo = {
|
||||
v: "0"
|
||||
};
|
@ -0,0 +1,3 @@
|
||||
foo = {
|
||||
v: (0).toFixed()
|
||||
};
|
Loading…
Reference in New Issue
Block a user