Skip to content

Commit c97bb10

Browse files
author
nicosammito
committed
feat: update function identifiers and default values for consistency and accuracy
1 parent 45bb77a commit c97bb10

13 files changed

Lines changed: 11492 additions & 72 deletions

src/extraction/getValueFromType.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,10 @@ export const getValueFromType = (
6262

6363
// 2. Handle Primitives and Literals
6464
if (flags & ts.TypeFlags.StringLiteral) return (t as ts.StringLiteralType).value;
65-
if (flags & ts.TypeFlags.String) return "sample";
65+
if (flags & ts.TypeFlags.String) return "";
6666

6767
if (flags & ts.TypeFlags.NumberLiteral) return (t as ts.NumberLiteralType).value;
68-
if (flags & ts.TypeFlags.Number) return 1;
68+
if (flags & ts.TypeFlags.Number) return 0;
6969

7070
if (flags & ts.TypeFlags.BooleanLiteral) return (t as any).intrinsicName === "true";
7171
if (flags & ts.TypeFlags.Boolean) return false;

src/utils.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ export const MINIMAL_LIB = `
4343
interface NewableFunction extends Function {}
4444
interface IArguments { }
4545
interface RegExp { }
46+
type Record<K extends keyof any, T> = { [P in K]: T; };
4647
type ReturnType<T extends (...args: any) => any> = T extends (...args: any) => infer R ? R : any;
4748
`;
4849

@@ -84,7 +85,7 @@ export function getSharedTypeDeclarations(dataTypes?: DataType[]): string {
8485
`type ${dt.identifier}${(dt.genericKeys?.length ?? 0) > 0 ? `<${dt.genericKeys?.join(",")}>` : ""} = ${dt.type};`
8586
).join("\n");
8687

87-
return `${typeAliasDeclarations}`;
88+
return `${genericDeclarations}\n${typeAliasDeclarations}`;
8889
}
8990

9091
/**

src/validation/getFlowValidation.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,8 @@ export const getFlowValidation = (
144144
};
145145
}).filter((e) => e !== null);
146146

147+
console.log(sourceCode)
148+
147149
return {
148150
isValid: !errors.some(e => e?.severity === "error"),
149151
returnType: "void",

src/validation/getNodeValidation.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@ export const getNodeValidation = (
7676
const result = testFunc(${funcCallArgs});
7777
`;
7878

79+
console.log(sourceCode)
80+
7981
// 3. Virtual compilation
8082
const fileName = "index.ts";
8183
const host = createCompilerHost(fileName, sourceCode);

src/validation/getValueValidation.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ export const getValueValidation = (
2222
const errors = diagnostics.map(d => {
2323
const message = ts.flattenDiagnosticMessageText(d.messageText, "\n");
2424
// Generic placeholders like T, R, K, V are often warnings rather than hard errors if they remains un-inferred
25-
const isGenericPlaceholder = /\b([TRKV])\b/.test(message);
2625

2726
// Match specific phrases that indicate a mock error from our code generation,
2827
// while allowing other "not assignable" errors (which represent real logic errors).
@@ -34,7 +33,7 @@ export const getValueValidation = (
3433
return {
3534
message,
3635
code: d.code,
37-
severity: (isGenericPlaceholder || isMockError ? "warning" : "error") as "error" | "warning",
36+
severity: (isMockError ? "warning" : "error") as "error" | "warning",
3837
};
3938
});
4039

0 commit comments

Comments
 (0)