mirror of
https://github.com/oxc-project/oxc.git
synced 2026-11-04 10:29:58 +00:00
perf(semantic): reorder numeric literal strict mode checks (#22657)
`check_number_literal` runs for every numeric literal, but these strict-mode diagnostics only apply to numeric literals whose raw source starts with a legacy- style leading zero. Given that most code we check is strict mode, `ctx.strict_mode()` is not a very selective guard here. Checking the raw literal shape first lets ordinary numeric literals fall through after a small byte check, and only queries the current scope’s strict-mode flags when the literal could actually produce one of these diagnostics.
This commit is contained in:
1 parent
4d5ddb1fe9
commit
0aff288116
1 file changed
+7
-9
@@ -397,16 +397,14 @@ pub fn check_number_literal(lit: &NumericLiteral, ctx: &SemanticBuilder<'_>) {
|
||||
false
|
||||
}
|
||||
|
||||
if ctx.strict_mode() {
|
||||
match lit.base {
|
||||
NumberBase::Octal if leading_zero(lit.raw) => {
|
||||
ctx.error(diagnostics::legacy_octal(lit.span));
|
||||
}
|
||||
NumberBase::Decimal | NumberBase::Float if leading_zero(lit.raw) => {
|
||||
ctx.error(diagnostics::leading_zero_decimal(lit.span));
|
||||
}
|
||||
_ => {}
|
||||
match lit.base {
|
||||
NumberBase::Octal if leading_zero(lit.raw) && ctx.strict_mode() => {
|
||||
ctx.error(diagnostics::legacy_octal(lit.span));
|
||||
}
|
||||
NumberBase::Decimal | NumberBase::Float if leading_zero(lit.raw) && ctx.strict_mode() => {
|
||||
ctx.error(diagnostics::leading_zero_decimal(lit.span));
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user