From d59436c21127f7086dfcca7fb283e8befa40933f Mon Sep 17 00:00:00 2001 From: Nick Guerrera Date: Tue, 7 Feb 2023 09:24:22 -0600 Subject: [PATCH] Fix issues with multiple copies of core being loaded --- .../compiler/shared-symbol_2023-02-07-15-24.json | 10 ++++++++++ .../rest/shared-symbol_2023-02-07-17-20.json | 10 ++++++++++ packages/compiler/lib/decorators.ts | 2 +- packages/rest/src/http/operations.ts | 4 +++- packages/rest/src/resource.ts | 7 ++++--- 5 files changed, 28 insertions(+), 5 deletions(-) create mode 100644 common/changes/@cadl-lang/compiler/shared-symbol_2023-02-07-15-24.json create mode 100644 common/changes/@cadl-lang/rest/shared-symbol_2023-02-07-17-20.json 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..633f9b3f89 --- /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 issues with multiple copies of compiler core being 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..cfd3565b60 --- /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 issues with multiple copies of compiler core being 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: [],