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 issues with multiple copies of compiler core being loaded #1627

Merged
merged 4 commits into from
Feb 9, 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": "@cadl-lang/compiler",
"comment": "Fix issue with projectedName decorator not working correctly when multiple copies of the compiler are loaded.",
"type": "none"
}
],
"packageName": "@cadl-lang/compiler"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@cadl-lang/rest",
"comment": "Fix issue with filtering of visibility decorator on resource key not working when multiple copies of the compiler are loaded.",
"type": "none"
}
],
"packageName": "@cadl-lang/rest"
}
2 changes: 1 addition & 1 deletion packages/compiler/lib/decorators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -961,7 +961,7 @@ export function getOverloadedOperation(
return program.stateMap(overloadsOperationKey).get(operation);
}

const projectedNameKey = Symbol("projectedNameKey");
const projectedNameKey = createStateSymbol("projectedNameKey");
nguerrera marked this conversation as resolved.
Show resolved Hide resolved
nguerrera marked this conversation as resolved.
Show resolved Hide resolved

/**
* `@projectedName` - Indicate that this entity should be renamed according to the given projection.
Expand Down
4 changes: 3 additions & 1 deletion packages/rest/src/http/operations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,9 @@ function validateProgram(program: Program, diagnostics: DiagnosticCollector) {
// interpretation of visibility into the core.
function checkForUnsupportedVisibility(property: ModelProperty) {
if (getVisibility(program, property)?.includes("write")) {
const decorator = property.decorators.find((d) => d.decorator === $visibility);
// NOTE: Check for name equality instead of function equality
// to deal with multiple copies of core being used.
const decorator = property.decorators.find((d) => d.decorator.name === $visibility.name);
const arg = decorator?.args.find(
(a) => a.node?.kind === SyntaxKind.StringLiteral && a.node.value === "write"
);
Expand Down
7 changes: 4 additions & 3 deletions packages/rest/src/resource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,11 @@ function cloneKeyProperties(context: DecoratorContext, target: Model, resourceTy
const { keyProperty } = resourceKey;
const keyName = getKeyName(program, keyProperty);

// Filter out the @visibility decorator because it might affect metadata
// filtering
const decorators = [
...keyProperty.decorators.filter((d) => d.decorator !== $visibility),
// Filter out the @visibility decorator because it might affect metadata
// filtering. NOTE: Check for name equality instead of function equality
// to deal with multiple copies of core being used.
...keyProperty.decorators.filter((d) => d.decorator.name !== $visibility.name),
nguerrera marked this conversation as resolved.
Show resolved Hide resolved
{
decorator: $path,
args: [],
Expand Down