@babel/types#BooleanLiteral TypeScript Examples

The following examples show how to use @babel/types#BooleanLiteral. 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: longBooleans.ts    From react-native-decompiler with GNU Affero General Public License v3.0 6 votes vote down vote up
getVisitor(): Visitor {
    return {
      UnaryExpression(path) {
        const node = path.node;
        if (node.operator !== '!' || !isNumericLiteral(node.argument) || (node.argument.value !== 0 && node.argument.value !== 1)) return;
        path.replaceWith(booleanLiteral(!node.argument.value));
      },
    };
  }
Example #2
Source File: longBooleans.ts    From react-native-decompiler with GNU Affero General Public License v3.0 6 votes vote down vote up
getVisitor(): Visitor {
    return {
      UnaryExpression(path) {
        const node = path.node;
        if (node.operator !== '!' || !isNumericLiteral(node.argument) || (node.argument.value !== 0 && node.argument.value !== 1)) return;
        path.replaceWith(booleanLiteral(!node.argument.value));
      },
    };
  }
Example #3
Source File: valueOperationCompiler.ts    From engine with MIT License 5 votes vote down vote up
valueOperationCompiler = (
  op: ValueOperation
): ObjectExpression => {
  let value = objectProperty(identifier("path"), stringLiteral("___"));
  const type = objectProperty(identifier("type"), stringLiteral(op.type));
  if (op.value.type === ValueTypes.CONST) {
    const val = op.value.value;

    let valType;
    if (val && val.__node__) {
      valType = val.__node__;
    } else if (typeof val === "string") {
      valType = stringLiteral(val);
    } else if (typeof val === "number") {
      valType = numericLiteral(val);
    } else if (typeof val === "boolean") {
      valType = booleanLiteral(val);
    } else {
      throw new Error("Value type not supported yet: " + typeof val);
    }

    value = objectProperty(
      identifier("value"),
      objectExpression([
        objectProperty(identifier("type"), stringLiteral(ValueTypes.CONST)),
        objectProperty(identifier("value"), valType),
      ])
    );
  } else if (
    op.value.type === ValueTypes.EXTERNAL ||
    op.value.type === ValueTypes.INTERNAL
  ) {
    const path = arrayExpression(op.value.path.map((x) => stringLiteral(x)));
    value = objectProperty(
      identifier("value"),
      objectExpression([
        objectProperty(identifier("type"), stringLiteral(op.value.type)),
        objectProperty(identifier("path"), path),
      ])
    );
  }
  return objectExpression([type, value]);
}
Example #4
Source File: babel-polyfill.ts    From nota with MIT License 5 votes vote down vote up
booleanLiteral = (value: boolean): BooleanLiteral => ({
  type: "BooleanLiteral",
  value,
  ...baseNode,
})