@babel/types#AssignmentPattern TypeScript Examples

The following examples show how to use @babel/types#AssignmentPattern. 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
processParamValue = (
  babel: typeof Babel,
  node: Babel.types.AssignmentPattern
): Operation | void => {
  const t = babel.types;
  let valueNode;
  if (t.isAssignmentPattern(node)) {
    valueNode = node.right;
  } else {
    valueNode = node;
  }

  if (valueNode && Values[valueNode.type]) {
    return Values[valueNode.type](babel, valueNode);
  } else {
    if (
      isIdentifier(valueNode) &&
      (valueNode.name === PathType.GET ||
        valueNode.name === PathType.OBSERVE ||
        valueNode.name === PathType.UPDATE)
    ) {
      return {
        type: OperationTypes.CONSTRUCTOR,
        value: valueNode.name,
      };
    } 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;
}