689 lines
23 KiB
JavaScript
Executable File
689 lines
23 KiB
JavaScript
Executable File
|
|
import {createRequire as __cjsCompatRequire} from 'module';
|
|
const require = __cjsCompatRequire(import.meta.url);
|
|
const __ESM_IMPORT_META_URL__ = import.meta.url;
|
|
|
|
import {
|
|
getDecorators,
|
|
getModifiers
|
|
} from "./chunk-DSVWG4QJ.js";
|
|
|
|
// bazel-out/k8-fastbuild/bin/packages/compiler-cli/src/ngtsc/reflection/src/typescript.mjs
|
|
import ts4 from "typescript";
|
|
|
|
// bazel-out/k8-fastbuild/bin/packages/compiler-cli/src/ngtsc/reflection/src/host.mjs
|
|
import ts from "typescript";
|
|
var Decorator = {
|
|
nodeForError: (decorator) => {
|
|
if (decorator.node !== null) {
|
|
return decorator.node;
|
|
} else {
|
|
return decorator.synthesizedFor;
|
|
}
|
|
}
|
|
};
|
|
function isDecoratorIdentifier(exp) {
|
|
return ts.isIdentifier(exp) || ts.isPropertyAccessExpression(exp) && ts.isIdentifier(exp.expression) && ts.isIdentifier(exp.name);
|
|
}
|
|
var ClassMemberKind;
|
|
(function(ClassMemberKind2) {
|
|
ClassMemberKind2[ClassMemberKind2["Constructor"] = 0] = "Constructor";
|
|
ClassMemberKind2[ClassMemberKind2["Getter"] = 1] = "Getter";
|
|
ClassMemberKind2[ClassMemberKind2["Setter"] = 2] = "Setter";
|
|
ClassMemberKind2[ClassMemberKind2["Property"] = 3] = "Property";
|
|
ClassMemberKind2[ClassMemberKind2["Method"] = 4] = "Method";
|
|
})(ClassMemberKind || (ClassMemberKind = {}));
|
|
var KnownDeclaration;
|
|
(function(KnownDeclaration2) {
|
|
KnownDeclaration2[KnownDeclaration2["JsGlobalObject"] = 0] = "JsGlobalObject";
|
|
KnownDeclaration2[KnownDeclaration2["TsHelperAssign"] = 1] = "TsHelperAssign";
|
|
KnownDeclaration2[KnownDeclaration2["TsHelperSpread"] = 2] = "TsHelperSpread";
|
|
KnownDeclaration2[KnownDeclaration2["TsHelperSpreadArrays"] = 3] = "TsHelperSpreadArrays";
|
|
KnownDeclaration2[KnownDeclaration2["TsHelperSpreadArray"] = 4] = "TsHelperSpreadArray";
|
|
KnownDeclaration2[KnownDeclaration2["TsHelperRead"] = 5] = "TsHelperRead";
|
|
})(KnownDeclaration || (KnownDeclaration = {}));
|
|
function isConcreteDeclaration(decl) {
|
|
return decl.kind === 0;
|
|
}
|
|
|
|
// bazel-out/k8-fastbuild/bin/packages/compiler-cli/src/ngtsc/reflection/src/type_to_value.mjs
|
|
import ts2 from "typescript";
|
|
function typeToValue(typeNode, checker) {
|
|
if (typeNode === null) {
|
|
return missingType();
|
|
}
|
|
if (!ts2.isTypeReferenceNode(typeNode)) {
|
|
return unsupportedType(typeNode);
|
|
}
|
|
const symbols = resolveTypeSymbols(typeNode, checker);
|
|
if (symbols === null) {
|
|
return unknownReference(typeNode);
|
|
}
|
|
const { local, decl } = symbols;
|
|
if (decl.valueDeclaration === void 0 || decl.flags & ts2.SymbolFlags.ConstEnum) {
|
|
let typeOnlyDecl = null;
|
|
if (decl.declarations !== void 0 && decl.declarations.length > 0) {
|
|
typeOnlyDecl = decl.declarations[0];
|
|
}
|
|
return noValueDeclaration(typeNode, typeOnlyDecl);
|
|
}
|
|
const firstDecl = local.declarations && local.declarations[0];
|
|
if (firstDecl !== void 0) {
|
|
if (ts2.isImportClause(firstDecl) && firstDecl.name !== void 0) {
|
|
if (firstDecl.isTypeOnly) {
|
|
return typeOnlyImport(typeNode, firstDecl);
|
|
}
|
|
return {
|
|
kind: 0,
|
|
expression: firstDecl.name,
|
|
defaultImportStatement: firstDecl.parent
|
|
};
|
|
} else if (ts2.isImportSpecifier(firstDecl)) {
|
|
if (firstDecl.isTypeOnly) {
|
|
return typeOnlyImport(typeNode, firstDecl);
|
|
}
|
|
if (firstDecl.parent.parent.isTypeOnly) {
|
|
return typeOnlyImport(typeNode, firstDecl.parent.parent);
|
|
}
|
|
const importedName = (firstDecl.propertyName || firstDecl.name).text;
|
|
const [_localName, ...nestedPath] = symbols.symbolNames;
|
|
const moduleName = extractModuleName(firstDecl.parent.parent.parent);
|
|
return {
|
|
kind: 1,
|
|
valueDeclaration: decl.valueDeclaration,
|
|
moduleName,
|
|
importedName,
|
|
nestedPath
|
|
};
|
|
} else if (ts2.isNamespaceImport(firstDecl)) {
|
|
if (firstDecl.parent.isTypeOnly) {
|
|
return typeOnlyImport(typeNode, firstDecl.parent);
|
|
}
|
|
if (symbols.symbolNames.length === 1) {
|
|
return namespaceImport(typeNode, firstDecl.parent);
|
|
}
|
|
const [_ns, importedName, ...nestedPath] = symbols.symbolNames;
|
|
const moduleName = extractModuleName(firstDecl.parent.parent);
|
|
return {
|
|
kind: 1,
|
|
valueDeclaration: decl.valueDeclaration,
|
|
moduleName,
|
|
importedName,
|
|
nestedPath
|
|
};
|
|
}
|
|
}
|
|
const expression = typeNodeToValueExpr(typeNode);
|
|
if (expression !== null) {
|
|
return {
|
|
kind: 0,
|
|
expression,
|
|
defaultImportStatement: null
|
|
};
|
|
} else {
|
|
return unsupportedType(typeNode);
|
|
}
|
|
}
|
|
function unsupportedType(typeNode) {
|
|
return {
|
|
kind: 2,
|
|
reason: { kind: 5, typeNode }
|
|
};
|
|
}
|
|
function noValueDeclaration(typeNode, decl) {
|
|
return {
|
|
kind: 2,
|
|
reason: { kind: 1, typeNode, decl }
|
|
};
|
|
}
|
|
function typeOnlyImport(typeNode, node) {
|
|
return {
|
|
kind: 2,
|
|
reason: { kind: 2, typeNode, node }
|
|
};
|
|
}
|
|
function unknownReference(typeNode) {
|
|
return {
|
|
kind: 2,
|
|
reason: { kind: 3, typeNode }
|
|
};
|
|
}
|
|
function namespaceImport(typeNode, importClause) {
|
|
return {
|
|
kind: 2,
|
|
reason: { kind: 4, typeNode, importClause }
|
|
};
|
|
}
|
|
function missingType() {
|
|
return {
|
|
kind: 2,
|
|
reason: { kind: 0 }
|
|
};
|
|
}
|
|
function typeNodeToValueExpr(node) {
|
|
if (ts2.isTypeReferenceNode(node)) {
|
|
return entityNameToValue(node.typeName);
|
|
} else {
|
|
return null;
|
|
}
|
|
}
|
|
function resolveTypeSymbols(typeRef, checker) {
|
|
const typeName = typeRef.typeName;
|
|
const typeRefSymbol = checker.getSymbolAtLocation(typeName);
|
|
if (typeRefSymbol === void 0) {
|
|
return null;
|
|
}
|
|
let local = typeRefSymbol;
|
|
let leftMost = typeName;
|
|
const symbolNames = [];
|
|
while (ts2.isQualifiedName(leftMost)) {
|
|
symbolNames.unshift(leftMost.right.text);
|
|
leftMost = leftMost.left;
|
|
}
|
|
symbolNames.unshift(leftMost.text);
|
|
if (leftMost !== typeName) {
|
|
const localTmp = checker.getSymbolAtLocation(leftMost);
|
|
if (localTmp !== void 0) {
|
|
local = localTmp;
|
|
}
|
|
}
|
|
let decl = typeRefSymbol;
|
|
if (typeRefSymbol.flags & ts2.SymbolFlags.Alias) {
|
|
decl = checker.getAliasedSymbol(typeRefSymbol);
|
|
}
|
|
return { local, decl, symbolNames };
|
|
}
|
|
function entityNameToValue(node) {
|
|
if (ts2.isQualifiedName(node)) {
|
|
const left = entityNameToValue(node.left);
|
|
return left !== null ? ts2.factory.createPropertyAccessExpression(left, node.right) : null;
|
|
} else if (ts2.isIdentifier(node)) {
|
|
const clone = ts2.setOriginalNode(ts2.factory.createIdentifier(node.text), node);
|
|
clone.parent = node.parent;
|
|
return clone;
|
|
} else {
|
|
return null;
|
|
}
|
|
}
|
|
function extractModuleName(node) {
|
|
if (!ts2.isStringLiteral(node.moduleSpecifier)) {
|
|
throw new Error("not a module specifier");
|
|
}
|
|
return node.moduleSpecifier.text;
|
|
}
|
|
|
|
// bazel-out/k8-fastbuild/bin/packages/compiler-cli/src/ngtsc/reflection/src/util.mjs
|
|
import ts3 from "typescript";
|
|
function isNamedClassDeclaration(node) {
|
|
return ts3.isClassDeclaration(node) && isIdentifier(node.name);
|
|
}
|
|
function isNamedFunctionDeclaration(node) {
|
|
return ts3.isFunctionDeclaration(node) && isIdentifier(node.name);
|
|
}
|
|
function isNamedVariableDeclaration(node) {
|
|
return ts3.isVariableDeclaration(node) && isIdentifier(node.name);
|
|
}
|
|
function isIdentifier(node) {
|
|
return node !== void 0 && ts3.isIdentifier(node);
|
|
}
|
|
|
|
// bazel-out/k8-fastbuild/bin/packages/compiler-cli/src/ngtsc/reflection/src/typescript.mjs
|
|
var TypeScriptReflectionHost = class {
|
|
constructor(checker) {
|
|
this.checker = checker;
|
|
}
|
|
getDecoratorsOfDeclaration(declaration) {
|
|
const decorators = getDecorators(declaration);
|
|
return decorators !== void 0 && decorators.length ? decorators.map((decorator) => this._reflectDecorator(decorator)).filter((dec) => dec !== null) : null;
|
|
}
|
|
getMembersOfClass(clazz) {
|
|
const tsClazz = castDeclarationToClassOrDie(clazz);
|
|
return tsClazz.members.map((member) => this._reflectMember(member)).filter((member) => member !== null);
|
|
}
|
|
getConstructorParameters(clazz) {
|
|
const tsClazz = castDeclarationToClassOrDie(clazz);
|
|
const isDeclaration = tsClazz.getSourceFile().isDeclarationFile;
|
|
const ctor = tsClazz.members.find((member) => ts4.isConstructorDeclaration(member) && (isDeclaration || member.body !== void 0));
|
|
if (ctor === void 0) {
|
|
return null;
|
|
}
|
|
return ctor.parameters.map((node) => {
|
|
const name = parameterName(node.name);
|
|
const decorators = this.getDecoratorsOfDeclaration(node);
|
|
let originalTypeNode = node.type || null;
|
|
let typeNode = originalTypeNode;
|
|
if (typeNode && ts4.isUnionTypeNode(typeNode)) {
|
|
let childTypeNodes = typeNode.types.filter((childTypeNode) => !(ts4.isLiteralTypeNode(childTypeNode) && childTypeNode.literal.kind === ts4.SyntaxKind.NullKeyword));
|
|
if (childTypeNodes.length === 1) {
|
|
typeNode = childTypeNodes[0];
|
|
}
|
|
}
|
|
const typeValueReference = typeToValue(typeNode, this.checker);
|
|
return {
|
|
name,
|
|
nameNode: node.name,
|
|
typeValueReference,
|
|
typeNode: originalTypeNode,
|
|
decorators
|
|
};
|
|
});
|
|
}
|
|
getImportOfIdentifier(id) {
|
|
const directImport = this.getDirectImportOfIdentifier(id);
|
|
if (directImport !== null) {
|
|
return directImport;
|
|
} else if (ts4.isQualifiedName(id.parent) && id.parent.right === id) {
|
|
return this.getImportOfNamespacedIdentifier(id, getQualifiedNameRoot(id.parent));
|
|
} else if (ts4.isPropertyAccessExpression(id.parent) && id.parent.name === id) {
|
|
return this.getImportOfNamespacedIdentifier(id, getFarLeftIdentifier(id.parent));
|
|
} else {
|
|
return null;
|
|
}
|
|
}
|
|
getExportsOfModule(node) {
|
|
if (!ts4.isSourceFile(node)) {
|
|
throw new Error(`getExportsOfModule() called on non-SourceFile in TS code`);
|
|
}
|
|
const symbol = this.checker.getSymbolAtLocation(node);
|
|
if (symbol === void 0) {
|
|
return null;
|
|
}
|
|
const map = /* @__PURE__ */ new Map();
|
|
this.checker.getExportsOfModule(symbol).forEach((exportSymbol) => {
|
|
const decl = this.getDeclarationOfSymbol(exportSymbol, null);
|
|
if (decl !== null) {
|
|
map.set(exportSymbol.name, decl);
|
|
}
|
|
});
|
|
return map;
|
|
}
|
|
isClass(node) {
|
|
return isNamedClassDeclaration(node);
|
|
}
|
|
hasBaseClass(clazz) {
|
|
return this.getBaseClassExpression(clazz) !== null;
|
|
}
|
|
getBaseClassExpression(clazz) {
|
|
if (!(ts4.isClassDeclaration(clazz) || ts4.isClassExpression(clazz)) || clazz.heritageClauses === void 0) {
|
|
return null;
|
|
}
|
|
const extendsClause = clazz.heritageClauses.find((clause) => clause.token === ts4.SyntaxKind.ExtendsKeyword);
|
|
if (extendsClause === void 0) {
|
|
return null;
|
|
}
|
|
const extendsType = extendsClause.types[0];
|
|
if (extendsType === void 0) {
|
|
return null;
|
|
}
|
|
return extendsType.expression;
|
|
}
|
|
getDeclarationOfIdentifier(id) {
|
|
let symbol = this.checker.getSymbolAtLocation(id);
|
|
if (symbol === void 0) {
|
|
return null;
|
|
}
|
|
return this.getDeclarationOfSymbol(symbol, id);
|
|
}
|
|
getDefinitionOfFunction(node) {
|
|
if (!ts4.isFunctionDeclaration(node) && !ts4.isMethodDeclaration(node) && !ts4.isFunctionExpression(node)) {
|
|
return null;
|
|
}
|
|
return {
|
|
node,
|
|
body: node.body !== void 0 ? Array.from(node.body.statements) : null,
|
|
parameters: node.parameters.map((param) => {
|
|
const name = parameterName(param.name);
|
|
const initializer = param.initializer || null;
|
|
return { name, node: param, initializer };
|
|
})
|
|
};
|
|
}
|
|
getGenericArityOfClass(clazz) {
|
|
if (!ts4.isClassDeclaration(clazz)) {
|
|
return null;
|
|
}
|
|
return clazz.typeParameters !== void 0 ? clazz.typeParameters.length : 0;
|
|
}
|
|
getVariableValue(declaration) {
|
|
return declaration.initializer || null;
|
|
}
|
|
getDtsDeclaration(_) {
|
|
return null;
|
|
}
|
|
getInternalNameOfClass(clazz) {
|
|
return clazz.name;
|
|
}
|
|
getAdjacentNameOfClass(clazz) {
|
|
return clazz.name;
|
|
}
|
|
isStaticallyExported(decl) {
|
|
let topLevel = decl;
|
|
if (ts4.isVariableDeclaration(decl) && ts4.isVariableDeclarationList(decl.parent)) {
|
|
topLevel = decl.parent.parent;
|
|
}
|
|
const modifiers = getModifiers(topLevel);
|
|
if (modifiers !== void 0 && modifiers.some((modifier) => modifier.kind === ts4.SyntaxKind.ExportKeyword)) {
|
|
return true;
|
|
}
|
|
if (topLevel.parent === void 0 || !ts4.isSourceFile(topLevel.parent)) {
|
|
return false;
|
|
}
|
|
const localExports = this.getLocalExportedDeclarationsOfSourceFile(decl.getSourceFile());
|
|
return localExports.has(decl);
|
|
}
|
|
getDirectImportOfIdentifier(id) {
|
|
const symbol = this.checker.getSymbolAtLocation(id);
|
|
if (symbol === void 0 || symbol.declarations === void 0 || symbol.declarations.length !== 1) {
|
|
return null;
|
|
}
|
|
const decl = symbol.declarations[0];
|
|
const importDecl = getContainingImportDeclaration(decl);
|
|
if (importDecl === null) {
|
|
return null;
|
|
}
|
|
if (!ts4.isStringLiteral(importDecl.moduleSpecifier)) {
|
|
return null;
|
|
}
|
|
return { from: importDecl.moduleSpecifier.text, name: getExportedName(decl, id) };
|
|
}
|
|
getImportOfNamespacedIdentifier(id, namespaceIdentifier) {
|
|
if (namespaceIdentifier === null) {
|
|
return null;
|
|
}
|
|
const namespaceSymbol = this.checker.getSymbolAtLocation(namespaceIdentifier);
|
|
if (!namespaceSymbol || namespaceSymbol.declarations === void 0) {
|
|
return null;
|
|
}
|
|
const declaration = namespaceSymbol.declarations.length === 1 ? namespaceSymbol.declarations[0] : null;
|
|
if (!declaration) {
|
|
return null;
|
|
}
|
|
const namespaceDeclaration = ts4.isNamespaceImport(declaration) ? declaration : null;
|
|
if (!namespaceDeclaration) {
|
|
return null;
|
|
}
|
|
const importDeclaration = namespaceDeclaration.parent.parent;
|
|
if (!ts4.isStringLiteral(importDeclaration.moduleSpecifier)) {
|
|
return null;
|
|
}
|
|
return {
|
|
from: importDeclaration.moduleSpecifier.text,
|
|
name: id.text
|
|
};
|
|
}
|
|
getDeclarationOfSymbol(symbol, originalId) {
|
|
let valueDeclaration = void 0;
|
|
if (symbol.valueDeclaration !== void 0) {
|
|
valueDeclaration = symbol.valueDeclaration;
|
|
} else if (symbol.declarations !== void 0 && symbol.declarations.length > 0) {
|
|
valueDeclaration = symbol.declarations[0];
|
|
}
|
|
if (valueDeclaration !== void 0 && ts4.isShorthandPropertyAssignment(valueDeclaration)) {
|
|
const shorthandSymbol = this.checker.getShorthandAssignmentValueSymbol(valueDeclaration);
|
|
if (shorthandSymbol === void 0) {
|
|
return null;
|
|
}
|
|
return this.getDeclarationOfSymbol(shorthandSymbol, originalId);
|
|
} else if (valueDeclaration !== void 0 && ts4.isExportSpecifier(valueDeclaration)) {
|
|
const targetSymbol = this.checker.getExportSpecifierLocalTargetSymbol(valueDeclaration);
|
|
if (targetSymbol === void 0) {
|
|
return null;
|
|
}
|
|
return this.getDeclarationOfSymbol(targetSymbol, originalId);
|
|
}
|
|
const importInfo = originalId && this.getImportOfIdentifier(originalId);
|
|
const viaModule = importInfo !== null && importInfo.from !== null && !importInfo.from.startsWith(".") ? importInfo.from : null;
|
|
while (symbol.flags & ts4.SymbolFlags.Alias) {
|
|
symbol = this.checker.getAliasedSymbol(symbol);
|
|
}
|
|
if (symbol.valueDeclaration !== void 0) {
|
|
return {
|
|
node: symbol.valueDeclaration,
|
|
known: null,
|
|
viaModule,
|
|
identity: null,
|
|
kind: 0
|
|
};
|
|
} else if (symbol.declarations !== void 0 && symbol.declarations.length > 0) {
|
|
return {
|
|
node: symbol.declarations[0],
|
|
known: null,
|
|
viaModule,
|
|
identity: null,
|
|
kind: 0
|
|
};
|
|
} else {
|
|
return null;
|
|
}
|
|
}
|
|
_reflectDecorator(node) {
|
|
let decoratorExpr = node.expression;
|
|
let args = null;
|
|
if (ts4.isCallExpression(decoratorExpr)) {
|
|
args = Array.from(decoratorExpr.arguments);
|
|
decoratorExpr = decoratorExpr.expression;
|
|
}
|
|
if (!isDecoratorIdentifier(decoratorExpr)) {
|
|
return null;
|
|
}
|
|
const decoratorIdentifier = ts4.isIdentifier(decoratorExpr) ? decoratorExpr : decoratorExpr.name;
|
|
const importDecl = this.getImportOfIdentifier(decoratorIdentifier);
|
|
return {
|
|
name: decoratorIdentifier.text,
|
|
identifier: decoratorExpr,
|
|
import: importDecl,
|
|
node,
|
|
args
|
|
};
|
|
}
|
|
_reflectMember(node) {
|
|
let kind = null;
|
|
let value = null;
|
|
let name = null;
|
|
let nameNode = null;
|
|
if (ts4.isPropertyDeclaration(node)) {
|
|
kind = ClassMemberKind.Property;
|
|
value = node.initializer || null;
|
|
} else if (ts4.isGetAccessorDeclaration(node)) {
|
|
kind = ClassMemberKind.Getter;
|
|
} else if (ts4.isSetAccessorDeclaration(node)) {
|
|
kind = ClassMemberKind.Setter;
|
|
} else if (ts4.isMethodDeclaration(node)) {
|
|
kind = ClassMemberKind.Method;
|
|
} else if (ts4.isConstructorDeclaration(node)) {
|
|
kind = ClassMemberKind.Constructor;
|
|
} else {
|
|
return null;
|
|
}
|
|
if (ts4.isConstructorDeclaration(node)) {
|
|
name = "constructor";
|
|
} else if (ts4.isIdentifier(node.name)) {
|
|
name = node.name.text;
|
|
nameNode = node.name;
|
|
} else if (ts4.isStringLiteral(node.name)) {
|
|
name = node.name.text;
|
|
nameNode = node.name;
|
|
} else {
|
|
return null;
|
|
}
|
|
const decorators = this.getDecoratorsOfDeclaration(node);
|
|
const modifiers = getModifiers(node);
|
|
const isStatic = modifiers !== void 0 && modifiers.some((mod) => mod.kind === ts4.SyntaxKind.StaticKeyword);
|
|
return {
|
|
node,
|
|
implementation: node,
|
|
kind,
|
|
type: node.type || null,
|
|
name,
|
|
nameNode,
|
|
decorators,
|
|
value,
|
|
isStatic
|
|
};
|
|
}
|
|
getLocalExportedDeclarationsOfSourceFile(file) {
|
|
const cacheSf = file;
|
|
if (cacheSf[LocalExportedDeclarations] !== void 0) {
|
|
return cacheSf[LocalExportedDeclarations];
|
|
}
|
|
const exportSet = /* @__PURE__ */ new Set();
|
|
cacheSf[LocalExportedDeclarations] = exportSet;
|
|
const sfSymbol = this.checker.getSymbolAtLocation(cacheSf);
|
|
if (sfSymbol === void 0 || sfSymbol.exports === void 0) {
|
|
return exportSet;
|
|
}
|
|
const iter = sfSymbol.exports.values();
|
|
let item = iter.next();
|
|
while (item.done !== true) {
|
|
let exportedSymbol = item.value;
|
|
if (exportedSymbol.flags & ts4.SymbolFlags.Alias) {
|
|
exportedSymbol = this.checker.getAliasedSymbol(exportedSymbol);
|
|
}
|
|
if (exportedSymbol.valueDeclaration !== void 0 && exportedSymbol.valueDeclaration.getSourceFile() === file) {
|
|
exportSet.add(exportedSymbol.valueDeclaration);
|
|
}
|
|
item = iter.next();
|
|
}
|
|
return exportSet;
|
|
}
|
|
};
|
|
function reflectTypeEntityToDeclaration(type, checker) {
|
|
let realSymbol = checker.getSymbolAtLocation(type);
|
|
if (realSymbol === void 0) {
|
|
throw new Error(`Cannot resolve type entity ${type.getText()} to symbol`);
|
|
}
|
|
while (realSymbol.flags & ts4.SymbolFlags.Alias) {
|
|
realSymbol = checker.getAliasedSymbol(realSymbol);
|
|
}
|
|
let node = null;
|
|
if (realSymbol.valueDeclaration !== void 0) {
|
|
node = realSymbol.valueDeclaration;
|
|
} else if (realSymbol.declarations !== void 0 && realSymbol.declarations.length === 1) {
|
|
node = realSymbol.declarations[0];
|
|
} else {
|
|
throw new Error(`Cannot resolve type entity symbol to declaration`);
|
|
}
|
|
if (ts4.isQualifiedName(type)) {
|
|
if (!ts4.isIdentifier(type.left)) {
|
|
throw new Error(`Cannot handle qualified name with non-identifier lhs`);
|
|
}
|
|
const symbol = checker.getSymbolAtLocation(type.left);
|
|
if (symbol === void 0 || symbol.declarations === void 0 || symbol.declarations.length !== 1) {
|
|
throw new Error(`Cannot resolve qualified type entity lhs to symbol`);
|
|
}
|
|
const decl = symbol.declarations[0];
|
|
if (ts4.isNamespaceImport(decl)) {
|
|
const clause = decl.parent;
|
|
const importDecl = clause.parent;
|
|
if (!ts4.isStringLiteral(importDecl.moduleSpecifier)) {
|
|
throw new Error(`Module specifier is not a string`);
|
|
}
|
|
return { node, from: importDecl.moduleSpecifier.text };
|
|
} else if (ts4.isModuleDeclaration(decl)) {
|
|
return { node, from: null };
|
|
} else {
|
|
throw new Error(`Unknown import type?`);
|
|
}
|
|
} else {
|
|
return { node, from: null };
|
|
}
|
|
}
|
|
function filterToMembersWithDecorator(members, name, module) {
|
|
return members.filter((member) => !member.isStatic).map((member) => {
|
|
if (member.decorators === null) {
|
|
return null;
|
|
}
|
|
const decorators = member.decorators.filter((dec) => {
|
|
if (dec.import !== null) {
|
|
return dec.import.name === name && (module === void 0 || dec.import.from === module);
|
|
} else {
|
|
return dec.name === name && module === void 0;
|
|
}
|
|
});
|
|
if (decorators.length === 0) {
|
|
return null;
|
|
}
|
|
return { member, decorators };
|
|
}).filter((value) => value !== null);
|
|
}
|
|
function reflectObjectLiteral(node) {
|
|
const map = /* @__PURE__ */ new Map();
|
|
node.properties.forEach((prop) => {
|
|
if (ts4.isPropertyAssignment(prop)) {
|
|
const name = propertyNameToString(prop.name);
|
|
if (name === null) {
|
|
return;
|
|
}
|
|
map.set(name, prop.initializer);
|
|
} else if (ts4.isShorthandPropertyAssignment(prop)) {
|
|
map.set(prop.name.text, prop.name);
|
|
} else {
|
|
return;
|
|
}
|
|
});
|
|
return map;
|
|
}
|
|
function castDeclarationToClassOrDie(declaration) {
|
|
if (!ts4.isClassDeclaration(declaration)) {
|
|
throw new Error(`Reflecting on a ${ts4.SyntaxKind[declaration.kind]} instead of a ClassDeclaration.`);
|
|
}
|
|
return declaration;
|
|
}
|
|
function parameterName(name) {
|
|
if (ts4.isIdentifier(name)) {
|
|
return name.text;
|
|
} else {
|
|
return null;
|
|
}
|
|
}
|
|
function propertyNameToString(node) {
|
|
if (ts4.isIdentifier(node) || ts4.isStringLiteral(node) || ts4.isNumericLiteral(node)) {
|
|
return node.text;
|
|
} else {
|
|
return null;
|
|
}
|
|
}
|
|
function getQualifiedNameRoot(qualifiedName) {
|
|
while (ts4.isQualifiedName(qualifiedName.left)) {
|
|
qualifiedName = qualifiedName.left;
|
|
}
|
|
return ts4.isIdentifier(qualifiedName.left) ? qualifiedName.left : null;
|
|
}
|
|
function getFarLeftIdentifier(propertyAccess) {
|
|
while (ts4.isPropertyAccessExpression(propertyAccess.expression)) {
|
|
propertyAccess = propertyAccess.expression;
|
|
}
|
|
return ts4.isIdentifier(propertyAccess.expression) ? propertyAccess.expression : null;
|
|
}
|
|
function getContainingImportDeclaration(node) {
|
|
return ts4.isImportSpecifier(node) ? node.parent.parent.parent : ts4.isNamespaceImport(node) ? node.parent.parent : null;
|
|
}
|
|
function getExportedName(decl, originalId) {
|
|
return ts4.isImportSpecifier(decl) ? (decl.propertyName !== void 0 ? decl.propertyName : decl.name).text : originalId.text;
|
|
}
|
|
var LocalExportedDeclarations = Symbol("LocalExportedDeclarations");
|
|
|
|
export {
|
|
Decorator,
|
|
isDecoratorIdentifier,
|
|
ClassMemberKind,
|
|
KnownDeclaration,
|
|
isConcreteDeclaration,
|
|
typeNodeToValueExpr,
|
|
isNamedClassDeclaration,
|
|
isNamedFunctionDeclaration,
|
|
isNamedVariableDeclaration,
|
|
TypeScriptReflectionHost,
|
|
reflectTypeEntityToDeclaration,
|
|
filterToMembersWithDecorator,
|
|
reflectObjectLiteral
|
|
};
|
|
/**
|
|
* @license
|
|
* Copyright Google LLC All Rights Reserved.
|
|
*
|
|
* Use of this source code is governed by an MIT-style license that can be
|
|
* found in the LICENSE file at https://angular.io/license
|
|
*/
|
|
//# sourceMappingURL=chunk-ALSLKTUB.js.map
|