Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 29 additions & 1 deletion engine/schema/transform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1516,6 +1516,32 @@ const getReturnFnFunction = async (
}
};

/**
* Searches for `export const DEFAULT_PROPS = { ... }` in the module AST.
* Returns the parsed object value if found, undefined otherwise.
*/
const findExportedDefaultProps = (
program: ParsedSource,
): JSONSchema7Type | undefined => {
for (const item of program.program.body) {
if (
item.type === "ExportDeclaration" &&
item.declaration.type === "VariableDeclaration"
) {
for (const decl of item.declaration.declarations) {
if (
decl.id.type === "Identifier" &&
decl.id.value === "DEFAULT_PROPS" &&
decl.init
) {
return generateObject(decl.init);
Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai bot Mar 13, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: DEFAULT_PROPS values that contain booleans are serialized as null because this path reuses a parser that does not handle BooleanLiteral.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At engine/schema/transform.ts, line 1537:

<comment>`DEFAULT_PROPS` values that contain booleans are serialized as `null` because this path reuses a parser that does not handle `BooleanLiteral`.</comment>

<file context>
@@ -1516,6 +1516,32 @@ const getReturnFnFunction = async (
+          decl.id.value === "DEFAULT_PROPS" &&
+          decl.init
+        ) {
+          return generateObject(decl.init);
+        }
+      }
</file context>
Fix with Cubic

}
Comment on lines +1532 to +1538
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Validate DEFAULT_PROPS is an object literal before applying it.

Right now any initializer is accepted, so DEFAULT_PROPS can become a non-object default for an object schema. That can produce invalid inputSchema.default values.

Proposed fix
         if (
           decl.id.type === "Identifier" &&
           decl.id.value === "DEFAULT_PROPS" &&
           decl.init
         ) {
-          return generateObject(decl.init);
+          if (decl.init.type !== "ObjectExpression") {
+            continue;
+          }
+          const parsed = generateObject(decl.init);
+          if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) {
+            return parsed;
+          }
         }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if (
decl.id.type === "Identifier" &&
decl.id.value === "DEFAULT_PROPS" &&
decl.init
) {
return generateObject(decl.init);
}
if (
decl.id.type === "Identifier" &&
decl.id.value === "DEFAULT_PROPS" &&
decl.init
) {
if (decl.init.type !== "ObjectExpression") {
continue;
}
const parsed = generateObject(decl.init);
if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) {
return parsed;
}
}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@engine/schema/transform.ts` around lines 1532 - 1538, The code currently
treats any initializer for the identifier DEFAULT_PROPS as an object by calling
generateObject(decl.init); update the conditional in the DEFAULT_PROPS branch to
first verify the initializer is an object literal (e.g., decl.init.type ===
"ObjectExpression" or the project's AST equivalent) before calling
generateObject, and skip/apply no-default if it's not an object so
inputSchema.default is not set to non-object values; refer to the DEFAULT_PROPS
identifier check and the generateObject(decl.init) call when making this change.

}
}
}
return undefined;
};

export const programToBlockRef = async (
importMapResolver: ImportMapResolver,
mPath: string,
Expand Down Expand Up @@ -1584,7 +1610,9 @@ export const programToBlockRef = async (
references: schemeableReferences,
});
if (inputSchema.type === "object") {
inputSchema.default = defaultValue;
// Priority: DEFAULT_PROPS export > function parameter default > nothing
const exportedDefaultProps = findExportedDefaultProps(mProgram);
Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai bot Mar 13, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: Look up DEFAULT_PROPS in the resolved function module, not the entry module, so re-exported blocks keep their defaults.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At engine/schema/transform.ts, line 1614:

<comment>Look up `DEFAULT_PROPS` in the resolved function module, not the entry module, so re-exported blocks keep their defaults.</comment>

<file context>
@@ -1584,7 +1610,9 @@ export const programToBlockRef = async (
     if (inputSchema.type === "object") {
-      inputSchema.default = defaultValue;
+      // Priority: DEFAULT_PROPS export > function parameter default > nothing
+      const exportedDefaultProps = findExportedDefaultProps(mProgram);
+      inputSchema.default = exportedDefaultProps ?? defaultValue;
     }
</file context>
Suggested change
const exportedDefaultProps = findExportedDefaultProps(mProgram);
const exportedDefaultProps = findExportedDefaultProps(parsedSource);
Fix with Cubic

inputSchema.default = exportedDefaultProps ?? defaultValue;
}
return {
...baseBlockRef,
Expand Down
Loading