Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

aether

Package Overview
Dependencies
Maintainers
1
Versions
101
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

aether - npm Package Compare versions

Comparing version 0.2.19 to 0.2.20

2

bower.json
{
"name": "aether",
"version": "0.2.19",
"version": "0.2.20",
"homepage": "https://github.com/codecombat/aether",

@@ -5,0 +5,0 @@ "authors": [

@@ -268,3 +268,3 @@ (function() {

Aether.prototype.purifyCode = function(rawCode) {
var error, instrumentedCode, interceptThis, normalized, normalizedAST, normalizedCode, normalizedNodeIndex, normalizedSourceMap, originalNodeRanges, parameter, postNormalizationTransforms, preNormalizationTransforms, preprocessedCode, problemOptions, purifiedCode, transformedAST, transformedCode, varNames, wrappedCode, _i, _len, _ref6, _ref7, _ref8, _ref9;
var error, instrumentedCode, interceptThis, normalized, normalizedAST, normalizedCode, normalizedNodeIndex, normalizedSourceMap, originalNodeRanges, parameter, postNormalizationTransforms, preNormalizationTransforms, preprocessedCode, problemOptions, purifiedCode, transformedAST, transformedCode, varNames, wrappedCode, _i, _len, _ref6, _ref7, _ref8;
preprocessedCode = this.language.hackCommonMistakes(rawCode, this);

@@ -368,10 +368,7 @@ wrappedCode = this.language.wrap(preprocessedCode, this);

postNormalizationTransforms = [];
if ((_ref9 = this.options.thisValue) != null ? _ref9.validateReturn : void 0) {
postNormalizationTransforms.unshift(transforms.validateReturns);
}
if (this.options.yieldConditionally) {
postNormalizationTransforms.unshift(transforms.yieldConditionally);
postNormalizationTransforms.unshift(transforms.makeYieldConditionally());
}
if (this.options.yieldAutomatically) {
postNormalizationTransforms.unshift(transforms.yieldAutomatically);
postNormalizationTransforms.unshift(transforms.makeYieldAutomatically());
}

@@ -378,0 +375,0 @@ if (this.options.includeFlow) {

(function() {
var S, SourceMap, checkIncompleteMembers, commonMethods, getFunctionNestingLevel, getParents, getParentsOfTypes, interceptEval, interceptThis, makeCheckThisKeywords, makeFindOriginalNodes, makeGatherNodeRanges, makeInstrumentCalls, makeInstrumentStatements, possiblyGeneratorifyAncestorFunction, ranges, statements, validateReturns, yieldAutomatically, yieldConditionally, _, _ref, _ref1, _ref2,
var S, SourceMap, checkIncompleteMembers, commonMethods, getFunctionNestingLevel, getParents, getParentsOfTypes, getUserFnExpr, getUserFnMap, interceptEval, interceptThis, makeCheckThisKeywords, makeFindOriginalNodes, makeGatherNodeRanges, makeInstrumentCalls, makeInstrumentStatements, makeYieldAutomatically, makeYieldConditionally, possiblyGeneratorifyAncestorFunction, possiblyGeneratorifyUserFunction, ranges, statements, _, _ref, _ref1, _ref2,
__indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };

@@ -37,2 +37,353 @@

possiblyGeneratorifyAncestorFunction = function(node) {
while (node.type !== S.FunctionExpression) {
node = node.parent;
}
return node.mustBecomeGeneratorFunction = true;
};
possiblyGeneratorifyUserFunction = function(fnExpr, node) {
var child, grandchild, key, _i, _len, _ref3, _ref4, _ref5;
if (!node) {
node = fnExpr;
}
for (key in node) {
child = node[key];
if (key === 'parent' || key === 'leadingComments' || key === 'originalNode') {
continue;
}
if ((child != null ? child.type : void 0) === S.ExpressionStatement && ((_ref3 = child.expression.right) != null ? _ref3.type : void 0) === S.CallExpression) {
return fnExpr.mustBecomeGeneratorFunction = true;
} else if ((child != null ? child.type : void 0) === S.FunctionExpression) {
continue;
} else if (_.isArray(child)) {
for (_i = 0, _len = child.length; _i < _len; _i++) {
grandchild = child[_i];
if (_.isString(grandchild != null ? grandchild.type : void 0)) {
if ((grandchild != null ? grandchild.type : void 0) === S.ExpressionStatement && ((_ref4 = grandchild.expression) != null ? (_ref5 = _ref4.right) != null ? _ref5.type : void 0 : void 0) === S.CallExpression) {
return fnExpr.mustBecomeGeneratorFunction = true;
}
if ((grandchild != null ? grandchild.type : void 0) === S.FunctionExpression) {
continue;
}
if (possiblyGeneratorifyUserFunction(fnExpr, grandchild)) {
return true;
}
}
}
} else if (_.isString(child != null ? child.type : void 0)) {
if (possiblyGeneratorifyUserFunction(fnExpr, child)) {
return true;
}
}
}
return false;
};
getUserFnMap = function(startNode) {
var call, callVal, error, findCall, fn, fnVal, getRootScope, parseVal, resolveCalls, resolveFunctions, resolveVal, resolvedCalls, resolvedFunctions, rootScope, updateVal, userFnMap, _i, _j, _len, _len1, _ref3, _ref4;
parseVal = function(node) {
var _ref3, _ref4;
if ((node != null ? node.type : void 0) === S.Literal) {
return node.value;
} else if ((node != null ? node.type : void 0) === S.Identifier) {
return node.name;
} else if ((node != null ? node.type : void 0) === S.ThisExpression) {
return 'this';
} else if ((node != null ? node.type : void 0) === S.MemberExpression) {
if ((((_ref3 = node.object) != null ? _ref3.name : void 0) != null) && (((_ref4 = node.property) != null ? _ref4.name : void 0) != null)) {
return [node.object.name, node.property.name];
}
}
};
updateVal = function(val, left, right) {
var j, _i, _ref3;
if (_.isArray(val)) {
for (j = _i = 0, _ref3 = val.length - 1; 0 <= _ref3 ? _i <= _ref3 : _i >= _ref3; j = 0 <= _ref3 ? ++_i : --_i) {
if (left === val[j]) {
if (_.isArray(right)) {
val.splice.apply(val, [j, 1].concat(right));
} else {
val[j] = right;
}
} else if (right === val[j] && _.isArray(left)) {
if (_.isArray(left)) {
val.splice.apply(val, [j, 1].concat(left));
} else {
val[j] = left;
}
}
}
} else {
if (left === val) {
val = right;
} else if (right === val && _.isArray(left)) {
val = left;
}
}
return val;
};
getRootScope = function() {
var buildCallMap, buildScope, buildVarMap, scope, wrapperFn;
buildVarMap = function(varMap, node) {
var child, grandchild, key, vLeft, vRight, _ref3, _results;
if ((node != null ? node.type : void 0) === S.ExpressionStatement && ((_ref3 = node.expression) != null ? _ref3.type : void 0) === S.AssignmentExpression) {
vLeft = parseVal(node.expression.left);
vRight = parseVal(node.expression.right);
if (vLeft && vRight) {
varMap.push([vLeft, vRight]);
}
}
_results = [];
for (key in node) {
child = node[key];
if (key === 'parent' || key === 'leadingComments' || key === 'originalNode') {
continue;
}
if ((child != null ? child.type : void 0) === S.FunctionExpression) {
continue;
}
if (_.isArray(child)) {
_results.push((function() {
var _i, _len, _results1;
_results1 = [];
for (_i = 0, _len = child.length; _i < _len; _i++) {
grandchild = child[_i];
if (_.isString(grandchild != null ? grandchild.type : void 0)) {
_results1.push(buildVarMap(varMap, grandchild));
} else {
_results1.push(void 0);
}
}
return _results1;
})());
} else if (_.isString(child != null ? child.type : void 0)) {
_results.push(buildVarMap(varMap, child));
} else {
_results.push(void 0);
}
}
return _results;
};
buildCallMap = function(calls, node) {
var child, grandchild, key, _ref3, _ref4, _results;
if ((node != null ? node.type : void 0) === S.ExpressionStatement && ((_ref3 = node.expression) != null ? _ref3.type : void 0) === S.AssignmentExpression) {
if (((_ref4 = node.expression.right) != null ? _ref4.type : void 0) === S.CallExpression) {
calls.push(node.expression);
}
}
_results = [];
for (key in node) {
child = node[key];
if (key === 'parent' || key === 'leadingComments' || key === 'originalNode') {
continue;
}
if ((child != null ? child.type : void 0) === S.FunctionExpression) {
continue;
}
if (_.isArray(child)) {
_results.push((function() {
var _i, _len, _results1;
_results1 = [];
for (_i = 0, _len = child.length; _i < _len; _i++) {
grandchild = child[_i];
if (_.isString(grandchild != null ? grandchild.type : void 0)) {
_results1.push(buildCallMap(calls, grandchild));
} else {
_results1.push(void 0);
}
}
return _results1;
})());
} else if (_.isString(child != null ? child.type : void 0)) {
_results.push(buildCallMap(calls, child));
} else {
_results.push(void 0);
}
}
return _results;
};
buildScope = function(scope, fn) {
var child, childScope, key, _ref3, _ref4, _ref5, _ref6, _results;
buildVarMap(scope.varMap, fn);
buildCallMap(scope.calls, fn);
if (((_ref3 = fn.body) != null ? _ref3.body : void 0) != null) {
_ref4 = fn.body.body;
_results = [];
for (key in _ref4) {
child = _ref4[key];
if (key === 'parent' || key === 'leadingComments' || key === 'originalNode') {
continue;
}
if ((child != null ? child.type : void 0) === S.ExpressionStatement && ((_ref5 = child.expression) != null ? _ref5.type : void 0) === S.AssignmentExpression) {
if (((_ref6 = child.expression.right) != null ? _ref6.type : void 0) === S.FunctionExpression) {
childScope = {
children: [],
varMap: [],
calls: [],
parent: scope,
current: child.expression
};
buildScope(childScope, child.expression.right);
_results.push(scope.children.push(childScope));
} else {
_results.push(void 0);
}
} else {
_results.push(void 0);
}
}
return _results;
}
};
wrapperFn = startNode;
while (wrapperFn && (wrapperFn.type !== S.FunctionExpression || getFunctionNestingLevel(wrapperFn) > 1)) {
wrapperFn = wrapperFn.parent;
}
scope = {
children: [],
varMap: [],
calls: [],
parent: null,
current: null
};
if (wrapperFn) {
buildScope(scope, wrapperFn);
}
return scope;
};
findCall = function(scope, fnVal) {
var c, cVal, call, childFn, childScope, _i, _j, _len, _len1, _ref3, _ref4;
if (!fnVal) {
return [null, null];
}
_ref3 = scope.calls;
for (_i = 0, _len = _ref3.length; _i < _len; _i++) {
c = _ref3[_i];
cVal = parseVal(c.right.callee);
cVal = resolveVal(scope, scope.varMap, cVal);
if (_.isEqual(cVal, fnVal)) {
return [scope, c.right];
}
}
_ref4 = scope.children;
for (_j = 0, _len1 = _ref4.length; _j < _len1; _j++) {
childScope = _ref4[_j];
if (childScope.current) {
childFn = parseVal(childScope.current.left);
if (childFn !== fnVal) {
if (call = findCall(childScope, fnVal)) {
return call;
}
}
}
}
return [null, null];
};
resolveVal = function(scope, vm, val) {
var argVal, callExpr, fnVal, i, newScope, pVal, _i, _j, _ref3, _ref4, _ref5, _ref6, _ref7;
if (!val) {
return;
}
if (vm.length > 0) {
for (i = _i = _ref3 = vm.length - 1; _ref3 <= 0 ? _i <= 0 : _i >= 0; i = _ref3 <= 0 ? ++_i : --_i) {
val = updateVal(val, vm[i][0], vm[i][1]);
}
}
if (((_ref4 = scope.current) != null ? (_ref5 = _ref4.right) != null ? _ref5.type : void 0 : void 0) === S.FunctionExpression && scope.current.right.params.length > 0) {
for (i = _j = 0, _ref6 = scope.current.right.params.length - 1; 0 <= _ref6 ? _j <= _ref6 : _j >= _ref6; i = 0 <= _ref6 ? ++_j : --_j) {
pVal = parseVal(scope.current.right.params[i]);
if ((_.isArray(val)) && val[0] === pVal || val === pVal) {
fnVal = parseVal(scope.current.left);
fnVal = resolveVal(scope, scope.varMap, fnVal);
_ref7 = findCall(rootScope, fnVal), newScope = _ref7[0], callExpr = _ref7[1];
if (newScope && callExpr) {
argVal = parseVal(callExpr["arguments"][i]);
if (_.isArray(val)) {
val[0] = argVal;
} else {
val = argVal;
}
val = resolveVal(newScope, newScope.varMap, val);
}
break;
}
}
}
if (scope.parent) {
val = resolveVal(scope.parent, scope.parent.varMap, val);
}
return val;
};
resolveFunctions = function(scope, fns) {
var childScope, fnVal, _i, _len, _ref3, _ref4, _ref5, _results;
if ((scope != null ? (_ref3 = scope.current) != null ? (_ref4 = _ref3.right) != null ? _ref4.type : void 0 : void 0 : void 0) === S.FunctionExpression) {
fnVal = parseVal(scope.current.left);
fnVal = resolveVal(scope, scope.varMap, fnVal);
fns.push([scope.current.right, fnVal]);
}
_ref5 = scope.children;
_results = [];
for (_i = 0, _len = _ref5.length; _i < _len; _i++) {
childScope = _ref5[_i];
_results.push(resolveFunctions(childScope, fns));
}
return _results;
};
resolveCalls = function(scope, calls) {
var call, childScope, val, _i, _j, _len, _len1, _ref3, _ref4, _results;
_ref3 = scope.calls;
for (_i = 0, _len = _ref3.length; _i < _len; _i++) {
call = _ref3[_i];
val = parseVal(call.right.callee);
val = resolveVal(scope, scope.varMap, val);
calls.push([call.right, val]);
}
_ref4 = scope.children;
_results = [];
for (_j = 0, _len1 = _ref4.length; _j < _len1; _j++) {
childScope = _ref4[_j];
_results.push(resolveCalls(childScope, calls));
}
return _results;
};
userFnMap = [];
try {
rootScope = getRootScope();
resolvedFunctions = [];
resolveFunctions(rootScope, resolvedFunctions);
resolvedCalls = [];
resolveCalls(rootScope, resolvedCalls);
for (_i = 0, _len = resolvedCalls.length; _i < _len; _i++) {
_ref3 = resolvedCalls[_i], call = _ref3[0], callVal = _ref3[1];
for (_j = 0, _len1 = resolvedFunctions.length; _j < _len1; _j++) {
_ref4 = resolvedFunctions[_j], fn = _ref4[0], fnVal = _ref4[1];
if (_.isEqual(callVal, fnVal)) {
userFnMap.push([call, fn]);
break;
} else if ((_.isArray(callVal)) && callVal[0] === fnVal) {
userFnMap.push([call, fn]);
break;
}
}
}
} catch (_error) {
error = _error;
console.log('ERROR in transforms.getUserFnMap', error);
}
return userFnMap;
};
getUserFnExpr = function(userFnMap, callExpr) {
var call, fn, _i, _len, _ref3;
if (userFnMap) {
for (_i = 0, _len = userFnMap.length; _i < _len; _i++) {
_ref3 = userFnMap[_i], call = _ref3[0], fn = _ref3[1];
if (callExpr === call) {
return fn;
}
}
}
};
module.exports.makeGatherNodeRanges = makeGatherNodeRanges = function(nodeRanges, code, codePrefix) {

@@ -111,14 +462,2 @@ return function(node) {

module.exports.validateReturns = validateReturns = function(node) {
var _ref3;
if (getFunctionNestingLevel(node) !== 2) {
return;
}
if (node.type === S.ReturnStatement && !node.argument) {
return node.update(node.source().replace("return;", "return this.validateReturn('" + this.options.functionName + "', null);"));
} else if (((_ref3 = node.parent) != null ? _ref3.type : void 0) === S.ReturnStatement) {
return node.update("this.validateReturn('" + this.options.functionName + "', (" + (node.source()) + "))");
}
};
module.exports.checkIncompleteMembers = checkIncompleteMembers = function(node) {

@@ -185,35 +524,68 @@ var exp, hint, kind, m, problem, _ref3;

possiblyGeneratorifyAncestorFunction = function(node) {
while (node.type !== S.FunctionExpression) {
node = node.parent;
}
return node.mustBecomeGeneratorFunction = true;
};
module.exports.yieldConditionally = yieldConditionally = function(node) {
var _ref3;
if (node.type === S.ExpressionStatement && ((_ref3 = node.expression.right) != null ? _ref3.type : void 0) === S.CallExpression) {
if (getFunctionNestingLevel(node) !== 2) {
return;
module.exports.makeYieldConditionally = makeYieldConditionally = function() {
var userFnMap;
userFnMap = null;
return function(node) {
var fnExpr, _ref3, _ref4, _ref5;
if (node.type === S.ExpressionStatement && ((_ref3 = node.expression.right) != null ? _ref3.type : void 0) === S.CallExpression) {
if (!(getFunctionNestingLevel(node) > 1)) {
return;
}
if (!userFnMap) {
userFnMap = getUserFnMap(node);
}
if (!((_ref4 = getUserFnExpr(userFnMap, node.expression.right)) != null ? _ref4.mustBecomeGeneratorFunction : void 0)) {
node.update("" + (node.source()) + " if (_aether._shouldYield) { var _yieldValue = _aether._shouldYield; _aether._shouldYield = false; yield _yieldValue; }");
}
node.yields = true;
if (!node.mustBecomeGeneratorFunction) {
return possiblyGeneratorifyAncestorFunction(node);
}
} else if (node.mustBecomeGeneratorFunction) {
return node.update(node.source().replace(/^function \(/, 'function* ('));
} else if (node.type === S.AssignmentExpression && ((_ref5 = node.right) != null ? _ref5.type : void 0) === S.CallExpression) {
if (!userFnMap) {
userFnMap = getUserFnMap(node);
}
if ((fnExpr = getUserFnExpr(userFnMap, node.right)) && possiblyGeneratorifyUserFunction(fnExpr)) {
return node.update("var __gen" + (node.left.source()) + " = " + (node.right.source()) + "; while (true) { var __result" + (node.left.source()) + " = __gen" + (node.left.source()) + ".next(); if (__result" + (node.left.source()) + ".done) { " + (node.left.source()) + " = __result" + (node.left.source()) + ".value; break; } yield __result" + (node.left.source()) + ".value;}");
}
}
node.update("" + (node.source()) + " if (_aether._shouldYield) { var _yieldValue = _aether._shouldYield; _aether._shouldYield = false; yield _yieldValue; }");
node.yields = true;
return possiblyGeneratorifyAncestorFunction(node);
} else if (node.mustBecomeGeneratorFunction) {
return node.update(node.source().replace(/^function \(/, 'function* ('));
}
};
};
module.exports.yieldAutomatically = yieldAutomatically = function(node) {
var _ref3;
if (_ref3 = node.type, __indexOf.call(statements, _ref3) >= 0) {
if (getFunctionNestingLevel(node) !== 2) {
return;
module.exports.makeYieldAutomatically = makeYieldAutomatically = function() {
var userFnMap;
userFnMap = null;
return function(node) {
var fnExpr, _ref3, _ref4, _ref5, _ref6;
if (_ref3 = node.type, __indexOf.call(statements, _ref3) >= 0) {
if (!(getFunctionNestingLevel(node) > 1)) {
return;
}
if (node.type === S.ExpressionStatement && ((_ref4 = node.expression.right) != null ? _ref4.type : void 0) === S.CallExpression) {
if (!userFnMap) {
userFnMap = getUserFnMap(node);
}
if (!((_ref5 = getUserFnExpr(userFnMap, node.expression.right)) != null ? _ref5.mustBecomeGeneratorFunction : void 0)) {
node.update("" + (node.source()) + " yield 'waiting...';");
}
} else {
node.update("" + (node.source()) + " yield 'waiting...';");
}
node.yields = true;
if (!node.mustBecomeGeneratorFunction) {
return possiblyGeneratorifyAncestorFunction(node);
}
} else if (node.mustBecomeGeneratorFunction) {
return node.update(node.source().replace(/^function \(/, 'function* ('));
} else if (node.type === S.AssignmentExpression && ((_ref6 = node.right) != null ? _ref6.type : void 0) === S.CallExpression) {
if (!userFnMap) {
userFnMap = getUserFnMap(node);
}
if ((fnExpr = getUserFnExpr(userFnMap, node.right)) && possiblyGeneratorifyUserFunction(fnExpr)) {
return node.update("var __gen" + (node.left.source()) + " = " + (node.right.source()) + "; while (true) { var __result" + (node.left.source()) + " = __gen" + (node.left.source()) + ".next(); if (__result" + (node.left.source()) + ".done) { " + (node.left.source()) + " = __result" + (node.left.source()) + ".value; break; } yield __result" + (node.left.source()) + ".value;}");
}
}
node.update("" + (node.source()) + " yield 'waiting...';");
node.yields = true;
return possiblyGeneratorifyAncestorFunction(node);
} else if (node.mustBecomeGeneratorFunction) {
return node.update(node.source().replace(/^function \(/, 'function* ('));
}
};
};

@@ -220,0 +592,0 @@

{
"name": "aether",
"version": "0.2.19",
"version": "0.2.20",
"description": "Analyzes, instruments, and transpiles JS to help beginners.",

@@ -5,0 +5,0 @@ "keywords": [

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc