How to use the @babel/types.isArrayExpression function in @babel/types

To help you get started, we’ve selected a few @babel/types examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github nicoespeon / abracadabra / src / ast / identity.ts View on Github external
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;
  }
github firefox-devtools / debugger / src / workers / parser / getSymbols.js View on Github external
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) {
github Gregoor / tofu / src / editor.tsx View on Github external
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,
github Polymer / tools / packages / analyzer / src / polymer / behavior-scanner.ts View on Github external
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;
  }
}
github shuidi-fed / vuese / packages / parser / lib / processProps.ts View on Github external
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
}
github salesforce / lwc / packages / lwc-template-compiler / src / codegen / index.ts View on Github external
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);
    }
github Polymer / tools / packages / analyzer / src / javascript / class-scanner.ts View on Github external
private _getObservedAttributes(
      node: babel.ClassDeclaration|babel.ClassExpression,
      document: JavaScriptDocument) {
    const returnedValue = getStaticGetterValue(node, 'observedAttributes');
    if (returnedValue && babel.isArrayExpression(returnedValue)) {
      return this._extractAttributesFromObservedAttributes(
          returnedValue, document);
    }
  }
github vadimdemedes / pastel / lib / parse-command.js View on Github external
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;
};