diff --git a/common/changes/@cadl-lang/compiler/shared-symbol_2023-02-07-15-24.json b/common/changes/@cadl-lang/compiler/shared-symbol_2023-02-07-15-24.json new file mode 100644 index 0000000000..dc7a84b724 --- /dev/null +++ b/common/changes/@cadl-lang/compiler/shared-symbol_2023-02-07-15-24.json @@ -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" +} \ No newline at end of file diff --git a/common/changes/@cadl-lang/rest/shared-symbol_2023-02-07-17-20.json b/common/changes/@cadl-lang/rest/shared-symbol_2023-02-07-17-20.json new file mode 100644 index 0000000000..d1b2df2db6 --- /dev/null +++ b/common/changes/@cadl-lang/rest/shared-symbol_2023-02-07-17-20.json @@ -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" +} \ No newline at end of file diff --git a/packages/compiler/lib/decorators.ts b/packages/compiler/lib/decorators.ts index 193081243e..deb08d4b2d 100644 --- a/packages/compiler/lib/decorators.ts +++ b/packages/compiler/lib/decorators.ts @@ -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. diff --git a/packages/rest/src/http/operations.ts b/packages/rest/src/http/operations.ts index 04076dfdf5..c6b72ae436 100644 --- a/packages/rest/src/http/operations.ts +++ b/packages/rest/src/http/operations.ts @@ -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" ); diff --git a/packages/rest/src/resource.ts b/packages/rest/src/resource.ts index 4bc00597ab..2bde616fbd 100644 --- a/packages/rest/src/resource.ts +++ b/packages/rest/src/resource.ts @@ -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: [],