diff --git a/README.md b/README.md index de5fcfc..b3ad4d1 100644 --- a/README.md +++ b/README.md @@ -798,6 +798,10 @@ The test is a simple set of nested loops calling async functions that don't do m Changelog ========== +06-Jun-16 v2.5.5 + +- Correct hoisting of destructing var declarations (implemented in nodejs >6.0.0) + 18-May-16 v2.5.4 - Bump acorn-es7-plugin (parses comments between async and function correctly) diff --git a/lib/arboriculture.js b/lib/arboriculture.js index db19ed6..edc0cfa 100644 --- a/lib/arboriculture.js +++ b/lib/arboriculture.js @@ -1939,17 +1939,44 @@ function asynchronize(pr, __sourceMapping, opts, logger) { var self = ref.self; var values = []; for (var i = 0;i < self.declarations.length; i++) { - var name = self.declarations[i].id.name; - var idx = definitions.indexOf(name); - if (idx >= 0) { - logger(where(self.declarations[i]) + "Duplicate 'var " + name + "' in '" + (node.name ? node.name.name : "anonymous") + "()'"); - } else { - definitions.push(name); + var name,idx ; + switch (self.declarations[i].id.type) { + case 'Identifier': + name = self.declarations[i].id.name; + idx = definitions.indexOf(name); + if (idx >= 0) { + logger(where(self.declarations[i]) + "Duplicate 'var " + name + "' in '" + (node.name ? node.name.name : "anonymous") + "()'"); + } else { + definitions.push(name); + } + break ; + case 'ObjectPattern': + self.declarations[i].id.properties.forEach(function(prop){ + name = prop.key.name; + idx = definitions.indexOf(name); + if (idx >= 0) { + logger(where(self.declarations[i]) + "Duplicate 'var " + name + "' in '" + (node.name ? node.name.name : "anonymous") + "()'"); + } else { + definitions.push(name); + } + }) ; + break ; + case 'ArrayPattern': + self.declarations[i].id.elements.forEach(function(prop){ + name = prop.name; + idx = definitions.indexOf(name); + if (idx >= 0) { + logger(where(self.declarations[i]) + "Duplicate 'var " + name + "' in '" + (node.name ? node.name.name : "anonymous") + "()'"); + } else { + definitions.push(name); + } + }) ; + break ; } if (self.declarations[i].init) { var value = { type: 'AssignmentExpression', - left: ident(name), + left: cloneNode(self.declarations[i].id), operator: '=', right: cloneNode(self.declarations[i].init) }; diff --git a/package.json b/package.json index 53e6d70..6689c7b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "nodent", - "version": "2.5.4", + "version": "2.5.5", "description": "NoDent - Asynchronous Javascript language extensions", "main": "nodent.js", "scripts": { diff --git a/tests/index.js b/tests/index.js index 8ec10e6..1a7cc16 100644 --- a/tests/index.js +++ b/tests/index.js @@ -82,13 +82,8 @@ try { p: require('promiscuous') }); } catch (ex) {} -var useQuick = false, quiet = false, useGenerators = false, useGenOnly = false, notES6 = false, syntaxTest = 0, forceStrict = ""; +var useQuick = false, quiet = false, useGenerators = false, useGenOnly = false, syntaxTest = 0, forceStrict = ""; var idx; -try { - eval("x=>0"); -} catch (ex) { - notES6 = true; -} for (idx = 0; idx < process.argv.length; idx++) { var fqPath = path.resolve(process.argv[idx]); if (fqPath == __filename || fqPath == __dirname) @@ -109,7 +104,7 @@ for (; idx < process.argv.length; idx++) { if (useGenOnly) providers.splice(1, 1); } catch (ex) { - console.warn("OOPS! Installed platform does not support Promises or Generators - skipping some tests"); + console.log(("v8 "+process.versions.v8+" does not support Promises or Generators (try a later version of nodejs). Skipping some tests. ").yellow) ; if (useGenOnly) process.exit(-1); } @@ -139,15 +134,7 @@ var files = (process.argv.length > idx ? process.argv.slice(idx) : fs.readdirSyn })).filter(function (n) { return n.match(/.*\.js$/); }); -if (notES6) { - files = files.filter(function (n) { - if (n.match(/es6-.*/)) { - console.log(n.split("/").pop() + " (skipped - ES6 platform not installed)".yellow); - return false; - } - return true; - }); -} + var tTotalCompilerTime = 0; var test = []; var i = 0; @@ -156,6 +143,10 @@ function time(hr) { return t[0] * 1000 + t[1] / 1e6; } +function DoNotTest() { + throw DoNotTest; +} + var types = []; files.forEach(function (n) { test[i] = { @@ -164,6 +155,7 @@ files.forEach(function (n) { }; process.stdout.write('\r- Compiling ' + test[i].name + ' \r'); var code = fs.readFileSync(n).toString(); + var compileException = false; for (var type = 0;type < (useGenerators ? 12 : 8); type++) { var opts = {}; // es7:true } ; if (!(type & 1)) @@ -180,7 +172,17 @@ files.forEach(function (n) { var tCompiler = process.hrtime(); var pr = nodent.compile(forceStrict + code, n, opts).code; tTotalCompilerTime += time(tCompiler); - test[i].fn[type] = new Function("module", "require", "Promise", "__unused", "nodent", "DoNotTest", pr); + try { + test[i].fn[type] = new Function("module", "require", "Promise", "__unused", "nodent", "DoNotTest", pr); + } catch (ex) { + if (!compileException) { + console.warn(test[i].name+(" not supported by v8 "+process.versions.v8+" (try a later version of nodejs): ").yellow+ex.message.red) ; + compileException = true ; + } + test[i].fn[type] = function(m) { + m.exports = DoNotTest ; + } + } } i += 1; }); @@ -189,9 +191,6 @@ if (useQuick) console.log(('Note: Timings with '+'--quick'.underline+' are subject to significant GC jitter. Remove '+'--quick'.underline+' for accurate timing comparison')); if (promiseImpls == providers.length) console.log('To test against some popular Promise implementations,', 'cd tests && npm i && cd ..'.yellow); -function DoNotTest() { - throw DoNotTest; -} async function runTest(test, provider, type) { if (provider.p && !(type & (4 | 8))) @@ -278,8 +277,6 @@ try { process.stdout.write('\u001B['+type+'B') ; console.log('\n\n\n\n') ; -// console.log(spaces+'\n') ; -// showPerformanceTable() function showPerformanceTable() { var i,j,lines = 0 ; diff --git a/tests/semantics/es6-destructure.js b/tests/semantics/es6-destructure.js new file mode 100644 index 0000000..94e46ac --- /dev/null +++ b/tests/semantics/es6-destructure.js @@ -0,0 +1,12 @@ +"use strict"; + +async function n(m) { + return m ; +} + +async function test(){ + var {a,b}={a:1,b:2} ; + var [c,d]=[3,4] ; + return await n(3)===a+b && await n(7)===c+d ; +} +module.exports = test ; diff --git a/tests/semantics/es6-interop.js b/tests/semantics/es6-interop.js index eb45f26..60a0521 100644 --- a/tests/semantics/es6-interop.js +++ b/tests/semantics/es6-interop.js @@ -4,6 +4,8 @@ var gen = [ require('./codegen/cg-generators.js') ]; +function* gen(){} + async function inter(i,j) { return (gen[j].name == await gen[j].call() && await gen[j].call() == await gen[i].consume(gen[j].call))?1:100 ; }