Skip to content

Commit

Permalink
Fix issues with multiple copies of core being loaded
Browse files Browse the repository at this point in the history
  • Loading branch information
nguerrera committed Feb 7, 2023
1 parent 2f7b0e7 commit 26b6dc4
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@cadl-lang/compiler",
"comment": "Fix issues with multiple copies of compiler core being loaded.",
"type": "none"
}
],
"packageName": "@cadl-lang/compiler"
}
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");

/**
* `@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),
{
decorator: $path,
args: [],
Expand Down

0 comments on commit 26b6dc4

Please sign in to comment.