How to use the esprima.Syntax.Literal 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 stryker-mutator / stryker / packages / stryker / src / mutators / BooleanSubstitutionMutator.ts View on Github external
public applyMutations(node: IdentifiedNode, copy:  (obj: T, deep?: boolean) => T): IdentifiedNode[] {
    const nodes: IdentifiedNode[] = [];

    // !a -> a
    if (node.type === Syntax.UnaryExpression && node.operator === '!') {
      const mutatedNode = copy(node.argument as Expression & Identified) as IdentifiedNode;
      mutatedNode.nodeID = node.nodeID;
      nodes.push(mutatedNode);
    }

    // true -> false or false -> true
    if (node.type === Syntax.Literal && typeof node.value === 'boolean') {
      const mutatedNode = copy(node);
      mutatedNode.value = !mutatedNode.value;
      nodes.push(mutatedNode);
    }
    return nodes;
  }
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 ) {
github SAP / ui5-builder / lib / lbt / utils / ASTUtils.js View on Github external
function getPropertyKey(property) {
	if ( property.key.type === Syntax.Identifier ) {
		return property.key.name;
	} else if ( property.key.type === Syntax.Literal ) {
		return String(property.key.value);
	} else {
		throw new Error();
	}
}
github stryker-mutator / stryker / packages / stryker / src / mutators / RemoveConditionalsMutator.ts View on Github external
private booleanLiteralNode(nodeID: number, value: boolean): estree.SimpleLiteral & Identified {
    return {
      nodeID,
      raw: value.toString(),
      type: Syntax.Literal,
      value
    };
  }