Skip to content

Commit

Permalink
Another
Browse files Browse the repository at this point in the history
  • Loading branch information
CarsonF committed Mar 25, 2024
1 parent 6fe5d49 commit be77527
Showing 1 changed file with 16 additions and 14 deletions.
30 changes: 16 additions & 14 deletions packages/generate/src/syntax/toEdgeQL.ts
Expand Up @@ -380,7 +380,7 @@ function walkExprTree(
param = param.__shapeElement__;
}
if (typeof param === "object") {
if (!!(param as any).__kind__) {
if ((param as any).__kind__) {
// param is expression
childExprs.push(...walkExprTree(param as any, expr as any, ctx));
} else {
Expand Down Expand Up @@ -656,8 +656,8 @@ function walkExprTree(
function renderEdgeQL(
_expr: TypeSet,
ctx: RenderCtx,
renderShape: boolean = true,
noImplicitDetached: boolean = false
renderShape = true,
noImplicitDetached = false
): string {
if (!(_expr as any).__kind__) {
throw new Error("Invalid expression.");
Expand Down Expand Up @@ -932,13 +932,15 @@ function renderEdgeQL(
expr.__element__.__name__ === "std::number"
? "std::float64"
: expr.__element__.__name__;
let inner = "{}";
if (expr.__expr__) {
const isCast = (expr.__expr__ as any).__kind__ === ExpressionKind.Cast;
const innerExpr = renderEdgeQL(expr.__expr__, ctx);
inner = isCast ? innerExpr.slice(1, -1) : innerExpr;
if (!expr.__expr__) {
return `<${typeName}>{}`;
}
return `(<${typeName}>${inner})`;
const innerExpr = renderEdgeQL(expr.__expr__, ctx);
const isCast =
(expr.__expr__ as any).__kind__ === ExpressionKind.Cast &&
innerExpr[0] === "(";
const expr = isCast ? innerExpr.slice(1, -1) : innerExpr;
return `(<${typeName}>${expr})`;
} else if (expr.__kind__ === ExpressionKind.Select) {
const lines: string[] = [];
if (isObjectType(expr.__element__)) {
Expand Down Expand Up @@ -1259,8 +1261,8 @@ function shapeToEdgeQL(
shape: object | null,
ctx: RenderCtx,
type: ObjectType | null = null,
keysOnly: boolean = false,
injectImplicitId: boolean = true
keysOnly = false,
injectImplicitId = true
) {
const pointers = type?.__pointers__ || null;
const isFreeObject = type?.__name__ === "std::FreeObject";
Expand All @@ -1287,10 +1289,10 @@ function shapeToEdgeQL(
let polyType: SomeExpression | null = null;

if (typeof val === "object" && !val.__element__) {
if (!!val["+="]) {
if (val["+="]) {
operator = "+=";
val = val["+="];
} else if (!!val["-="]) {
} else if (val["-="]) {
operator = "-=";
val = val["-="];
}
Expand Down Expand Up @@ -1567,7 +1569,7 @@ function indent(str: string, depth: number) {

// backtick quote identifiers if needed
// https://github.com/edgedb/edgedb/blob/master/edb/edgeql/quote.py
function q(ident: string, allowBacklinks: boolean = true): string {
function q(ident: string, allowBacklinks = true): string {
if (
!ident ||
ident.startsWith("@") ||
Expand Down

0 comments on commit be77527

Please sign in to comment.