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.
This commit is contained in:
Jessica Janiuk
2026-11-09 13:12:37 -08:00
committed by Jessica Janiuk
parent 7e3ff04abc
commit 30aee51dcd
2 changed files with 31 additions and 45 deletions
@@ -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<InputOptions['inputSourceMap']> {
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'},
@@ -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};
<!-- Use the literals so they don't get flagged as unused. -->
{{array}} {{object}}
`
}
]
}
],
null,
null
);
})();
(() => {
(typeof ngDevMode === "undefined" || ngDevMode) &&
i0.ɵsetClassDebugInfo(VoidComp, {
className: "VoidComp",
filePath: "literal_void.ts",
lineNumber: 12
});
})();