Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const insertMethod = property.name === 'model' ?
'insertAfter' :
'insertBefore';
const collection = points
// get parent statement
.map(path => path.parent)
.at(0);
collection[insertMethod].call(
collection,
j.expressionStatement(
j.callExpression(
j.memberExpression(object, j.identifier('model')),
[
j.callExpression(j.identifier('require'), [
j.literal(modelPath)
])
]
)
)
);
},
visitMemberExpression(path: NodePath) {
const memberPath = getMemberPath(path.node);
if (!memberPath) {
this.traverse(path);
return;
}
const memberName = memberPath.join('.');
const assignmentPath = getPathOfAssignmentTo(path);
if (assignmentPath) {
const setterName = getSetterName(memberPath);
const exportOfMember = namespacedExports.get(setterName);
if (!exportOfMember || exportOfMember.url === convertedUrl) {
this.traverse(path);
return;
}
const [callPath] = assignmentPath.replace(jsc.callExpression(
jsc.identifier(setterName), [assignmentPath.node.right]));
if (!callPath) {
throw new Error(
'Failed to replace a namespace object property set with a setter function call.');
}
addToImportedReferences(exportOfMember, callPath.get('callee')!);
return false;
}
const exportOfMember = namespacedExports.get(memberName);
if (!exportOfMember || exportOfMember.url === convertedUrl) {
this.traverse(path);
return;
}
// Store the imported reference
addToImportedReferences(exportOfMember, path);
return false;
});
const { object, property } = points.get().value.callee;
const insertMethod = property.name === 'model' ?
'insertAfter' :
'insertBefore';
const collection = points
// get parent statement
.map(path => path.parent)
.at(0);
collection[insertMethod].call(
collection,
j.expressionStatement(
j.callExpression(
j.memberExpression(object, j.identifier('model')),
[
j.callExpression(j.identifier('require'), [
j.literal(modelPath)
])
]
)
)
);
},
jsc.identifier(varName),
jsc.callExpression(
jsc.memberExpression(
jsc.identifier('document'), jsc.identifier('createElement')),
[jsc.literal('template')]))]);
const setDocumentContainerStatement =
jsc.expressionStatement(jsc.assignmentExpression(
'=',
jsc.memberExpression(
jsc.identifier(varName), jsc.identifier('innerHTML')),
templateValue));
const targetNode = activeInBody ? 'body' : 'head';
return [
createElementTemplate,
setDocumentContainerStatement,
jsc.expressionStatement(jsc.callExpression(
jsc.memberExpression(
jsc.memberExpression(
jsc.identifier('document'), jsc.identifier(targetNode)),
jsc.identifier('appendChild')),
[jsc.memberExpression(
jsc.identifier(varName), jsc.identifier('content'))]))
];
}
export function createDomNodeInsertStatements(
nodes: parse5.ASTNode[], activeInBody = false): estree.Statement[] {
const varName = `$_documentContainer`;
const fragment = {
nodeName: '#document-fragment',
attrs: [],
childNodes: nodes,
};
const templateValue = serializeNodeToTemplateLiteral(fragment as any, false);
const createElementDiv = jsc.variableDeclaration(
'const',
[jsc.variableDeclarator(
jsc.identifier(varName),
jsc.callExpression(
jsc.memberExpression(
jsc.identifier('document'), jsc.identifier('createElement')),
[jsc.literal('template')]))]);
const setDocumentContainerStatement =
jsc.expressionStatement(jsc.assignmentExpression(
'=',
jsc.memberExpression(
jsc.identifier(varName), jsc.identifier('innerHTML')),
templateValue));
if (activeInBody) {
return [
createElementDiv,
setDocumentContainerStatement,
jsc.expressionStatement(jsc.callExpression(
jsc.memberExpression(
jsc.memberExpression(
export function createAssertion(assertionNameOrProperty, args) {
const assertionName = (assertionNameOrProperty.name == null)
? assertionNameOrProperty
: assertionNameOrProperty.name;
return j.callExpression(
j.memberExpression(j.identifier('assert'), j.identifier(assertionName), false),
args,
);
}
.forEach(prop =>
prop.value.elements.push(j.callExpression(j.identifier(name), []))
);
jsc.identifier(varName),
jsc.callExpression(
jsc.memberExpression(
jsc.identifier('document'), jsc.identifier('createElement')),
[jsc.literal('template')]))]);
const setDocumentContainerStatement =
jsc.expressionStatement(jsc.assignmentExpression(
'=',
jsc.memberExpression(
jsc.identifier(varName), jsc.identifier('innerHTML')),
templateValue));
if (activeInBody) {
return [
createElementDiv,
setDocumentContainerStatement,
jsc.expressionStatement(jsc.callExpression(
jsc.memberExpression(
jsc.memberExpression(
jsc.identifier('document'), jsc.identifier('body')),
jsc.identifier('appendChild')),
[jsc.memberExpression(
jsc.identifier(varName), jsc.identifier('content'))]))
];
}
const setDisplayNoneStatement = jsc.expressionStatement(jsc.callExpression(
jsc.memberExpression(
jsc.identifier(varName), jsc.identifier('setAttribute')),
[jsc.literal('style'), jsc.literal('display: none;')]));
return [
createElementDiv,
setDisplayNoneStatement,
setDocumentContainerStatement,
export function createDomNodeInsertStatements(
nodes: parse5.ASTNode[], activeInBody = false): estree.Statement[] {
const varName = `$_documentContainer`;
const fragment = {
nodeName: '#document-fragment',
attrs: [],
childNodes: nodes,
__location: {} as parse5.ElementLocationInfo,
};
const templateValue = serializeNodeToTemplateLiteral(fragment, false);
const createElementTemplate = jsc.variableDeclaration(
'const',
[jsc.variableDeclarator(
jsc.identifier(varName),
jsc.callExpression(
jsc.memberExpression(
jsc.identifier('document'), jsc.identifier('createElement')),
[jsc.literal('template')]))]);
const setDocumentContainerStatement =
jsc.expressionStatement(jsc.assignmentExpression(
'=',
jsc.memberExpression(
jsc.identifier(varName), jsc.identifier('innerHTML')),
templateValue));
const targetNode = activeInBody ? 'body' : 'head';
return [
createElementTemplate,
setDocumentContainerStatement,
jsc.expressionStatement(jsc.callExpression(
jsc.memberExpression(
jsc.memberExpression(