Skip to content

Bug: negative and minus sign lexical conflict #32

Description

@BQXBQX

When you write code like the following

const expr = "2 -3";
console.log(evaluate(expr)); // 2

You will get 2 instead of -1, this is because the tokenizer parses -3 into a number instead of an operator and a number.

If you want to get -1,please add a space before 3, like below

const expr = "2 - 3";
console.log(evaluate(expr)); // -1

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions