UNPKG

@angular/compiler-cli

Version:
1,495 lines (1,461 loc) • 298 kB
import {createRequire as __cjsCompatRequire} from 'module'; const require = __cjsCompatRequire(import.meta.url); import { CompilationMode, CompletionKind, ComponentDecoratorHandler, ComponentScopeKind, CompoundComponentScopeReader, CompoundMetadataReader, CompoundMetadataRegistry, DirectiveDecoratorHandler, DtsMetadataReader, DtsTransformRegistry, ExportedProviderStatusResolver, HostDirectivesResolver, InjectableClassRegistry, InjectableDecoratorHandler, LocalMetadataRegistry, LocalModuleScopeRegistry, MetaKind, MetadataDtsModuleScopeResolver, NgModuleDecoratorHandler, NoopReferencesRegistry, OptimizeFor, PartialEvaluator, PipeDecoratorHandler, PotentialImportKind, PotentialImportMode, ResourceRegistry, SemanticDepGraphUpdater, SymbolKind, TraitCompiler, TypeCheckScopeRegistry, aliasTransformFactory, declarationTransformFactory, ivyTransformFactory } from "./chunk-FYJ5FZGI.js"; import { TypeScriptReflectionHost, isNamedClassDeclaration } from "./chunk-4NU6EGYK.js"; import { ImportManager, translateExpression, translateType } from "./chunk-JCLVSACV.js"; import { AbsoluteModuleStrategy, AliasStrategy, COMPILER_ERRORS_WITH_GUIDES, DefaultImportTracker, ERROR_DETAILS_PAGE_BASE_URL, ErrorCode, ExtendedTemplateDiagnosticName, FatalDiagnosticError, ImportFlags, LocalIdentifierStrategy, LogicalProjectStrategy, ModuleResolver, NoopImportRewriter, PrivateExportAliasingHost, R3SymbolsImportRewriter, Reference, ReferenceEmitter, RelativePathStrategy, UnifiedModulesAliasingHost, UnifiedModulesStrategy, addDiagnosticChain, assertSuccessfulReferenceEmit, getRootDirs, getSourceFileOrNull, getTokenAtPosition, isAssignment, isDtsPath, isNonDeclarationTsPath, isSymbolWithValueDeclaration, makeDiagnostic, makeDiagnosticChain, makeRelatedInformation, ngErrorCode, normalizeSeparators, relativePathBetween, replaceTsWithNgInErrors, toUnredirectedSourceFile } from "./chunk-7RPZKH3B.js"; import { ActivePerfRecorder, DelegatingPerfRecorder, PerfCheckpoint, PerfEvent, PerfPhase } from "./chunk-URH5LEAG.js"; import { LogicalFileSystem, absoluteFrom, absoluteFromSourceFile, dirname, getFileSystem, getSourceFileOrError, join, resolve } from "./chunk-K2U2VZ7S.js"; // bazel-out/darwin-fastbuild/bin/packages/compiler-cli/src/transformers/api.mjs var DEFAULT_ERROR_CODE = 100; var UNKNOWN_ERROR_CODE = 500; var SOURCE = "angular"; function isTsDiagnostic(diagnostic) { return diagnostic != null && diagnostic.source !== "angular"; } var EmitFlags; (function(EmitFlags2) { EmitFlags2[EmitFlags2["DTS"] = 1] = "DTS"; EmitFlags2[EmitFlags2["JS"] = 2] = "JS"; EmitFlags2[EmitFlags2["Metadata"] = 4] = "Metadata"; EmitFlags2[EmitFlags2["I18nBundle"] = 8] = "I18nBundle"; EmitFlags2[EmitFlags2["Codegen"] = 16] = "Codegen"; EmitFlags2[EmitFlags2["Default"] = 19] = "Default"; EmitFlags2[EmitFlags2["All"] = 31] = "All"; })(EmitFlags || (EmitFlags = {})); // bazel-out/darwin-fastbuild/bin/packages/compiler-cli/src/transformers/compiler_host.mjs import ts from "typescript"; var wrapHostForTest = null; function createCompilerHost({ options, tsHost = ts.createCompilerHost(options, true) }) { if (wrapHostForTest !== null) { tsHost = wrapHostForTest(tsHost); } return tsHost; } // bazel-out/darwin-fastbuild/bin/packages/compiler-cli/src/ngtsc/program.mjs import { HtmlParser, MessageBundle } from "@angular/compiler"; import ts32 from "typescript"; // bazel-out/darwin-fastbuild/bin/packages/compiler-cli/src/transformers/i18n.mjs import { Xliff, Xliff2, Xmb } from "@angular/compiler"; import * as path from "path"; function i18nGetExtension(formatName) { const format = formatName.toLowerCase(); switch (format) { case "xmb": return "xmb"; case "xlf": case "xlif": case "xliff": case "xlf2": case "xliff2": return "xlf"; } throw new Error(`Unsupported format "${formatName}"`); } function i18nExtract(formatName, outFile, host, options, bundle, pathResolve = path.resolve) { formatName = formatName || "xlf"; const ext = i18nGetExtension(formatName); const content = i18nSerialize(bundle, formatName, options); const dstFile = outFile || `messages.${ext}`; const dstPath = pathResolve(options.outDir || options.basePath, dstFile); host.writeFile(dstPath, content, false, void 0, []); return [dstPath]; } function i18nSerialize(bundle, formatName, options) { const format = formatName.toLowerCase(); let serializer; switch (format) { case "xmb": serializer = new Xmb(); break; case "xliff2": case "xlf2": serializer = new Xliff2(); break; case "xlf": case "xliff": default: serializer = new Xliff(); } return bundle.write(serializer, getPathNormalizer(options.basePath)); } function getPathNormalizer(basePath) { return (sourcePath) => { sourcePath = basePath ? path.relative(basePath, sourcePath) : sourcePath; return sourcePath.split(path.sep).join("/"); }; } // bazel-out/darwin-fastbuild/bin/packages/compiler-cli/src/typescript_support.mjs import ts2 from "typescript"; // bazel-out/darwin-fastbuild/bin/packages/compiler-cli/src/version_helpers.mjs function toNumbers(value) { const suffixIndex = value.lastIndexOf("-"); return value.slice(0, suffixIndex === -1 ? value.length : suffixIndex).split(".").map((segment) => { const parsed = parseInt(segment, 10); if (isNaN(parsed)) { throw Error(`Unable to parse version string ${value}.`); } return parsed; }); } function compareNumbers(a, b) { const max = Math.max(a.length, b.length); const min = Math.min(a.length, b.length); for (let i = 0; i < min; i++) { if (a[i] > b[i]) return 1; if (a[i] < b[i]) return -1; } if (min !== max) { const longestArray = a.length === max ? a : b; const comparisonResult = a.length === max ? 1 : -1; for (let i = min; i < max; i++) { if (longestArray[i] > 0) { return comparisonResult; } } } return 0; } function compareVersions(v1, v2) { return compareNumbers(toNumbers(v1), toNumbers(v2)); } // bazel-out/darwin-fastbuild/bin/packages/compiler-cli/src/typescript_support.mjs var MIN_TS_VERSION = "4.9.3"; var MAX_TS_VERSION = "5.1.0"; var tsVersion = ts2.version; function checkVersion(version, minVersion, maxVersion) { if (compareVersions(version, minVersion) < 0 || compareVersions(version, maxVersion) >= 0) { throw new Error(`The Angular Compiler requires TypeScript >=${minVersion} and <${maxVersion} but ${version} was found instead.`); } } function verifySupportedTypeScriptVersion() { checkVersion(tsVersion, MIN_TS_VERSION, MAX_TS_VERSION); } // bazel-out/darwin-fastbuild/bin/packages/compiler-cli/src/ngtsc/core/src/compiler.mjs import ts30 from "typescript"; // bazel-out/darwin-fastbuild/bin/packages/compiler-cli/src/ngtsc/cycles/src/analyzer.mjs var CycleAnalyzer = class { constructor(importGraph) { this.importGraph = importGraph; this.cachedResults = null; } wouldCreateCycle(from, to) { if (this.cachedResults === null || this.cachedResults.from !== from) { this.cachedResults = new CycleResults(from, this.importGraph); } return this.cachedResults.wouldBeCyclic(to) ? new Cycle(this.importGraph, from, to) : null; } recordSyntheticImport(from, to) { this.cachedResults = null; this.importGraph.addSyntheticImport(from, to); } }; var NgCyclicResult = Symbol("NgCyclicResult"); var CycleResults = class { constructor(from, importGraph) { this.from = from; this.importGraph = importGraph; this.cyclic = {}; this.acyclic = {}; } wouldBeCyclic(sf) { const cached = this.getCachedResult(sf); if (cached !== null) { return cached; } if (sf === this.from) { return true; } this.markAcyclic(sf); const imports = this.importGraph.importsOf(sf); for (const imported of imports) { if (this.wouldBeCyclic(imported)) { this.markCyclic(sf); return true; } } return false; } getCachedResult(sf) { const result = sf[NgCyclicResult]; if (result === this.cyclic) { return true; } else if (result === this.acyclic) { return false; } else { return null; } } markCyclic(sf) { sf[NgCyclicResult] = this.cyclic; } markAcyclic(sf) { sf[NgCyclicResult] = this.acyclic; } }; var Cycle = class { constructor(importGraph, from, to) { this.importGraph = importGraph; this.from = from; this.to = to; } getPath() { return [this.from, ...this.importGraph.findPath(this.to, this.from)]; } }; // bazel-out/darwin-fastbuild/bin/packages/compiler-cli/src/ngtsc/cycles/src/imports.mjs import ts3 from "typescript"; var ImportGraph = class { constructor(checker, perf) { this.checker = checker; this.perf = perf; this.imports = /* @__PURE__ */ new Map(); } importsOf(sf) { if (!this.imports.has(sf)) { this.imports.set(sf, this.scanImports(sf)); } return this.imports.get(sf); } findPath(start, end) { if (start === end) { return [start]; } const found = /* @__PURE__ */ new Set([start]); const queue = [new Found(start, null)]; while (queue.length > 0) { const current = queue.shift(); const imports = this.importsOf(current.sourceFile); for (const importedFile of imports) { if (!found.has(importedFile)) { const next = new Found(importedFile, current); if (next.sourceFile === end) { return next.toPath(); } found.add(importedFile); queue.push(next); } } } return null; } addSyntheticImport(sf, imported) { if (isLocalFile(imported)) { this.importsOf(sf).add(imported); } } scanImports(sf) { return this.perf.inPhase(PerfPhase.CycleDetection, () => { const imports = /* @__PURE__ */ new Set(); for (const stmt of sf.statements) { if (!ts3.isImportDeclaration(stmt) && !ts3.isExportDeclaration(stmt) || stmt.moduleSpecifier === void 0) { continue; } if (ts3.isImportDeclaration(stmt) && stmt.importClause !== void 0 && isTypeOnlyImportClause(stmt.importClause)) { continue; } const symbol = this.checker.getSymbolAtLocation(stmt.moduleSpecifier); if (symbol === void 0 || symbol.valueDeclaration === void 0) { continue; } const moduleFile = symbol.valueDeclaration; if (ts3.isSourceFile(moduleFile) && isLocalFile(moduleFile)) { imports.add(moduleFile); } } return imports; }); } }; function isLocalFile(sf) { return !sf.isDeclarationFile; } function isTypeOnlyImportClause(node) { if (node.isTypeOnly) { return true; } if (node.namedBindings !== void 0 && ts3.isNamedImports(node.namedBindings) && node.namedBindings.elements.every((specifier) => specifier.isTypeOnly)) { return true; } return false; } var Found = class { constructor(sourceFile, parent) { this.sourceFile = sourceFile; this.parent = parent; } toPath() { const array = []; let current = this; while (current !== null) { array.push(current.sourceFile); current = current.parent; } return array.reverse(); } }; // bazel-out/darwin-fastbuild/bin/packages/compiler-cli/src/ngtsc/entry_point/src/generator.mjs import ts4 from "typescript"; var FlatIndexGenerator = class { constructor(entryPoint, relativeFlatIndexPath, moduleName) { this.entryPoint = entryPoint; this.moduleName = moduleName; this.shouldEmit = true; this.flatIndexPath = join(dirname(entryPoint), relativeFlatIndexPath).replace(/\.js$/, "") + ".ts"; } makeTopLevelShim() { const relativeEntryPoint = relativePathBetween(this.flatIndexPath, this.entryPoint); const contents = `/** * Generated bundle index. Do not edit. */ export * from '${relativeEntryPoint}'; `; const genFile = ts4.createSourceFile(this.flatIndexPath, contents, ts4.ScriptTarget.ES2015, true, ts4.ScriptKind.TS); if (this.moduleName !== null) { genFile.moduleName = this.moduleName; } return genFile; } }; // bazel-out/darwin-fastbuild/bin/packages/compiler-cli/src/ngtsc/entry_point/src/logic.mjs function findFlatIndexEntryPoint(rootFiles) { const tsFiles = rootFiles.filter((file) => isNonDeclarationTsPath(file)); let resolvedEntryPoint = null; if (tsFiles.length === 1) { resolvedEntryPoint = tsFiles[0]; } else { for (const tsFile of tsFiles) { if (getFileSystem().basename(tsFile) === "index.ts" && (resolvedEntryPoint === null || tsFile.length <= resolvedEntryPoint.length)) { resolvedEntryPoint = tsFile; } } } return resolvedEntryPoint; } // bazel-out/darwin-fastbuild/bin/packages/compiler-cli/src/ngtsc/entry_point/src/private_export_checker.mjs import ts5 from "typescript"; function checkForPrivateExports(entryPoint, checker, refGraph) { const diagnostics = []; const topLevelExports = /* @__PURE__ */ new Set(); const moduleSymbol = checker.getSymbolAtLocation(entryPoint); if (moduleSymbol === void 0) { throw new Error(`Internal error: failed to get symbol for entrypoint`); } const exportedSymbols = checker.getExportsOfModule(moduleSymbol); exportedSymbols.forEach((symbol) => { if (symbol.flags & ts5.SymbolFlags.Alias) { symbol = checker.getAliasedSymbol(symbol); } const decl = symbol.valueDeclaration; if (decl !== void 0) { topLevelExports.add(decl); } }); const checkedSet = /* @__PURE__ */ new Set(); topLevelExports.forEach((mainExport) => { refGraph.transitiveReferencesOf(mainExport).forEach((transitiveReference) => { if (checkedSet.has(transitiveReference)) { return; } checkedSet.add(transitiveReference); if (!topLevelExports.has(transitiveReference)) { const descriptor = getDescriptorOfDeclaration(transitiveReference); const name = getNameOfDeclaration(transitiveReference); let visibleVia = "NgModule exports"; const transitivePath = refGraph.pathFrom(mainExport, transitiveReference); if (transitivePath !== null) { visibleVia = transitivePath.map((seg) => getNameOfDeclaration(seg)).join(" -> "); } const diagnostic = { category: ts5.DiagnosticCategory.Error, code: ngErrorCode(ErrorCode.SYMBOL_NOT_EXPORTED), file: transitiveReference.getSourceFile(), ...getPosOfDeclaration(transitiveReference), messageText: `Unsupported private ${descriptor} ${name}. This ${descriptor} is visible to consumers via ${visibleVia}, but is not exported from the top-level library entrypoint.` }; diagnostics.push(diagnostic); } }); }); return diagnostics; } function getPosOfDeclaration(decl) { const node = getIdentifierOfDeclaration(decl) || decl; return { start: node.getStart(), length: node.getEnd() + 1 - node.getStart() }; } function getIdentifierOfDeclaration(decl) { if ((ts5.isClassDeclaration(decl) || ts5.isVariableDeclaration(decl) || ts5.isFunctionDeclaration(decl)) && decl.name !== void 0 && ts5.isIdentifier(decl.name)) { return decl.name; } else { return null; } } function getNameOfDeclaration(decl) { const id = getIdentifierOfDeclaration(decl); return id !== null ? id.text : "(unnamed)"; } function getDescriptorOfDeclaration(decl) { switch (decl.kind) { case ts5.SyntaxKind.ClassDeclaration: return "class"; case ts5.SyntaxKind.FunctionDeclaration: return "function"; case ts5.SyntaxKind.VariableDeclaration: return "variable"; case ts5.SyntaxKind.EnumDeclaration: return "enum"; default: return "declaration"; } } // bazel-out/darwin-fastbuild/bin/packages/compiler-cli/src/ngtsc/entry_point/src/reference_graph.mjs var ReferenceGraph = class { constructor() { this.references = /* @__PURE__ */ new Map(); } add(from, to) { if (!this.references.has(from)) { this.references.set(from, /* @__PURE__ */ new Set()); } this.references.get(from).add(to); } transitiveReferencesOf(target) { const set = /* @__PURE__ */ new Set(); this.collectTransitiveReferences(set, target); return set; } pathFrom(source, target) { return this.collectPathFrom(source, target, /* @__PURE__ */ new Set()); } collectPathFrom(source, target, seen) { if (source === target) { return [target]; } else if (seen.has(source)) { return null; } seen.add(source); if (!this.references.has(source)) { return null; } else { let candidatePath = null; this.references.get(source).forEach((edge) => { if (candidatePath !== null) { return; } const partialPath = this.collectPathFrom(edge, target, seen); if (partialPath !== null) { candidatePath = [source, ...partialPath]; } }); return candidatePath; } } collectTransitiveReferences(set, decl) { if (this.references.has(decl)) { this.references.get(decl).forEach((ref) => { if (!set.has(ref)) { set.add(ref); this.collectTransitiveReferences(set, ref); } }); } } }; // bazel-out/darwin-fastbuild/bin/packages/compiler-cli/src/ngtsc/program_driver/src/api.mjs var NgOriginalFile = Symbol("NgOriginalFile"); var UpdateMode; (function(UpdateMode2) { UpdateMode2[UpdateMode2["Complete"] = 0] = "Complete"; UpdateMode2[UpdateMode2["Incremental"] = 1] = "Incremental"; })(UpdateMode || (UpdateMode = {})); // bazel-out/darwin-fastbuild/bin/packages/compiler-cli/src/ngtsc/program_driver/src/ts_create_program_driver.mjs import ts7 from "typescript"; // bazel-out/darwin-fastbuild/bin/packages/compiler-cli/src/ngtsc/shims/src/adapter.mjs import ts6 from "typescript"; // bazel-out/darwin-fastbuild/bin/packages/compiler-cli/src/ngtsc/shims/src/expando.mjs var NgExtension = Symbol("NgExtension"); function isExtended(sf) { return sf[NgExtension] !== void 0; } function sfExtensionData(sf) { const extSf = sf; if (extSf[NgExtension] !== void 0) { return extSf[NgExtension]; } const extension = { isTopLevelShim: false, fileShim: null, originalReferencedFiles: null, taggedReferenceFiles: null }; extSf[NgExtension] = extension; return extension; } function isFileShimSourceFile(sf) { return isExtended(sf) && sf[NgExtension].fileShim !== null; } function isShim(sf) { return isExtended(sf) && (sf[NgExtension].fileShim !== null || sf[NgExtension].isTopLevelShim); } function copyFileShimData(from, to) { if (!isFileShimSourceFile(from)) { return; } sfExtensionData(to).fileShim = sfExtensionData(from).fileShim; } function untagAllTsFiles(program) { for (const sf of program.getSourceFiles()) { untagTsFile(sf); } } function retagAllTsFiles(program) { for (const sf of program.getSourceFiles()) { retagTsFile(sf); } } function untagTsFile(sf) { if (sf.isDeclarationFile || !isExtended(sf)) { return; } const ext = sfExtensionData(sf); if (ext.originalReferencedFiles !== null) { sf.referencedFiles = ext.originalReferencedFiles; } } function retagTsFile(sf) { if (sf.isDeclarationFile || !isExtended(sf)) { return; } const ext = sfExtensionData(sf); if (ext.taggedReferenceFiles !== null) { sf.referencedFiles = ext.taggedReferenceFiles; } } // bazel-out/darwin-fastbuild/bin/packages/compiler-cli/src/ngtsc/shims/src/util.mjs var TS_EXTENSIONS = /\.tsx?$/i; function makeShimFileName(fileName, suffix) { return absoluteFrom(fileName.replace(TS_EXTENSIONS, suffix)); } // bazel-out/darwin-fastbuild/bin/packages/compiler-cli/src/ngtsc/shims/src/adapter.mjs var ShimAdapter = class { constructor(delegate, tsRootFiles, topLevelGenerators, perFileGenerators, oldProgram) { this.delegate = delegate; this.shims = /* @__PURE__ */ new Map(); this.priorShims = /* @__PURE__ */ new Map(); this.notShims = /* @__PURE__ */ new Set(); this.generators = []; this.ignoreForEmit = /* @__PURE__ */ new Set(); this.extensionPrefixes = []; for (const gen of perFileGenerators) { const pattern = `^(.*)\\.${gen.extensionPrefix}\\.ts$`; const regexp = new RegExp(pattern, "i"); this.generators.push({ generator: gen, test: regexp, suffix: `.${gen.extensionPrefix}.ts` }); this.extensionPrefixes.push(gen.extensionPrefix); } const extraInputFiles = []; for (const gen of topLevelGenerators) { const sf = gen.makeTopLevelShim(); sfExtensionData(sf).isTopLevelShim = true; if (!gen.shouldEmit) { this.ignoreForEmit.add(sf); } const fileName = absoluteFromSourceFile(sf); this.shims.set(fileName, sf); extraInputFiles.push(fileName); } for (const rootFile of tsRootFiles) { for (const gen of this.generators) { extraInputFiles.push(makeShimFileName(rootFile, gen.suffix)); } } this.extraInputFiles = extraInputFiles; if (oldProgram !== null) { for (const oldSf of oldProgram.getSourceFiles()) { if (oldSf.isDeclarationFile || !isFileShimSourceFile(oldSf)) { continue; } this.priorShims.set(absoluteFromSourceFile(oldSf), oldSf); } } } maybeGenerate(fileName) { if (this.notShims.has(fileName)) { return null; } else if (this.shims.has(fileName)) { return this.shims.get(fileName); } if (isDtsPath(fileName)) { this.notShims.add(fileName); return null; } for (const record of this.generators) { const match = record.test.exec(fileName); if (match === null) { continue; } const prefix = match[1]; let baseFileName = absoluteFrom(prefix + ".ts"); let inputFile = this.delegate.getSourceFile(baseFileName, ts6.ScriptTarget.Latest); if (inputFile === void 0) { baseFileName = absoluteFrom(prefix + ".tsx"); inputFile = this.delegate.getSourceFile(baseFileName, ts6.ScriptTarget.Latest); } if (inputFile === void 0 || isShim(inputFile)) { return void 0; } return this.generateSpecific(fileName, record.generator, inputFile); } this.notShims.add(fileName); return null; } generateSpecific(fileName, generator, inputFile) { let priorShimSf = null; if (this.priorShims.has(fileName)) { priorShimSf = this.priorShims.get(fileName); this.priorShims.delete(fileName); } const shimSf = generator.generateShimForFile(inputFile, fileName, priorShimSf); sfExtensionData(shimSf).fileShim = { extension: generator.extensionPrefix, generatedFrom: absoluteFromSourceFile(inputFile) }; if (!generator.shouldEmit) { this.ignoreForEmit.add(shimSf); } this.shims.set(fileName, shimSf); return shimSf; } }; // bazel-out/darwin-fastbuild/bin/packages/compiler-cli/src/ngtsc/shims/src/reference_tagger.mjs var ShimReferenceTagger = class { constructor(shimExtensions) { this.tagged = /* @__PURE__ */ new Set(); this.enabled = true; this.suffixes = shimExtensions.map((extension) => `.${extension}.ts`); } tag(sf) { if (!this.enabled || sf.isDeclarationFile || isShim(sf) || this.tagged.has(sf) || !isNonDeclarationTsPath(sf.fileName)) { return; } const ext = sfExtensionData(sf); if (ext.originalReferencedFiles === null) { ext.originalReferencedFiles = sf.referencedFiles; } const referencedFiles = [...ext.originalReferencedFiles]; const sfPath = absoluteFromSourceFile(sf); for (const suffix of this.suffixes) { referencedFiles.push({ fileName: makeShimFileName(sfPath, suffix), pos: 0, end: 0 }); } ext.taggedReferenceFiles = referencedFiles; sf.referencedFiles = referencedFiles; this.tagged.add(sf); } finalize() { this.enabled = false; this.tagged.clear(); } }; // bazel-out/darwin-fastbuild/bin/packages/compiler-cli/src/ngtsc/program_driver/src/ts_create_program_driver.mjs var DelegatingCompilerHost = class { constructor(delegate) { this.delegate = delegate; this.createHash = this.delegateMethod("createHash"); this.directoryExists = this.delegateMethod("directoryExists"); this.getCancellationToken = this.delegateMethod("getCancellationToken"); this.getCanonicalFileName = this.delegateMethod("getCanonicalFileName"); this.getCurrentDirectory = this.delegateMethod("getCurrentDirectory"); this.getDefaultLibFileName = this.delegateMethod("getDefaultLibFileName"); this.getDefaultLibLocation = this.delegateMethod("getDefaultLibLocation"); this.getDirectories = this.delegateMethod("getDirectories"); this.getEnvironmentVariable = this.delegateMethod("getEnvironmentVariable"); this.getNewLine = this.delegateMethod("getNewLine"); this.getParsedCommandLine = this.delegateMethod("getParsedCommandLine"); this.getSourceFileByPath = this.delegateMethod("getSourceFileByPath"); this.readDirectory = this.delegateMethod("readDirectory"); this.readFile = this.delegateMethod("readFile"); this.realpath = this.delegateMethod("realpath"); this.resolveModuleNames = this.delegateMethod("resolveModuleNames"); this.resolveTypeReferenceDirectives = this.delegateMethod("resolveTypeReferenceDirectives"); this.trace = this.delegateMethod("trace"); this.useCaseSensitiveFileNames = this.delegateMethod("useCaseSensitiveFileNames"); this.getModuleResolutionCache = this.delegateMethod("getModuleResolutionCache"); this.hasInvalidatedResolutions = this.delegateMethod("hasInvalidatedResolutions"); this.resolveModuleNameLiterals = this.delegateMethod("resolveModuleNameLiterals"); this.resolveTypeReferenceDirectiveReferences = this.delegateMethod("resolveTypeReferenceDirectiveReferences"); } delegateMethod(name) { return this.delegate[name] !== void 0 ? this.delegate[name].bind(this.delegate) : void 0; } }; var UpdatedProgramHost = class extends DelegatingCompilerHost { constructor(sfMap, originalProgram, delegate, shimExtensionPrefixes) { super(delegate); this.originalProgram = originalProgram; this.shimExtensionPrefixes = shimExtensionPrefixes; this.shimTagger = new ShimReferenceTagger(this.shimExtensionPrefixes); this.sfMap = sfMap; } getSourceFile(fileName, languageVersion, onError, shouldCreateNewSourceFile) { let delegateSf = this.originalProgram.getSourceFile(fileName); if (delegateSf === void 0) { delegateSf = this.delegate.getSourceFile(fileName, languageVersion, onError, shouldCreateNewSourceFile); } if (delegateSf === void 0) { return void 0; } let sf; if (this.sfMap.has(fileName)) { sf = this.sfMap.get(fileName); copyFileShimData(delegateSf, sf); } else { sf = delegateSf; } sf = toUnredirectedSourceFile(sf); this.shimTagger.tag(sf); return sf; } postProgramCreationCleanup() { this.shimTagger.finalize(); } writeFile() { throw new Error(`TypeCheckProgramHost should never write files`); } fileExists(fileName) { return this.sfMap.has(fileName) || this.delegate.fileExists(fileName); } }; var TsCreateProgramDriver = class { constructor(originalProgram, originalHost, options, shimExtensionPrefixes) { this.originalProgram = originalProgram; this.originalHost = originalHost; this.options = options; this.shimExtensionPrefixes = shimExtensionPrefixes; this.sfMap = /* @__PURE__ */ new Map(); this.supportsInlineOperations = true; this.program = this.originalProgram; } getProgram() { return this.program; } updateFiles(contents, updateMode) { if (contents.size === 0) { if (updateMode !== UpdateMode.Complete || this.sfMap.size === 0) { return; } } if (updateMode === UpdateMode.Complete) { this.sfMap.clear(); } for (const [filePath, { newText, originalFile }] of contents.entries()) { const sf = ts7.createSourceFile(filePath, newText, ts7.ScriptTarget.Latest, true); if (originalFile !== null) { sf[NgOriginalFile] = originalFile; } this.sfMap.set(filePath, sf); } const host = new UpdatedProgramHost(this.sfMap, this.originalProgram, this.originalHost, this.shimExtensionPrefixes); const oldProgram = this.program; retagAllTsFiles(oldProgram); this.program = ts7.createProgram({ host, rootNames: this.program.getRootFileNames(), options: this.options, oldProgram }); host.postProgramCreationCleanup(); untagAllTsFiles(this.program); untagAllTsFiles(oldProgram); } }; // bazel-out/darwin-fastbuild/bin/packages/compiler-cli/src/ngtsc/incremental/src/dependency_tracking.mjs var FileDependencyGraph = class { constructor() { this.nodes = /* @__PURE__ */ new Map(); } addDependency(from, on) { this.nodeFor(from).dependsOn.add(absoluteFromSourceFile(on)); } addResourceDependency(from, resource) { this.nodeFor(from).usesResources.add(resource); } recordDependencyAnalysisFailure(file) { this.nodeFor(file).failedAnalysis = true; } getResourceDependencies(from) { const node = this.nodes.get(from); return node ? [...node.usesResources] : []; } updateWithPhysicalChanges(previous, changedTsPaths, deletedTsPaths, changedResources) { const logicallyChanged = /* @__PURE__ */ new Set(); for (const sf of previous.nodes.keys()) { const sfPath = absoluteFromSourceFile(sf); const node = previous.nodeFor(sf); if (isLogicallyChanged(sf, node, changedTsPaths, deletedTsPaths, changedResources)) { logicallyChanged.add(sfPath); } else if (!deletedTsPaths.has(sfPath)) { this.nodes.set(sf, { dependsOn: new Set(node.dependsOn), usesResources: new Set(node.usesResources), failedAnalysis: false }); } } return logicallyChanged; } nodeFor(sf) { if (!this.nodes.has(sf)) { this.nodes.set(sf, { dependsOn: /* @__PURE__ */ new Set(), usesResources: /* @__PURE__ */ new Set(), failedAnalysis: false }); } return this.nodes.get(sf); } }; function isLogicallyChanged(sf, node, changedTsPaths, deletedTsPaths, changedResources) { if (node.failedAnalysis) { return true; } const sfPath = absoluteFromSourceFile(sf); if (changedTsPaths.has(sfPath) || deletedTsPaths.has(sfPath)) { return true; } for (const dep of node.dependsOn) { if (changedTsPaths.has(dep) || deletedTsPaths.has(dep)) { return true; } } for (const dep of node.usesResources) { if (changedResources.has(dep)) { return true; } } return false; } // bazel-out/darwin-fastbuild/bin/packages/compiler-cli/src/ngtsc/incremental/src/state.mjs var IncrementalStateKind; (function(IncrementalStateKind2) { IncrementalStateKind2[IncrementalStateKind2["Fresh"] = 0] = "Fresh"; IncrementalStateKind2[IncrementalStateKind2["Delta"] = 1] = "Delta"; IncrementalStateKind2[IncrementalStateKind2["Analyzed"] = 2] = "Analyzed"; })(IncrementalStateKind || (IncrementalStateKind = {})); // bazel-out/darwin-fastbuild/bin/packages/compiler-cli/src/ngtsc/incremental/src/incremental.mjs var PhaseKind; (function(PhaseKind2) { PhaseKind2[PhaseKind2["Analysis"] = 0] = "Analysis"; PhaseKind2[PhaseKind2["TypeCheckAndEmit"] = 1] = "TypeCheckAndEmit"; })(PhaseKind || (PhaseKind = {})); var IncrementalCompilation = class { constructor(state, depGraph, versions, step) { this.depGraph = depGraph; this.versions = versions; this.step = step; this._state = state; this.phase = { kind: PhaseKind.Analysis, semanticDepGraphUpdater: new SemanticDepGraphUpdater(step !== null ? step.priorState.semanticDepGraph : null) }; } static fresh(program, versions) { const state = { kind: IncrementalStateKind.Fresh }; return new IncrementalCompilation(state, new FileDependencyGraph(), versions, null); } static incremental(program, newVersions, oldProgram, oldState, modifiedResourceFiles, perf) { return perf.inPhase(PerfPhase.Reconciliation, () => { const physicallyChangedTsFiles = /* @__PURE__ */ new Set(); const changedResourceFiles = new Set(modifiedResourceFiles != null ? modifiedResourceFiles : []); let priorAnalysis; switch (oldState.kind) { case IncrementalStateKind.Fresh: return IncrementalCompilation.fresh(program, newVersions); case IncrementalStateKind.Analyzed: priorAnalysis = oldState; break; case IncrementalStateKind.Delta: priorAnalysis = oldState.lastAnalyzedState; for (const sfPath of oldState.physicallyChangedTsFiles) { physicallyChangedTsFiles.add(sfPath); } for (const resourcePath of oldState.changedResourceFiles) { changedResourceFiles.add(resourcePath); } break; } const oldVersions = priorAnalysis.versions; const oldFilesArray = oldProgram.getSourceFiles().map(toOriginalSourceFile); const oldFiles = new Set(oldFilesArray); const deletedTsFiles = new Set(oldFilesArray.map((sf) => absoluteFromSourceFile(sf))); for (const possiblyRedirectedNewFile of program.getSourceFiles()) { const sf = toOriginalSourceFile(possiblyRedirectedNewFile); const sfPath = absoluteFromSourceFile(sf); deletedTsFiles.delete(sfPath); if (oldFiles.has(sf)) { if (oldVersions === null || newVersions === null) { continue; } if (oldVersions.has(sfPath) && newVersions.has(sfPath) && oldVersions.get(sfPath) === newVersions.get(sfPath)) { continue; } } if (sf.isDeclarationFile) { return IncrementalCompilation.fresh(program, newVersions); } physicallyChangedTsFiles.add(sfPath); } for (const deletedFileName of deletedTsFiles) { physicallyChangedTsFiles.delete(resolve(deletedFileName)); } const depGraph = new FileDependencyGraph(); const logicallyChangedTsFiles = depGraph.updateWithPhysicalChanges(priorAnalysis.depGraph, physicallyChangedTsFiles, deletedTsFiles, changedResourceFiles); for (const sfPath of physicallyChangedTsFiles) { logicallyChangedTsFiles.add(sfPath); } const state = { kind: IncrementalStateKind.Delta, physicallyChangedTsFiles, changedResourceFiles, lastAnalyzedState: priorAnalysis }; return new IncrementalCompilation(state, depGraph, newVersions, { priorState: priorAnalysis, logicallyChangedTsFiles }); }); } get state() { return this._state; } get semanticDepGraphUpdater() { if (this.phase.kind !== PhaseKind.Analysis) { throw new Error(`AssertionError: Cannot update the SemanticDepGraph after analysis completes`); } return this.phase.semanticDepGraphUpdater; } recordSuccessfulAnalysis(traitCompiler) { if (this.phase.kind !== PhaseKind.Analysis) { throw new Error(`AssertionError: Incremental compilation in phase ${PhaseKind[this.phase.kind]}, expected Analysis`); } const { needsEmit, needsTypeCheckEmit, newGraph } = this.phase.semanticDepGraphUpdater.finalize(); let emitted; if (this.step === null) { emitted = /* @__PURE__ */ new Set(); } else { emitted = new Set(this.step.priorState.emitted); for (const sfPath of this.step.logicallyChangedTsFiles) { emitted.delete(sfPath); } for (const sfPath of needsEmit) { emitted.delete(sfPath); } } this._state = { kind: IncrementalStateKind.Analyzed, versions: this.versions, depGraph: this.depGraph, semanticDepGraph: newGraph, priorAnalysis: traitCompiler.getAnalyzedRecords(), typeCheckResults: null, emitted }; this.phase = { kind: PhaseKind.TypeCheckAndEmit, needsEmit, needsTypeCheckEmit }; } recordSuccessfulTypeCheck(results) { if (this._state.kind !== IncrementalStateKind.Analyzed) { throw new Error(`AssertionError: Expected successfully analyzed compilation.`); } else if (this.phase.kind !== PhaseKind.TypeCheckAndEmit) { throw new Error(`AssertionError: Incremental compilation in phase ${PhaseKind[this.phase.kind]}, expected TypeCheck`); } this._state.typeCheckResults = results; } recordSuccessfulEmit(sf) { if (this._state.kind !== IncrementalStateKind.Analyzed) { throw new Error(`AssertionError: Expected successfully analyzed compilation.`); } this._state.emitted.add(absoluteFromSourceFile(sf)); } priorAnalysisFor(sf) { if (this.step === null) { return null; } const sfPath = absoluteFromSourceFile(sf); if (this.step.logicallyChangedTsFiles.has(sfPath)) { return null; } const priorAnalysis = this.step.priorState.priorAnalysis; if (!priorAnalysis.has(sf)) { return null; } return priorAnalysis.get(sf); } priorTypeCheckingResultsFor(sf) { if (this.phase.kind !== PhaseKind.TypeCheckAndEmit) { throw new Error(`AssertionError: Expected successfully analyzed compilation.`); } if (this.step === null) { return null; } const sfPath = absoluteFromSourceFile(sf); if (this.step.logicallyChangedTsFiles.has(sfPath) || this.phase.needsTypeCheckEmit.has(sfPath)) { return null; } if (this.step.priorState.typeCheckResults === null || !this.step.priorState.typeCheckResults.has(sfPath)) { return null; } const priorResults = this.step.priorState.typeCheckResults.get(sfPath); if (priorResults.hasInlines) { return null; } return priorResults; } safeToSkipEmit(sf) { if (this.step === null) { return false; } const sfPath = absoluteFromSourceFile(sf); if (this.step.logicallyChangedTsFiles.has(sfPath)) { return false; } if (this.phase.kind !== PhaseKind.TypeCheckAndEmit) { throw new Error(`AssertionError: Expected successful analysis before attempting to emit files`); } if (this.phase.needsEmit.has(sfPath)) { return false; } return this.step.priorState.emitted.has(sfPath); } }; function toOriginalSourceFile(sf) { const unredirectedSf = toUnredirectedSourceFile(sf); const originalFile = unredirectedSf[NgOriginalFile]; if (originalFile !== void 0) { return originalFile; } else { return unredirectedSf; } } // bazel-out/darwin-fastbuild/bin/packages/compiler-cli/src/ngtsc/incremental/src/strategy.mjs var TrackedIncrementalBuildStrategy = class { constructor() { this.state = null; this.isSet = false; } getIncrementalState() { return this.state; } setIncrementalState(state) { this.state = state; this.isSet = true; } toNextBuildStrategy() { const strategy = new TrackedIncrementalBuildStrategy(); strategy.state = this.isSet ? this.state : null; return strategy; } }; var PatchedProgramIncrementalBuildStrategy = class { getIncrementalState(program) { const state = program[SYM_INCREMENTAL_STATE]; if (state === void 0) { return null; } return state; } setIncrementalState(state, program) { program[SYM_INCREMENTAL_STATE] = state; } toNextBuildStrategy() { return this; } }; var SYM_INCREMENTAL_STATE = Symbol("NgIncrementalState"); // bazel-out/darwin-fastbuild/bin/packages/compiler-cli/src/ngtsc/indexer/src/api.mjs var IdentifierKind; (function(IdentifierKind2) { IdentifierKind2[IdentifierKind2["Property"] = 0] = "Property"; IdentifierKind2[IdentifierKind2["Method"] = 1] = "Method"; IdentifierKind2[IdentifierKind2["Element"] = 2] = "Element"; IdentifierKind2[IdentifierKind2["Template"] = 3] = "Template"; IdentifierKind2[IdentifierKind2["Attribute"] = 4] = "Attribute"; IdentifierKind2[IdentifierKind2["Reference"] = 5] = "Reference"; IdentifierKind2[IdentifierKind2["Variable"] = 6] = "Variable"; })(IdentifierKind || (IdentifierKind = {})); var AbsoluteSourceSpan = class { constructor(start, end) { this.start = start; this.end = end; } }; // bazel-out/darwin-fastbuild/bin/packages/compiler-cli/src/ngtsc/indexer/src/context.mjs var IndexingContext = class { constructor() { this.components = /* @__PURE__ */ new Set(); } addComponent(info) { this.components.add(info); } }; // bazel-out/darwin-fastbuild/bin/packages/compiler-cli/src/ngtsc/indexer/src/transform.mjs import { ParseSourceFile } from "@angular/compiler"; // bazel-out/darwin-fastbuild/bin/packages/compiler-cli/src/ngtsc/indexer/src/template.mjs import { ASTWithSource, ImplicitReceiver, PropertyRead, PropertyWrite, RecursiveAstVisitor, TmplAstElement, TmplAstRecursiveVisitor, TmplAstReference, TmplAstTemplate } from "@angular/compiler"; var ExpressionVisitor = class extends RecursiveAstVisitor { constructor(expressionStr, absoluteOffset, boundTemplate, targetToIdentifier) { super(); this.expressionStr = expressionStr; this.absoluteOffset = absoluteOffset; this.boundTemplate = boundTemplate; this.targetToIdentifier = targetToIdentifier; this.identifiers = []; this.errors = []; } static getIdentifiers(ast, source, absoluteOffset, boundTemplate, targetToIdentifier) { const visitor = new ExpressionVisitor(source, absoluteOffset, boundTemplate, targetToIdentifier); visitor.visit(ast); return { identifiers: visitor.identifiers, errors: visitor.errors }; } visit(ast) { ast.visit(this); } visitPropertyRead(ast, context) { this.visitIdentifier(ast, IdentifierKind.Property); super.visitPropertyRead(ast, context); } visitPropertyWrite(ast, context) { this.visitIdentifier(ast, IdentifierKind.Property); super.visitPropertyWrite(ast, context); } visitIdentifier(ast, kind) { if (!(ast.receiver instanceof ImplicitReceiver)) { return; } let identifierStart = ast.sourceSpan.start - this.absoluteOffset; if (ast instanceof PropertyRead || ast instanceof PropertyWrite) { identifierStart = ast.nameSpan.start - this.absoluteOffset; } if (!this.expressionStr.substring(identifierStart).startsWith(ast.name)) { this.errors.push(new Error(`Impossible state: "${ast.name}" not found in "${this.expressionStr}" at location ${identifierStart}`)); return; } const absoluteStart = this.absoluteOffset + identifierStart; const span = new AbsoluteSourceSpan(absoluteStart, absoluteStart + ast.name.length); const targetAst = this.boundTemplate.getExpressionTarget(ast); const target = targetAst ? this.targetToIdentifier(targetAst) : null; const identifier = { name: ast.name, span, kind, target }; this.identifiers.push(identifier); } }; var TemplateVisitor = class extends TmplAstRecursiveVisitor { constructor(boundTemplate) { super(); this.boundTemplate = boundTemplate; this.identifiers = /* @__PURE__ */ new Set(); this.errors = []; this.targetIdentifierCache = /* @__PURE__ */ new Map(); this.elementAndTemplateIdentifierCache = /* @__PURE__ */ new Map(); } visit(node) { node.visit(this); } visitAll(nodes) { nodes.forEach((node) => this.visit(node)); } visitElement(element) { const elementIdentifier = this.elementOrTemplateToIdentifier(element); if (elementIdentifier !== null) { this.identifiers.add(elementIdentifier); } this.visitAll(element.references); this.visitAll(element.inputs); this.visitAll(element.attributes); this.visitAll(element.children); this.visitAll(element.outputs); } visitTemplate(template) { const templateIdentifier = this.elementOrTemplateToIdentifier(template); if (templateIdentifier !== null) { this.identifiers.add(templateIdentifier); } this.visitAll(template.variables); this.visitAll(template.attributes); this.visitAll(template.templateAttrs); this.visitAll(template.children); this.visitAll(template.references); } visitBoundAttribute(attribute) { if (attribute.valueSpan === void 0) { return; } const { identifiers, errors } = ExpressionVisitor.getIdentifiers(attribute.value, attribute.valueSpan.toString(), attribute.valueSpan.start.offset, this.boundTemplate, this.targetToIdentifier.bind(this)); identifiers.forEach((id) => this.identifiers.add(id)); this.errors.push(...errors); } visitBoundEvent(attribute) { this.visitExpression(attribute.handler); } visitBoundText(text) { this.visitExpression(text.value); } visitReference(reference) { const referenceIdentifier = this.targetToIdentifier(reference); if (referenceIdentifier === null) { return; } this.identifiers.add(referenceIdentifier); } visitVariable(variable) { const variableIdentifier = this.targetToIdentifier(variable); if (variableIdentifier === null) { return; } this.identifiers.add(variableIdentifier); } elementOrTemplateToIdentifier(node) { var _a; if (this.elementAndTemplateIdentifierCache.has(node)) { return this.elementAndTemplateIdentifierCache.get(node); } let name; let kind; if (node instanceof TmplAstTemplate) { name = (_a = node.tagName) != null ? _a : "ng-template"; kind = IdentifierKind.Template; } else { name = node.name; kind = IdentifierKind.Element; } if (name.startsWith(":")) { name = name.split(":").pop(); } const sourceSpan = node.startSourceSpan; const start = this.getStartLocation(name, sourceSpan); if (start === null) { return null; } const absoluteSpan = new AbsoluteSourceSpan(start, start + name.length); const attributes = node.attributes.map(({ name: name2, sourceSpan: sourceSpan2 }) => { return { name: name2, span: new AbsoluteSourceSpan(sourceSpan2.start.offset, sourceSpan2.end.offset), kind: IdentifierKind.Attribute }; }); const usedDirectives = this.boundTemplate.getDirectivesOfNode(node) || []; const identifier = { name, span: absoluteSpan, kind, attributes: new Set(attributes), usedDirectives: new Set(usedDirectives.map((dir) => { return { node: dir.ref.node, selector: dir.selector }; })) }; this.elementAndTemplateIdentifierCache.set(node, identifier); return identifier; } targetToIdentifier(node) { if (this.targetIdentifierCache.has(node)) { return this.targetIdentifierCache.get(node); } const { name, sourceSpan } = node; const start = this.getStartLocation(name, sourceSpan); if (start === null) { return null; } const span = new AbsoluteSourceSpan(start, start + name.length); let identifier; if (node instanceof TmplAstReference) { const refTarget = this.boundTemplate.getReferenceTarget(node); let target = null; if (refTarget) { let node2 = null; let directive = null; if (refTarget instanceof TmplAstElement || refTarget instanceof TmplAstTemplate) { node2 = this.elementOrTemplateToIdentifier(refTarget); } else { node2 = this.elementOrTemplateToIdentifier(refTarget.node); directive = refTarget.directive.ref.node; } if (node2 === null) { return null; } target = { node: node2, directive }; } identifier = { name, span, kind: IdentifierKind.Reference, target }; } else { identifier = { name, span, kind: IdentifierKind.Variable }; } this.targetIdentifierCache.set(node, identifier); return identifier; } getStartLocation(name, context) { const localStr = context.toString(); if (!localStr.includes(name)) { this.errors.push(new Error(`Impossible state: "${name}" not found in "${localStr}"`)); return null; } return context.start.offset + localStr.indexOf(name); } visitExpression(ast) { if (ast instanceof ASTWithSource && ast.source !== null) { const targetToIdentifier = this.targetToIdentifier.bind(this); const absoluteOffset = ast.sourceSpan.start; const { identifiers, errors } = ExpressionVisitor.getIdentifiers(ast, ast.source, absoluteOffset, this.boundTemplate, targetToIdentifier); identifiers.forEach((id) => this.identifiers.add(id)); this.errors.push(...errors); } } }; function getTemplateIdentifiers(boundTemplate) { const visitor = new TemplateVisitor(boundTemplate); if (boundTemplate.target.template !== void 0) { visitor.visitAll(boundTemplate.target.template); } return { identifiers: visitor.identifiers, errors: visitor.errors }; } // bazel-out/darwin-fastbuild/bin/packages/compiler-cli/src/ngtsc/indexer/src/transform.mjs function generateAnalysis(context) { const analysis = /* @__PURE__ */ new Map(); context.components.forEach(({ declaration, selector, boundTemplate, templateMeta }) => { const name = declaration.name.getText(); const usedComponents = /* @__PURE__ */ new Set(); const usedDirs = boundTemplate.getUsedDirectives(); usedDirs.forEach((dir) => { if (dir.isComponent) { usedComponents.add(dir.ref.node); } }); const componentFile = new ParseSourceFile(declaration.getSourceFile().getF