Content-Length: 401691 | pFad | https://github.com/angular/angular/commit/fc946c5f7261ee3e49fa037bc55703b9ffcfbff3

FC fix(compiler-cli): ensure HMR works with different output module type… · angular/angular@fc946c5 · GitHub
Skip to content

Commit fc946c5

Browse files
crisbetoatscott
authored andcommitted
fix(compiler-cli): ensure HMR works with different output module type (#60797)
Currently when we transpile the HMR update module, we use the project's compiler options verbatim. This appears to break down with some module types, whereas we have to use a native export. These changes override the compiler options to ensure that the user's options don't end up breaking HMR. Fixes #60795. PR Close #60797
1 parent d99935a commit fc946c5

File tree

2 files changed

+41
-3
lines changed

2 files changed

+41
-3
lines changed

Diff for: packages/compiler-cli/src/ngtsc/core/src/compiler.ts

+9-1
Original file line numberDiff line numberDiff line change
@@ -965,7 +965,15 @@ export class NgCompiler {
965965
const nodeText = printer.printNode(ts.EmitHint.Unspecified, callback, sourceFile);
966966

967967
return ts.transpileModule(nodeText, {
968-
compilerOptions: this.options,
968+
compilerOptions: {
969+
...this.options,
970+
971+
// Some module types can produce additional code (see #60795) whereas we need the
972+
// HMR update module to use a native `export`. Override the `target` and `module`
973+
// to ensure that it looks as expected.
974+
module: ts.ModuleKind.ES2022,
975+
target: ts.ScriptTarget.ES2022,
976+
} as ts.CompilerOptions,
969977
fileName: sourceFile.fileName,
970978
reportDiagnostics: false,
971979
}).outputText;

Diff for: packages/compiler-cli/test/ngtsc/hmr_spec.ts

+32-2
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,18 @@ runInEachFileSystem(() => {
2424
env.tsconfig();
2525
});
2626

27-
function enableHmr(additionalOptions: Record<string, unknown> = {}): void {
27+
function enableHmr(
28+
additionalAngularOptions: Record<string, unknown> = {},
29+
additionalCompilerOptions: Record<string, unknown> = {},
30+
): void {
2831
env.write(
2932
'tsconfig.json',
3033
JSON.stringify({
3134
extends: './tsconfig-base.json',
35+
...additionalCompilerOptions,
3236
angularCompilerOptions: {
3337
_enableHmr: true,
34-
...additionalOptions,
38+
...additionalAngularOptions,
3539
},
3640
}),
3741
);
@@ -971,5 +975,31 @@ runInEachFileSystem(() => {
971975
expect(jsContents).toContain('newProp = 123');
972976
expect(hmrContents).toContain('export default function Cmp_UpdateMetadata');
973977
});
978+
979+
it('should generate an HMR initializer and update function for a class that depends on multiple namespaces', () => {
980+
enableHmr(undefined, {
981+
compilerOptions: {
982+
module: 'NodeNext',
983+
moduleResolution: 'NodeNext',
984+
},
985+
});
986+
987+
env.write(
988+
'test.ts',
989+
`
990+
import {Component} from '@angular/core';
991+
992+
@Component({selector: 'cmp', template: ''})
993+
export class Cmp {}
994+
`,
995+
);
996+
997+
env.driveMain();
998+
999+
const hmrContents = env.driveHmr('test.ts', 'Cmp');
1000+
expect(hmrContents).toContain(
1001+
'export default function Cmp_UpdateMetadata(Cmp, ɵɵnamespaces, Component) {',
1002+
);
1003+
});
9741004
});
9751005
});

0 commit comments

Comments
 (0)








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: https://github.com/angular/angular/commit/fc946c5f7261ee3e49fa037bc55703b9ffcfbff3

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy