Skip to content

Commit

Permalink
updates
Browse files Browse the repository at this point in the history
  • Loading branch information
pyramation committed Oct 30, 2024
1 parent 72c38d2 commit fc4fe2f
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 18 deletions.
7 changes: 5 additions & 2 deletions __fixtures__/decorators/src/class.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { admin, creator } from '@hyperweb/decorators';
import { admin, creator, external, internal } from '@hyperweb/decorators';
import { BigNumber } from 'jsd-std';

export interface State {
Expand All @@ -13,11 +13,14 @@ export class Counter {
}

// Public by default (no decorator needed)
@external
@admin
public getCount(): BigNumber {
return this.state.count;
}

// Only admin and creator can increment
@internal
@admin
public increment(amount: BigNumber): void {
this.state.count = this.state.count.add(amount);
Expand Down
7 changes: 5 additions & 2 deletions __fixtures__/decorators/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
export * from './class';
export * from './object';
class MyClass {
@log('debug')
@permission('debug', 'level')
@performance
async fetchData() {
// ... method implementation
}
}
}

export default MyClass;
export {MyClass};
3 changes: 3 additions & 0 deletions __output__/decorators/bundle.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions __output__/decorators/bundle.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 22 additions & 10 deletions __output__/decorators/decorators.json
Original file line number Diff line number Diff line change
@@ -1,32 +1,44 @@
{
"../../__fixtures__/decorators/src/index.ts": [
{
"name": "log",
"name": "permission",
"args": [
"debug"
"debug",
"level"
],
"targetName": "fetchData",
"targetType": "method"
"targetName": "fetchData"
},
{
"name": "performance",
"args": [],
"targetName": "fetchData",
"targetType": "method"
"targetName": "fetchData"
}
],
"../../__fixtures__/decorators/src/class.ts": [
{
"name": "external",
"args": [],
"targetName": "getCount"
},
{
"name": "admin",
"args": [],
"targetName": "getCount"
},
{
"name": "internal",
"args": [],
"targetName": "increment"
},
{
"name": "admin",
"args": [],
"targetName": "increment",
"targetType": "method"
"targetName": "increment"
},
{
"name": "creator",
"args": [],
"targetName": "decrement",
"targetType": "method"
"targetName": "decrement"
}
]
}
4 changes: 2 additions & 2 deletions packages/build/src/decorators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ interface DecoratorInfo {
name: string;
args: any[];
targetName: string;
targetType: 'method' | 'function';
targetType?: 'method' | 'function';
location?: {
file: string;
line: number;
Expand Down Expand Up @@ -102,7 +102,7 @@ export const createDecoratorExtractorPlugin = (
? (parent.key as t.Identifier).name
: (parent as t.FunctionDeclaration).id?.name || 'anonymous',
// @ts-ignore
targetType: t.isClassMethod(parent) ? 'method' : 'function',
// targetType: t.isClassMethod(parent) ? 'method' : 'function',

// location: {
// file: normalizedPath,
Expand Down

0 comments on commit fc4fe2f

Please sign in to comment.