Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
sourceRange: element.sourceRange!
}).toString());
continue;
}
const node = nodePath.node;
if (node.type === 'ClassDeclaration' || node.type === 'ClassExpression') {
// A Polymer 2.0 class-based element
node.body.body.splice(
0,
0,
jsc.methodDefinition(
'get',
jsc.identifier('template'),
jsc.functionExpression(
null, [], jsc.blockStatement([jsc.returnStatement(
templateLiteral)])),
true));
} else if (node.type === 'CallExpression') {
// A Polymer hybrid/legacy factory function element
const arg = node.arguments[0];
if (arg && arg.type === 'ObjectExpression') {
arg.properties.unshift(jsc.property(
'init', jsc.identifier('_template'), templateLiteral));
}
} else {
console.error(`Internal Error, Class or CallExpression expected, got ${
node.type}`);
}
}
return claimedDomModules;
}
continue;
}
const importMeta = jsc.memberExpression(
jsc.identifier('import'), jsc.identifier('meta'));
const node = nodePath.node;
if (node.type === 'ClassDeclaration' || node.type === 'ClassExpression') {
// A Polymer 2.0 class-based element
const getter = jsc.methodDefinition(
'get',
jsc.identifier('importMeta'),
jsc.functionExpression(
null,
[],
jsc.blockStatement([jsc.returnStatement(importMeta)])),
true);
node.body.body.splice(0, 0, getter);
} else if (node.type === 'CallExpression') {
// A Polymer hybrid/legacy factory function element
const arg = node.arguments[0];
if (arg && arg.type === 'ObjectExpression') {
arg.properties.unshift(
jsc.property('init', jsc.identifier('importMeta'), importMeta));
}
} else {
console.error(`Internal Error, Class or CallExpression expected, got ${
node.type}`);
}
}
}
export function getBlockStatementFromFunction({body}) {
if (!j.BlockStatement.check(body)) {
return j.blockStatement([j.returnStatement(body)]);
}
return body;
}
function appendActionCreatorFunction({ast, constantName, actionCreatorName}) {
const newFunction = j.functionDeclaration(j.identifier(actionCreatorName), [], j.blockStatement([
j.returnStatement(
j.objectExpression([
j.property('init', j.literal('type'), j.identifier(constantName)),
])
),
]))
const newExport = j.exportNamedDeclaration(newFunction, [], null)
const exports = ast
.find(j.ExportNamedDeclaration)
exports
.at(exports.length - 1)
.insertAfter(newExport)
}
export default function appendActionToReducer({ast, constantName}) {
appendConstantImport({ast, constantName})
const switchCase = j.switchCase(j.identifier(constantName), [
j.returnStatement(j.identifier('state')),
])
return ast
.find(j.SwitchCase, node => node.test === null)
.insertBefore(switchCase)
}