swh:1:snp:3af1a03cd091600016317ad7197cfc7dfd1319c7
Tip revision: 37cb6fe0febcb7845ec0cee709578c2ac7e1195c authored by Andreas Stuhlmüller on 01 October 2015, 21:14:01 UTC
0.2.1
0.2.1
Tip revision: 37cb6fe
store.js
'use strict';
var estraverse = require('estraverse');
var Syntax = estraverse.Syntax;
var build = require('ast-types').builders;
var isPrimitive = require('../syntax').isPrimitive;
var storeIdNode = build.identifier('globalStore');
function store(node) {
switch (node.type) {
// have to add the store argument to each function
case Syntax.FunctionExpression:
return build.functionExpression(node.id,
[storeIdNode].concat(node.params),
node.body);
// pass the store variable at each call (that isn't primitive)
case Syntax.CallExpression:
if (isPrimitive(node.callee)) {
return node;
}
else if (node.arguments.length > 0 &&
node.arguments[0].type === 'Identifier' &&
node.arguments[0].name === 'globalStore') {
return node;
}
else {
return build.callExpression(node.callee,
[storeIdNode].concat(node.arguments));
}
default:
return node;
}
}
function storeMain(node) {
return estraverse.replace(node, {leave: store});
}
module.exports = {
store: storeMain
};