__Pure__ annotation in Zod source code.
In this article, we will review Pureannotation in zod source code.
We will look at:
-
Where to find pure annotation in Zod source code?
-
pure annotations issue in evanw/esbuild.
Where to find pure annotation in Zod source code?
You will find pureannotation in zod source code at this location- https://github.com/colinhacks/zod/blob/main/packages/zod/src/v4/classic/parse.ts#L20C35-L20C44]
export const parseAsync: <T extends core.$ZodType>(
schema: T,
value: unknown,
_ctx?: core.ParseContext<core.$ZodIssue>,
_params?: { callee?: core.util.AnyFunc; Err?: core.$ZodErrorClass }
) => Promise<core.output<T>> = /* @__PURE__ */ core._parseAsync(ZodRealError) as any;
pure annotations issue in evanw/esbuild
You will find an issue related to pureannotations in esbuild repository.
Issue 503
Below is the issue description:
Currently, the /* @__PURE__ */
annotation must be used individually on every returned value for a given call.
Could it be possible to allow using the annotation on a function, so all its returned values are considered pure? Like in the following.
/**
* The function is pure, so if the result is not used, it can be removed.
*
* @__PURE__
*/
function addTwo(number: number) {
return number + 2;
}
// Will be removed
addTwo(4);
// Will be removed
const x = addTwo(3);
// This will be kept
export const y = addTwo(2);
this is what @evanw had to say
About me:
Hey, my name is Ramu Narasinga. I study large open-source projects and create content about their codebase architecture and best practices, sharing it through articles, videos.
Email — ramu@thinkthroo.com
My Github — https://github.com/ramu-narasinga
My website — https://ramunarasinga.com
My YouTube channel — https://www.youtube.com/@ramu-narasinga
Learning platform — https://thinkthroo.com
Codebase Architecture — https://app.thinkthroo.com/architecture
Best practices — https://app.thinkthroo.com/best-practices
Production-grade projects — https://app.thinkthroo.com/production-grade-projects