From 8749bc28a6a33d22a723ea0b54b7a474ae043ef8 Mon Sep 17 00:00:00 2001 From: Charles Lyding <19598772+clydin@users.noreply.github.com> Date: Wed, 22 Nov 2023 18:08:36 -0500 Subject: [PATCH] fix(compiler): allow TS jsDocParsingMode host option to be programmatically set When the AOT compiler creates a delegated host for a provided TypeScript CompilerHost, it delegates functionality back to the original via a series of internal method delegations. However, unlike other members of the CompilerHost, `jsDocParsingMode` is not a method and cannot be delegated in this way. Attempting to call bind on the property will result in a runtime error. Instead, `jsDocParsingMode` is now delegated via get/set accessors. Additionally, the override of `getSourceFile` now has an updated type signature to reflect the additional of the `jsDocParsingMode` option for the method. --- .../compiler-cli/src/ngtsc/core/src/host.ts | 21 ++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/packages/compiler-cli/src/ngtsc/core/src/host.ts b/packages/compiler-cli/src/ngtsc/core/src/host.ts index 555d9dd93670..2c5a72f3deda 100644 --- a/packages/compiler-cli/src/ngtsc/core/src/host.ts +++ b/packages/compiler-cli/src/ngtsc/core/src/host.ts @@ -61,7 +61,17 @@ export class DelegatingCompilerHost implements hasInvalidatedResolutions; resolveModuleNameLiterals; resolveTypeReferenceDirectiveReferences; - jsDocParsingMode; + + // jsDocParsingMode is not a method like the other elements above + // TODO: ignore usage can be dropped once 5.2 support is dropped + get jsDocParsingMode() { + // @ts-ignore + return this.delegate.jsDocParsingMode; + } + set jsDocParsingMode(mode) { + // @ts-ignore + this.delegate.jsDocParsingMode = mode; + } constructor(protected delegate: ExtendedTsCompilerHost) { // Excluded are 'getSourceFile' and 'fileExists', which are actually implemented by @@ -97,9 +107,6 @@ export class DelegatingCompilerHost implements this.resolveModuleNameLiterals = this.delegateMethod('resolveModuleNameLiterals'); this.resolveTypeReferenceDirectiveReferences = this.delegateMethod('resolveTypeReferenceDirectiveReferences'); - // TODO(crisbeto): can be removed when we drop support for TS 5.2. - // @ts-ignore - this.jsDocParsingMode = this.delegateMethod('jsDocParsingMode'); } private delegateMethod(name: M): @@ -256,7 +263,7 @@ export class NgCompilerHost extends DelegatingCompilerHost implements } getSourceFile( - fileName: string, languageVersion: ts.ScriptTarget, + fileName: string, languageVersionOrOptions: ts.ScriptTarget|ts.CreateSourceFileOptions, onError?: ((message: string) => void)|undefined, shouldCreateNewSourceFile?: boolean|undefined): ts.SourceFile|undefined { // Is this a previously known shim? @@ -267,8 +274,8 @@ export class NgCompilerHost extends DelegatingCompilerHost implements } // No, so it's a file which might need shims (or a file which doesn't exist). - const sf = - this.delegate.getSourceFile(fileName, languageVersion, onError, shouldCreateNewSourceFile); + const sf = this.delegate.getSourceFile( + fileName, languageVersionOrOptions, onError, shouldCreateNewSourceFile); if (sf === undefined) { return undefined; }