Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function cjsImport(graphql, others, opts) {
// Require the entity resolver
var declarations = [
b.variableDeclaration('var',
[b.variableDeclarator(
b.identifier('getEntityResolver'),
b.callExpression(
b.identifier('require'),
[b.literal('../util/entity-resolver')]
)
)]
)
];
if (opts.relay && graphql.indexOf('GraphQLList') >= 0) {
declarations.push(
b.variableDeclaration('var',
[b.variableDeclarator(
b.identifier('getConnectionResolver'),
b.callExpression(
b.identifier('require'),
function convertImport(tempIdentifier: ESTree.Identifier, specifier: ESTree.ImportSpecifier
| ESTree.ImportDefaultSpecifier | ESTree.ImportNamespaceSpecifier): ESTree.VariableDeclarator {
if (n.ImportSpecifier.check(specifier)) {
// e.g. import { a as b, c } from './dep';
return b.variableDeclarator(
b.identifier(specifier.local.name),
b.memberExpression(
b.memberExpression(
tempIdentifier,
b.identifier('exports'),
false
),
b.literal(specifier.imported.name),
true
)
);
} else if (n.ImportDefaultSpecifier.check(specifier)) {
// e.g. import dep from './dep';
return b.variableDeclarator(
b.identifier(specifier.local.name),
b.memberExpression(
function replaceImports(path: Path, importModuleIndex: number): void {
const tempIdentifier = path.scope.declareTemporary(`__import${importModuleIndex}`);
const imports = path.node.specifiers.map((specifier) => convertImport(tempIdentifier, specifier));
path.replace(
b.variableDeclaration(
'var',
[
b.variableDeclarator(
tempIdentifier,
b.callExpression(
b.identifier('__paeckchen_require__'),
[
b.literal(importModuleIndex)
]
)
),
...imports
]
)
);
}
return false;
}
});
if (processPath === undefined) {
return Promise.resolve();
}
const processModulePath = await getModulePath('.', 'process', context);
const processIndex = getModuleIndex(processModulePath, state);
const body = processPath.get('body');
body.get(body.value.length - 1).insertBefore(
b.variableDeclaration(
'var',
[
b.variableDeclarator(
b.identifier('process'),
b.memberExpression(
b.callExpression(
b.identifier('__paeckchen_require__'),
[
b.literal(processIndex)
]
),
b.identifier('exports'),
false
)
)
]
)
);
enqueueModule(processModulePath, state, context);
];
}
return [
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
)
)]
)
];
}
node.left = id;
nodes.push(util.template("variable-declare", {
KEY: id
}));
}
return node;
});
//
var argumentsId = util.aliasArguments(generateUid, node);
if (argumentsId) {
nodes.push(b.variableDeclaration("var", [
b.variableDeclarator(argumentsId, b.identifier("arguments"))
]));
}
//
var block = b.blockStatement([]);
block.body = node;
var func = b.functionExpression(null, [], block, false);
//
var templateName = "function-call";
if (traverse.hasType(node, "ThisExpression")) templateName += "-this";
if (traverse.hasType(node, "ReturnStatement", traverse.FUNCTION_TYPES)) templateName += "-return";
var body = node.body;
var built = buildNode(node.body, generateUid);
node.body = built.node;
traverse(built.body, function (node) {
if (node.type === "ContinueStatement") {
return b.returnStatement(null);
}
}, blockTypes);
if (traverse.hasType(body, "BreakStatement", blockTypes)) {
var id = b.identifier(generateUid("break"));
node.body.unshift(b.variableDeclaration("var", [
b.variableDeclarator(id, b.literal(false))
]));
traverse(built.body, function (node) {
if (node.type === "BreakStatement") {
return b.returnStatement(b.assignmentExpression("=", id, b.literal(true)));
}
}, blockTypes);
node.body.push(b.ifStatement(id, b.breakStatement()));
}
};
if (!opts.relay) {
return [];
}
if (opts.es6) {
return [
b.importDeclaration(
[importSpecifier('connectionDefinitions')],
b.literal('graphql-relay')
)
];
}
return [
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
)
]),
),
)
let listStoreId = b.identifier(camelCase(path.node.id.name + 'List'))
listStoreId.typeAnnotation = b.typeAnnotation(
b.genericTypeAnnotation(
b.identifier('Store'),
b.typeParameterInstantiation([
b.arrayTypeAnnotation(b.genericTypeAnnotation(path.node.id, null)),
]),
),
)
path.parentPath.insertAfter(
b.exportNamedDeclaration(
b.variableDeclaration('const', [
b.variableDeclarator(
listStoreId,
b.callExpression(b.identifier('createStore'), [
b.arrayExpression([]),
]),
),
]),
),
)
path.parentPath.insertAfter(
b.exportNamedDeclaration(
b.variableDeclaration('const', [
b.variableDeclarator(
singleStoreId,
b.callExpression(b.identifier('createStore'), [
b.identifier('null'),
]),
b.memberExpression(
b.thisExpression(),
b.identifier('moveCursor')),
[b.literal(2)])));
write_stmts.push(
b.expressionStatement(b.callExpression(
b.memberExpression(
b.thisExpression(),
b.identifier('moveCursor')),
[b.literal(2)])));
}
read_stmts.push(
b.variableDeclaration(
'var',
[b.variableDeclarator(
b.identifier('value'),
b.newExpression(b.identifier('Map'), []))]));
read_stmts.push(b.expressionStatement(
b.assignmentExpression(
'=',
b.memberExpression(
b.identifier('obj'), b.identifier('value')),
b.identifier('value'))));
read_stmts.push(b.forOfStatement(
b.variableDeclaration(
'let',
[b.identifier('field')]),
b.memberExpression(
b.identifier('obj'), b.identifier(value_mask_name)),