From 580d5a6ea12f7cbcb3776675d9ef08e9b2abd472 Mon Sep 17 00:00:00 2001 From: exuanbo Date: Wed, 23 Oct 2024 11:14:15 +0100 Subject: [PATCH] feat: add treeshake annotations --- eslint.config.mjs | 3 +++ src/decorators.ts | 3 +++ src/registry.ts | 2 ++ src/token.ts | 1 + 4 files changed, 9 insertions(+) diff --git a/eslint.config.mjs b/eslint.config.mjs index 19e2a06..19fd593 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -99,6 +99,9 @@ export default tseslint.config( ], rules: { "@stylistic/object-curly-spacing": ["error", "never"], + "@stylistic/spaced-comment": ["error", "always", { + exceptions: ["@__PURE__", "@__NO_SIDE_EFFECTS__"], + }], }, }, ); diff --git a/src/decorators.ts b/src/decorators.ts index 6b7e204..fcda2de 100644 --- a/src/decorators.ts +++ b/src/decorators.ts @@ -18,6 +18,7 @@ export type ClassFieldInitializer = ( initialValue: Value, ) => Value; +/*@__NO_SIDE_EFFECTS__*/ export function Injectable(...tokens: Token[]): ClassDecorator> { return (Class, _context) => { const metadata = getMetadata(Class); @@ -25,6 +26,7 @@ export function Injectable(...tokens: Token[]): Class }; } +/*@__NO_SIDE_EFFECTS__*/ export function Scoped(scope: Scope): ClassDecorator> { return (Class, _context) => { const metadata = getMetadata(Class); @@ -32,6 +34,7 @@ export function Scoped(scope: Scope): ClassDecorator(enable = true): ClassDecorator> { return (Class, _context) => { const metadata = getMetadata(Class); diff --git a/src/registry.ts b/src/registry.ts index 98e29ce..6600efa 100644 --- a/src/registry.ts +++ b/src/registry.ts @@ -99,6 +99,7 @@ export class Registry { } } +/*@__NO_SIDE_EFFECTS__*/ export function Build(factory: (...args: []) => Value): Type { const typeName = getTypeName(factory); const token = Type(`Build<${typeName}>`); @@ -110,6 +111,7 @@ export function Build(factory: (...args: []) => Value): Type { return token; } +/*@__NO_SIDE_EFFECTS__*/ export function Value(value: T): Type { const typeName = getTypeName(value); const token = Type(`Value<${typeName}>`); diff --git a/src/token.ts b/src/token.ts index f1443f5..5ad940c 100644 --- a/src/token.ts +++ b/src/token.ts @@ -11,6 +11,7 @@ export interface Type { union(typeName: string, U: Type): Type; } +/*@__NO_SIDE_EFFECTS__*/ export function Type(typeName: string): Type { const name = `Type<${typeName}>`; const type = {