ccxvii / mujs

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

Declaring classes after functions causes a syntax error #190

Closed 3405691582 closed 2 months ago

3405691582 commented 2 months ago

Sample input:

$ cat /tmp/b.js
function f() { return 1; }

class A {
  constructor() {
  }
}

console.log(new A());

mujs:

$ mujs /tmp/b.js
SyntaxError: /tmp/b.js:3: unexpected token: (identifier) (expected ';')

Other engines or using the console in a browser with this input seems to process this input fine, either with [object Object] or A {}.

ccxvii commented 2 months ago

Classes are not in the ES5 language that MuJS supports. They were introduced with ES6. If you want to use the class syntax, you will need to use a transpiler like Babel to convert your source to ES5 syntax.