-
Notifications
You must be signed in to change notification settings - Fork 323
Decorator post validator #9104
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Decorator post validator #9104
Changes from 3 commits
a7d6dd7
42631ef
dddb6bc
d770491
0236b2a
e428f17
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -48,11 +48,27 @@ export interface DecoratorApplication { | |
| node?: DecoratorExpressionNode | AugmentDecoratorStatementNode; | ||
| } | ||
|
|
||
| /** | ||
| * Signature for a decorator JS implementation function. | ||
| * Use `@typespec/tspd` to generate an accurate signature from the `extern dec` | ||
| */ | ||
| export interface DecoratorFunction { | ||
| (program: DecoratorContext, target: any, ...customArgs: any[]): void; | ||
| (program: DecoratorContext, target: any, ...customArgs: any[]): DecoratorPostValidator | void; | ||
| namespace?: string; | ||
| } | ||
|
|
||
| export interface DecoratorPostValidator { | ||
| /** | ||
| * When should this validator run. | ||
| * "postSelf": After all decorators are run on the same type. Useful if trying to validate this decorator is compatible with other decorators without relying on the order they are applied. | ||
| * "post": After everything is checked in the program. Useful when trying to get an overall view of the program. | ||
| */ | ||
| readonly kind: "postSelf" | "post"; | ||
|
|
||
| /** Validator implementation. This function will be run according to the kind defined above. */ | ||
| readonly validator: () => readonly Diagnostic[]; | ||
| } | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. open to suggestion on the property names, the union values as well as a good way to have a oneliner function to build this object // 1
const myDec: MyDecDecorator = (contex, target) => {
return context.validate.postSelf(() => {
// ....
})
}
// 2
const myDec: MyDecDecorator = (contex, target) => {
return DecoratorPostValidator.postSelf(() => {
// ....
})
}
// 3
const myDec: MyDecDecorator = (contex, target) => {
return postSelf(() => {
// ....
})
}
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Current name suggestions |
||
|
|
||
| export interface BaseType { | ||
| readonly entityKind: "Type"; | ||
| kind: string; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
right now have this expecting an array of diagnostic, this feels nicer that always expecting it to be reported to the program but also less consistent with the rest. It also doesn't pervent you from directly reporting to program if you prefer. What do people think?