ccxvii / mujs

An embeddable Javascript interpreter in C.
http://mujs.com/
ISC License
812 stars 98 forks source link

SyntaxError caused by the trailing comma in the function parameters. #181

Open ahaoboy opened 11 months ago

ahaoboy commented 11 months ago
print(1,)
// SyntaxError: ./i.js: 1: unexpected token in expression: ')'
ccxvii commented 11 months ago

Trailing commas in function calls are not valid ES5 syntax. These were introduced in a much later revision of the language.

ahaoboy commented 10 months ago

Trailing commas in function calls are not valid ES5 syntax. These were introduced in a much later revision of the language.

Have you considered supporting trailing comma syntax? Some formatting tools may generate code like this:

print(
  1,
  2,
  3,
)
Kagami commented 10 months ago

Some formatting tools may generate code like this

Transpile your code to ES5 before running with MuJS. If you use TypeScript, it's just --target es5 option.

ahaoboy commented 10 months ago

More issues arise in bundle tools. Library providers will use any available tools to build code, and bundle tools will directly use the code they have built. While some settings or formatting adjustments can be made after bundle, it undoubtedly adds complexity. For Mujs, this functionality indeed goes beyond the scope of ES5. So, feel free to close this issue.