cson-parser icon indicating copy to clipboard operation
cson-parser copied to clipboard

Numbers prefixed with a plus shouldn't throw errors

Open Alhadis opened this issue 5 years ago • 2 comments

+1 is valid in both CoffeeScript and JavaScript, but cson-parser treats it as an error:

λ ~: echo '+2' | cson2json
/usr/local/lib/node_modules/cson/esnext/cli.js:72
      throw result;
      ^

SyntaxError: Syntax error on line 1, column 1: Unknown unary operator +
    at Op (/usr/local/lib/node_modules/cson/node_modules/cson-parser/lib/parse.js:190:17)
    at transformNode (/usr/local/lib/node_modules/cson/node_modules/cson-parser/lib/parse.js:216:12)
    at Block (/usr/local/lib/node_modules/cson/node_modules/cson-parser/lib/parse.js:94:12)
    at transformNode (/usr/local/lib/node_modules/cson/node_modules/cson-parser/lib/parse.js:216:12)
    at Object.parse (/usr/local/lib/node_modules/cson/node_modules/cson-parser/lib/parse.js:222:16)

Alhadis avatar Aug 05 '18 14:08 Alhadis

Hm, interesting. Is there a specific use case for using unary plus in a config? I'd be fine with adding it but I don't think it'd be something we would get around to soon.

jkrems avatar Aug 07 '18 15:08 jkrems

Probably only for cosmetic affairs like alignment and consistency with other numerals:

 a: +2,
 b: -3,
 3: +3,

Alhadis avatar Aug 07 '18 16:08 Alhadis