How to use the esprima.Syntax.ArrayExpression function in esprima

To help you get started, we’ve selected a few esprima 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 sophiebits / es3ify / index.js View on Github external
function visitArrayOrObjectExpression(traverse, node, path, state) {
    // Copy the opening '[' or '{'
    utils.catchup(node.range[0] + 1, state);

    var elements = node.type === Syntax.ArrayExpression ?
        node.elements :
        node.properties;
    elements.forEach(function(element, i) {
        if (element == null && i === elements.length - 1) {
            throw new Error(
                "Elisions ending an array are interpreted inconsistently " +
                "in IE8; remove the extra comma or use 'undefined' explicitly");
        }
        if (element != null) {
            // Copy commas from after previous element, if any
            utils.catchup(element.range[0], state);
            traverse(element, path, state);
            utils.catchup(element.range[1], state);
        }
    });
github SAP / ui5-builder / lib / lbt / calls / SapUiDefine.js View on Github external
constructor(node, moduleName) {
		this.node = node;
		this.name = moduleName;
		this.dependencyArray = null;
		this.factory = null;

		const args = node.arguments;
		let i = 0;
		let params;

		if ( args[i].type === Syntax.Literal ) {
			// assert(String)
			this.name = args[i++].value;
		}

		if ( args[i].type === Syntax.ArrayExpression ) {
			this.dependencyArray = args[i++];
			this.dependencies = this.dependencyArray.elements.map( (elem) => {
				if ( !isString(elem) ) {
					throw new TypeError();
				}
				return ModuleName.resolveRelativeRequireJSName(this.name, elem.value);
			});
			this.dependencyInsertionIdx = this.dependencyArray.elements.length;
		}

		if ( args[i].type === Syntax.FunctionExpression ) {
			this.factory = args[i++];
			params = this.factory.params;
			this.paramNames = params.map( (param) => {
				if ( param.type !== Syntax.Identifier ) {
					throw new TypeError();
github stryker-mutator / stryker / packages / stryker / src / mutators / ArrayDeclaratorMutator.ts View on Github external
public applyMutations(node: IdentifiedNode, copy:  (obj: T, deep?: boolean) => T): void | IdentifiedNode {
    if ((node.type === Syntax.CallExpression || node.type === Syntax.NewExpression) && node.callee.type === Syntax.Identifier && node.callee.name === 'Array' && node.arguments.length > 0) {
      const mutatedNode = copy(node);
      mutatedNode.arguments = [];
      return mutatedNode;
    }

    if (node.type === Syntax.ArrayExpression && node.elements.length > 0) {
      const mutatedNode = copy(node);
      mutatedNode.elements = [];
      return mutatedNode;
    }
  }
}