node icon indicating copy to clipboard operation
node copied to clipboard

SyntaxError: Unexpected reserved word

Open gs00s opened this issue 11 years ago • 4 comments

Yesterday installed the new iojs version with nvm install iojs-v1.0.3 then wrote my first class definition. But for my disappointment i got the following error when tried to run a simple file:

/home/blacksonic/workspace/es6/class.js:3
class View {
^^^^^
SyntaxError: Unexpected reserved word
    at exports.runInThisContext (vm.js:54:16)
    at Module._compile (module.js:429:25)
    at Object.Module._extensions..js (module.js:464:10)
    at Module.load (module.js:341:32)
    at Function.Module._load (module.js:296:12)
    at Function.Module.runMain (module.js:487:10)
    at startup (node.js:111:16)
    at node.js:809:3

The content of the file:

"use strict";

class View {
    constructor(model) {
        this.model = model;
    }

    render() {
        console.log(this.model);
    }
}

var myView = new View({table: true});
myView.render();

I ran it with: node --harmony es6/class.js also tried it with

What i checked:

node -v
v1.0.3

gs00s avatar Jan 22 '15 20:01 gs00s

Currently Classes are behind the --es_staging flag and in strict mode only. https://iojs.org/es6.html

This is because the spec had to be reconsidered a bit and the implementation has to be slightly adjusted. Class support should land when we ship the stable version of v8 4.1. (still going to be a few weeks at least).

Fishrock123 avatar Jan 22 '15 20:01 Fishrock123

ES6 class syntax isn't supported yet – it was pulled from v8 due to some retooling of the spec as I understand it. It should be in soon, though; and it's available behind the --harmony-classes flag.

chrisdickinson avatar Jan 22 '15 20:01 chrisdickinson

Oh, looks like you tried to run it with --harmony. Sorry about that.

The --harmony flag no longer exists and has mostly been superseded by --es_staging.

Fishrock123 avatar Jan 22 '15 20:01 Fishrock123

e.g. iojs --es_staging --use-strict -e "class A { constructor() { console.log('cats') }}; new A()" prints cats.

Fishrock123 avatar Jan 22 '15 20:01 Fishrock123