Ho usato il seguente esempio per testare chiamata ricorsione in coda con Babel e il es2016
preimpostata:Babel utilizza l'ottimizzazione di chiamata tail implementata con `es2016`?
'use strict';
try {
function r(n) {
if (n%5000===0)
console.log(`reached a depth of ${n}`);
r(n+1);
}
r(0);
} catch (e) {
if (!(e instanceof RangeError))
throw e;
else
console.log('stack blown');
}
Il mio file package.json
è:
{
"name": "tail-call-optimization",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"build": "babel es6 --out-dir es5 --source-maps",
"watch": "babel es6 --out-dir es5 --source-maps --watch",
"start": "node es5/app.js"
},
"author": "",
"license": "ISC",
"devDependencies": {
"babel-cli": "^6.6.5",
"babel-core": "^6.7.4",
"babel-loader": "^6.2.4",
"babel-polyfill": "^6.7.4",
"babel-preset-es2016": "^6.0.10",
"babel-runtime": "^6.6.1"
},
"dependencies": {
"babel-polyfill": "^6.7.4",
"source-map-support": "^0.4.0"
}
}
... e il .babelrc
è semplicemente:
{
"presets": ["es2016"]
}
Esecuzione di quanto sopra con:
npm run build && npm run start
... genera il seguente output della console:
reached a depth of 0
reached a depth of 5000
reached a depth of 10000
reached a depth of 15000
stack blown
In effetti, guardando il file nella directory transpiled es5
, non c'è nulla che suggerisca che il TCO è stato implementato.
mi sto perdendo qualcosa?
La versione del mio nodo è 4.3.2
.