UNPKG

@angular/compiler-cli

Version:
1,352 lines (1,321 loc) • 202 kB
import {createRequire as __cjsCompatRequire} from 'module'; const require = __cjsCompatRequire(import.meta.url); import { angularJitApplicationTransform } from "./chunk-K6EUONET.js"; import { CompilationMode, ComponentDecoratorHandler, ComponentScopeKind, CompoundComponentScopeReader, CompoundMetadataReader, CompoundMetadataRegistry, DirectiveDecoratorHandler, DtsMetadataReader, DtsTransformRegistry, ExportedProviderStatusResolver, HostDirectivesResolver, INPUT_INITIALIZER_FN, InjectableClassRegistry, InjectableDecoratorHandler, JitDeclarationRegistry, LocalMetadataRegistry, LocalModuleScopeRegistry, MODEL_INITIALIZER_FN, MetaKind, MetadataDtsModuleScopeResolver, NgModuleDecoratorHandler, NgOriginalFile, NoopReferencesRegistry, OUTPUT_INITIALIZER_FNS, OptimizeFor, PartialEvaluator, PipeDecoratorHandler, QUERY_INITIALIZER_FNS, ResourceRegistry, SemanticDepGraphUpdater, ShimAdapter, ShimReferenceTagger, SymbolKind, TemplateTypeCheckerImpl, TraitCompiler, TsCreateProgramDriver, TypeCheckScopeRegistry, TypeCheckShimGenerator, aliasTransformFactory, declarationTransformFactory, isShim, ivyTransformFactory, retagAllTsFiles, tryParseInitializerApi, untagAllTsFiles } from "./chunk-XABJ5FUR.js"; import { AbsoluteModuleStrategy, AliasStrategy, COMPILER_ERRORS_WITH_GUIDES, DefaultImportTracker, DeferredSymbolTracker, ERROR_DETAILS_PAGE_BASE_URL, ErrorCode, ExtendedTemplateDiagnosticName, ImportedSymbolsTracker, LocalCompilationExtraImportsTracker, LocalIdentifierStrategy, LogicalProjectStrategy, ModuleResolver, NoopImportRewriter, PrivateExportAliasingHost, R3SymbolsImportRewriter, Reference, ReferenceEmitter, RelativePathStrategy, TypeScriptReflectionHost, UnifiedModulesAliasingHost, UnifiedModulesStrategy, getRootDirs, getSourceFileOrNull, isDtsPath, isFatalDiagnosticError, isNamedClassDeclaration, isNonDeclarationTsPath, makeDiagnostic, ngErrorCode, normalizeSeparators, relativePathBetween, replaceTsWithNgInErrors, toUnredirectedSourceFile } from "./chunk-XRSJELB6.js"; import { ActivePerfRecorder, DelegatingPerfRecorder, PerfCheckpoint, PerfEvent, PerfPhase } from "./chunk-Q2WE7ECN.js"; import { LogicalFileSystem, absoluteFrom, absoluteFromSourceFile, createFileSystemTsReadDirectoryFn, dirname, getFileSystem, join, resolve } from "./chunk-37JMVF7H.js"; // bazel-out/k8-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/k8-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/k8-fastbuild/bin/packages/compiler-cli/src/ngtsc/docs/src/entities.mjs var EntryType; (function(EntryType2) { EntryType2["Block"] = "block"; EntryType2["Component"] = "component"; EntryType2["Constant"] = "constant"; EntryType2["Decorator"] = "decorator"; EntryType2["Directive"] = "directive"; EntryType2["Element"] = "element"; EntryType2["Enum"] = "enum"; EntryType2["Function"] = "function"; EntryType2["Interface"] = "interface"; EntryType2["NgModule"] = "ng_module"; EntryType2["Pipe"] = "pipe"; EntryType2["TypeAlias"] = "type_alias"; EntryType2["UndecoratedClass"] = "undecorated_class"; EntryType2["InitializerApiFunction"] = "initializer_api_function"; })(EntryType || (EntryType = {})); var MemberType; (function(MemberType2) { MemberType2["Property"] = "property"; MemberType2["Method"] = "method"; MemberType2["Getter"] = "getter"; MemberType2["Setter"] = "setter"; MemberType2["EnumItem"] = "enum_item"; })(MemberType || (MemberType = {})); var DecoratorType; (function(DecoratorType2) { DecoratorType2["Class"] = "class"; DecoratorType2["Member"] = "member"; DecoratorType2["Parameter"] = "parameter"; })(DecoratorType || (DecoratorType = {})); var MemberTags; (function(MemberTags2) { MemberTags2["Abstract"] = "abstract"; MemberTags2["Static"] = "static"; MemberTags2["Readonly"] = "readonly"; MemberTags2["Protected"] = "protected"; MemberTags2["Optional"] = "optional"; MemberTags2["Input"] = "input"; MemberTags2["Output"] = "output"; MemberTags2["Inherited"] = "override"; })(MemberTags || (MemberTags = {})); function isDocEntryWithSourceInfo(entry) { return "source" in entry; } // bazel-out/k8-fastbuild/bin/packages/compiler-cli/src/ngtsc/docs/src/extractor.mjs import ts12 from "typescript"; // bazel-out/k8-fastbuild/bin/packages/compiler-cli/src/ngtsc/docs/src/class_extractor.mjs import ts6 from "typescript"; // bazel-out/k8-fastbuild/bin/packages/compiler-cli/src/ngtsc/docs/src/filters.mjs function isAngularPrivateName(name) { var _a; const firstChar = (_a = name[0]) != null ? _a : ""; return firstChar === "\u0275" || firstChar === "_"; } // bazel-out/k8-fastbuild/bin/packages/compiler-cli/src/ngtsc/docs/src/function_extractor.mjs import ts4 from "typescript"; // bazel-out/k8-fastbuild/bin/packages/compiler-cli/src/ngtsc/docs/src/generics_extractor.mjs function extractGenerics(declaration) { var _a, _b; return (_b = (_a = declaration.typeParameters) == null ? void 0 : _a.map((typeParam) => { var _a2, _b2; return { name: typeParam.name.getText(), constraint: (_a2 = typeParam.constraint) == null ? void 0 : _a2.getText(), default: (_b2 = typeParam.default) == null ? void 0 : _b2.getText() }; })) != null ? _b : []; } // bazel-out/k8-fastbuild/bin/packages/compiler-cli/src/ngtsc/docs/src/jsdoc_extractor.mjs import ts2 from "typescript"; var decoratorExpression = /@(?=(Injectable|Component|Directive|Pipe|NgModule|Input|Output|HostBinding|HostListener|Inject|Optional|Self|Host|SkipSelf|ViewChild|ViewChildren|ContentChild|ContentChildren))/g; function extractJsDocTags(node) { const escapedNode = getEscapedNode(node); return ts2.getJSDocTags(escapedNode).map((t) => { var _a; return { name: t.tagName.getText(), comment: unescapeAngularDecorators((_a = ts2.getTextOfJSDocComment(t.comment)) != null ? _a : "") }; }); } function extractJsDocDescription(node) { var _a, _b; const escapedNode = getEscapedNode(node); const commentOrTag = ts2.getJSDocCommentsAndTags(escapedNode).find((d) => { return ts2.isJSDoc(d) || ts2.isJSDocParameterTag(d); }); const comment = (_a = commentOrTag == null ? void 0 : commentOrTag.comment) != null ? _a : ""; const description = typeof comment === "string" ? comment : (_b = ts2.getTextOfJSDocComment(comment)) != null ? _b : ""; return unescapeAngularDecorators(description); } function extractRawJsDoc(node) { var _a, _b; const comment = (_b = (_a = ts2.getJSDocCommentsAndTags(node).find(ts2.isJSDoc)) == null ? void 0 : _a.getFullText()) != null ? _b : ""; return unescapeAngularDecorators(comment); } function getEscapedNode(node) { if (ts2.isParameter(node)) { return node; } const rawComment = extractRawJsDoc(node); const escaped = escapeAngularDecorators(rawComment); const file = ts2.createSourceFile("x.ts", `${escaped}class X {}`, ts2.ScriptTarget.ES2020, true); return file.statements.find((s) => ts2.isClassDeclaration(s)); } function escapeAngularDecorators(comment) { return comment.replace(decoratorExpression, "_NG_AT_"); } function unescapeAngularDecorators(comment) { return comment.replace(/_NG_AT_/g, "@"); } // bazel-out/k8-fastbuild/bin/packages/compiler-cli/src/ngtsc/docs/src/type_extractor.mjs import ts3 from "typescript"; function extractResolvedTypeString(node, checker) { return checker.typeToString(checker.getTypeAtLocation(node), void 0, ts3.TypeFormatFlags.NoTruncation); } // bazel-out/k8-fastbuild/bin/packages/compiler-cli/src/ngtsc/docs/src/function_extractor.mjs var FunctionExtractor = class { name; exportDeclaration; typeChecker; constructor(name, exportDeclaration, typeChecker) { this.name = name; this.exportDeclaration = exportDeclaration; this.typeChecker = typeChecker; } extract() { var _a, _b; const signature = this.typeChecker.getSignatureFromDeclaration(this.exportDeclaration); const returnType = signature ? this.typeChecker.typeToString( this.typeChecker.getReturnTypeOfSignature(signature), void 0, ts4.TypeFormatFlags.NoTypeReduction | ts4.TypeFormatFlags.NoTruncation ) : "unknown"; const implementation = (_a = findImplementationOfFunction(this.exportDeclaration, this.typeChecker)) != null ? _a : this.exportDeclaration; const type = this.typeChecker.getTypeAtLocation(this.exportDeclaration); const overloads = ts4.isConstructorDeclaration(this.exportDeclaration) ? constructorOverloads(this.exportDeclaration, this.typeChecker) : extractCallSignatures(this.name, this.typeChecker, type); const jsdocsTags = extractJsDocTags(implementation); const description = extractJsDocDescription(implementation); return { name: this.name, signatures: overloads, implementation: { params: extractAllParams(implementation.parameters, this.typeChecker), isNewType: ts4.isConstructSignatureDeclaration(implementation), returnType, returnDescription: (_b = jsdocsTags.find((tag) => tag.name === "returns")) == null ? void 0 : _b.comment, generics: extractGenerics(implementation), name: this.name, description, entryType: EntryType.Function, jsdocTags: jsdocsTags, rawComment: extractRawJsDoc(implementation) }, entryType: EntryType.Function, description, jsdocTags: jsdocsTags, rawComment: extractRawJsDoc(implementation) }; } }; function constructorOverloads(constructorDeclaration, typeChecker) { const classDeclaration = constructorDeclaration.parent; const constructorNode = classDeclaration.members.filter((member) => { return ts4.isConstructorDeclaration(member) && !member.body; }); return constructorNode.map((n) => { var _a; return { name: "constructor", params: extractAllParams(n.parameters, typeChecker), returnType: (_a = typeChecker.getTypeAtLocation(classDeclaration)) == null ? void 0 : _a.symbol.name, description: extractJsDocDescription(n), entryType: EntryType.Function, jsdocTags: extractJsDocTags(n), rawComment: extractRawJsDoc(n), generics: extractGenerics(n), isNewType: false }; }); } function extractAllParams(params, typeChecker) { return params.map((param) => ({ name: param.name.getText(), description: extractJsDocDescription(param), type: extractResolvedTypeString(param, typeChecker), isOptional: !!(param.questionToken || param.initializer), isRestParam: !!param.dotDotDotToken })); } function filterSignatureDeclarations(signatures) { const result = []; for (const signature of signatures) { const decl = signature.getDeclaration(); if (ts4.isFunctionDeclaration(decl) || ts4.isCallSignatureDeclaration(decl) || ts4.isMethodDeclaration(decl) || ts4.isConstructSignatureDeclaration(decl)) { result.push({ signature, decl }); } } return result; } function extractCallSignatures(name, typeChecker, type) { return filterSignatureDeclarations(type.getCallSignatures()).map(({ decl, signature }) => ({ name, entryType: EntryType.Function, description: extractJsDocDescription(decl), generics: extractGenerics(decl), isNewType: false, jsdocTags: extractJsDocTags(decl), params: extractAllParams(decl.parameters, typeChecker), rawComment: extractRawJsDoc(decl), returnType: typeChecker.typeToString( typeChecker.getReturnTypeOfSignature(signature), void 0, ts4.TypeFormatFlags.NoTypeReduction | ts4.TypeFormatFlags.NoTruncation ) })); } function findImplementationOfFunction(node, typeChecker) { var _a; if (node.body !== void 0 || node.name === void 0) { return node; } const symbol = typeChecker.getSymbolAtLocation(node.name); const implementation = (_a = symbol == null ? void 0 : symbol.declarations) == null ? void 0 : _a.find((s) => ts4.isFunctionDeclaration(s) && s.body !== void 0); return implementation; } // bazel-out/k8-fastbuild/bin/packages/compiler-cli/src/ngtsc/docs/src/internal.mjs import ts5 from "typescript"; function isInternal(member) { return extractJsDocTags(member).some((tag) => tag.name === "internal") || hasLeadingInternalComment(member); } function hasLeadingInternalComment(member) { var _a; const memberText = member.getSourceFile().text; return (_a = ts5.reduceEachLeadingCommentRange( memberText, member.getFullStart(), (pos, end, kind, hasTrailingNewLine, containsInternal) => { return containsInternal || memberText.slice(pos, end).includes("@internal"); }, false, false )) != null ? _a : false; } // bazel-out/k8-fastbuild/bin/packages/compiler-cli/src/ngtsc/docs/src/class_extractor.mjs var ClassExtractor = class { declaration; typeChecker; constructor(declaration, typeChecker) { this.declaration = declaration; this.typeChecker = typeChecker; } extract() { return { name: this.declaration.name.text, isAbstract: this.isAbstract(), entryType: ts6.isInterfaceDeclaration(this.declaration) ? EntryType.Interface : EntryType.UndecoratedClass, members: this.extractSignatures().concat(this.extractAllClassMembers()), generics: extractGenerics(this.declaration), description: extractJsDocDescription(this.declaration), jsdocTags: extractJsDocTags(this.declaration), rawComment: extractRawJsDoc(this.declaration), extends: this.extractInheritance(this.declaration), implements: this.extractInterfaceConformance(this.declaration) }; } extractAllClassMembers() { const members = []; for (const member of this.getMemberDeclarations()) { if (this.isMemberExcluded(member)) continue; const memberEntry = this.extractClassMember(member); if (memberEntry) { members.push(memberEntry); } } return members; } extractClassMember(memberDeclaration) { if (this.isMethod(memberDeclaration)) { return this.extractMethod(memberDeclaration); } else if (this.isProperty(memberDeclaration) && !this.hasPrivateComputedProperty(memberDeclaration)) { return this.extractClassProperty(memberDeclaration); } else if (ts6.isAccessor(memberDeclaration)) { return this.extractGetterSetter(memberDeclaration); } else if (ts6.isConstructorDeclaration(memberDeclaration)) { return this.extractConstructor(memberDeclaration); } return void 0; } extractSignatures() { return this.computeAllSignatureDeclarations().map((s) => this.extractSignature(s)); } extractMethod(methodDeclaration) { const functionExtractor = new FunctionExtractor(methodDeclaration.name.getText(), methodDeclaration, this.typeChecker); return { ...functionExtractor.extract(), memberType: MemberType.Method, memberTags: this.getMemberTags(methodDeclaration) }; } extractSignature(signature) { const functionExtractor = new FunctionExtractor(ts6.isConstructSignatureDeclaration(signature) ? "new" : "", signature, this.typeChecker); return { ...functionExtractor.extract(), memberType: MemberType.Method, memberTags: [] }; } extractClassProperty(propertyDeclaration) { return { name: propertyDeclaration.name.getText(), type: extractResolvedTypeString(propertyDeclaration, this.typeChecker), memberType: MemberType.Property, memberTags: this.getMemberTags(propertyDeclaration), description: extractJsDocDescription(propertyDeclaration), jsdocTags: extractJsDocTags(propertyDeclaration) }; } extractGetterSetter(accessor) { return { ...this.extractClassProperty(accessor), memberType: ts6.isGetAccessor(accessor) ? MemberType.Getter : MemberType.Setter }; } extractConstructor(constructorDeclaration) { const functionExtractor = new FunctionExtractor("constructor", constructorDeclaration, this.typeChecker); return { ...functionExtractor.extract(), memberType: MemberType.Method, memberTags: this.getMemberTags(constructorDeclaration) }; } extractInheritance(declaration) { if (!declaration.heritageClauses) { return void 0; } for (const clause of declaration.heritageClauses) { if (clause.token === ts6.SyntaxKind.ExtendsKeyword) { const types = clause.types; if (types.length > 0) { const baseClass = types[0]; return baseClass.getText(); } } } return void 0; } extractInterfaceConformance(declaration) { var _a, _b; const implementClause = (_a = declaration.heritageClauses) == null ? void 0 : _a.find((clause) => clause.token === ts6.SyntaxKind.ImplementsKeyword); return (_b = implementClause == null ? void 0 : implementClause.types.map((m) => m.getText())) != null ? _b : []; } getMemberTags(member) { var _a; const tags = this.getMemberTagsFromModifiers((_a = member.modifiers) != null ? _a : []); if (member.questionToken) { tags.push(MemberTags.Optional); } if (member.parent !== this.declaration) { tags.push(MemberTags.Inherited); } return tags; } computeAllSignatureDeclarations() { const type = this.typeChecker.getTypeAtLocation(this.declaration); const signatures = [...type.getCallSignatures(), ...type.getConstructSignatures()]; const result = []; for (const signature of signatures) { const decl = signature.getDeclaration(); if (this.isDocumentableSignature(decl) && this.isDocumentableMember(decl)) { result.push(decl); } } return result; } getMemberDeclarations() { var _a, _b, _c; const type = this.typeChecker.getTypeAtLocation(this.declaration); const members = type.getProperties(); const constructor = (_b = (_a = type.getSymbol()) == null ? void 0 : _a.members) == null ? void 0 : _b.get(ts6.InternalSymbolName.Constructor); const typeOfConstructor = this.typeChecker.getTypeOfSymbol(type.symbol); const staticMembers = typeOfConstructor.getProperties(); const result = []; for (const member of [...constructor ? [constructor] : [], ...members, ...staticMembers]) { const memberDeclarations = this.filterMethodOverloads((_c = member.getDeclarations()) != null ? _c : []); for (const memberDeclaration of memberDeclarations) { if (this.isDocumentableMember(memberDeclaration)) { result.push(memberDeclaration); } } } return result; } filterMethodOverloads(declarations) { return declarations.filter((declaration, index) => { var _a; if (ts6.isFunctionDeclaration(declaration) || ts6.isMethodDeclaration(declaration) || ts6.isConstructorDeclaration(declaration)) { const nextDeclaration = declarations[index + 1]; const isNextMethodWithSameName = nextDeclaration && (ts6.isMethodDeclaration(nextDeclaration) && nextDeclaration.name.getText() === ((_a = declaration.name) == null ? void 0 : _a.getText()) || ts6.isConstructorDeclaration(nextDeclaration) && ts6.isConstructorDeclaration(declaration)); return !isNextMethodWithSameName; } return true; }); } getMemberTagsFromModifiers(mods) { const tags = []; for (const mod of mods) { const tag = this.getTagForMemberModifier(mod); if (tag) tags.push(tag); } return tags; } getTagForMemberModifier(mod) { switch (mod.kind) { case ts6.SyntaxKind.StaticKeyword: return MemberTags.Static; case ts6.SyntaxKind.ReadonlyKeyword: return MemberTags.Readonly; case ts6.SyntaxKind.ProtectedKeyword: return MemberTags.Protected; case ts6.SyntaxKind.AbstractKeyword: return MemberTags.Abstract; default: return void 0; } } isMemberExcluded(member) { var _a; if (ts6.isConstructorDeclaration(member)) { return false; } return !member.name || !this.isDocumentableMember(member) || !ts6.isCallSignatureDeclaration(member) && ((_a = member.modifiers) == null ? void 0 : _a.some((mod) => mod.kind === ts6.SyntaxKind.PrivateKeyword)) || member.name.getText() === "prototype" || isAngularPrivateName(member.name.getText()) || isInternal(member); } isDocumentableMember(member) { return this.isMethod(member) || this.isProperty(member) || ts6.isAccessor(member) || ts6.isConstructorDeclaration(member) || ts6.isCallSignatureDeclaration(member); } isPublicConstructorParameterProperty(node) { if (ts6.isParameterPropertyDeclaration(node, node.parent) && node.modifiers) { return node.modifiers.some((modifier) => modifier.kind === ts6.SyntaxKind.PublicKeyword); } return false; } isProperty(member) { return ts6.isPropertyDeclaration(member) || ts6.isPropertySignature(member) || this.isPublicConstructorParameterProperty(member); } isMethod(member) { return ts6.isMethodDeclaration(member) || ts6.isMethodSignature(member); } isDocumentableSignature(signature) { return ts6.isConstructSignatureDeclaration(signature) || ts6.isCallSignatureDeclaration(signature); } isAbstract() { var _a; const modifiers = (_a = this.declaration.modifiers) != null ? _a : []; return modifiers.some((mod) => mod.kind === ts6.SyntaxKind.AbstractKeyword); } hasPrivateComputedProperty(property) { return ts6.isComputedPropertyName(property.name) && property.name.expression.getText().startsWith("\u0275"); } }; var DirectiveExtractor = class extends ClassExtractor { reference; metadata; constructor(declaration, reference, metadata, checker) { super(declaration, checker); this.reference = reference; this.metadata = metadata; } extract() { var _a, _b; return { ...super.extract(), isStandalone: this.metadata.isStandalone, selector: (_a = this.metadata.selector) != null ? _a : "", exportAs: (_b = this.metadata.exportAs) != null ? _b : [], entryType: this.metadata.isComponent ? EntryType.Component : EntryType.Directive }; } extractClassProperty(propertyDeclaration) { const entry = super.extractClassProperty(propertyDeclaration); const inputMetadata = this.getInputMetadata(propertyDeclaration); if (inputMetadata) { entry.memberTags.push(MemberTags.Input); entry.inputAlias = inputMetadata.bindingPropertyName; entry.isRequiredInput = inputMetadata.required; } const outputMetadata = this.getOutputMetadata(propertyDeclaration); if (outputMetadata) { entry.memberTags.push(MemberTags.Output); entry.outputAlias = outputMetadata.bindingPropertyName; } return entry; } getInputMetadata(prop) { var _a, _b; const propName = prop.name.getText(); return (_b = (_a = this.metadata.inputs) == null ? void 0 : _a.getByClassPropertyName(propName)) != null ? _b : void 0; } getOutputMetadata(prop) { var _a, _b, _c; const propName = prop.name.getText(); return (_c = (_b = (_a = this.metadata) == null ? void 0 : _a.outputs) == null ? void 0 : _b.getByClassPropertyName(propName)) != null ? _c : void 0; } }; var PipeExtractor = class extends ClassExtractor { reference; metadata; constructor(declaration, reference, metadata, typeChecker) { super(declaration, typeChecker); this.reference = reference; this.metadata = metadata; } extract() { return { ...super.extract(), pipeName: this.metadata.name, entryType: EntryType.Pipe, isStandalone: this.metadata.isStandalone }; } }; var NgModuleExtractor = class extends ClassExtractor { reference; metadata; constructor(declaration, reference, metadata, typeChecker) { super(declaration, typeChecker); this.reference = reference; this.metadata = metadata; } extract() { return { ...super.extract(), entryType: EntryType.NgModule }; } }; function extractClass(classDeclaration, metadataReader, typeChecker) { const ref = new Reference(classDeclaration); let extractor; let directiveMetadata = metadataReader.getDirectiveMetadata(ref); let pipeMetadata = metadataReader.getPipeMetadata(ref); let ngModuleMetadata = metadataReader.getNgModuleMetadata(ref); if (directiveMetadata) { extractor = new DirectiveExtractor(classDeclaration, ref, directiveMetadata, typeChecker); } else if (pipeMetadata) { extractor = new PipeExtractor(classDeclaration, ref, pipeMetadata, typeChecker); } else if (ngModuleMetadata) { extractor = new NgModuleExtractor(classDeclaration, ref, ngModuleMetadata, typeChecker); } else { extractor = new ClassExtractor(classDeclaration, typeChecker); } return extractor.extract(); } function extractInterface(declaration, typeChecker) { const extractor = new ClassExtractor(declaration, typeChecker); return extractor.extract(); } // bazel-out/k8-fastbuild/bin/packages/compiler-cli/src/ngtsc/docs/src/constant_extractor.mjs import ts7 from "typescript"; var LITERAL_AS_ENUM_TAG = "object-literal-as-enum"; function extractConstant(declaration, typeChecker) { const resolvedType = typeChecker.getBaseTypeOfLiteralType(typeChecker.getTypeAtLocation(declaration)); const rawComment = extractRawJsDoc(declaration.parent.parent); const jsdocTags = extractJsDocTags(declaration); const description = extractJsDocDescription(declaration); const name = declaration.name.getText(); if (jsdocTags.some((tag) => tag.name === LITERAL_AS_ENUM_TAG)) { return { name, entryType: EntryType.Enum, members: extractLiteralPropertiesAsEnumMembers(declaration), rawComment, description, jsdocTags: jsdocTags.filter((tag) => tag.name !== LITERAL_AS_ENUM_TAG) }; } return { name, type: typeChecker.typeToString(resolvedType), entryType: EntryType.Constant, rawComment, description, jsdocTags }; } function isSyntheticAngularConstant(declaration) { return declaration.name.getText() === "USED_FOR_NG_TYPE_CHECKING"; } function extractLiteralPropertiesAsEnumMembers(declaration) { let initializer = declaration.initializer; while (initializer && (ts7.isAsExpression(initializer) || ts7.isParenthesizedExpression(initializer))) { initializer = initializer.expression; } if (initializer === void 0 || !ts7.isObjectLiteralExpression(initializer)) { throw new Error(`Declaration tagged with "${LITERAL_AS_ENUM_TAG}" must be initialized to an object literal, but received ${initializer ? ts7.SyntaxKind[initializer.kind] : "undefined"}`); } return initializer.properties.map((prop) => { if (!ts7.isPropertyAssignment(prop) || !ts7.isIdentifier(prop.name)) { throw new Error(`Property in declaration tagged with "${LITERAL_AS_ENUM_TAG}" must be a property assignment with a static name`); } if (!ts7.isNumericLiteral(prop.initializer) && !ts7.isStringLiteralLike(prop.initializer)) { throw new Error(`Property in declaration tagged with "${LITERAL_AS_ENUM_TAG}" must be initialized to a number or string literal`); } return { name: prop.name.text, type: `${declaration.name.getText()}.${prop.name.text}`, value: prop.initializer.getText(), memberType: MemberType.EnumItem, jsdocTags: extractJsDocTags(prop), description: extractJsDocDescription(prop), memberTags: [] }; }); } // bazel-out/k8-fastbuild/bin/packages/compiler-cli/src/ngtsc/docs/src/decorator_extractor.mjs import ts8 from "typescript"; function extractorDecorator(declaration, typeChecker) { const documentedNode = getDecoratorJsDocNode(declaration); const decoratorType = getDecoratorType(declaration); if (!decoratorType) { throw new Error(`"${declaration.name.getText()} is not a decorator."`); } return { name: declaration.name.getText(), decoratorType, entryType: EntryType.Decorator, rawComment: extractRawJsDoc(documentedNode), description: extractJsDocDescription(documentedNode), jsdocTags: extractJsDocTags(documentedNode), members: getDecoratorOptions(declaration, typeChecker) }; } function isDecoratorDeclaration(declaration) { return !!getDecoratorType(declaration); } function isDecoratorOptionsInterface(declaration) { return declaration.getSourceFile().statements.some((s) => ts8.isVariableStatement(s) && s.declarationList.declarations.some((d) => isDecoratorDeclaration(d) && d.name.getText() === declaration.name.getText())); } function getDecoratorType(declaration) { var _a, _b; const initializer = (_b = (_a = declaration.initializer) == null ? void 0 : _a.getFullText()) != null ? _b : ""; if (initializer.includes("makeDecorator")) return DecoratorType.Class; if (initializer.includes("makePropDecorator")) return DecoratorType.Member; if (initializer.includes("makeParamDecorator")) return DecoratorType.Parameter; return void 0; } function getDecoratorOptions(declaration, typeChecker) { var _a, _b; const name = declaration.name.getText(); const optionsDeclaration = declaration.getSourceFile().statements.find((node) => { return (ts8.isInterfaceDeclaration(node) || ts8.isTypeAliasDeclaration(node)) && node.name.getText() === name; }); if (!optionsDeclaration) { throw new Error(`Decorator "${name}" has no corresponding options interface.`); } let optionsInterface; if (ts8.isTypeAliasDeclaration(optionsDeclaration)) { const aliasedType = typeChecker.getTypeAtLocation(optionsDeclaration.type); optionsInterface = ((_b = (_a = aliasedType.getSymbol()) == null ? void 0 : _a.getDeclarations()) != null ? _b : []).find((d) => ts8.isInterfaceDeclaration(d)); } else { optionsInterface = optionsDeclaration; } if (!optionsInterface || !ts8.isInterfaceDeclaration(optionsInterface)) { throw new Error(`Options for decorator "${name}" is not an interface.`); } return extractInterface(optionsInterface, typeChecker).members; } function getDecoratorJsDocNode(declaration) { const name = declaration.name.getText(); const decoratorInterface = declaration.getSourceFile().statements.find((s) => { return ts8.isInterfaceDeclaration(s) && s.name.getText() === `${name}Decorator`; }); if (!decoratorInterface || !ts8.isInterfaceDeclaration(decoratorInterface)) { throw new Error(`No interface "${name}Decorator" found.`); } const callSignature = decoratorInterface.members.find((node) => { return ts8.isCallSignatureDeclaration(node) && extractRawJsDoc(node); }); if (!callSignature || !ts8.isCallSignatureDeclaration(callSignature)) { throw new Error(`No call signature with JsDoc on "${name}Decorator"`); } return callSignature; } // bazel-out/k8-fastbuild/bin/packages/compiler-cli/src/ngtsc/docs/src/enum_extractor.mjs import ts9 from "typescript"; function extractEnum(declaration, typeChecker) { return { name: declaration.name.getText(), entryType: EntryType.Enum, members: extractEnumMembers(declaration, typeChecker), rawComment: extractRawJsDoc(declaration), description: extractJsDocDescription(declaration), jsdocTags: extractJsDocTags(declaration) }; } function extractEnumMembers(declaration, checker) { return declaration.members.map((member) => ({ name: member.name.getText(), type: extractResolvedTypeString(member, checker), value: getEnumMemberValue(member), memberType: MemberType.EnumItem, jsdocTags: extractJsDocTags(member), description: extractJsDocDescription(member), memberTags: [] })); } function getEnumMemberValue(memberNode) { var _a; const literal = memberNode.getChildren().find((n) => { return ts9.isNumericLiteral(n) || ts9.isStringLiteral(n) || ts9.isPrefixUnaryExpression(n) && n.operator === ts9.SyntaxKind.MinusToken && ts9.isNumericLiteral(n.operand); }); return (_a = literal == null ? void 0 : literal.getText()) != null ? _a : ""; } // bazel-out/k8-fastbuild/bin/packages/compiler-cli/src/ngtsc/docs/src/initializer_api_function_extractor.mjs import ts10 from "typescript"; var initializerApiTag = "initializerApiFunction"; function isInitializerApiFunction(node, typeChecker) { if (ts10.isFunctionDeclaration(node) && node.name !== void 0 && node.body === void 0) { const implementation = findImplementationOfFunction(node, typeChecker); if (implementation !== void 0) { node = implementation; } } if (!ts10.isFunctionDeclaration(node) && !ts10.isVariableDeclaration(node)) { return false; } let tagContainer = ts10.isFunctionDeclaration(node) ? node : getContainerVariableStatement(node); if (tagContainer === null) { return false; } const tags = ts10.getJSDocTags(tagContainer); return tags.some((t) => t.tagName.text === initializerApiTag); } function extractInitializerApiFunction(node, typeChecker) { var _a; if (node.name === void 0 || !ts10.isIdentifier(node.name)) { throw new Error(`Initializer API: Expected literal variable name.`); } const container = ts10.isFunctionDeclaration(node) ? node : getContainerVariableStatement(node); if (container === null) { throw new Error("Initializer API: Could not find container AST node of variable."); } const name = node.name.text; const type = typeChecker.getTypeAtLocation(node); const callFunction = extractFunctionWithOverloads(name, type, typeChecker); const subFunctions = []; for (const property of type.getProperties()) { const subName = property.getName(); const subDecl = (_a = property.getDeclarations()) == null ? void 0 : _a[0]; if (subDecl === void 0 || !ts10.isPropertySignature(subDecl)) { throw new Error(`Initializer API: Could not resolve declaration of sub-property: ${name}.${subName}`); } const subType = typeChecker.getTypeAtLocation(subDecl); subFunctions.push(extractFunctionWithOverloads(subName, subType, typeChecker)); } let jsdocTags; let description; let rawComment; if (ts10.isFunctionDeclaration(node)) { const implementation = findImplementationOfFunction(node, typeChecker); if (implementation === void 0) { throw new Error(`Initializer API: Could not find implementation of function: ${name}`); } callFunction.implementation = { name, entryType: EntryType.Function, isNewType: false, description: extractJsDocDescription(implementation), generics: extractGenerics(implementation), jsdocTags: extractJsDocTags(implementation), params: extractAllParams(implementation.parameters, typeChecker), rawComment: extractRawJsDoc(implementation), returnType: typeChecker.typeToString(typeChecker.getReturnTypeOfSignature(typeChecker.getSignatureFromDeclaration(implementation))) }; jsdocTags = callFunction.implementation.jsdocTags; description = callFunction.implementation.description; rawComment = callFunction.implementation.description; } else { jsdocTags = extractJsDocTags(container); description = extractJsDocDescription(container); rawComment = extractRawJsDoc(container); } const metadataTag = jsdocTags.find((t) => t.name === initializerApiTag); if (metadataTag === void 0) { throw new Error(`Initializer API: Detected initializer API function does not have "@initializerApiFunction" tag: ${name}`); } let parsedMetadata = void 0; if (metadataTag.comment.trim() !== "") { try { parsedMetadata = JSON.parse(metadataTag.comment); } catch (e) { throw new Error(`Could not parse initializer API function metadata: ${e}`); } } return { entryType: EntryType.InitializerApiFunction, name, description, jsdocTags, rawComment, callFunction, subFunctions, __docsMetadata__: parsedMetadata }; } function getContainerVariableStatement(node) { if (!ts10.isVariableDeclarationList(node.parent)) { return null; } if (!ts10.isVariableStatement(node.parent.parent)) { return null; } return node.parent.parent; } function extractFunctionWithOverloads(name, type, typeChecker) { return { name, signatures: extractCallSignatures(name, typeChecker, type), implementation: null }; } // bazel-out/k8-fastbuild/bin/packages/compiler-cli/src/ngtsc/docs/src/type_alias_extractor.mjs function extractTypeAlias(declaration) { return { name: declaration.name.getText(), type: declaration.type.getText(), entryType: EntryType.TypeAlias, generics: extractGenerics(declaration), rawComment: extractRawJsDoc(declaration), description: extractJsDocDescription(declaration), jsdocTags: extractJsDocTags(declaration) }; } // bazel-out/k8-fastbuild/bin/packages/compiler-cli/src/ngtsc/docs/src/import_extractor.mjs import ts11 from "typescript"; function getImportedSymbols(sourceFile) { const importSpecifiers = /* @__PURE__ */ new Map(); function visit(node) { var _a; if (ts11.isImportDeclaration(node)) { let moduleSpecifier = node.moduleSpecifier.getText(sourceFile).replace(/['"]/g, ""); if (moduleSpecifier.startsWith("@angular/")) { const namedBindings = (_a = node.importClause) == null ? void 0 : _a.namedBindings; if (namedBindings && ts11.isNamedImports(namedBindings)) { namedBindings.elements.forEach((importSpecifier) => { const importName = importSpecifier.name.text; const importAlias = importSpecifier.propertyName ? importSpecifier.propertyName.text : void 0; importSpecifiers.set(importAlias != null ? importAlias : importName, moduleSpecifier); }); } } } ts11.forEachChild(node, visit); } visit(sourceFile); return importSpecifiers; } // bazel-out/k8-fastbuild/bin/packages/compiler-cli/src/ngtsc/docs/src/extractor.mjs var DocsExtractor = class { typeChecker; metadataReader; constructor(typeChecker, metadataReader) { this.typeChecker = typeChecker; this.metadataReader = metadataReader; } extractAll(sourceFile, rootDir, privateModules) { const entries = []; const symbols = /* @__PURE__ */ new Map(); const exportedDeclarations = this.getExportedDeclarations(sourceFile); for (const [exportName, node] of exportedDeclarations) { if (isAngularPrivateName(exportName)) { continue; } const entry = this.extractDeclaration(node); if (entry && !isIgnoredDocEntry(entry)) { const realSourceFile = node.getSourceFile(); const importedSymbols = getImportedSymbols(realSourceFile); importedSymbols.forEach((moduleName, symbolName) => { if (symbolName.startsWith("\u0275") || privateModules.has(moduleName)) { return; } if (symbols.has(symbolName) && symbols.get(symbolName) !== moduleName) { throw new Error(`Ambigous symbol \`${symbolName}\` exported by both ${symbols.get(symbolName)} & ${moduleName}`); } symbols.set(symbolName, moduleName); }); entry.source = { filePath: getRelativeFilePath(realSourceFile, rootDir), startLine: ts12.getLineAndCharacterOfPosition(realSourceFile, node.getStart()).line + 1, endLine: ts12.getLineAndCharacterOfPosition(realSourceFile, node.getEnd()).line + 1 }; entries.push({ ...entry, name: exportName }); } } return { entries, symbols }; } extractDeclaration(node) { if (isNamedClassDeclaration(node)) { return extractClass(node, this.metadataReader, this.typeChecker); } if (isInitializerApiFunction(node, this.typeChecker)) { return extractInitializerApiFunction(node, this.typeChecker); } if (ts12.isInterfaceDeclaration(node) && !isIgnoredInterface(node)) { return extractInterface(node, this.typeChecker); } if (ts12.isFunctionDeclaration(node)) { const functionExtractor = new FunctionExtractor(node.name.getText(), node, this.typeChecker); return functionExtractor.extract(); } if (ts12.isVariableDeclaration(node) && !isSyntheticAngularConstant(node)) { return isDecoratorDeclaration(node) ? extractorDecorator(node, this.typeChecker) : extractConstant(node, this.typeChecker); } if (ts12.isTypeAliasDeclaration(node)) { return extractTypeAlias(node); } if (ts12.isEnumDeclaration(node)) { return extractEnum(node, this.typeChecker); } return null; } getExportedDeclarations(sourceFile) { var _a; const reflector = new TypeScriptReflectionHost(this.typeChecker, false, true); const exportedDeclarationMap = reflector.getExportsOfModule(sourceFile); let exportedDeclarations = Array.from((_a = exportedDeclarationMap == null ? void 0 : exportedDeclarationMap.entries()) != null ? _a : []).map(([exportName, declaration]) => [exportName, declaration.node]); return exportedDeclarations.sort(([a, declarationA], [b, declarationB]) => declarationA.pos - declarationB.pos); } }; function isIgnoredInterface(node) { return node.name.getText().endsWith("Decorator") || isDecoratorOptionsInterface(node); } function isIgnoredDocEntry(entry) { const isDocsPrivate = entry.jsdocTags.find((e) => e.name === "docsPrivate"); if (isDocsPrivate !== void 0 && isDocsPrivate.comment === "") { throw new Error(`Docs extraction: Entry "${entry.name}" is marked as "@docsPrivate" but without reasoning.`); } return isDocsPrivate !== void 0; } function getRelativeFilePath(sourceFile, rootDir) { const fullPath = sourceFile.fileName; const relativePath = fullPath.replace(rootDir, ""); return relativePath; } // bazel-out/k8-fastbuild/bin/packages/compiler-cli/src/ngtsc/program.mjs import { HtmlParser, MessageBundle } from "@angular/compiler"; import ts27 from "typescript"; // bazel-out/k8-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/k8-fastbuild/bin/packages/compiler-cli/src/typescript_support.mjs import ts13 from "typescript"; // bazel-out/k8-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/k8-fastbuild/bin/packages/compiler-cli/src/typescript_support.mjs var MIN_TS_VERSION = "5.5.0"; var MAX_TS_VERSION = "5.9.0"; var tsVersion = ts13.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/k8-fastbuild/bin/packages/compiler-cli/src/ngtsc/core/src/compiler.mjs import { R3Identifiers } from "@angular/compiler"; import ts25 from "typescript"; // bazel-out/k8-fastbuild/bin/packages/compiler-cli/src/ngtsc/cycles/src/analyzer.mjs var CycleAnalyzer = class { importGraph; cachedResults = null; constructor(importGraph) { this.importGraph = importGraph; } 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 { from; importGraph; cyclic = {}; acyclic = {}; constructor(from, importGraph) { this.from = from; this.importGraph = importGraph; } 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 { importGraph; from; to; 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/k8-fastbuild/bin/packages/compiler-cli/src/ngtsc/cycles/src/imports.mjs import ts14 from "typescript"; var ImportGraph = class { checker; perf; imports = /* @__PURE__ */ new Map(); constructor(checker, perf) { this.checker = checker; this.perf = perf; } 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 (!ts14.isImportDeclaration(stmt) && !ts14.isExportDeclaration(stmt) || stmt.moduleSpecifier === void 0) { continue; } if (ts14.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 (ts14.isSourceFile(moduleFile) && isLocalFile(moduleFile)) {