Skip to content

Commit

Permalink
feat: add treeshake annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
exuanbo committed Oct 23, 2024
1 parent 4060f6e commit 580d5a6
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 0 deletions.
3 changes: 3 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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__"],
}],
},
},
);
3 changes: 3 additions & 0 deletions src/decorators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,23 @@ export type ClassFieldInitializer<This extends object, Value> = (
initialValue: Value,
) => Value;

/*@__NO_SIDE_EFFECTS__*/
export function Injectable<This extends object>(...tokens: Token<This>[]): ClassDecorator<Constructor<This>> {
return (Class, _context) => {
const metadata = getMetadata(Class);
metadata.tokens.push(...tokens);
};
}

/*@__NO_SIDE_EFFECTS__*/
export function Scoped<This extends object>(scope: Scope): ClassDecorator<Constructor<This>> {
return (Class, _context) => {
const metadata = getMetadata(Class);
metadata.scope = scope;
};
}

/*@__NO_SIDE_EFFECTS__*/
export function AutoRegister<This extends object>(enable = true): ClassDecorator<Constructor<This>> {
return (Class, _context) => {
const metadata = getMetadata(Class);
Expand Down
2 changes: 2 additions & 0 deletions src/registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ export class Registry {
}
}

/*@__NO_SIDE_EFFECTS__*/
export function Build<Value>(factory: (...args: []) => Value): Type<Value> {
const typeName = getTypeName(factory);
const token = Type<Value>(`Build<${typeName}>`);
Expand All @@ -110,6 +111,7 @@ export function Build<Value>(factory: (...args: []) => Value): Type<Value> {
return token;
}

/*@__NO_SIDE_EFFECTS__*/
export function Value<T>(value: T): Type<T> {
const typeName = getTypeName(value);
const token = Type<T>(`Value<${typeName}>`);
Expand Down
1 change: 1 addition & 0 deletions src/token.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export interface Type<T> {
union<U>(typeName: string, U: Type<U>): Type<T | U>;
}

/*@__NO_SIDE_EFFECTS__*/
export function Type<T>(typeName: string): Type<T> {
const name = `Type<${typeName}>`;
const type = {
Expand Down

0 comments on commit 580d5a6

Please sign in to comment.