Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
'use strict';
const { Syntax } = require('estraverse');
const { getParentNode, getCurrentKey } = require('../controller-utils');
const caputuringTargetTypes = [
// Syntax.Property,
Syntax.ObjectExpression,
Syntax.ArrayExpression,
// Syntax.ConditionalExpression,
Syntax.Identifier,
Syntax.MemberExpression,
Syntax.CallExpression,
Syntax.UnaryExpression,
Syntax.BinaryExpression,
Syntax.LogicalExpression,
Syntax.AssignmentExpression,
Syntax.NewExpression,
Syntax.UpdateExpression,
Syntax.YieldExpression,
Syntax.AwaitExpression,
Syntax.TemplateLiteral,
Syntax.TaggedTemplateExpression
];
const isCaputuringTargetType = (currentNode) => {
return caputuringTargetTypes.indexOf(currentNode.type) !== -1;
};
const isCalleeOfParent = (parentNode, currentKey) => {
return (parentNode.type === Syntax.CallExpression || parentNode.type === Syntax.NewExpression) && currentKey === 'callee';
createOperator: function(vecCount, operator, node, args, parent) {
var other = Vec.generateVecFromArgs(vecCount, node.arguments);
var replace = {
type: Syntax.BinaryExpression,
operator: operator,
left: node.callee.object,
right: other
};
ANNO(replace).copy(ANNO(node));
return replace;
},
generateLengthCall: function (node) {
if (node.arguments.length == 0) {
return Vec.createFunctionCall('length', 0, node);
}
else {
var replace = {
type: Syntax.BinaryExpression,
operator: '*',
left: node.callee.object,
right: {
type: Syntax.BinaryExpression,
operator: '/',
left: node.arguments[0],
right: Vec.createFunctionCall('length', 0, node)
}
};
ANNO(replace.right).setType(TYPES.NUMBER);
ANNO(replace).copyFrom(ANNO(node));
return replace;
}
},
transformPoint: { callExp: function(callExpression, parent, context, state){
var transform = getSpaceTransform(callExpression.arguments[0], false);
var result = { type: Syntax.MemberExpression,
object: { type: Syntax.BinaryExpression, operator: "*",
left: { type: Syntax.Identifier, name: transform},
right: {type: Syntax.CallExpression,
callee: {type: Syntax.Identifier, name: "vec4"},
arguments: [
callExpression.arguments[1],
{ type: Syntax.Literal, value: 1, raw: 1}
]
}
},
property: { type: Syntax.Identifier, name: "xyz" }
};
ANNO(result).setType(TYPES.OBJECT, KINDS.FLOAT3);
ANNO(result.object).setType(TYPES.OBJECT, KINDS.FLOAT4);
ANNO(result.object.left).setType(TYPES.OBJECT, KINDS.MATRIX4);
ANNO(result.object.right).setType(TYPES.OBJECT, KINDS.FLOAT4);
ANNO(result.object.right.arguments[1]).setType(TYPES.NUMBER);
createOperator: function(vecCount, operator, node, args, parent) {
var other = Vec.generateVecFromArgs(vecCount, node.arguments);
var replace = {
type: Syntax.BinaryExpression,
operator: operator,
left: node.callee.object,
right: other
};
ANNO(replace).copy(ANNO(node));
return replace;
},
'use strict';
const { Syntax } = require('estraverse');
module.exports = [
Syntax.Identifier,
Syntax.MemberExpression,
Syntax.CallExpression,
Syntax.UnaryExpression,
Syntax.BinaryExpression,
Syntax.LogicalExpression,
Syntax.AssignmentExpression,
Syntax.ObjectExpression,
Syntax.NewExpression,
Syntax.ArrayExpression,
Syntax.ConditionalExpression,
Syntax.UpdateExpression,
Syntax.SequenceExpression,
Syntax.TemplateLiteral,
Syntax.TaggedTemplateExpression,
Syntax.SpreadElement,
Syntax.YieldExpression,
Syntax.AwaitExpression,
Syntax.Property
];
default: return value;
}
}
if (node.type == Syntax.MemberExpression || node.type == Syntax.CallExpression || node.type == Syntax.Identifier || node.type == Syntax.NewExpression || node.type == Syntax.LogicalExpression) {
return ANNO(node).getStaticValue();
}
if (node.type === Syntax.UnaryExpression) {
if (node.operator == "typeof") {
return ANNO(node).getStaticValue();
}
if(UnaryFunctions.hasOwnProperty(node.operator)) {
return UnaryFunctions[node.operator](getStaticValue(node.argument));
}
Shade.throwError(node, "Unknown unary operator: " + node.operator);
}
if (node.type === Syntax.BinaryExpression) {
if(BinaryFunctions.hasOwnProperty(node.operator)) {
return BinaryFunctions[node.operator](getStaticValue(node.left), getStaticValue(node.right));
}
Shade.throwError(node, "Unknown binary operator: " + node.operator);
}
Shade.throwError(node, "Evaluating static value for node type: " + node.type);
};
transformDirection: { callExp: function(callExpression, parent, context, state){
var transform = getSpaceTransform(callExpression.arguments[0], true);
var result = { type: Syntax.BinaryExpression, operator: "*",
left: { type: Syntax.Identifier, name: transform},
right: callExpression.arguments[1]
};
ANNO(result).setType(TYPES.OBJECT, KINDS.FLOAT3);
ANNO(result.left).setType(TYPES.OBJECT, KINDS.MATRIX3);
ANNO(result.right).setType(TYPES.OBJECT, KINDS.FLOAT3);
var systemName = Tools.getNameForSystem(transform);
state.usedParameters.system[systemName] = state.systemParameters[transform];
return result;
} },
transformPoint: { callExp: function(callExpression, parent, context, state){
function createScaledClosure(color, closureName, node) {
return {
type: Syntax.BinaryExpression,
operator: "*",
left: {
type: Syntax.CallExpression,
callee: {
type: Syntax.Identifier,
name: "color"
},
arguments: [ color ]
},
right: {
type: Syntax.CallExpression,
callee: {
type: Syntax.Identifier,
name: closureName
},
arguments: node.arguments
clause(Syntax.ArrayExpression, function(elements) {
return atomizeStar(elements, function(elements) {
return metaK(build.arrayExpression(elements));
});
}),
clause(Syntax.AssignmentExpression, function(left, right) {
assert(left.type === Syntax.MemberExpression &&
left.object.name === 'globalStore',
'Assignment is allowed only to fields of globalStore.');
return atomize(left, function(left) {
return atomize(right, function(right) {
return metaK(build.assignmentExpression(node.operator, left, right));
});
});
}),
clause(Syntax.BinaryExpression, function(left, right) {
return atomize(left, function(left) {
return atomize(right, function(right) {
return metaK(build.binaryExpression(node.operator, left, right));
});
});
}),
clause(Syntax.CallExpression, function(callee, args) {
if (isPrimitive(callee)) {
return atomize(callee, function(callee) {
return atomizeStar(args, function(args) {
return metaK(build.callExpression(callee, args));
});
});
}
else {
var x = genvar('result');