Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function areEqual(nodeA: t.Node | null, nodeB: t.Node | null): boolean {
if (nodeA === null) return false;
if (nodeB === null) return false;
if (t.isNullLiteral(nodeA) && t.isNullLiteral(nodeB)) return true;
if (isUndefinedLiteral(nodeA) && isUndefinedLiteral(nodeB)) return true;
if (t.isThisExpression(nodeA) && t.isThisExpression(nodeB)) return true;
// Arrays
if (t.isArrayExpression(nodeA) && t.isArrayExpression(nodeB)) {
return areAllEqual(nodeA.elements, nodeB.elements);
}
// Objects
if (t.isObjectExpression(nodeA) && t.isObjectExpression(nodeB)) {
return areAllEqual(nodeA.properties, nodeB.properties);
}
if (t.isObjectProperty(nodeA) && t.isObjectProperty(nodeB)) {
return areEqual(nodeA.key, nodeB.key) && areEqual(nodeA.value, nodeB.value);
}
// Identifiers
if (t.isIdentifier(nodeA) && t.isIdentifier(nodeB)) {
return nodeA.name === nodeB.name;
}
function extendSnippet(
name: string,
expression: string,
path?: { node: Node },
prevPath?: SimplePath
) {
const computed = path && path.node.computed;
const prevComputed = prevPath && prevPath.node.computed;
const prevArray = t.isArrayExpression(prevPath);
const array = t.isArrayExpression(path);
const value =
(path &&
path.node.property &&
path.node.property.extra &&
path.node.property.extra.raw) ||
"";
if (expression === "") {
if (computed) {
return name === undefined ? `[${value}]` : `[${name}]`;
}
return name;
}
if (computed || array) {
if (["'", '"', '`'].includes(key)) {
data += data;
}
if (
!event.ctrlKey &&
!event.altKey &&
!event.metaKey &&
key.length == 1
) {
this.updateCode({
code: replaceCode(
code,
[selectionStart, selectionEnd],
data +
(t.isArrayExpression(node) && start > node.start && end < node.end
? ','
: '')
),
cursor: [selectionStart + data.length, selectionEnd + data.length]
});
this.moveCursor(null);
event.preventDefault();
return;
}
}
if (key == 'Tab') {
this.updateCode({
cursor: moveCursor(
ast,
code,
return node.init;
}
if (babel.isAssignmentExpression(node)) {
return node.right;
}
if (babel.isExportDefaultDeclaration(node) ||
babel.isExportNamedDeclaration(node)) {
return behaviorExpression(node.declaration);
}
if (babel.isExpressionStatement(node)) {
return behaviorExpression(node.expression);
}
if (babel.isVariableDeclaration(node)) {
return behaviorExpression(node.declarations[0]);
}
if (babel.isObjectExpression(node) || babel.isArrayExpression(node)) {
return node;
}
}
function getTypeByTypeNode(typeNode: bt.Node): PropType {
if (bt.isIdentifier(typeNode)) return typeNode.name
if (bt.isArrayExpression(typeNode)) {
if (!typeNode.elements.length) return null
return typeNode.elements
.filter(node => node && bt.isIdentifier(node))
.map(node => (node as bt.Identifier).name)
}
return null
}
function applyTemplateFor(
element: IRElement,
fragmentNodes: t.Expression,
): t.Expression {
let expression = fragmentNodes;
if (t.isArrayExpression(expression) && expression.elements.length === 1) {
expression = expression.elements[0] as t.Expression;
}
return applyInlineFor(element, expression);
}
private _getObservedAttributes(
node: babel.ClassDeclaration|babel.ClassExpression,
document: JavaScriptDocument) {
const returnedValue = getStaticGetterValue(node, 'observedAttributes');
if (returnedValue && babel.isArrayExpression(returnedValue)) {
return this._extractAttributesFromObservedAttributes(
returnedValue, document);
}
}
const parsePositionalArgs = node => {
if (!types.isArrayExpression(node)) {
return [];
}
const positionalArgs = [];
for (const element of node.elements) {
if (types.isStringLiteral(element)) {
positionalArgs.push(element.value);
}
}
return positionalArgs;
};