mirror of
https://github.com/danbulant/oxc
synced 2026-05-25 12:51:57 +00:00
fix(minifier): do not compare bigint with object (#7294)
@Boshen, could you please update the snap of runtime and commit to this PR? I want to see the effects after the unit tests are added.
This commit is contained in:
parent
20d9080d59
commit
cf99be0a0d
3 changed files with 11 additions and 10 deletions
|
|
@ -362,14 +362,14 @@ impl<'a, 'b> PeepholeFoldConstants {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if matches!(left, ValueType::String | ValueType::Number)
|
if matches!(left, ValueType::String | ValueType::Number | ValueType::BigInt)
|
||||||
&& matches!(right, ValueType::Object)
|
&& matches!(right, ValueType::Object)
|
||||||
{
|
{
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
|
||||||
if matches!(left, ValueType::Object)
|
if matches!(left, ValueType::Object)
|
||||||
&& matches!(right, ValueType::String | ValueType::Number)
|
&& matches!(right, ValueType::String | ValueType::Number | ValueType::BigInt)
|
||||||
{
|
{
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
|
@ -873,6 +873,13 @@ mod test {
|
||||||
test("'1' !== 1n", "true");
|
test("'1' !== 1n", "true");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_object_bigint_comparison() {
|
||||||
|
test_same("{ valueOf: function() { return 0n; } } != 0n");
|
||||||
|
test_same("0n != { valueOf: function() { return 0n; } }");
|
||||||
|
test_same("0n != { toString: function() { return '0'; } }");
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_nan_comparison() {
|
fn test_nan_comparison() {
|
||||||
test("NaN < 1", "false");
|
test("NaN < 1", "false");
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@ use crate::{node_util::Ctx, CompressorPass};
|
||||||
pub struct PeepholeSubstituteAlternateSyntax {
|
pub struct PeepholeSubstituteAlternateSyntax {
|
||||||
/// Do not compress syntaxes that are hard to analyze inside the fixed loop.
|
/// Do not compress syntaxes that are hard to analyze inside the fixed loop.
|
||||||
/// e.g. Do not compress `undefined -> void 0`, `true` -> `!0`.
|
/// e.g. Do not compress `undefined -> void 0`, `true` -> `!0`.
|
||||||
/// Opposite of `late` in Closure Compier.
|
/// Opposite of `late` in Closure Compiler.
|
||||||
in_fixed_loop: bool,
|
in_fixed_loop: bool,
|
||||||
|
|
||||||
// states
|
// states
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ commit: 06454619
|
||||||
|
|
||||||
runtime Summary:
|
runtime Summary:
|
||||||
AST Parsed : 18055/18055 (100.00%)
|
AST Parsed : 18055/18055 (100.00%)
|
||||||
Positive Passed: 17796/18055 (98.57%)
|
Positive Passed: 17798/18055 (98.58%)
|
||||||
tasks/coverage/test262/test/language/arguments-object/async-gen-meth-args-trailing-comma-multiple.js
|
tasks/coverage/test262/test/language/arguments-object/async-gen-meth-args-trailing-comma-multiple.js
|
||||||
transform error: Test262Error: Expected SameValue(«0», «2») to be true
|
transform error: Test262Error: Expected SameValue(«0», «2») to be true
|
||||||
|
|
||||||
|
|
@ -447,12 +447,6 @@ transform error: Test262Error: Expected a TypeError to be thrown but no exceptio
|
||||||
tasks/coverage/test262/test/language/expressions/class/heritage-async-arrow-function.js
|
tasks/coverage/test262/test/language/expressions/class/heritage-async-arrow-function.js
|
||||||
transform error: Test262Error: Expected a TypeError to be thrown but no exception was thrown at all
|
transform error: Test262Error: Expected a TypeError to be thrown but no exception was thrown at all
|
||||||
|
|
||||||
tasks/coverage/test262/test/language/expressions/does-not-equals/bigint-and-object.js
|
|
||||||
minify error: Test262Error: The result of (0n != {valueOf: function() {return 0n;}}) is false Expected SameValue(«true», «false») to be true
|
|
||||||
|
|
||||||
tasks/coverage/test262/test/language/expressions/equals/bigint-and-object.js
|
|
||||||
minify error: Test262Error: The result of (0n == {valueOf: function() {return 0n;}}) is true Expected SameValue(«false», «true») to be true
|
|
||||||
|
|
||||||
tasks/coverage/test262/test/language/expressions/exponentiation/bigint-negative-exponent-throws.js
|
tasks/coverage/test262/test/language/expressions/exponentiation/bigint-negative-exponent-throws.js
|
||||||
transform error: Test262Error: (-1n) ** -1n throws RangeError Expected a RangeError but got a TypeError
|
transform error: Test262Error: (-1n) ** -1n throws RangeError Expected a RangeError but got a TypeError
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue