How to check harmony / ES 6 / ECMAScript 6 JavaScript?

According to the title, I'm trying to test some AMD modules written in ES6 JS powered by nodejs.

I tried Intern first: even after turning on --harmony in nodejs, I ran into the Intern dependency chain where I was unable to turn on Harmony, for example, Istanbul, esprima and others (I opened issue for this).

Then I switched to mocha and here I am stuck ... weird. I have included Harmony for both nodejs and mocha, here is the package.json test script:

 "test": "node --harmony node_modules\\mocha\\bin\\mocha tests --harmony --recursive" 

which I run from the command line as npm test my_test_folder . However, some ES6 constructs (such as const ) go fine, but then it suffocates when destructuring is assigned. Here are the first output lines:

 const { log, dir } = require('../consoleLogger.js'); ^ SyntaxError: Unexpected token { at Module._compile (module.js:439:25) at Object.Module._extensions..js (module.js:474:10) [...continues...] 

I also checked this SO thread and heard about transpilers, but I really don't know if they can work , and now I'm trying to make transpilers work in this case.

Any idea on how to solve this problem without resorting to changing all the ES6 bits distributed in the code? TA.

+5
source share
2 answers

V8 does not yet implement destructuring, so it will not be available in node for some time. In most cases, ownership of blocks (including const) is implemented, but keep in mind that the version of const-pre-ES6 was always available, so you may need to double-check what you are actually observing - you could try to declare " let "for less ambiguity.

+1
source

I used

 npm install mocha-traceur mocha ./tests/* --compilers js:mocha-traceur 

and it works like a charm!

+4
source

Source: https://habr.com/ru/post/1204439/


All Articles