@babel/types#isAssignmentPattern TypeScript Examples

The following examples show how to use @babel/types#isAssignmentPattern. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: valueParser.ts    From engine with MIT License 6 votes vote down vote up
processValue = (node: ObjectProperty): Operation | void => {
  let valueNode;
  if (isAssignmentPattern(node.value)) {
    valueNode = node.value.right;
  } else {
    valueNode = node.value;
  }

  if (valueNode && Values[valueNode.type]) {
    return Values[valueNode.type](valueNode);
  } else {
    return constValue({ __node__: valueNode });
  }
}
Example #2
Source File: valueParser.ts    From engine with MIT License 6 votes vote down vote up
processParamValue = (
  node: AssignmentPattern
): Operation | void => {
  let valueNode;
  if (isAssignmentPattern(node)) {
    valueNode = node.right;
  } else {
    valueNode = node;
  }

  if (valueNode && Values[valueNode.type]) {
    return Values[valueNode.type](valueNode);
  } else {
    return constValue({ __node__: valueNode });
  }
}
Example #3
Source File: paramsParser.ts    From engine with MIT License 5 votes vote down vote up
paramsParser = (params: ObjectPattern): StructOperation => {
  if (!params) {
    return {
      type: OperationTypes.STRUCT,
      value: {},
    };
  }
  const result = params.properties.reduce(
    (acc, x, idx) => {
      if (isObjectProperty(x)) {
        if (isIdentifier(x.value)) {
          const node = x.value as Identifier;
          const propName = node.name;
          const propValue = {
            type: OperationTypes.VALUE,
            value: {
              type: ValueTypes.EXTERNAL,
              path: [propName],
            },
          } as ValueOperation;
          acc.value[propName] = propValue;
        } else if (isAssignmentPattern(x.value)) {
          const node = x.value as AssignmentPattern;
          const left = node.left as Identifier;
          const propName = left.name;
          const propValue = processParamValue(node);
          if (propValue) {
            acc.value[propName] = propValue;
          } else {
            throw new Error(
              "Property " + propName + " could not be processed."
            );
          }
        } else {
          console.log("Not object property", x);
        }
      } else if (isRestElement(x)) {
        throw new Error("Rest operator is not supported.");
      }
      return acc;
    },
    {
      type: OperationTypes.STRUCT,
      value: {},
    } as StructOperation
  );

  result.meta = {};

  return result;
}