From 9b9e7ad5cf4878909dafcbf955809eaad5aa61aa Mon Sep 17 00:00:00 2001 From: JoostK Date: Sat, 10 Apr 2021 21:34:30 +0200 Subject: [PATCH] test(compiler-cli): disable `emitDecoratorMetadata` in the compiler test environment (#41557) The `emitDecoratorMetadata` compiler option does not have to be enabled as Angular decorators are transformed by the AOT compiler. Having the option enabled in our tests can hide issues around import preservation, as with `emitDecoratorMetadata` enabled the TypeScript compiler itself does not elide imports even if they are only used in type-positions. This is unlike having `emitDecoratorMetadata` disabled, however; in that case the Angular compiler has to actively trick TypeScript into retaining default imports when an identifier in a type-only position has been reified into a value position for DI purposes. A subsequent commit addresses a bug in default import preservation that relies on this flag being `false`. PR Close #41557 --- packages/compiler-cli/test/ngtsc/env.ts | 2 +- packages/compiler-cli/test/ngtsc/ngtsc_spec.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/compiler-cli/test/ngtsc/env.ts b/packages/compiler-cli/test/ngtsc/env.ts index baad8f3286..b456573d72 100644 --- a/packages/compiler-cli/test/ngtsc/env.ts +++ b/packages/compiler-cli/test/ngtsc/env.ts @@ -53,7 +53,7 @@ export class NgtscTestEnvironment { env.write(absoluteFrom('/tsconfig-base.json'), `{ "compilerOptions": { - "emitDecoratorMetadata": true, + "emitDecoratorMetadata": false, "experimentalDecorators": true, "skipLibCheck": true, "noImplicitAny": true, diff --git a/packages/compiler-cli/test/ngtsc/ngtsc_spec.ts b/packages/compiler-cli/test/ngtsc/ngtsc_spec.ts index ae696115d8..f98377ea0f 100644 --- a/packages/compiler-cli/test/ngtsc/ngtsc_spec.ts +++ b/packages/compiler-cli/test/ngtsc/ngtsc_spec.ts @@ -4648,7 +4648,7 @@ function allTests(os: string) { env.driveMain(); const jsContents = trim(env.getContents('test.js')); - expect(jsContents).toContain(`import { KeyCodes } from './keycodes';`); + expect(jsContents).toContain(`import * as i1 from "./keycodes";`); expect(jsContents).toMatch(setClassMetadataRegExp('type: i1.KeyCodes')); });