Skip to content

Commit c76d6ad

Browse files
committed
Small optimization for numeric operators that precoerces numbers that
are sourced from other operators.
1 parent 741a2b9 commit c76d6ad

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

defaultMethods.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1002,6 +1002,13 @@ function numberCoercion (i, buildState) {
10021002
// regex match
10031003
if (/^-?\d+(\.\d*)?$/.test(f)) return '+' + f
10041004

1005+
// if it starts with " it's a string
1006+
if (f.startsWith('"')) return '+' + precoerceNumber(+JSON.parse(f))
1007+
if (f === 'true') return '1'
1008+
if (f === 'false') return '0'
1009+
if (f === 'null') return '0'
1010+
if (f.startsWith('[') || f.startsWith('{')) return precoerceNumber(NaN)
1011+
10051012
return `(+precoerceNumber(${f}))`
10061013
}
10071014

0 commit comments

Comments
 (0)