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;
};
function isPrimitive(node) {
switch (node.type) {
case Syntax.FunctionExpression:
case Syntax.Identifier:
case Syntax.CallExpression:
return false;
case Syntax.MemberExpression:
return (types.Identifier.check(node.object) ||
(!node.computed) && types.Identifier.check(node.property));
default:
console.log(node);
throw "isPrimitive doesn't handle node";
}
}
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);
for (var i = 0; i < vecCount; ++i) {
var thisValue = {
type: Syntax.MemberExpression,
object: node.callee.object,
property: {
type: Syntax.Identifier,
name: VecBase.indexToSwizzle(i)
}
};
if (indices[i] !== undefined) {
replace.arguments[i] = {
type: Syntax.BinaryExpression,
operator: operator,
left: thisValue,
right: singular ? argObject : {
type: Syntax.MemberExpression,
object: argObject,
property: {
type: Syntax.Identifier,
name: VecBase.indexToSwizzle(indices[i])
}
}
}
}
else {
replace.arguments[i] = thisValue
}
}
ANNO(replace).copy(ANNO(node));
return replace;
},
function getSpaceTransform(spaceArg, normal){
if( spaceArg.type != Syntax.MemberExpression ||
spaceArg.object.type != Syntax.Identifier ||
spaceArg.object.name != "Space" ||
spaceArg.property.type != Syntax.Identifier)
Shade.throwError(spaceArg, "We only support Space enums for the first argument of transformDirection and transformPoint");
switch(spaceArg.property.name){
case "VIEW": return normal ? "modelViewMatrixN" : "modelViewMatrix";
case "WORLD": return normal ? "modelMatrixN" : "modelMatrix";
default: Shade.throwError(spaceArg, "Unknown Space Type: '" + spaceArg.property.name + "'");
}
}
property: function (node, parent, context, state) {
var parameterName = Tools.getNameForSystem(SystemDefines.CANVAS_DIMENSIONS);
state.usedParameters.system[parameterName] = state.systemParameters[SystemDefines.CANVAS_DIMENSIONS];
return {
type: Syntax.NewExpression,
callee: {
type: Syntax.Identifier,
name: "Vec3"
},
arguments: [
{
type: Syntax.BinaryExpression,
left: {
type: Syntax.MemberExpression,
object: {
type: Syntax.Identifier,
name: "gl_FragCoord"
},
property: {
type: Syntax.Identifier,
name: "xyz"
}
},
right: {
type: Syntax.Identifier,
name: Tools.getNameForSystem(SystemDefines.CANVAS_DIMENSIONS)
},
operator: "/",
extra: {
type: Shade.TYPES.OBJECT,
indices[idx] = i;
}
for(var i = 0; i < vecCount; ++i){
if(indices[i] !== undefined){
replace.arguments[i] = singular ? argObject : {
type: Syntax.MemberExpression,
object: argObject,
property: {
type: Syntax.Identifier,
name: VecBase.indexToSwizzle(indices[i])
}
};
}
else{
replace.arguments[i] = {
type: Syntax.MemberExpression,
object: node.callee.object,
property: {
type: Syntax.Identifier,
name: VecBase.indexToSwizzle(i)
}
};
}
}
ANNO(replace).copy(ANNO(node));
return replace;
},
function createOSLClosure(node, closureName, color) {
var callee = node.callee;
assert(callee.type == Syntax.MemberExpression);
var closure = color ? createScaledClosure(color, closureName, node) : createSimpleClosure(closureName, node);
if (callee.object.type == Syntax.NewExpression)
return closure;
//assert.equal(callee.object.type, Syntax.BinaryExpression);
return {
type: Syntax.BinaryExpression,
operator: "+",
left: callee.object,
right: closure,
extra: {
type: Shade.TYPES.OBJECT,
kind: Shade.OBJECT_KINDS.COLOR_CLOSURE
function cps(node, k) {
switch (node.type) {
case Syntax.ArrayExpression:
case Syntax.AssignmentExpression:
case Syntax.BinaryExpression:
case Syntax.FunctionExpression:
case Syntax.Identifier:
case Syntax.Literal:
case Syntax.MemberExpression:
case Syntax.ObjectExpression:
case Syntax.UnaryExpression:
case Syntax.DebuggerStatement:
return atomize(node, function(node) {
return buildContinuationCall(k, node);
});
default:
return match(node, [
clause(Syntax.CallExpression, function(callee, args) {
return atomize(callee, function(callee) {
return atomizeStar(args, function(args) {
if (isPrimitive(callee)) {
return buildContinuationCall(k, buildCall(callee, args));
}
else {
return buildCall(callee, [k].concat(args));