Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
for (let _enum of doc.find('enum')) {
let name = _enum.attr('name').value();
let values = new Map();
let bits = new Map();
if (name === 'Atom') {
// TODO: Bojizzle the Atom Enum
console.error('TODO: Implement Atom Enum');
continue;
}
var parent_klass = `${_enum.find('*/bit').length ? 'Bit' : 'Value'}Enum`;
var enum_klass = klasses.newClass(`${name}Enum`, parent_klass);
enums.set(name, b.identifier(enum_klass.name));
for (let item of _enum.find('item')) {
let item_name = item.attr('name').value();
let child = item.get('*');
if (!child) {
console.error('Enum item without a child, wut?!', item_name);
continue;
}
let item_value = parseInt(child.text());
switch (child.name()) {
case 'value':
values.set(item_value, item_name);
break;
case 'bit':
var bindAddress = build.variableDeclaration('var', [
build.variableDeclarator(
build.identifier(localVarName),
addressParam)]);
// Use member expression so that this isn't cps'd. Writing as an
// assignment statement doesn't work as it is wrapped in a thunk and
// returned early from the function.
var saveAddress = build.expressionStatement(
build.callExpression(
build.memberExpression(
build.identifier(saveAddressFn[0]),
build.identifier(saveAddressFn[1])
), [
build.identifier(globalVarName),
addressParam]));
var expr = build.functionExpression(
node.id,
node.params,
build.blockStatement([bindAddress, saveAddress].concat(node.body.body))
);
expr.loc = node.loc;
return expr;
}
__addSymMethod(name, callname, read) {
var callArguments = [];
if (!read) {
callArguments = [b.spreadElement(b.identifier('arguments'))];
}
this.addMethod(
name,
[],
[(read ? b.returnStatement : b.expressionStatement)(b.callExpression(
b.memberExpression(
b.thisExpression(),
b.identifier(callname)),
callArguments
))]);
}
gen() {
var extend = null;
if (this.extend) {
extend = b.identifier(this.extend);
}
return b.classDeclaration(
b.identifier(this.name),
b.classBody(this.body),
extend,
[]);
}
}
[b.variableDeclarator(
b.identifier('connectionArgs'),
b.memberExpression(
b.identifier('GraphQLRelay'),
b.identifier('connectionArgs'),
false
)
)]
));
}
}
declarations.push(
b.variableDeclaration('var',
[b.variableDeclarator(
b.identifier('getType'),
b.memberExpression(
b.identifier('resolveMap'),
b.identifier('getType'),
false
)
)]
)
);
declarations.push(
b.variableDeclaration('var',
[b.variableDeclarator(
b.identifier('registerType'),
b.memberExpression(
b.identifier('resolveMap'),
b.identifier('registerType'),
function generateLimitOffsetArgs() {
return b.property('init', b.identifier('args'), b.objectExpression([
b.property('init', b.identifier('limit'), b.objectExpression([
b.property('init', b.identifier('name'), b.literal('limit')),
b.property('init', b.identifier('type'), b.identifier('GraphQLInt'))
])),
b.property('init', b.identifier('offset'), b.objectExpression([
b.property('init', b.identifier('name'), b.literal('offset')),
b.property('init', b.identifier('type'), b.identifier('GraphQLInt'))
]))
]));
}
b.variableDeclaration('var',
[b.variableDeclarator(
b.identifier('GraphQLRelay'),
b.callExpression(
b.identifier('require'),
[b.literal('graphql-relay')]
)
)]
),
b.variableDeclaration('var',
[b.variableDeclarator(
b.identifier('connectionDefinitions'),
b.memberExpression(
b.identifier('GraphQLRelay'),
b.identifier('connectionDefinitions'),
false
)
)]
)
];
}
module.exports = function buildType(type, opts) {
var imports = buildTypeImports(type, opts);
var typeAst = type.ast;
var typeExport = [buildExports(b.identifier(type.varName), opts)];
var register = [b.expressionStatement(
b.callExpression(
b.identifier('registerType'),
[b.identifier(type.varName)]
)
)];
return b.program([]
.concat(imports)
.concat(typeAst)
.concat(register)
.concat(typeExport)
);
};
} else {
statements.push(b.variableDeclaration(
'var',
[b.variableDeclarator(
expr,
arg
)]
));
}
if (node.value !== undefined && node.value !== null) {
statements.push(b.ifStatement(
b.binaryExpression(
'===',
arg,
b.identifier('undefined')
),
b.expressionStatement(b.assignmentExpression(
'=',
expr,
mapExpression(node.value, meta)
))
));
}
return statements;
}