riot-js

Open full view…

Problem referencing this in ES6 tags

Stuart Rackham
Mon, 02 Feb 2015 04:12:13 GMT

Referencing `this` at the top level in a tag and compile with `--type=es6` I get a 6to5 compile error: Here's what happens compiling the example ES6 `test` tag from the compiler documentation https://muut.com/riotjs/compiler.html#ecmascript-6 ``` $ riot --type es6 es6-test.tag ReferenceError: unknown: Line 4: Top level `this` is `undefined` in strict mode 2 |· 3 | var type = 'JavaScript' > 4 | this.test = `This is ${type}` | ^ ``` Any idea what I'm missing? I'm using Riot 2.0.7, 6to5 3.3.2

Stuart Rackham
Mon, 02 Feb 2015 08:53:06 GMT

This issue can be resolved by making a change to the Riot compiler: Compile the whole of the tag constructor instead of just the constructor body. I submitted a pull request https://github.com/muut/riotjs/pull/280

Stuart Rackham
Wed, 04 Feb 2015 02:24:14 GMT

My proposed solution is flawed so I closed the pull request. Irrespective of the resolution of the above `this` problem, if you use `--type=es6` then you cannot use the Riot "ES6-like" method syntax because it is not valid ES6 and throws 6to5 compile errors (the riot compiler only pre-processes ES6-like methods when `--type` is not explicitly specified). All in all, I'm not convinced `--type=es6` as a transpiler option is useful, you are better off using the default ES5 + "ES6-like" method syntax.

Tero Piirainen
Wed, 11 Feb 2015 06:39:44 GMT

This issue is fixed with [this commit](https://github.com/muut/riotjs/commit/af32c6758b9f73a8f20e50ce3202f9d307b9545e)

Stuart Rackham
Sun, 15 Feb 2015 09:04:48 GMT

Yes, seems fixed in 2.0.9.