From 30aee51dcd5e3baaba2c6e91ce5beceefd0bf57e Mon Sep 17 00:00:00 2001 From: Jessica Janiuk Date: Mon, 9 Nov 2026 20:59:47 +0000 Subject: [PATCH] fix(compiler-cli): fix compliance test golden and ignore missing input sourcemap on 22.2.x When Babel 8 was introduced, Babel started resolving input source maps from source mapping URL comments on disk by default unless inputSourceMap is explicitly provided. In the linked compilation compliance tests, the virtual test files do not exist on the real filesystem, which led to ENOENT errors when Babel attempted to read non-existent source map files. This change maps sourceMap to Babel's inputSourceMap format and defaults to false when no source map is provided. Additionally, updates the literal_void.js golden test case to use the standard ellipsis matcher (// ...) for the component declaration, matching the emit convention on 22.2.x. --- .../compliance/linked/linked_compile_spec.ts | 23 +++++++- .../value_composition/literal_void.js | 53 ++++--------------- 2 files changed, 31 insertions(+), 45 deletions(-) diff --git a/packages/compiler-cli/test/compliance/linked/linked_compile_spec.ts b/packages/compiler-cli/test/compliance/linked/linked_compile_spec.ts index 21705efb011..669a419fb8e 100644 --- a/packages/compiler-cli/test/compliance/linked/linked_compile_spec.ts +++ b/packages/compiler-cli/test/compliance/linked/linked_compile_spec.ts @@ -5,7 +5,7 @@ * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://angular.dev/license */ -import {PluginItem, transformSync} from '@babel/core'; +import {InputOptions, PluginItem, transformSync} from '@babel/core'; import {needsLinking} from '../../../linker'; import {createEs2015LinkerPlugin} from '../../../linker/babel'; @@ -92,6 +92,26 @@ function linkPartials(fileSystem: FileSystem, test: ComplianceTest): CompileResu * @param linkerPlugin The linker plugin to apply. * @returns The file's source content, which has been transformed using the linker if necessary. */ +function toBabelInputSourceMap( + sourceMap: RawSourceMap | undefined, +): NonNullable { + if (sourceMap === undefined) { + return false; + } + return { + version: + typeof sourceMap.version === 'string' ? parseInt(sourceMap.version, 10) : sourceMap.version, + sources: sourceMap.sources, + names: sourceMap.names, + sourceRoot: sourceMap.sourceRoot, + sourcesContent: sourceMap.sourcesContent + ? sourceMap.sourcesContent.map((s) => s ?? '') + : undefined, + mappings: sourceMap.mappings, + file: sourceMap.file ?? '', + }; +} + function applyLinker( cwd: string, filename: string, @@ -105,6 +125,7 @@ function applyLinker( const result = transformSync(source, { cwd, filename, + inputSourceMap: toBabelInputSourceMap(sourceMap), sourceMaps: !!sourceMap, plugins: [linkerPlugin], parserOpts: {sourceType: 'unambiguous'}, diff --git a/packages/compiler-cli/test/compliance/test_cases/r3_compiler_compliance/components_and_directives/value_composition/literal_void.js b/packages/compiler-cli/test/compliance/test_cases/r3_compiler_compliance/components_and_directives/value_composition/literal_void.js index 140be4cad14..8489da8bc9b 100644 --- a/packages/compiler-cli/test/compliance/test_cases/r3_compiler_compliance/components_and_directives/value_composition/literal_void.js +++ b/packages/compiler-cli/test/compliance/test_cases/r3_compiler_compliance/components_and_directives/value_composition/literal_void.js @@ -1,58 +1,23 @@ -import { Component } from "@angular/core"; -import * as i0 from "@angular/core"; -const _c0 = () => [void 0, 1]; -const _c1 = () => ({ a: void 0, b: 2 }); +const $c0$ = () => [void 0, 1]; +const $c1$ = () => ({ a: void 0, b: 2 }); +// ... export class VoidComp { - static ɵfac = function VoidComp_Factory(__ngFactoryType__) { - return new (__ngFactoryType__ || VoidComp)(); - }; - static ɵcmp = /*@__PURE__*/ i0.ɵɵdefineComponent({ + // ... + static ɵcmp = /*@__PURE__*/ $r3$.ɵɵdefineComponent({ type: VoidComp, selectors: [["ng-component"]], decls: 1, vars: 4, template: function VoidComp_Template(rf, ctx) { if (rf & 1) { - i0.ɵɵtext(0); + $r3$.ɵɵtext(0); } if (rf & 2) { - const array_r1 = i0.ɵɵpureFunction0(2, _c0); - const object_r2 = i0.ɵɵpureFunction0(3, _c1); - i0.ɵɵtextInterpolate2(" ", array_r1, " ", object_r2, " "); + const $array_r1$ = $r3$.ɵɵpureFunction0(2, $c0$); + const $object_r2$ = $r3$.ɵɵpureFunction0(3, $c1$); + $r3$.ɵɵtextInterpolate2(" ", $array_r1$, " ", $object_r2$, " "); } }, encapsulation: 2 }); } -(() => { - (typeof ngDevMode === "undefined" || ngDevMode) && - i0.ɵsetClassMetadata( - VoidComp, - [ - { - type: Component, - args: [ - { - template: ` - @let array = [void 0, 1]; - @let object = {a: void 0, b: 2}; - - - {{array}} {{object}} - ` - } - ] - } - ], - null, - null - ); -})(); -(() => { - (typeof ngDevMode === "undefined" || ngDevMode) && - i0.ɵsetClassDebugInfo(VoidComp, { - className: "VoidComp", - filePath: "literal_void.ts", - lineNumber: 12 - }); -})();