Skip to content
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

Fix: @withVisibility decorator #2544

Merged
merged 7 commits into from
Oct 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@typespec/compiler",
"comment": "Fix: Properties filtered with `@withVisibility` will have their visibility removed. This prevent visibility from being applied twice and rendering invalid models",
"type": "none"
}
],
"packageName": "@typespec/compiler"
}
5 changes: 5 additions & 0 deletions packages/compiler/src/lib/decorators.ts
Copy link
Member Author

@timotheeguerin timotheeguerin Oct 6, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Todo need to update the doc to explain this new behavior
Todo add tests

Original file line number Diff line number Diff line change
Expand Up @@ -811,12 +811,17 @@ export function getVisibility(program: Program, target: Type): string[] | undefi
return program.stateMap(visibilitySettingsKey).get(target);
}

function clearVisibilities(program: Program, target: Type) {
program.stateMap(visibilitySettingsKey).delete(target);
}

export function $withVisibility(
context: DecoratorContext,
target: Model,
...visibilities: string[]
) {
filterModelPropertiesInPlace(target, (p) => isVisible(context.program, p, visibilities));
[...target.properties.values()].forEach((p) => clearVisibilities(context.program, p));
}

export function isVisible(
Expand Down