Skip to content

Commit

Permalink
Correct hoisting of destructing var declarations (implemented in nodejs
Browse files Browse the repository at this point in the history
>6.0.0)
Update test script to be more discerning about how to detect JS feature
implementations in V8
  • Loading branch information
matAtWork committed Jun 6, 2016
1 parent 350b0a8 commit 31161c8
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 30 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
41 changes: 34 additions & 7 deletions lib/arboriculture.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
};
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "nodent",
"version": "2.5.4",
"version": "2.5.5",
"description": "NoDent - Asynchronous Javascript language extensions",
"main": "nodent.js",
"scripts": {
Expand Down
41 changes: 19 additions & 22 deletions tests/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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);
}
Expand Down Expand Up @@ -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;
Expand All @@ -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] = {
Expand All @@ -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))
Expand All @@ -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;
});
Expand All @@ -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)))
Expand Down Expand Up @@ -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 ;
Expand Down
12 changes: 12 additions & 0 deletions tests/semantics/es6-destructure.js
Original file line number Diff line number Diff line change
@@ -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 ;
2 changes: 2 additions & 0 deletions tests/semantics/es6-interop.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 ;
}
Expand Down

0 comments on commit 31161c8

Please sign in to comment.