Skip to content

Number conversion bugs #1629

@LibertasIoT

Description

@LibertasIoT

This project is fantastic! Nevertheless, there are a few nuances that need to be fixed.

One thing that troubles me is the number conversions. in example code below:

const s = "12345"
const n1 = +s
const n2 = parseInt(s)
if (isNaN(n2)) {
    print("Impossible!")
}

Transpiled code below:

s = "12345"
n1 = s
n2 = __TS__ParseInt(s)
if __TS__NumberIsNaN(__TS__Number(n2)) then
    print("Impossible!")
end

Code const n1 = +s is wrongly transpiled. It does nothing resulting the wrong type.
isNaN always forces a Number() conversion on the operand, resulting in a performance penalty.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions