1 |
|
2 | import {createRequire as __cjsCompatRequire} from 'module';
|
3 | const require = __cjsCompatRequire(import.meta.url);
|
4 | const __ESM_IMPORT_META_URL__ = import.meta.url;
|
5 |
|
6 | import {
|
7 | CycleAnalyzer,
|
8 | ImportGraph,
|
9 | LocalModuleScopeRegistry,
|
10 | MetadataDtsModuleScopeResolver,
|
11 | TypeCheckScopeRegistry,
|
12 | isShim,
|
13 | readConfiguration
|
14 | } from "./chunk-ZPZWKMTE.js";
|
15 | import {
|
16 | CompilationMode,
|
17 | ComponentDecoratorHandler,
|
18 | CompoundMetadataReader,
|
19 | CompoundMetadataRegistry,
|
20 | DirectiveDecoratorHandler,
|
21 | DtsMetadataReader,
|
22 | DtsTransformRegistry,
|
23 | HandlerFlags,
|
24 | InjectableClassRegistry,
|
25 | InjectableDecoratorHandler,
|
26 | LocalMetadataRegistry,
|
27 | NgModuleDecoratorHandler,
|
28 | PartialEvaluator,
|
29 | PipeDecoratorHandler,
|
30 | ResourceRegistry,
|
31 | TraitCompiler,
|
32 | TraitState,
|
33 | forwardRefResolver,
|
34 | readBaseClass
|
35 | } from "./chunk-KAJ5EOEG.js";
|
36 | import {
|
37 | ClassMemberKind,
|
38 | KnownDeclaration,
|
39 | TypeScriptReflectionHost,
|
40 | isConcreteDeclaration,
|
41 | isDecoratorIdentifier,
|
42 | isNamedClassDeclaration,
|
43 | isNamedFunctionDeclaration,
|
44 | isNamedVariableDeclaration,
|
45 | reflectObjectLiteral
|
46 | } from "./chunk-Q5GIQ3RV.js";
|
47 | import {
|
48 | ConsoleLogger,
|
49 | LogLevel
|
50 | } from "./chunk-LX5Q27EF.js";
|
51 | import {
|
52 | ContentOrigin,
|
53 | SourceFileLoader
|
54 | } from "./chunk-EIFOOEXQ.js";
|
55 | import {
|
56 | AbsoluteModuleStrategy,
|
57 | ImportManager,
|
58 | LocalIdentifierStrategy,
|
59 | LogicalProjectStrategy,
|
60 | ModuleResolver,
|
61 | NoopImportRewriter,
|
62 | PrivateExportAliasingHost,
|
63 | R3SymbolsImportRewriter,
|
64 | Reference,
|
65 | ReferenceEmitter,
|
66 | isAssignment,
|
67 | isDtsPath,
|
68 | isFatalDiagnosticError,
|
69 | isFromDtsFile,
|
70 | isSymbolWithValueDeclaration,
|
71 | replaceTsWithNgInErrors,
|
72 | translateStatement,
|
73 | translateType,
|
74 | validateAndRewriteCoreSymbol
|
75 | } from "./chunk-WXB5AWIG.js";
|
76 | import {
|
77 | LogicalFileSystem,
|
78 | NgtscCompilerHost,
|
79 | absoluteFrom,
|
80 | absoluteFromSourceFile,
|
81 | dirname,
|
82 | getFileSystem,
|
83 | isLocalRelativePath,
|
84 | isRooted,
|
85 | relative,
|
86 | toRelativeImport
|
87 | } from "./chunk-CLV7JFJQ.js";
|
88 | import {
|
89 | NOOP_PERF_RECORDER
|
90 | } from "./chunk-R4NY3TJC.js";
|
91 | import {
|
92 | __spreadProps,
|
93 | __spreadValues
|
94 | } from "./chunk-GMSUYBZP.js";
|
95 |
|
96 |
|
97 | import ts23 from "typescript";
|
98 |
|
99 |
|
100 | import ts7 from "typescript";
|
101 |
|
102 |
|
103 | import ts6 from "typescript";
|
104 |
|
105 |
|
106 | import ts from "typescript";
|
107 | function isDefined(value) {
|
108 | return value !== void 0 && value !== null;
|
109 | }
|
110 | function getNameText(name) {
|
111 | return ts.isIdentifier(name) || ts.isLiteralExpression(name) ? name.text : name.getText();
|
112 | }
|
113 | function hasNameIdentifier(declaration) {
|
114 | const namedDeclaration = declaration;
|
115 | return namedDeclaration.name !== void 0 && ts.isIdentifier(namedDeclaration.name);
|
116 | }
|
117 | function isRelativePath(path) {
|
118 | return isRooted(path) || /^\.\.?(\/|\\|$)/.test(path);
|
119 | }
|
120 | var FactoryMap = class {
|
121 | constructor(factory, entries) {
|
122 | this.factory = factory;
|
123 | this.internalMap = new Map(entries);
|
124 | }
|
125 | get(key) {
|
126 | if (!this.internalMap.has(key)) {
|
127 | this.internalMap.set(key, this.factory(key));
|
128 | }
|
129 | return this.internalMap.get(key);
|
130 | }
|
131 | set(key, value) {
|
132 | this.internalMap.set(key, value);
|
133 | }
|
134 | };
|
135 | function resolveFileWithPostfixes(fs, path, postFixes) {
|
136 | for (const postFix of postFixes) {
|
137 | const testPath = absoluteFrom(path + postFix);
|
138 | if (fs.exists(testPath) && fs.stat(testPath).isFile()) {
|
139 | return testPath;
|
140 | }
|
141 | }
|
142 | return null;
|
143 | }
|
144 | function getTsHelperFnFromDeclaration(decl) {
|
145 | if (!ts.isFunctionDeclaration(decl) && !ts.isVariableDeclaration(decl)) {
|
146 | return null;
|
147 | }
|
148 | if (decl.name === void 0 || !ts.isIdentifier(decl.name)) {
|
149 | return null;
|
150 | }
|
151 | return getTsHelperFnFromIdentifier(decl.name);
|
152 | }
|
153 | function getTsHelperFnFromIdentifier(id) {
|
154 | switch (stripDollarSuffix(id.text)) {
|
155 | case "__assign":
|
156 | return KnownDeclaration.TsHelperAssign;
|
157 | case "__spread":
|
158 | return KnownDeclaration.TsHelperSpread;
|
159 | case "__spreadArrays":
|
160 | return KnownDeclaration.TsHelperSpreadArrays;
|
161 | case "__spreadArray":
|
162 | return KnownDeclaration.TsHelperSpreadArray;
|
163 | case "__read":
|
164 | return KnownDeclaration.TsHelperRead;
|
165 | default:
|
166 | return null;
|
167 | }
|
168 | }
|
169 | function stripDollarSuffix(value) {
|
170 | return value.replace(/\$\d+$/, "");
|
171 | }
|
172 | function stripExtension(fileName) {
|
173 | return fileName.replace(/\..+$/, "");
|
174 | }
|
175 |
|
176 |
|
177 | import ts2 from "typescript";
|
178 | function findNamespaceOfIdentifier(id) {
|
179 | return id.parent && ts2.isPropertyAccessExpression(id.parent) && id.parent.name === id && ts2.isIdentifier(id.parent.expression) ? id.parent.expression : null;
|
180 | }
|
181 | function findRequireCallReference(id, checker) {
|
182 | var _a, _b;
|
183 | const symbol = checker.getSymbolAtLocation(id) || null;
|
184 | const declaration = (_b = symbol == null ? void 0 : symbol.valueDeclaration) != null ? _b : (_a = symbol == null ? void 0 : symbol.declarations) == null ? void 0 : _a[0];
|
185 | const initializer = declaration && ts2.isVariableDeclaration(declaration) && declaration.initializer || null;
|
186 | return initializer && isRequireCall(initializer) ? initializer : null;
|
187 | }
|
188 | function isWildcardReexportStatement(stmt) {
|
189 | if (!ts2.isExpressionStatement(stmt) || !ts2.isCallExpression(stmt.expression)) {
|
190 | return false;
|
191 | }
|
192 | let fnName = null;
|
193 | if (ts2.isIdentifier(stmt.expression.expression)) {
|
194 | fnName = stmt.expression.expression.text;
|
195 | } else if (ts2.isPropertyAccessExpression(stmt.expression.expression) && ts2.isIdentifier(stmt.expression.expression.name)) {
|
196 | fnName = stmt.expression.expression.name.text;
|
197 | }
|
198 | if (fnName !== "__export" && fnName !== "__exportStar") {
|
199 | return false;
|
200 | }
|
201 | return stmt.expression.arguments.length > 0;
|
202 | }
|
203 | function isDefinePropertyReexportStatement(stmt) {
|
204 | if (!ts2.isExpressionStatement(stmt) || !ts2.isCallExpression(stmt.expression)) {
|
205 | return false;
|
206 | }
|
207 | if (!ts2.isPropertyAccessExpression(stmt.expression.expression) || !ts2.isIdentifier(stmt.expression.expression.expression) || stmt.expression.expression.expression.text !== "Object" || !ts2.isIdentifier(stmt.expression.expression.name) || stmt.expression.expression.name.text !== "defineProperty") {
|
208 | return false;
|
209 | }
|
210 | const args = stmt.expression.arguments;
|
211 | if (args.length !== 3) {
|
212 | return false;
|
213 | }
|
214 | const exportsObject = args[0];
|
215 | if (!ts2.isIdentifier(exportsObject) || exportsObject.text !== "exports") {
|
216 | return false;
|
217 | }
|
218 | const propertyKey = args[1];
|
219 | if (!ts2.isStringLiteral(propertyKey)) {
|
220 | return false;
|
221 | }
|
222 | const propertyDescriptor = args[2];
|
223 | if (!ts2.isObjectLiteralExpression(propertyDescriptor)) {
|
224 | return false;
|
225 | }
|
226 | return propertyDescriptor.properties.some((prop) => prop.name !== void 0 && ts2.isIdentifier(prop.name) && prop.name.text === "get");
|
227 | }
|
228 | function extractGetterFnExpression(statement) {
|
229 | const args = statement.expression.arguments;
|
230 | const getterFn = args[2].properties.find((prop) => prop.name !== void 0 && ts2.isIdentifier(prop.name) && prop.name.text === "get");
|
231 | if (getterFn === void 0 || !ts2.isPropertyAssignment(getterFn) || !ts2.isFunctionExpression(getterFn.initializer)) {
|
232 | return null;
|
233 | }
|
234 | const returnStatement = getterFn.initializer.body.statements[0];
|
235 | if (!ts2.isReturnStatement(returnStatement) || returnStatement.expression === void 0) {
|
236 | return null;
|
237 | }
|
238 | return returnStatement.expression;
|
239 | }
|
240 | function isRequireCall(node) {
|
241 | return ts2.isCallExpression(node) && ts2.isIdentifier(node.expression) && node.expression.text === "require" && node.arguments.length === 1 && ts2.isStringLiteral(node.arguments[0]);
|
242 | }
|
243 | function isExternalImport(path) {
|
244 | return !/^\.\.?(\/|$)/.test(path);
|
245 | }
|
246 | function isExportsDeclaration(expr) {
|
247 | return expr.parent && isExportsAssignment(expr.parent);
|
248 | }
|
249 | function isExportsAssignment(expr) {
|
250 | return isAssignment(expr) && ts2.isPropertyAccessExpression(expr.left) && ts2.isIdentifier(expr.left.expression) && expr.left.expression.text === "exports" && ts2.isIdentifier(expr.left.name);
|
251 | }
|
252 | function isExportsStatement(stmt) {
|
253 | return ts2.isExpressionStatement(stmt) && isExportsAssignment(stmt.expression);
|
254 | }
|
255 | function skipAliases(node) {
|
256 | while (isAssignment(node)) {
|
257 | node = node.right;
|
258 | }
|
259 | return node;
|
260 | }
|
261 |
|
262 |
|
263 | import ts4 from "typescript";
|
264 |
|
265 |
|
266 | function isWithinPackage(packagePath, filePath) {
|
267 | const relativePath = relative(packagePath, filePath);
|
268 | return isLocalRelativePath(relativePath) && !relativePath.startsWith("node_modules/");
|
269 | }
|
270 | var NoopDependencyTracker = class {
|
271 | addDependency() {
|
272 | }
|
273 | addResourceDependency() {
|
274 | }
|
275 | recordDependencyAnalysisFailure() {
|
276 | }
|
277 | };
|
278 | var NOOP_DEPENDENCY_TRACKER = new NoopDependencyTracker();
|
279 |
|
280 |
|
281 | import ts3 from "typescript";
|
282 | function stripParentheses(node) {
|
283 | return ts3.isParenthesizedExpression(node) ? node.expression : node;
|
284 | }
|
285 |
|
286 |
|
287 | var DECORATORS = "decorators";
|
288 | var PROP_DECORATORS = "propDecorators";
|
289 | var CONSTRUCTOR = "__constructor";
|
290 | var CONSTRUCTOR_PARAMS = "ctorParameters";
|
291 | var Esm2015ReflectionHost = class extends TypeScriptReflectionHost {
|
292 | constructor(logger, isCore, src, dts = null) {
|
293 | super(src.program.getTypeChecker());
|
294 | this.logger = logger;
|
295 | this.isCore = isCore;
|
296 | this.src = src;
|
297 | this.dts = dts;
|
298 | this.publicDtsDeclarationMap = null;
|
299 | this.privateDtsDeclarationMap = null;
|
300 | this.preprocessedSourceFiles = new Set();
|
301 | this.aliasedClassDeclarations = new Map();
|
302 | this.decoratorCache = new Map();
|
303 | }
|
304 | getClassSymbol(declaration) {
|
305 | const symbol = this.getClassSymbolFromOuterDeclaration(declaration);
|
306 | if (symbol !== void 0) {
|
307 | return symbol;
|
308 | }
|
309 | const innerDeclaration = this.getInnerDeclarationFromAliasOrInner(declaration);
|
310 | return this.getClassSymbolFromInnerDeclaration(innerDeclaration);
|
311 | }
|
312 | getDecoratorsOfDeclaration(declaration) {
|
313 | const symbol = this.getClassSymbol(declaration);
|
314 | if (!symbol) {
|
315 | return null;
|
316 | }
|
317 | return this.getDecoratorsOfSymbol(symbol);
|
318 | }
|
319 | getMembersOfClass(clazz) {
|
320 | const classSymbol = this.getClassSymbol(clazz);
|
321 | if (!classSymbol) {
|
322 | throw new Error(`Attempted to get members of a non-class: "${clazz.getText()}"`);
|
323 | }
|
324 | return this.getMembersOfSymbol(classSymbol);
|
325 | }
|
326 | getConstructorParameters(clazz) {
|
327 | const classSymbol = this.getClassSymbol(clazz);
|
328 | if (!classSymbol) {
|
329 | throw new Error(`Attempted to get constructor parameters of a non-class: "${clazz.getText()}"`);
|
330 | }
|
331 | const parameterNodes = this.getConstructorParameterDeclarations(classSymbol);
|
332 | if (parameterNodes) {
|
333 | return this.getConstructorParamInfo(classSymbol, parameterNodes);
|
334 | }
|
335 | return null;
|
336 | }
|
337 | getBaseClassExpression(clazz) {
|
338 | const superBaseClassIdentifier = super.getBaseClassExpression(clazz);
|
339 | if (superBaseClassIdentifier) {
|
340 | return superBaseClassIdentifier;
|
341 | }
|
342 | const classSymbol = this.getClassSymbol(clazz);
|
343 | if ((classSymbol == null ? void 0 : classSymbol.implementation.valueDeclaration) === void 0 || !isNamedDeclaration(classSymbol.implementation.valueDeclaration)) {
|
344 | return null;
|
345 | }
|
346 | return super.getBaseClassExpression(classSymbol.implementation.valueDeclaration);
|
347 | }
|
348 | getInternalNameOfClass(clazz) {
|
349 | const classSymbol = this.getClassSymbol(clazz);
|
350 | if (classSymbol === void 0) {
|
351 | throw new Error(`getInternalNameOfClass() called on a non-class: expected ${clazz.name.text} to be a class declaration.`);
|
352 | }
|
353 | return this.getNameFromClassSymbolDeclaration(classSymbol, classSymbol.implementation.valueDeclaration);
|
354 | }
|
355 | getAdjacentNameOfClass(clazz) {
|
356 | const classSymbol = this.getClassSymbol(clazz);
|
357 | if (classSymbol === void 0) {
|
358 | throw new Error(`getAdjacentNameOfClass() called on a non-class: expected ${clazz.name.text} to be a class declaration.`);
|
359 | }
|
360 | return this.getAdjacentNameOfClassSymbol(classSymbol);
|
361 | }
|
362 | getNameFromClassSymbolDeclaration(classSymbol, declaration) {
|
363 | if (declaration === void 0) {
|
364 | throw new Error(`getInternalNameOfClass() called on a class with an undefined internal declaration. External class name: ${classSymbol.name}; internal class name: ${classSymbol.implementation.name}.`);
|
365 | }
|
366 | if (!isNamedDeclaration(declaration)) {
|
367 | throw new Error(`getInternalNameOfClass() called on a class with an anonymous inner declaration: expected a name on:
|
368 | ${declaration.getText()}`);
|
369 | }
|
370 | return declaration.name;
|
371 | }
|
372 | isClass(node) {
|
373 | return super.isClass(node) || this.getClassSymbol(node) !== void 0;
|
374 | }
|
375 | getDeclarationOfIdentifier(id) {
|
376 | const superDeclaration = super.getDeclarationOfIdentifier(id);
|
377 | if (superDeclaration === null) {
|
378 | return superDeclaration;
|
379 | }
|
380 | if (superDeclaration.known !== null || isConcreteDeclaration(superDeclaration) && superDeclaration.identity !== null) {
|
381 | return superDeclaration;
|
382 | }
|
383 | let declarationNode = superDeclaration.node;
|
384 | if (isNamedVariableDeclaration(superDeclaration.node) && !isTopLevel(superDeclaration.node)) {
|
385 | const variableValue = this.getVariableValue(superDeclaration.node);
|
386 | if (variableValue !== null && ts4.isClassExpression(variableValue)) {
|
387 | declarationNode = getContainingStatement(variableValue);
|
388 | }
|
389 | }
|
390 | const outerNode = getOuterNodeFromInnerDeclaration(declarationNode);
|
391 | const declaration = outerNode !== null && isNamedVariableDeclaration(outerNode) ? this.getDeclarationOfIdentifier(outerNode.name) : superDeclaration;
|
392 | if (declaration === null || declaration.known !== null || isConcreteDeclaration(declaration) && declaration.identity !== null) {
|
393 | return declaration;
|
394 | }
|
395 | const aliasedIdentifier = this.resolveAliasedClassIdentifier(declaration.node);
|
396 | if (aliasedIdentifier !== null) {
|
397 | return this.getDeclarationOfIdentifier(aliasedIdentifier);
|
398 | }
|
399 | if (isConcreteDeclaration(declaration) && ts4.isVariableDeclaration(declaration.node)) {
|
400 | const enumMembers = this.resolveEnumMembers(declaration.node);
|
401 | if (enumMembers !== null) {
|
402 | declaration.identity = { kind: 0, enumMembers };
|
403 | }
|
404 | }
|
405 | return declaration;
|
406 | }
|
407 | getDecoratorsOfSymbol(symbol) {
|
408 | const { classDecorators } = this.acquireDecoratorInfo(symbol);
|
409 | if (classDecorators === null) {
|
410 | return null;
|
411 | }
|
412 | return Array.from(classDecorators);
|
413 | }
|
414 | getVariableValue(declaration) {
|
415 | const value = super.getVariableValue(declaration);
|
416 | if (value) {
|
417 | return value;
|
418 | }
|
419 | const block = declaration.parent.parent.parent;
|
420 | const symbol = this.checker.getSymbolAtLocation(declaration.name);
|
421 | if (symbol && (ts4.isBlock(block) || ts4.isSourceFile(block))) {
|
422 | const decorateCall = this.findDecoratedVariableValue(block, symbol);
|
423 | const target = decorateCall && decorateCall.arguments[1];
|
424 | if (target && ts4.isIdentifier(target)) {
|
425 | const targetSymbol = this.checker.getSymbolAtLocation(target);
|
426 | const targetDeclaration = targetSymbol && targetSymbol.valueDeclaration;
|
427 | if (targetDeclaration) {
|
428 | if (ts4.isClassDeclaration(targetDeclaration) || ts4.isFunctionDeclaration(targetDeclaration)) {
|
429 | return targetDeclaration.name || null;
|
430 | } else if (ts4.isVariableDeclaration(targetDeclaration)) {
|
431 | let targetValue = targetDeclaration.initializer;
|
432 | while (targetValue && isAssignment2(targetValue)) {
|
433 | targetValue = targetValue.right;
|
434 | }
|
435 | if (targetValue) {
|
436 | return targetValue;
|
437 | }
|
438 | }
|
439 | }
|
440 | }
|
441 | }
|
442 | return null;
|
443 | }
|
444 | findClassSymbols(sourceFile) {
|
445 | const classes = new Map();
|
446 | this.getModuleStatements(sourceFile).forEach((statement) => this.addClassSymbolsFromStatement(classes, statement));
|
447 | return Array.from(classes.values());
|
448 | }
|
449 | getGenericArityOfClass(clazz) {
|
450 | const dtsDeclaration = this.getDtsDeclaration(clazz);
|
451 | if (dtsDeclaration && ts4.isClassDeclaration(dtsDeclaration)) {
|
452 | return dtsDeclaration.typeParameters ? dtsDeclaration.typeParameters.length : 0;
|
453 | }
|
454 | return null;
|
455 | }
|
456 | getDtsDeclaration(declaration) {
|
457 | if (this.dts === null) {
|
458 | return null;
|
459 | }
|
460 | if (!isNamedDeclaration(declaration)) {
|
461 | throw new Error(`Cannot get the dts file for a declaration that has no name: ${declaration.getText()} in ${declaration.getSourceFile().fileName}`);
|
462 | }
|
463 | const decl = this.getDeclarationOfIdentifier(declaration.name);
|
464 | if (decl === null) {
|
465 | throw new Error(`Cannot get the dts file for a node that cannot be associated with a declaration ${declaration.getText()} in ${declaration.getSourceFile().fileName}`);
|
466 | }
|
467 | if (this.publicDtsDeclarationMap === null) {
|
468 | this.publicDtsDeclarationMap = this.computePublicDtsDeclarationMap(this.src, this.dts);
|
469 | }
|
470 | if (this.publicDtsDeclarationMap.has(decl.node)) {
|
471 | return this.publicDtsDeclarationMap.get(decl.node);
|
472 | }
|
473 | if (this.privateDtsDeclarationMap === null) {
|
474 | this.privateDtsDeclarationMap = this.computePrivateDtsDeclarationMap(this.src, this.dts);
|
475 | }
|
476 | if (this.privateDtsDeclarationMap.has(decl.node)) {
|
477 | return this.privateDtsDeclarationMap.get(decl.node);
|
478 | }
|
479 | return null;
|
480 | }
|
481 | getEndOfClass(classSymbol) {
|
482 | const implementation = classSymbol.implementation;
|
483 | let last = implementation.valueDeclaration;
|
484 | const implementationStatement = getContainingStatement(last);
|
485 | if (implementationStatement === null)
|
486 | return last;
|
487 | const container = implementationStatement.parent;
|
488 | if (ts4.isBlock(container)) {
|
489 | const returnStatementIndex = container.statements.findIndex(ts4.isReturnStatement);
|
490 | if (returnStatementIndex === -1) {
|
491 | throw new Error(`Compiled class wrapper IIFE does not have a return statement: ${classSymbol.name} in ${classSymbol.declaration.valueDeclaration.getSourceFile().fileName}`);
|
492 | }
|
493 | last = container.statements[returnStatementIndex - 1];
|
494 | } else if (ts4.isSourceFile(container)) {
|
495 | if (implementation.exports !== void 0) {
|
496 | implementation.exports.forEach((exportSymbol) => {
|
497 | if (exportSymbol.valueDeclaration === void 0) {
|
498 | return;
|
499 | }
|
500 | const exportStatement = getContainingStatement(exportSymbol.valueDeclaration);
|
501 | if (exportStatement !== null && last.getEnd() < exportStatement.getEnd()) {
|
502 | last = exportStatement;
|
503 | }
|
504 | });
|
505 | }
|
506 | const helpers = this.getHelperCallsForClass(classSymbol, ["__decorate", "__extends", "__param", "__metadata"]);
|
507 | helpers.forEach((helper) => {
|
508 | const helperStatement = getContainingStatement(helper);
|
509 | if (helperStatement !== null && last.getEnd() < helperStatement.getEnd()) {
|
510 | last = helperStatement;
|
511 | }
|
512 | });
|
513 | }
|
514 | return last;
|
515 | }
|
516 | detectKnownDeclaration(decl) {
|
517 | if (decl.known === null && this.isJavaScriptObjectDeclaration(decl)) {
|
518 | decl.known = KnownDeclaration.JsGlobalObject;
|
519 | }
|
520 | return decl;
|
521 | }
|
522 | addClassSymbolsFromStatement(classes, statement) {
|
523 | if (ts4.isVariableStatement(statement)) {
|
524 | statement.declarationList.declarations.forEach((declaration) => {
|
525 | const classSymbol = this.getClassSymbol(declaration);
|
526 | if (classSymbol) {
|
527 | classes.set(classSymbol.implementation, classSymbol);
|
528 | }
|
529 | });
|
530 | } else if (ts4.isClassDeclaration(statement)) {
|
531 | const classSymbol = this.getClassSymbol(statement);
|
532 | if (classSymbol) {
|
533 | classes.set(classSymbol.implementation, classSymbol);
|
534 | }
|
535 | }
|
536 | }
|
537 | getInnerDeclarationFromAliasOrInner(declaration) {
|
538 | if (declaration.parent !== void 0 && isNamedVariableDeclaration(declaration.parent)) {
|
539 | const variableValue = this.getVariableValue(declaration.parent);
|
540 | if (variableValue !== null) {
|
541 | declaration = variableValue;
|
542 | }
|
543 | }
|
544 | return declaration;
|
545 | }
|
546 | getClassSymbolFromOuterDeclaration(declaration) {
|
547 | if (isNamedClassDeclaration(declaration) && isTopLevel(declaration)) {
|
548 | return this.createClassSymbol(declaration.name, null);
|
549 | }
|
550 | if (!isInitializedVariableClassDeclaration(declaration)) {
|
551 | return void 0;
|
552 | }
|
553 | const innerDeclaration = getInnerClassDeclaration(skipClassAliases(declaration));
|
554 | if (innerDeclaration === null) {
|
555 | return void 0;
|
556 | }
|
557 | return this.createClassSymbol(declaration.name, innerDeclaration);
|
558 | }
|
559 | getClassSymbolFromInnerDeclaration(declaration) {
|
560 | let outerDeclaration = void 0;
|
561 | if (ts4.isClassExpression(declaration) && hasNameIdentifier(declaration)) {
|
562 | outerDeclaration = getFarLeftHandSideOfAssignment(declaration);
|
563 | if (outerDeclaration !== void 0 && !isTopLevel(outerDeclaration)) {
|
564 | outerDeclaration = getContainingVariableDeclaration(outerDeclaration);
|
565 | }
|
566 | } else if (isNamedClassDeclaration(declaration)) {
|
567 | if (isTopLevel(declaration)) {
|
568 | outerDeclaration = declaration;
|
569 | } else {
|
570 | outerDeclaration = getContainingVariableDeclaration(declaration);
|
571 | }
|
572 | }
|
573 | if (outerDeclaration === void 0 || !hasNameIdentifier(outerDeclaration)) {
|
574 | return void 0;
|
575 | }
|
576 | return this.createClassSymbol(outerDeclaration.name, declaration);
|
577 | }
|
578 | createClassSymbol(outerDeclaration, innerDeclaration) {
|
579 | const declarationSymbol = this.checker.getSymbolAtLocation(outerDeclaration);
|
580 | if (declarationSymbol === void 0) {
|
581 | return void 0;
|
582 | }
|
583 | let implementationSymbol = declarationSymbol;
|
584 | if (innerDeclaration !== null && isNamedDeclaration(innerDeclaration)) {
|
585 | implementationSymbol = this.checker.getSymbolAtLocation(innerDeclaration.name);
|
586 | }
|
587 | if (!isSymbolWithValueDeclaration(implementationSymbol)) {
|
588 | return void 0;
|
589 | }
|
590 | const classSymbol = {
|
591 | name: declarationSymbol.name,
|
592 | declaration: declarationSymbol,
|
593 | implementation: implementationSymbol,
|
594 | adjacent: this.getAdjacentSymbol(declarationSymbol, implementationSymbol)
|
595 | };
|
596 | return classSymbol;
|
597 | }
|
598 | getAdjacentSymbol(declarationSymbol, implementationSymbol) {
|
599 | if (declarationSymbol === implementationSymbol) {
|
600 | return void 0;
|
601 | }
|
602 | const innerDeclaration = implementationSymbol.valueDeclaration;
|
603 | if (!ts4.isClassExpression(innerDeclaration) && !ts4.isFunctionExpression(innerDeclaration)) {
|
604 | return void 0;
|
605 | }
|
606 | const adjacentDeclaration = getFarLeftHandSideOfAssignment(innerDeclaration);
|
607 | if (adjacentDeclaration === void 0 || !isNamedVariableDeclaration(adjacentDeclaration)) {
|
608 | return void 0;
|
609 | }
|
610 | const adjacentSymbol = this.checker.getSymbolAtLocation(adjacentDeclaration.name);
|
611 | if (adjacentSymbol === declarationSymbol || adjacentSymbol === implementationSymbol || !isSymbolWithValueDeclaration(adjacentSymbol)) {
|
612 | return void 0;
|
613 | }
|
614 | return adjacentSymbol;
|
615 | }
|
616 | getDeclarationOfSymbol(symbol, originalId) {
|
617 | const declaration = super.getDeclarationOfSymbol(symbol, originalId);
|
618 | if (declaration === null) {
|
619 | return null;
|
620 | }
|
621 | return this.detectKnownDeclaration(declaration);
|
622 | }
|
623 | resolveAliasedClassIdentifier(declaration) {
|
624 | this.ensurePreprocessed(declaration.getSourceFile());
|
625 | return this.aliasedClassDeclarations.has(declaration) ? this.aliasedClassDeclarations.get(declaration) : null;
|
626 | }
|
627 | ensurePreprocessed(sourceFile) {
|
628 | if (!this.preprocessedSourceFiles.has(sourceFile)) {
|
629 | this.preprocessedSourceFiles.add(sourceFile);
|
630 | for (const statement of this.getModuleStatements(sourceFile)) {
|
631 | this.preprocessStatement(statement);
|
632 | }
|
633 | }
|
634 | }
|
635 | preprocessStatement(statement) {
|
636 | if (!ts4.isVariableStatement(statement)) {
|
637 | return;
|
638 | }
|
639 | const declarations = statement.declarationList.declarations;
|
640 | if (declarations.length !== 1) {
|
641 | return;
|
642 | }
|
643 | const declaration = declarations[0];
|
644 | const initializer = declaration.initializer;
|
645 | if (!ts4.isIdentifier(declaration.name) || !initializer || !isAssignment2(initializer) || !ts4.isIdentifier(initializer.left) || !this.isClass(declaration)) {
|
646 | return;
|
647 | }
|
648 | const aliasedIdentifier = initializer.left;
|
649 | const aliasedDeclaration = this.getDeclarationOfIdentifier(aliasedIdentifier);
|
650 | if (aliasedDeclaration === null) {
|
651 | throw new Error(`Unable to locate declaration of ${aliasedIdentifier.text} in "${statement.getText()}"`);
|
652 | }
|
653 | this.aliasedClassDeclarations.set(aliasedDeclaration.node, declaration.name);
|
654 | }
|
655 | getModuleStatements(sourceFile) {
|
656 | return Array.from(sourceFile.statements);
|
657 | }
|
658 | findDecoratedVariableValue(node, symbol) {
|
659 | if (!node) {
|
660 | return null;
|
661 | }
|
662 | if (ts4.isBinaryExpression(node) && node.operatorToken.kind === ts4.SyntaxKind.EqualsToken) {
|
663 | const left = node.left;
|
664 | const right = node.right;
|
665 | if (ts4.isIdentifier(left) && this.checker.getSymbolAtLocation(left) === symbol) {
|
666 | return ts4.isCallExpression(right) && getCalleeName(right) === "__decorate" ? right : null;
|
667 | }
|
668 | return this.findDecoratedVariableValue(right, symbol);
|
669 | }
|
670 | return node.forEachChild((node2) => this.findDecoratedVariableValue(node2, symbol)) || null;
|
671 | }
|
672 | getStaticProperty(symbol, propertyName) {
|
673 | var _a, _b, _c, _d;
|
674 | return ((_a = symbol.implementation.exports) == null ? void 0 : _a.get(propertyName)) || ((_c = (_b = symbol.adjacent) == null ? void 0 : _b.exports) == null ? void 0 : _c.get(propertyName)) || ((_d = symbol.declaration.exports) == null ? void 0 : _d.get(propertyName));
|
675 | }
|
676 | acquireDecoratorInfo(classSymbol) {
|
677 | const decl = classSymbol.declaration.valueDeclaration;
|
678 | if (this.decoratorCache.has(decl)) {
|
679 | return this.decoratorCache.get(decl);
|
680 | }
|
681 | const staticProps = this.computeDecoratorInfoFromStaticProperties(classSymbol);
|
682 | const helperCalls = this.computeDecoratorInfoFromHelperCalls(classSymbol);
|
683 | const decoratorInfo = {
|
684 | classDecorators: staticProps.classDecorators || helperCalls.classDecorators,
|
685 | memberDecorators: staticProps.memberDecorators || helperCalls.memberDecorators,
|
686 | constructorParamInfo: staticProps.constructorParamInfo || helperCalls.constructorParamInfo
|
687 | };
|
688 | this.decoratorCache.set(decl, decoratorInfo);
|
689 | return decoratorInfo;
|
690 | }
|
691 | computeDecoratorInfoFromStaticProperties(classSymbol) {
|
692 | let classDecorators = null;
|
693 | let memberDecorators = null;
|
694 | let constructorParamInfo = null;
|
695 | const decoratorsProperty = this.getStaticProperty(classSymbol, DECORATORS);
|
696 | if (decoratorsProperty !== void 0) {
|
697 | classDecorators = this.getClassDecoratorsFromStaticProperty(decoratorsProperty);
|
698 | }
|
699 | const propDecoratorsProperty = this.getStaticProperty(classSymbol, PROP_DECORATORS);
|
700 | if (propDecoratorsProperty !== void 0) {
|
701 | memberDecorators = this.getMemberDecoratorsFromStaticProperty(propDecoratorsProperty);
|
702 | }
|
703 | const constructorParamsProperty = this.getStaticProperty(classSymbol, CONSTRUCTOR_PARAMS);
|
704 | if (constructorParamsProperty !== void 0) {
|
705 | constructorParamInfo = this.getParamInfoFromStaticProperty(constructorParamsProperty);
|
706 | }
|
707 | return { classDecorators, memberDecorators, constructorParamInfo };
|
708 | }
|
709 | getClassDecoratorsFromStaticProperty(decoratorsSymbol) {
|
710 | const decoratorsIdentifier = decoratorsSymbol.valueDeclaration;
|
711 | if (decoratorsIdentifier && decoratorsIdentifier.parent) {
|
712 | if (ts4.isBinaryExpression(decoratorsIdentifier.parent) && decoratorsIdentifier.parent.operatorToken.kind === ts4.SyntaxKind.EqualsToken) {
|
713 | const decoratorsArray = decoratorsIdentifier.parent.right;
|
714 | return this.reflectDecorators(decoratorsArray).filter((decorator) => this.isFromCore(decorator));
|
715 | }
|
716 | }
|
717 | return null;
|
718 | }
|
719 | getMembersOfSymbol(symbol) {
|
720 | const members = [];
|
721 | const { memberDecorators } = this.acquireDecoratorInfo(symbol);
|
722 | const decoratorsMap = new Map(memberDecorators);
|
723 | if (symbol.implementation.members) {
|
724 | symbol.implementation.members.forEach((value, key) => {
|
725 | const decorators = decoratorsMap.get(key);
|
726 | const reflectedMembers = this.reflectMembers(value, decorators);
|
727 | if (reflectedMembers) {
|
728 | decoratorsMap.delete(key);
|
729 | members.push(...reflectedMembers);
|
730 | }
|
731 | });
|
732 | }
|
733 | if (symbol.implementation.exports) {
|
734 | symbol.implementation.exports.forEach((value, key) => {
|
735 | const decorators = decoratorsMap.get(key);
|
736 | const reflectedMembers = this.reflectMembers(value, decorators, true);
|
737 | if (reflectedMembers) {
|
738 | decoratorsMap.delete(key);
|
739 | members.push(...reflectedMembers);
|
740 | }
|
741 | });
|
742 | }
|
743 | if (ts4.isVariableDeclaration(symbol.declaration.valueDeclaration)) {
|
744 | if (symbol.declaration.exports) {
|
745 | symbol.declaration.exports.forEach((value, key) => {
|
746 | const decorators = decoratorsMap.get(key);
|
747 | const reflectedMembers = this.reflectMembers(value, decorators, true);
|
748 | if (reflectedMembers) {
|
749 | decoratorsMap.delete(key);
|
750 | members.push(...reflectedMembers);
|
751 | }
|
752 | });
|
753 | }
|
754 | }
|
755 | if (symbol.adjacent !== void 0) {
|
756 | if (ts4.isVariableDeclaration(symbol.adjacent.valueDeclaration)) {
|
757 | if (symbol.adjacent.exports !== void 0) {
|
758 | symbol.adjacent.exports.forEach((value, key) => {
|
759 | const decorators = decoratorsMap.get(key);
|
760 | const reflectedMembers = this.reflectMembers(value, decorators, true);
|
761 | if (reflectedMembers) {
|
762 | decoratorsMap.delete(key);
|
763 | members.push(...reflectedMembers);
|
764 | }
|
765 | });
|
766 | }
|
767 | }
|
768 | }
|
769 | decoratorsMap.forEach((value, key) => {
|
770 | members.push({
|
771 | implementation: null,
|
772 | decorators: value,
|
773 | isStatic: false,
|
774 | kind: ClassMemberKind.Property,
|
775 | name: key,
|
776 | nameNode: null,
|
777 | node: null,
|
778 | type: null,
|
779 | value: null
|
780 | });
|
781 | });
|
782 | return members;
|
783 | }
|
784 | getMemberDecoratorsFromStaticProperty(decoratorsProperty) {
|
785 | const memberDecorators = new Map();
|
786 | const propDecoratorsMap = getPropertyValueFromSymbol(decoratorsProperty);
|
787 | if (propDecoratorsMap && ts4.isObjectLiteralExpression(propDecoratorsMap)) {
|
788 | const propertiesMap = reflectObjectLiteral(propDecoratorsMap);
|
789 | propertiesMap.forEach((value, name) => {
|
790 | const decorators = this.reflectDecorators(value).filter((decorator) => this.isFromCore(decorator));
|
791 | if (decorators.length) {
|
792 | memberDecorators.set(name, decorators);
|
793 | }
|
794 | });
|
795 | }
|
796 | return memberDecorators;
|
797 | }
|
798 | computeDecoratorInfoFromHelperCalls(classSymbol) {
|
799 | let classDecorators = null;
|
800 | const memberDecorators = new Map();
|
801 | const constructorParamInfo = [];
|
802 | const getConstructorParamInfo = (index) => {
|
803 | let param = constructorParamInfo[index];
|
804 | if (param === void 0) {
|
805 | param = constructorParamInfo[index] = { decorators: null, typeExpression: null };
|
806 | }
|
807 | return param;
|
808 | };
|
809 | const helperCalls = this.getHelperCallsForClass(classSymbol, ["__decorate"]);
|
810 | const outerDeclaration = classSymbol.declaration.valueDeclaration;
|
811 | const innerDeclaration = classSymbol.implementation.valueDeclaration;
|
812 | const adjacentDeclaration = this.getAdjacentNameOfClassSymbol(classSymbol).parent;
|
813 | const matchesClass = (identifier) => {
|
814 | const decl = this.getDeclarationOfIdentifier(identifier);
|
815 | return decl !== null && (decl.node === adjacentDeclaration || decl.node === outerDeclaration || decl.node === innerDeclaration);
|
816 | };
|
817 | for (const helperCall of helperCalls) {
|
818 | if (isClassDecorateCall(helperCall, matchesClass)) {
|
819 | const helperArgs = helperCall.arguments[0];
|
820 | for (const element of helperArgs.elements) {
|
821 | const entry = this.reflectDecorateHelperEntry(element);
|
822 | if (entry === null) {
|
823 | continue;
|
824 | }
|
825 | if (entry.type === "decorator") {
|
826 | if (this.isFromCore(entry.decorator)) {
|
827 | (classDecorators || (classDecorators = [])).push(entry.decorator);
|
828 | }
|
829 | } else if (entry.type === "param:decorators") {
|
830 | const param = getConstructorParamInfo(entry.index);
|
831 | (param.decorators || (param.decorators = [])).push(entry.decorator);
|
832 | } else if (entry.type === "params") {
|
833 | entry.types.forEach((type, index) => getConstructorParamInfo(index).typeExpression = type);
|
834 | }
|
835 | }
|
836 | } else if (isMemberDecorateCall(helperCall, matchesClass)) {
|
837 | const helperArgs = helperCall.arguments[0];
|
838 | const memberName = helperCall.arguments[2].text;
|
839 | for (const element of helperArgs.elements) {
|
840 | const entry = this.reflectDecorateHelperEntry(element);
|
841 | if (entry === null) {
|
842 | continue;
|
843 | }
|
844 | if (entry.type === "decorator") {
|
845 | if (this.isFromCore(entry.decorator)) {
|
846 | const decorators = memberDecorators.has(memberName) ? memberDecorators.get(memberName) : [];
|
847 | decorators.push(entry.decorator);
|
848 | memberDecorators.set(memberName, decorators);
|
849 | }
|
850 | } else {
|
851 | }
|
852 | }
|
853 | }
|
854 | }
|
855 | return { classDecorators, memberDecorators, constructorParamInfo };
|
856 | }
|
857 | reflectDecorateHelperEntry(expression) {
|
858 | if (!ts4.isCallExpression(expression)) {
|
859 | return null;
|
860 | }
|
861 | const call = expression;
|
862 | const helperName = getCalleeName(call);
|
863 | if (helperName === "__metadata") {
|
864 | const key = call.arguments[0];
|
865 | if (key === void 0 || !ts4.isStringLiteral(key) || key.text !== "design:paramtypes") {
|
866 | return null;
|
867 | }
|
868 | const value = call.arguments[1];
|
869 | if (value === void 0 || !ts4.isArrayLiteralExpression(value)) {
|
870 | return null;
|
871 | }
|
872 | return {
|
873 | type: "params",
|
874 | types: Array.from(value.elements)
|
875 | };
|
876 | }
|
877 | if (helperName === "__param") {
|
878 | const indexArg = call.arguments[0];
|
879 | const index = indexArg && ts4.isNumericLiteral(indexArg) ? parseInt(indexArg.text, 10) : NaN;
|
880 | if (isNaN(index)) {
|
881 | return null;
|
882 | }
|
883 | const decoratorCall = call.arguments[1];
|
884 | if (decoratorCall === void 0 || !ts4.isCallExpression(decoratorCall)) {
|
885 | return null;
|
886 | }
|
887 | const decorator2 = this.reflectDecoratorCall(decoratorCall);
|
888 | if (decorator2 === null) {
|
889 | return null;
|
890 | }
|
891 | return {
|
892 | type: "param:decorators",
|
893 | index,
|
894 | decorator: decorator2
|
895 | };
|
896 | }
|
897 | const decorator = this.reflectDecoratorCall(call);
|
898 | if (decorator === null) {
|
899 | return null;
|
900 | }
|
901 | return {
|
902 | type: "decorator",
|
903 | decorator
|
904 | };
|
905 | }
|
906 | reflectDecoratorCall(call) {
|
907 | const decoratorExpression = call.expression;
|
908 | if (!isDecoratorIdentifier(decoratorExpression)) {
|
909 | return null;
|
910 | }
|
911 | const decoratorIdentifier = ts4.isIdentifier(decoratorExpression) ? decoratorExpression : decoratorExpression.name;
|
912 | return {
|
913 | name: decoratorIdentifier.text,
|
914 | identifier: decoratorExpression,
|
915 | import: this.getImportOfIdentifier(decoratorIdentifier),
|
916 | node: call,
|
917 | args: Array.from(call.arguments)
|
918 | };
|
919 | }
|
920 | getHelperCall(statement, helperNames) {
|
921 | if ((ts4.isExpressionStatement(statement) || ts4.isReturnStatement(statement)) && statement.expression) {
|
922 | let expression = statement.expression;
|
923 | while (isAssignment2(expression)) {
|
924 | expression = expression.right;
|
925 | }
|
926 | if (ts4.isCallExpression(expression)) {
|
927 | const calleeName = getCalleeName(expression);
|
928 | if (calleeName !== null && helperNames.includes(calleeName)) {
|
929 | return expression;
|
930 | }
|
931 | }
|
932 | }
|
933 | return null;
|
934 | }
|
935 | reflectDecorators(decoratorsArray) {
|
936 | const decorators = [];
|
937 | if (ts4.isArrayLiteralExpression(decoratorsArray)) {
|
938 | decoratorsArray.elements.forEach((node) => {
|
939 | if (ts4.isObjectLiteralExpression(node)) {
|
940 | const decorator = reflectObjectLiteral(node);
|
941 | if (decorator.has("type")) {
|
942 | let decoratorType = decorator.get("type");
|
943 | if (isDecoratorIdentifier(decoratorType)) {
|
944 | const decoratorIdentifier = ts4.isIdentifier(decoratorType) ? decoratorType : decoratorType.name;
|
945 | decorators.push({
|
946 | name: decoratorIdentifier.text,
|
947 | identifier: decoratorType,
|
948 | import: this.getImportOfIdentifier(decoratorIdentifier),
|
949 | node,
|
950 | args: getDecoratorArgs(node)
|
951 | });
|
952 | }
|
953 | }
|
954 | }
|
955 | });
|
956 | }
|
957 | return decorators;
|
958 | }
|
959 | reflectMembers(symbol, decorators, isStatic) {
|
960 | if (symbol.flags & ts4.SymbolFlags.Accessor) {
|
961 | const members = [];
|
962 | const setter = symbol.declarations && symbol.declarations.find(ts4.isSetAccessor);
|
963 | const getter = symbol.declarations && symbol.declarations.find(ts4.isGetAccessor);
|
964 | const setterMember = setter && this.reflectMember(setter, ClassMemberKind.Setter, decorators, isStatic);
|
965 | if (setterMember) {
|
966 | members.push(setterMember);
|
967 | decorators = void 0;
|
968 | }
|
969 | const getterMember = getter && this.reflectMember(getter, ClassMemberKind.Getter, decorators, isStatic);
|
970 | if (getterMember) {
|
971 | members.push(getterMember);
|
972 | }
|
973 | return members;
|
974 | }
|
975 | let kind = null;
|
976 | if (symbol.flags & ts4.SymbolFlags.Method) {
|
977 | kind = ClassMemberKind.Method;
|
978 | } else if (symbol.flags & ts4.SymbolFlags.Property) {
|
979 | kind = ClassMemberKind.Property;
|
980 | }
|
981 | const node = symbol.valueDeclaration || symbol.declarations && symbol.declarations[0];
|
982 | if (!node) {
|
983 | return null;
|
984 | }
|
985 | const member = this.reflectMember(node, kind, decorators, isStatic);
|
986 | if (!member) {
|
987 | return null;
|
988 | }
|
989 | return [member];
|
990 | }
|
991 | reflectMember(node, kind, decorators, isStatic) {
|
992 | let value = null;
|
993 | let name = null;
|
994 | let nameNode = null;
|
995 | if (!isClassMemberType(node)) {
|
996 | return null;
|
997 | }
|
998 | if (isStatic && isPropertyAccess(node)) {
|
999 | name = node.name.text;
|
1000 | value = kind === ClassMemberKind.Property ? node.parent.right : null;
|
1001 | } else if (isThisAssignment(node)) {
|
1002 | kind = ClassMemberKind.Property;
|
1003 | name = node.left.name.text;
|
1004 | value = node.right;
|
1005 | isStatic = false;
|
1006 | } else if (ts4.isConstructorDeclaration(node)) {
|
1007 | kind = ClassMemberKind.Constructor;
|
1008 | name = "constructor";
|
1009 | isStatic = false;
|
1010 | }
|
1011 | if (kind === null) {
|
1012 | this.logger.warn(`Unknown member type: "${node.getText()}`);
|
1013 | return null;
|
1014 | }
|
1015 | if (!name) {
|
1016 | if (isNamedDeclaration(node)) {
|
1017 | name = node.name.text;
|
1018 | nameNode = node.name;
|
1019 | } else {
|
1020 | return null;
|
1021 | }
|
1022 | }
|
1023 | if (isStatic === void 0) {
|
1024 | isStatic = node.modifiers !== void 0 && node.modifiers.some((mod) => mod.kind === ts4.SyntaxKind.StaticKeyword);
|
1025 | }
|
1026 | const type = node.type || null;
|
1027 | return {
|
1028 | node,
|
1029 | implementation: node,
|
1030 | kind,
|
1031 | type,
|
1032 | name,
|
1033 | nameNode,
|
1034 | value,
|
1035 | isStatic,
|
1036 | decorators: decorators || []
|
1037 | };
|
1038 | }
|
1039 | getConstructorParameterDeclarations(classSymbol) {
|
1040 | const members = classSymbol.implementation.members;
|
1041 | if (members && members.has(CONSTRUCTOR)) {
|
1042 | const constructorSymbol = members.get(CONSTRUCTOR);
|
1043 | const constructor = constructorSymbol.declarations && constructorSymbol.declarations[0];
|
1044 | if (!constructor) {
|
1045 | return [];
|
1046 | }
|
1047 | if (constructor.parameters.length > 0) {
|
1048 | return Array.from(constructor.parameters);
|
1049 | }
|
1050 | if (isSynthesizedConstructor(constructor)) {
|
1051 | return null;
|
1052 | }
|
1053 | return [];
|
1054 | }
|
1055 | return null;
|
1056 | }
|
1057 | getConstructorParamInfo(classSymbol, parameterNodes) {
|
1058 | const { constructorParamInfo } = this.acquireDecoratorInfo(classSymbol);
|
1059 | return parameterNodes.map((node, index) => {
|
1060 | const { decorators, typeExpression } = constructorParamInfo[index] ? constructorParamInfo[index] : { decorators: null, typeExpression: null };
|
1061 | const nameNode = node.name;
|
1062 | const typeValueReference = this.typeToValue(typeExpression);
|
1063 | return {
|
1064 | name: getNameText(nameNode),
|
1065 | nameNode,
|
1066 | typeValueReference,
|
1067 | typeNode: null,
|
1068 | decorators
|
1069 | };
|
1070 | });
|
1071 | }
|
1072 | typeToValue(typeExpression) {
|
1073 | if (typeExpression === null) {
|
1074 | return {
|
1075 | kind: 2,
|
1076 | reason: { kind: 0 }
|
1077 | };
|
1078 | }
|
1079 | const imp = this.getImportOfExpression(typeExpression);
|
1080 | const decl = this.getDeclarationOfExpression(typeExpression);
|
1081 | if (imp === null || decl === null) {
|
1082 | return {
|
1083 | kind: 0,
|
1084 | expression: typeExpression,
|
1085 | defaultImportStatement: null
|
1086 | };
|
1087 | }
|
1088 | return {
|
1089 | kind: 1,
|
1090 | valueDeclaration: decl.node,
|
1091 | moduleName: imp.from,
|
1092 | importedName: imp.name,
|
1093 | nestedPath: null
|
1094 | };
|
1095 | }
|
1096 | getImportOfExpression(expression) {
|
1097 | if (ts4.isIdentifier(expression)) {
|
1098 | return this.getImportOfIdentifier(expression);
|
1099 | } else if (ts4.isPropertyAccessExpression(expression) && ts4.isIdentifier(expression.name)) {
|
1100 | return this.getImportOfIdentifier(expression.name);
|
1101 | } else {
|
1102 | return null;
|
1103 | }
|
1104 | }
|
1105 | getParamInfoFromStaticProperty(paramDecoratorsProperty) {
|
1106 | const paramDecorators = getPropertyValueFromSymbol(paramDecoratorsProperty);
|
1107 | if (paramDecorators) {
|
1108 | const container = ts4.isArrowFunction(paramDecorators) ? paramDecorators.body : paramDecorators;
|
1109 | if (ts4.isArrayLiteralExpression(container)) {
|
1110 | const elements = container.elements;
|
1111 | return elements.map((element) => ts4.isObjectLiteralExpression(element) ? reflectObjectLiteral(element) : null).map((paramInfo) => {
|
1112 | const typeExpression = paramInfo && paramInfo.has("type") ? paramInfo.get("type") : null;
|
1113 | const decoratorInfo = paramInfo && paramInfo.has("decorators") ? paramInfo.get("decorators") : null;
|
1114 | const decorators = decoratorInfo && this.reflectDecorators(decoratorInfo).filter((decorator) => this.isFromCore(decorator));
|
1115 | return { typeExpression, decorators };
|
1116 | });
|
1117 | } else if (paramDecorators !== void 0) {
|
1118 | this.logger.warn("Invalid constructor parameter decorator in " + paramDecorators.getSourceFile().fileName + ":\n", paramDecorators.getText());
|
1119 | }
|
1120 | }
|
1121 | return null;
|
1122 | }
|
1123 | getHelperCallsForClass(classSymbol, helperNames) {
|
1124 | return this.getStatementsForClass(classSymbol).map((statement) => this.getHelperCall(statement, helperNames)).filter(isDefined);
|
1125 | }
|
1126 | getStatementsForClass(classSymbol) {
|
1127 | const classNode = classSymbol.implementation.valueDeclaration;
|
1128 | if (isTopLevel(classNode)) {
|
1129 | return this.getModuleStatements(classNode.getSourceFile());
|
1130 | }
|
1131 | const statement = getContainingStatement(classNode);
|
1132 | if (ts4.isBlock(statement.parent)) {
|
1133 | return Array.from(statement.parent.statements);
|
1134 | }
|
1135 | throw new Error(`Unable to find adjacent statements for ${classSymbol.name}`);
|
1136 | }
|
1137 | isFromCore(decorator) {
|
1138 | if (this.isCore) {
|
1139 | return !decorator.import || /^\./.test(decorator.import.from);
|
1140 | } else {
|
1141 | return !!decorator.import && decorator.import.from === "@angular/core";
|
1142 | }
|
1143 | }
|
1144 | computePublicDtsDeclarationMap(src, dts) {
|
1145 | const declarationMap = new Map();
|
1146 | const dtsDeclarationMap = new Map();
|
1147 | const rootDts = getRootFileOrFail(dts);
|
1148 | this.collectDtsExportedDeclarations(dtsDeclarationMap, rootDts, dts.program.getTypeChecker());
|
1149 | const rootSrc = getRootFileOrFail(src);
|
1150 | this.collectSrcExportedDeclarations(declarationMap, dtsDeclarationMap, rootSrc);
|
1151 | return declarationMap;
|
1152 | }
|
1153 | computePrivateDtsDeclarationMap(src, dts) {
|
1154 | const declarationMap = new Map();
|
1155 | const dtsDeclarationMap = new Map();
|
1156 | const typeChecker = dts.program.getTypeChecker();
|
1157 | const dtsFiles = getNonRootPackageFiles(dts);
|
1158 | for (const dtsFile of dtsFiles) {
|
1159 | this.collectDtsExportedDeclarations(dtsDeclarationMap, dtsFile, typeChecker);
|
1160 | }
|
1161 | const srcFiles = getNonRootPackageFiles(src);
|
1162 | for (const srcFile of srcFiles) {
|
1163 | this.collectSrcExportedDeclarations(declarationMap, dtsDeclarationMap, srcFile);
|
1164 | }
|
1165 | return declarationMap;
|
1166 | }
|
1167 | collectDtsExportedDeclarations(dtsDeclarationMap, srcFile, checker) {
|
1168 | const srcModule = srcFile && checker.getSymbolAtLocation(srcFile);
|
1169 | const moduleExports = srcModule && checker.getExportsOfModule(srcModule);
|
1170 | if (moduleExports) {
|
1171 | moduleExports.forEach((exportedSymbol) => {
|
1172 | const name = exportedSymbol.name;
|
1173 | if (exportedSymbol.flags & ts4.SymbolFlags.Alias) {
|
1174 | exportedSymbol = checker.getAliasedSymbol(exportedSymbol);
|
1175 | }
|
1176 | const declaration = exportedSymbol.valueDeclaration;
|
1177 | if (declaration && !dtsDeclarationMap.has(name)) {
|
1178 | dtsDeclarationMap.set(name, declaration);
|
1179 | }
|
1180 | });
|
1181 | }
|
1182 | }
|
1183 | collectSrcExportedDeclarations(declarationMap, dtsDeclarationMap, srcFile) {
|
1184 | const fileExports = this.getExportsOfModule(srcFile);
|
1185 | if (fileExports !== null) {
|
1186 | for (const [exportName, { node: declarationNode }] of fileExports) {
|
1187 | if (dtsDeclarationMap.has(exportName)) {
|
1188 | declarationMap.set(declarationNode, dtsDeclarationMap.get(exportName));
|
1189 | }
|
1190 | }
|
1191 | }
|
1192 | }
|
1193 | getDeclarationOfExpression(expression) {
|
1194 | if (ts4.isIdentifier(expression)) {
|
1195 | return this.getDeclarationOfIdentifier(expression);
|
1196 | }
|
1197 | if (!ts4.isPropertyAccessExpression(expression) || !ts4.isIdentifier(expression.expression)) {
|
1198 | return null;
|
1199 | }
|
1200 | const namespaceDecl = this.getDeclarationOfIdentifier(expression.expression);
|
1201 | if (!namespaceDecl || !ts4.isSourceFile(namespaceDecl.node)) {
|
1202 | return null;
|
1203 | }
|
1204 | const namespaceExports = this.getExportsOfModule(namespaceDecl.node);
|
1205 | if (namespaceExports === null) {
|
1206 | return null;
|
1207 | }
|
1208 | if (!namespaceExports.has(expression.name.text)) {
|
1209 | return null;
|
1210 | }
|
1211 | const exportDecl = namespaceExports.get(expression.name.text);
|
1212 | return __spreadProps(__spreadValues({}, exportDecl), { viaModule: namespaceDecl.viaModule });
|
1213 | }
|
1214 | isJavaScriptObjectDeclaration(decl) {
|
1215 | const node = decl.node;
|
1216 | if (!ts4.isVariableDeclaration(node) || !ts4.isIdentifier(node.name) || node.name.text !== "Object" || node.type === void 0) {
|
1217 | return false;
|
1218 | }
|
1219 | const typeNode = node.type;
|
1220 | if (!ts4.isTypeReferenceNode(typeNode) || !ts4.isIdentifier(typeNode.typeName) || typeNode.typeName.text !== "ObjectConstructor") {
|
1221 | return false;
|
1222 | }
|
1223 | return this.src.program.isSourceFileDefaultLibrary(node.getSourceFile());
|
1224 | }
|
1225 | resolveEnumMembers(declaration) {
|
1226 | if (declaration.initializer !== void 0)
|
1227 | return null;
|
1228 | const variableStmt = declaration.parent.parent;
|
1229 | if (!ts4.isVariableStatement(variableStmt))
|
1230 | return null;
|
1231 | const block = variableStmt.parent;
|
1232 | if (!ts4.isBlock(block) && !ts4.isSourceFile(block))
|
1233 | return null;
|
1234 | const declarationIndex = block.statements.findIndex((statement) => statement === variableStmt);
|
1235 | if (declarationIndex === -1 || declarationIndex === block.statements.length - 1)
|
1236 | return null;
|
1237 | const subsequentStmt = block.statements[declarationIndex + 1];
|
1238 | if (!ts4.isExpressionStatement(subsequentStmt))
|
1239 | return null;
|
1240 | const iife = stripParentheses(subsequentStmt.expression);
|
1241 | if (!ts4.isCallExpression(iife) || !isEnumDeclarationIife(iife))
|
1242 | return null;
|
1243 | const fn = stripParentheses(iife.expression);
|
1244 | if (!ts4.isFunctionExpression(fn))
|
1245 | return null;
|
1246 | return this.reflectEnumMembers(fn);
|
1247 | }
|
1248 | reflectEnumMembers(fn) {
|
1249 | if (fn.parameters.length !== 1)
|
1250 | return null;
|
1251 | const enumName = fn.parameters[0].name;
|
1252 | if (!ts4.isIdentifier(enumName))
|
1253 | return null;
|
1254 | const enumMembers = [];
|
1255 | for (const statement of fn.body.statements) {
|
1256 | const enumMember = this.reflectEnumMember(enumName, statement);
|
1257 | if (enumMember === null) {
|
1258 | return null;
|
1259 | }
|
1260 | enumMembers.push(enumMember);
|
1261 | }
|
1262 | return enumMembers;
|
1263 | }
|
1264 | reflectEnumMember(enumName, statement) {
|
1265 | if (!ts4.isExpressionStatement(statement))
|
1266 | return null;
|
1267 | const expression = statement.expression;
|
1268 | if (!isEnumAssignment(enumName, expression)) {
|
1269 | return null;
|
1270 | }
|
1271 | const assignment = reflectEnumAssignment(expression);
|
1272 | if (assignment != null) {
|
1273 | return assignment;
|
1274 | }
|
1275 | const innerExpression = expression.left.argumentExpression;
|
1276 | if (!isEnumAssignment(enumName, innerExpression)) {
|
1277 | return null;
|
1278 | }
|
1279 | return reflectEnumAssignment(innerExpression);
|
1280 | }
|
1281 | getAdjacentNameOfClassSymbol(classSymbol) {
|
1282 | if (classSymbol.adjacent !== void 0) {
|
1283 | return this.getNameFromClassSymbolDeclaration(classSymbol, classSymbol.adjacent.valueDeclaration);
|
1284 | } else {
|
1285 | return this.getNameFromClassSymbolDeclaration(classSymbol, classSymbol.implementation.valueDeclaration);
|
1286 | }
|
1287 | }
|
1288 | };
|
1289 | function isEnumDeclarationIife(iife) {
|
1290 | if (iife.arguments.length !== 1)
|
1291 | return false;
|
1292 | const arg = iife.arguments[0];
|
1293 | if (!ts4.isBinaryExpression(arg) || arg.operatorToken.kind !== ts4.SyntaxKind.BarBarToken || !ts4.isParenthesizedExpression(arg.right)) {
|
1294 | return false;
|
1295 | }
|
1296 | const right = arg.right.expression;
|
1297 | if (!ts4.isBinaryExpression(right) || right.operatorToken.kind !== ts4.SyntaxKind.EqualsToken) {
|
1298 | return false;
|
1299 | }
|
1300 | if (!ts4.isObjectLiteralExpression(right.right) || right.right.properties.length !== 0) {
|
1301 | return false;
|
1302 | }
|
1303 | return true;
|
1304 | }
|
1305 | function isEnumAssignment(enumName, expression) {
|
1306 | if (!ts4.isBinaryExpression(expression) || expression.operatorToken.kind !== ts4.SyntaxKind.EqualsToken || !ts4.isElementAccessExpression(expression.left)) {
|
1307 | return false;
|
1308 | }
|
1309 | const enumIdentifier = expression.left.expression;
|
1310 | return ts4.isIdentifier(enumIdentifier) && enumIdentifier.text === enumName.text;
|
1311 | }
|
1312 | function reflectEnumAssignment(expression) {
|
1313 | const memberName = expression.left.argumentExpression;
|
1314 | if (!ts4.isPropertyName(memberName))
|
1315 | return null;
|
1316 | return { name: memberName, initializer: expression.right };
|
1317 | }
|
1318 | function isAssignmentStatement(statement) {
|
1319 | return ts4.isExpressionStatement(statement) && isAssignment2(statement.expression) && ts4.isIdentifier(statement.expression.left);
|
1320 | }
|
1321 | function getIifeBody(expression) {
|
1322 | const call = stripParentheses(expression);
|
1323 | if (!ts4.isCallExpression(call)) {
|
1324 | return void 0;
|
1325 | }
|
1326 | const fn = stripParentheses(call.expression);
|
1327 | if (!ts4.isFunctionExpression(fn) && !ts4.isArrowFunction(fn)) {
|
1328 | return void 0;
|
1329 | }
|
1330 | return fn.body;
|
1331 | }
|
1332 | function isAssignment2(node) {
|
1333 | return ts4.isBinaryExpression(node) && node.operatorToken.kind === ts4.SyntaxKind.EqualsToken;
|
1334 | }
|
1335 | function isClassDecorateCall(call, matches) {
|
1336 | const helperArgs = call.arguments[0];
|
1337 | if (helperArgs === void 0 || !ts4.isArrayLiteralExpression(helperArgs)) {
|
1338 | return false;
|
1339 | }
|
1340 | const target = call.arguments[1];
|
1341 | return target !== void 0 && ts4.isIdentifier(target) && matches(target);
|
1342 | }
|
1343 | function isMemberDecorateCall(call, matches) {
|
1344 | const helperArgs = call.arguments[0];
|
1345 | if (helperArgs === void 0 || !ts4.isArrayLiteralExpression(helperArgs)) {
|
1346 | return false;
|
1347 | }
|
1348 | const target = call.arguments[1];
|
1349 | if (target === void 0 || !ts4.isPropertyAccessExpression(target) || !ts4.isIdentifier(target.expression) || !matches(target.expression) || target.name.text !== "prototype") {
|
1350 | return false;
|
1351 | }
|
1352 | const memberName = call.arguments[2];
|
1353 | return memberName !== void 0 && ts4.isStringLiteral(memberName);
|
1354 | }
|
1355 | function getPropertyValueFromSymbol(propSymbol) {
|
1356 | const propIdentifier = propSymbol.valueDeclaration;
|
1357 | const parent = propIdentifier && propIdentifier.parent;
|
1358 | return parent && ts4.isBinaryExpression(parent) ? parent.right : void 0;
|
1359 | }
|
1360 | function getCalleeName(call) {
|
1361 | if (ts4.isIdentifier(call.expression)) {
|
1362 | return stripDollarSuffix(call.expression.text);
|
1363 | }
|
1364 | if (ts4.isPropertyAccessExpression(call.expression)) {
|
1365 | return stripDollarSuffix(call.expression.name.text);
|
1366 | }
|
1367 | return null;
|
1368 | }
|
1369 | function isInitializedVariableClassDeclaration(node) {
|
1370 | return isNamedVariableDeclaration(node) && node.initializer !== void 0;
|
1371 | }
|
1372 | function skipClassAliases(node) {
|
1373 | let expression = node.initializer;
|
1374 | while (isAssignment2(expression)) {
|
1375 | expression = expression.right;
|
1376 | }
|
1377 | return expression;
|
1378 | }
|
1379 | function getInnerClassDeclaration(expression) {
|
1380 | if (ts4.isClassExpression(expression) && hasNameIdentifier(expression)) {
|
1381 | return expression;
|
1382 | }
|
1383 | const iifeBody = getIifeBody(expression);
|
1384 | if (iifeBody === void 0) {
|
1385 | return null;
|
1386 | }
|
1387 | if (!ts4.isBlock(iifeBody)) {
|
1388 | return ts4.isClassExpression(iifeBody) && isNamedDeclaration(iifeBody) ? iifeBody : null;
|
1389 | } else {
|
1390 | for (const statement of iifeBody.statements) {
|
1391 | if (isNamedClassDeclaration(statement) || isNamedFunctionDeclaration(statement)) {
|
1392 | return statement;
|
1393 | }
|
1394 | if (ts4.isVariableStatement(statement)) {
|
1395 | for (const declaration of statement.declarationList.declarations) {
|
1396 | if (isInitializedVariableClassDeclaration(declaration)) {
|
1397 | const expression2 = skipClassAliases(declaration);
|
1398 | if (ts4.isClassExpression(expression2) && hasNameIdentifier(expression2)) {
|
1399 | return expression2;
|
1400 | }
|
1401 | }
|
1402 | }
|
1403 | }
|
1404 | }
|
1405 | }
|
1406 | return null;
|
1407 | }
|
1408 | function getDecoratorArgs(node) {
|
1409 | const argsProperty = node.properties.filter(ts4.isPropertyAssignment).find((property2) => getNameText(property2.name) === "args");
|
1410 | const argsExpression = argsProperty && argsProperty.initializer;
|
1411 | return argsExpression && ts4.isArrayLiteralExpression(argsExpression) ? Array.from(argsExpression.elements) : [];
|
1412 | }
|
1413 | function isPropertyAccess(node) {
|
1414 | return !!node.parent && ts4.isBinaryExpression(node.parent) && ts4.isPropertyAccessExpression(node);
|
1415 | }
|
1416 | function isThisAssignment(node) {
|
1417 | return ts4.isBinaryExpression(node) && ts4.isPropertyAccessExpression(node.left) && node.left.expression.kind === ts4.SyntaxKind.ThisKeyword;
|
1418 | }
|
1419 | function isNamedDeclaration(node) {
|
1420 | const anyNode = node;
|
1421 | return !!anyNode.name && ts4.isIdentifier(anyNode.name);
|
1422 | }
|
1423 | function isClassMemberType(node) {
|
1424 | return (ts4.isClassElement(node) || isPropertyAccess(node) || ts4.isBinaryExpression(node)) && !ts4.isIndexSignatureDeclaration(node);
|
1425 | }
|
1426 | function getFarLeftHandSideOfAssignment(declaration) {
|
1427 | let node = declaration.parent;
|
1428 | if (isAssignment2(node) && ts4.isIdentifier(node.left)) {
|
1429 | node = node.parent;
|
1430 | }
|
1431 | return ts4.isVariableDeclaration(node) ? node : void 0;
|
1432 | }
|
1433 | function getContainingVariableDeclaration(node) {
|
1434 | node = node.parent;
|
1435 | while (node !== void 0) {
|
1436 | if (isNamedVariableDeclaration(node)) {
|
1437 | return node;
|
1438 | }
|
1439 | node = node.parent;
|
1440 | }
|
1441 | return void 0;
|
1442 | }
|
1443 | function isSynthesizedConstructor(constructor) {
|
1444 | if (!constructor.body)
|
1445 | return false;
|
1446 | const firstStatement = constructor.body.statements[0];
|
1447 | if (!firstStatement || !ts4.isExpressionStatement(firstStatement))
|
1448 | return false;
|
1449 | return isSynthesizedSuperCall(firstStatement.expression);
|
1450 | }
|
1451 | function isSynthesizedSuperCall(expression) {
|
1452 | if (!ts4.isCallExpression(expression))
|
1453 | return false;
|
1454 | if (expression.expression.kind !== ts4.SyntaxKind.SuperKeyword)
|
1455 | return false;
|
1456 | if (expression.arguments.length !== 1)
|
1457 | return false;
|
1458 | const argument = expression.arguments[0];
|
1459 | return ts4.isSpreadElement(argument) && ts4.isIdentifier(argument.expression) && argument.expression.text === "arguments";
|
1460 | }
|
1461 | function getContainingStatement(node) {
|
1462 | while (node.parent) {
|
1463 | if (ts4.isBlock(node.parent) || ts4.isSourceFile(node.parent)) {
|
1464 | break;
|
1465 | }
|
1466 | node = node.parent;
|
1467 | }
|
1468 | return node;
|
1469 | }
|
1470 | function getRootFileOrFail(bundle) {
|
1471 | const rootFile = bundle.program.getSourceFile(bundle.path);
|
1472 | if (rootFile === void 0) {
|
1473 | throw new Error(`The given rootPath ${rootFile} is not a file of the program.`);
|
1474 | }
|
1475 | return rootFile;
|
1476 | }
|
1477 | function getNonRootPackageFiles(bundle) {
|
1478 | const rootFile = bundle.program.getSourceFile(bundle.path);
|
1479 | return bundle.program.getSourceFiles().filter((f) => f !== rootFile && isWithinPackage(bundle.package, absoluteFromSourceFile(f)));
|
1480 | }
|
1481 | function isTopLevel(node) {
|
1482 | while (node = node.parent) {
|
1483 | if (ts4.isBlock(node)) {
|
1484 | return false;
|
1485 | }
|
1486 | }
|
1487 | return true;
|
1488 | }
|
1489 | function getOuterNodeFromInnerDeclaration(node) {
|
1490 | if (!ts4.isFunctionDeclaration(node) && !ts4.isClassDeclaration(node) && !ts4.isVariableStatement(node)) {
|
1491 | return null;
|
1492 | }
|
1493 | let outerNode = node.parent;
|
1494 | if (!outerNode || !ts4.isBlock(outerNode))
|
1495 | return null;
|
1496 | outerNode = outerNode.parent;
|
1497 | if (!outerNode || !ts4.isFunctionExpression(outerNode) && !ts4.isArrowFunction(outerNode)) {
|
1498 | return null;
|
1499 | }
|
1500 | outerNode = outerNode.parent;
|
1501 | if (outerNode && ts4.isParenthesizedExpression(outerNode))
|
1502 | outerNode = outerNode.parent;
|
1503 | if (!outerNode || !ts4.isCallExpression(outerNode))
|
1504 | return null;
|
1505 | outerNode = outerNode.parent;
|
1506 | if (outerNode && ts4.isParenthesizedExpression(outerNode))
|
1507 | outerNode = outerNode.parent;
|
1508 | while (isAssignment2(outerNode.parent)) {
|
1509 | outerNode = outerNode.parent;
|
1510 | }
|
1511 | return outerNode;
|
1512 | }
|
1513 |
|
1514 |
|
1515 | import ts5 from "typescript";
|
1516 | var Esm5ReflectionHost = class extends Esm2015ReflectionHost {
|
1517 | getBaseClassExpression(clazz) {
|
1518 | const superBaseClassExpression = super.getBaseClassExpression(clazz);
|
1519 | if (superBaseClassExpression !== null) {
|
1520 | return superBaseClassExpression;
|
1521 | }
|
1522 | const iife = getIifeFn(this.getClassSymbol(clazz));
|
1523 | if (iife === null)
|
1524 | return null;
|
1525 | if (iife.parameters.length !== 1 || !isSuperIdentifier(iife.parameters[0].name)) {
|
1526 | return null;
|
1527 | }
|
1528 | if (!ts5.isCallExpression(iife.parent)) {
|
1529 | return null;
|
1530 | }
|
1531 | return iife.parent.arguments[0];
|
1532 | }
|
1533 | getDeclarationOfIdentifier(id) {
|
1534 | const declaration = super.getDeclarationOfIdentifier(id);
|
1535 | if (declaration === null) {
|
1536 | const nonEmittedNorImportedTsHelperDeclaration = getTsHelperFnFromIdentifier(id);
|
1537 | if (nonEmittedNorImportedTsHelperDeclaration !== null) {
|
1538 | return {
|
1539 | kind: 1,
|
1540 | node: id,
|
1541 | known: nonEmittedNorImportedTsHelperDeclaration,
|
1542 | viaModule: null
|
1543 | };
|
1544 | }
|
1545 | }
|
1546 | if (declaration === null || declaration.node === null || declaration.known !== null) {
|
1547 | return declaration;
|
1548 | }
|
1549 | if (!ts5.isVariableDeclaration(declaration.node) || declaration.node.initializer !== void 0 || !ts5.isBlock(declaration.node.parent.parent.parent)) {
|
1550 | return declaration;
|
1551 | }
|
1552 | const block = declaration.node.parent.parent.parent;
|
1553 | const aliasSymbol = this.checker.getSymbolAtLocation(declaration.node.name);
|
1554 | for (let i = 0; i < block.statements.length; i++) {
|
1555 | const statement = block.statements[i];
|
1556 | if (isAssignmentStatement(statement) && ts5.isIdentifier(statement.expression.left) && ts5.isIdentifier(statement.expression.right) && this.checker.getSymbolAtLocation(statement.expression.left) === aliasSymbol) {
|
1557 | return this.getDeclarationOfIdentifier(statement.expression.right);
|
1558 | }
|
1559 | }
|
1560 | return declaration;
|
1561 | }
|
1562 | getDefinitionOfFunction(node) {
|
1563 | const definition = super.getDefinitionOfFunction(node);
|
1564 | if (definition === null) {
|
1565 | return null;
|
1566 | }
|
1567 | if (definition.body !== null) {
|
1568 | let lookingForInitializers = true;
|
1569 | const statements = definition.body.filter((s) => {
|
1570 | lookingForInitializers = lookingForInitializers && captureParamInitializer(s, definition.parameters);
|
1571 | return !lookingForInitializers;
|
1572 | });
|
1573 | definition.body = statements;
|
1574 | }
|
1575 | return definition;
|
1576 | }
|
1577 | detectKnownDeclaration(decl) {
|
1578 | decl = super.detectKnownDeclaration(decl);
|
1579 | if (decl.known === null && decl.node !== null) {
|
1580 | decl.known = getTsHelperFnFromDeclaration(decl.node);
|
1581 | }
|
1582 | return decl;
|
1583 | }
|
1584 | getClassSymbolFromInnerDeclaration(declaration) {
|
1585 | const classSymbol = super.getClassSymbolFromInnerDeclaration(declaration);
|
1586 | if (classSymbol !== void 0) {
|
1587 | return classSymbol;
|
1588 | }
|
1589 | if (!isNamedFunctionDeclaration(declaration)) {
|
1590 | return void 0;
|
1591 | }
|
1592 | const outerNode = getOuterNodeFromInnerDeclaration(declaration);
|
1593 | if (outerNode === null || !hasNameIdentifier(outerNode)) {
|
1594 | return void 0;
|
1595 | }
|
1596 | return this.createClassSymbol(outerNode.name, declaration);
|
1597 | }
|
1598 | getConstructorParameterDeclarations(classSymbol) {
|
1599 | const constructor = classSymbol.implementation.valueDeclaration;
|
1600 | if (!ts5.isFunctionDeclaration(constructor))
|
1601 | return null;
|
1602 | if (constructor.parameters.length > 0) {
|
1603 | return Array.from(constructor.parameters);
|
1604 | }
|
1605 | if (this.isSynthesizedConstructor(constructor)) {
|
1606 | return null;
|
1607 | }
|
1608 | return [];
|
1609 | }
|
1610 | getParamInfoFromStaticProperty(paramDecoratorsProperty) {
|
1611 | const paramDecorators = getPropertyValueFromSymbol(paramDecoratorsProperty);
|
1612 | const returnStatement = getReturnStatement(paramDecorators);
|
1613 | const expression = returnStatement ? returnStatement.expression : paramDecorators;
|
1614 | if (expression && ts5.isArrayLiteralExpression(expression)) {
|
1615 | const elements = expression.elements;
|
1616 | return elements.map(reflectArrayElement).map((paramInfo) => {
|
1617 | const typeExpression = paramInfo && paramInfo.has("type") ? paramInfo.get("type") : null;
|
1618 | const decoratorInfo = paramInfo && paramInfo.has("decorators") ? paramInfo.get("decorators") : null;
|
1619 | const decorators = decoratorInfo && this.reflectDecorators(decoratorInfo);
|
1620 | return { typeExpression, decorators };
|
1621 | });
|
1622 | } else if (paramDecorators !== void 0) {
|
1623 | this.logger.warn("Invalid constructor parameter decorator in " + paramDecorators.getSourceFile().fileName + ":\n", paramDecorators.getText());
|
1624 | }
|
1625 | return null;
|
1626 | }
|
1627 | reflectMembers(symbol, decorators, isStatic) {
|
1628 | const node = symbol.valueDeclaration || symbol.declarations && symbol.declarations[0];
|
1629 | const propertyDefinition = node && getPropertyDefinition(node);
|
1630 | if (propertyDefinition) {
|
1631 | const members2 = [];
|
1632 | if (propertyDefinition.setter) {
|
1633 | members2.push({
|
1634 | node,
|
1635 | implementation: propertyDefinition.setter,
|
1636 | kind: ClassMemberKind.Setter,
|
1637 | type: null,
|
1638 | name: symbol.name,
|
1639 | nameNode: null,
|
1640 | value: null,
|
1641 | isStatic: isStatic || false,
|
1642 | decorators: decorators || []
|
1643 | });
|
1644 | decorators = void 0;
|
1645 | }
|
1646 | if (propertyDefinition.getter) {
|
1647 | members2.push({
|
1648 | node,
|
1649 | implementation: propertyDefinition.getter,
|
1650 | kind: ClassMemberKind.Getter,
|
1651 | type: null,
|
1652 | name: symbol.name,
|
1653 | nameNode: null,
|
1654 | value: null,
|
1655 | isStatic: isStatic || false,
|
1656 | decorators: decorators || []
|
1657 | });
|
1658 | }
|
1659 | return members2;
|
1660 | }
|
1661 | const members = super.reflectMembers(symbol, decorators, isStatic);
|
1662 | members && members.forEach((member) => {
|
1663 | if (member && member.kind === ClassMemberKind.Method && member.isStatic && member.node && ts5.isPropertyAccessExpression(member.node) && member.node.parent && ts5.isBinaryExpression(member.node.parent) && ts5.isFunctionExpression(member.node.parent.right)) {
|
1664 | member.implementation = member.node.parent.right;
|
1665 | }
|
1666 | });
|
1667 | return members;
|
1668 | }
|
1669 | getStatementsForClass(classSymbol) {
|
1670 | const classDeclarationParent = classSymbol.implementation.valueDeclaration.parent;
|
1671 | return ts5.isBlock(classDeclarationParent) ? Array.from(classDeclarationParent.statements) : [];
|
1672 | }
|
1673 | isSynthesizedConstructor(constructor) {
|
1674 | if (!constructor.body)
|
1675 | return false;
|
1676 | const firstStatement = constructor.body.statements[0];
|
1677 | if (!firstStatement)
|
1678 | return false;
|
1679 | return this.isSynthesizedSuperThisAssignment(firstStatement) || this.isSynthesizedSuperReturnStatement(firstStatement);
|
1680 | }
|
1681 | isSynthesizedSuperThisAssignment(statement) {
|
1682 | if (!ts5.isVariableStatement(statement))
|
1683 | return false;
|
1684 | const variableDeclarations = statement.declarationList.declarations;
|
1685 | if (variableDeclarations.length !== 1)
|
1686 | return false;
|
1687 | const variableDeclaration = variableDeclarations[0];
|
1688 | if (!ts5.isIdentifier(variableDeclaration.name) || !variableDeclaration.name.text.startsWith("_this"))
|
1689 | return false;
|
1690 | const initializer = variableDeclaration.initializer;
|
1691 | if (!initializer)
|
1692 | return false;
|
1693 | return this.isSynthesizedDefaultSuperCall(initializer);
|
1694 | }
|
1695 | isSynthesizedSuperReturnStatement(statement) {
|
1696 | if (!ts5.isReturnStatement(statement))
|
1697 | return false;
|
1698 | const expression = statement.expression;
|
1699 | if (!expression)
|
1700 | return false;
|
1701 | return this.isSynthesizedDefaultSuperCall(expression);
|
1702 | }
|
1703 | isSynthesizedDefaultSuperCall(expression) {
|
1704 | if (!isBinaryExpr(expression, ts5.SyntaxKind.BarBarToken))
|
1705 | return false;
|
1706 | if (expression.right.kind !== ts5.SyntaxKind.ThisKeyword)
|
1707 | return false;
|
1708 | const left = expression.left;
|
1709 | if (isBinaryExpr(left, ts5.SyntaxKind.AmpersandAmpersandToken)) {
|
1710 | return isSuperNotNull(left.left) && this.isSuperApplyCall(left.right);
|
1711 | } else {
|
1712 | return this.isSuperApplyCall(left);
|
1713 | }
|
1714 | }
|
1715 | isSuperApplyCall(expression) {
|
1716 | if (!ts5.isCallExpression(expression) || expression.arguments.length !== 2)
|
1717 | return false;
|
1718 | const targetFn = expression.expression;
|
1719 | if (!ts5.isPropertyAccessExpression(targetFn))
|
1720 | return false;
|
1721 | if (!isSuperIdentifier(targetFn.expression))
|
1722 | return false;
|
1723 | if (targetFn.name.text !== "apply")
|
1724 | return false;
|
1725 | const thisArgument = expression.arguments[0];
|
1726 | if (thisArgument.kind !== ts5.SyntaxKind.ThisKeyword)
|
1727 | return false;
|
1728 | const argumentsExpr = expression.arguments[1];
|
1729 | if (isArgumentsIdentifier(argumentsExpr)) {
|
1730 | return true;
|
1731 | }
|
1732 | return this.isSpreadArgumentsExpression(argumentsExpr);
|
1733 | }
|
1734 | isSpreadArgumentsExpression(expression) {
|
1735 | const call = this.extractKnownHelperCall(expression);
|
1736 | if (call === null) {
|
1737 | return false;
|
1738 | }
|
1739 | if (call.helper === KnownDeclaration.TsHelperSpread) {
|
1740 | return call.args.length === 1 && isArgumentsIdentifier(call.args[0]);
|
1741 | } else if (call.helper === KnownDeclaration.TsHelperSpreadArray) {
|
1742 | if (call.args.length !== 2 && call.args.length !== 3) {
|
1743 | return false;
|
1744 | }
|
1745 | const firstArg = call.args[0];
|
1746 | if (!ts5.isArrayLiteralExpression(firstArg) || firstArg.elements.length !== 0) {
|
1747 | return false;
|
1748 | }
|
1749 | const secondArg = this.extractKnownHelperCall(call.args[1]);
|
1750 | if (secondArg === null || secondArg.helper !== KnownDeclaration.TsHelperRead) {
|
1751 | return false;
|
1752 | }
|
1753 | return secondArg.args.length === 1 && isArgumentsIdentifier(secondArg.args[0]);
|
1754 | } else {
|
1755 | return false;
|
1756 | }
|
1757 | }
|
1758 | extractKnownHelperCall(expression) {
|
1759 | if (!ts5.isCallExpression(expression)) {
|
1760 | return null;
|
1761 | }
|
1762 | const receiverExpr = expression.expression;
|
1763 | let receiver = null;
|
1764 | if (ts5.isIdentifier(receiverExpr)) {
|
1765 | receiver = this.getDeclarationOfIdentifier(receiverExpr);
|
1766 | } else if (ts5.isPropertyAccessExpression(receiverExpr) && ts5.isIdentifier(receiverExpr.name)) {
|
1767 | receiver = this.getDeclarationOfIdentifier(receiverExpr.name);
|
1768 | }
|
1769 | if (receiver === null || receiver.known === null) {
|
1770 | return null;
|
1771 | }
|
1772 | return {
|
1773 | helper: receiver.known,
|
1774 | args: expression.arguments
|
1775 | };
|
1776 | }
|
1777 | };
|
1778 | function getPropertyDefinition(node) {
|
1779 | if (!ts5.isCallExpression(node))
|
1780 | return null;
|
1781 | const fn = node.expression;
|
1782 | if (!ts5.isPropertyAccessExpression(fn) || !ts5.isIdentifier(fn.expression) || fn.expression.text !== "Object" || fn.name.text !== "defineProperty")
|
1783 | return null;
|
1784 | const descriptor = node.arguments[2];
|
1785 | if (!descriptor || !ts5.isObjectLiteralExpression(descriptor))
|
1786 | return null;
|
1787 | return {
|
1788 | setter: readPropertyFunctionExpression(descriptor, "set"),
|
1789 | getter: readPropertyFunctionExpression(descriptor, "get")
|
1790 | };
|
1791 | }
|
1792 | function readPropertyFunctionExpression(object, name) {
|
1793 | const property2 = object.properties.find((p) => ts5.isPropertyAssignment(p) && ts5.isIdentifier(p.name) && p.name.text === name);
|
1794 | return property2 && ts5.isFunctionExpression(property2.initializer) && property2.initializer || null;
|
1795 | }
|
1796 | function getReturnStatement(declaration) {
|
1797 | return declaration && ts5.isFunctionExpression(declaration) ? declaration.body.statements.find(ts5.isReturnStatement) : void 0;
|
1798 | }
|
1799 | function reflectArrayElement(element) {
|
1800 | return ts5.isObjectLiteralExpression(element) ? reflectObjectLiteral(element) : null;
|
1801 | }
|
1802 | function isArgumentsIdentifier(expression) {
|
1803 | return ts5.isIdentifier(expression) && expression.text === "arguments";
|
1804 | }
|
1805 | function isSuperNotNull(expression) {
|
1806 | return isBinaryExpr(expression, ts5.SyntaxKind.ExclamationEqualsEqualsToken) && isSuperIdentifier(expression.left);
|
1807 | }
|
1808 | function isBinaryExpr(expression, operator) {
|
1809 | return ts5.isBinaryExpression(expression) && expression.operatorToken.kind === operator;
|
1810 | }
|
1811 | function isSuperIdentifier(node) {
|
1812 | return ts5.isIdentifier(node) && node.text.startsWith("_super");
|
1813 | }
|
1814 | function captureParamInitializer(statement, parameters) {
|
1815 | if (ts5.isIfStatement(statement) && isUndefinedComparison(statement.expression) && ts5.isBlock(statement.thenStatement) && statement.thenStatement.statements.length === 1) {
|
1816 | const ifStatementComparison = statement.expression;
|
1817 | const thenStatement = statement.thenStatement.statements[0];
|
1818 | if (isAssignmentStatement(thenStatement)) {
|
1819 | const comparisonName = ifStatementComparison.left.text;
|
1820 | const assignmentName = thenStatement.expression.left.text;
|
1821 | if (comparisonName === assignmentName) {
|
1822 | const parameter = parameters.find((p) => p.name === comparisonName);
|
1823 | if (parameter) {
|
1824 | parameter.initializer = thenStatement.expression.right;
|
1825 | return true;
|
1826 | }
|
1827 | }
|
1828 | }
|
1829 | }
|
1830 | return false;
|
1831 | }
|
1832 | function isUndefinedComparison(expression) {
|
1833 | return ts5.isBinaryExpression(expression) && expression.operatorToken.kind === ts5.SyntaxKind.EqualsEqualsEqualsToken && ts5.isVoidExpression(expression.right) && ts5.isIdentifier(expression.left);
|
1834 | }
|
1835 | function getIifeFn(classSymbol) {
|
1836 | if (classSymbol === void 0) {
|
1837 | return null;
|
1838 | }
|
1839 | const innerDeclaration = classSymbol.implementation.valueDeclaration;
|
1840 | const iifeBody = innerDeclaration.parent;
|
1841 | if (!ts5.isBlock(iifeBody)) {
|
1842 | return null;
|
1843 | }
|
1844 | const iifeWrapper = iifeBody.parent;
|
1845 | return iifeWrapper && ts5.isFunctionExpression(iifeWrapper) ? iifeWrapper : null;
|
1846 | }
|
1847 |
|
1848 |
|
1849 | var UmdReflectionHost = class extends Esm5ReflectionHost {
|
1850 | constructor(logger, isCore, src, dts = null) {
|
1851 | super(logger, isCore, src, dts);
|
1852 | this.umdModules = new FactoryMap((sf) => this.computeUmdModule(sf));
|
1853 | this.umdExports = new FactoryMap((sf) => this.computeExportsOfUmdModule(sf));
|
1854 | this.umdImportPaths = new FactoryMap((param) => this.computeImportPath(param));
|
1855 | this.program = src.program;
|
1856 | this.compilerHost = src.host;
|
1857 | }
|
1858 | getImportOfIdentifier(id) {
|
1859 | const nsIdentifier = findNamespaceOfIdentifier(id);
|
1860 | const importParameter = nsIdentifier && this.findUmdImportParameter(nsIdentifier);
|
1861 | const from = importParameter && this.getUmdImportPath(importParameter);
|
1862 | return from !== null ? { from, name: id.text } : null;
|
1863 | }
|
1864 | getDeclarationOfIdentifier(id) {
|
1865 | const declaration = this.getExportsDeclaration(id) || this.getUmdModuleDeclaration(id) || this.getUmdDeclaration(id);
|
1866 | if (declaration !== null) {
|
1867 | return declaration;
|
1868 | }
|
1869 | const superDeclaration = super.getDeclarationOfIdentifier(id);
|
1870 | if (superDeclaration === null) {
|
1871 | return null;
|
1872 | }
|
1873 | const outerNode = getOuterNodeFromInnerDeclaration(superDeclaration.node);
|
1874 | if (outerNode === null) {
|
1875 | return superDeclaration;
|
1876 | }
|
1877 | if (!isExportsAssignment(outerNode)) {
|
1878 | return superDeclaration;
|
1879 | }
|
1880 | return {
|
1881 | kind: 1,
|
1882 | node: outerNode.left,
|
1883 | implementation: outerNode.right,
|
1884 | known: null,
|
1885 | viaModule: null
|
1886 | };
|
1887 | }
|
1888 | getExportsOfModule(module) {
|
1889 | return super.getExportsOfModule(module) || this.umdExports.get(module.getSourceFile());
|
1890 | }
|
1891 | getUmdModule(sourceFile) {
|
1892 | if (sourceFile.isDeclarationFile) {
|
1893 | return null;
|
1894 | }
|
1895 | return this.umdModules.get(sourceFile);
|
1896 | }
|
1897 | getUmdImportPath(importParameter) {
|
1898 | return this.umdImportPaths.get(importParameter);
|
1899 | }
|
1900 | getModuleStatements(sourceFile) {
|
1901 | const umdModule = this.getUmdModule(sourceFile);
|
1902 | return umdModule !== null ? Array.from(umdModule.factoryFn.body.statements) : [];
|
1903 | }
|
1904 | getClassSymbolFromOuterDeclaration(declaration) {
|
1905 | const superSymbol = super.getClassSymbolFromOuterDeclaration(declaration);
|
1906 | if (superSymbol) {
|
1907 | return superSymbol;
|
1908 | }
|
1909 | if (!isExportsDeclaration(declaration)) {
|
1910 | return void 0;
|
1911 | }
|
1912 | let initializer = skipAliases(declaration.parent.right);
|
1913 | if (ts6.isIdentifier(initializer)) {
|
1914 | const implementation = this.getDeclarationOfIdentifier(initializer);
|
1915 | if (implementation !== null) {
|
1916 | const implementationSymbol = this.getClassSymbol(implementation.node);
|
1917 | if (implementationSymbol !== null) {
|
1918 | return implementationSymbol;
|
1919 | }
|
1920 | }
|
1921 | }
|
1922 | const innerDeclaration = getInnerClassDeclaration(initializer);
|
1923 | if (innerDeclaration !== null) {
|
1924 | return this.createClassSymbol(declaration.name, innerDeclaration);
|
1925 | }
|
1926 | return void 0;
|
1927 | }
|
1928 | getClassSymbolFromInnerDeclaration(declaration) {
|
1929 | const superClassSymbol = super.getClassSymbolFromInnerDeclaration(declaration);
|
1930 | if (superClassSymbol !== void 0) {
|
1931 | return superClassSymbol;
|
1932 | }
|
1933 | if (!isNamedFunctionDeclaration(declaration)) {
|
1934 | return void 0;
|
1935 | }
|
1936 | const outerNode = getOuterNodeFromInnerDeclaration(declaration);
|
1937 | if (outerNode === null || !isExportsAssignment(outerNode)) {
|
1938 | return void 0;
|
1939 | }
|
1940 | return this.createClassSymbol(outerNode.left.name, declaration);
|
1941 | }
|
1942 | addClassSymbolsFromStatement(classes, statement) {
|
1943 | super.addClassSymbolsFromStatement(classes, statement);
|
1944 | if (isExportsStatement(statement)) {
|
1945 | const classSymbol = this.getClassSymbol(statement.expression.left);
|
1946 | if (classSymbol) {
|
1947 | classes.set(classSymbol.implementation, classSymbol);
|
1948 | }
|
1949 | }
|
1950 | }
|
1951 | preprocessStatement(statement) {
|
1952 | super.preprocessStatement(statement);
|
1953 | if (!isExportsStatement(statement)) {
|
1954 | return;
|
1955 | }
|
1956 | const declaration = statement.expression.left;
|
1957 | const initializer = statement.expression.right;
|
1958 | if (!isAssignment2(initializer) || !ts6.isIdentifier(initializer.left) || !this.isClass(declaration)) {
|
1959 | return;
|
1960 | }
|
1961 | const aliasedIdentifier = initializer.left;
|
1962 | const aliasedDeclaration = this.getDeclarationOfIdentifier(aliasedIdentifier);
|
1963 | if (aliasedDeclaration === null || aliasedDeclaration.node === null) {
|
1964 | throw new Error(`Unable to locate declaration of ${aliasedIdentifier.text} in "${statement.getText()}"`);
|
1965 | }
|
1966 | this.aliasedClassDeclarations.set(aliasedDeclaration.node, declaration.name);
|
1967 | }
|
1968 | computeUmdModule(sourceFile) {
|
1969 | if (sourceFile.statements.length !== 1) {
|
1970 | throw new Error(`Expected UMD module file (${sourceFile.fileName}) to contain exactly one statement, but found ${sourceFile.statements.length}.`);
|
1971 | }
|
1972 | return parseStatementForUmdModule(sourceFile.statements[0]);
|
1973 | }
|
1974 | computeExportsOfUmdModule(sourceFile) {
|
1975 | const moduleMap = new Map();
|
1976 | for (const statement of this.getModuleStatements(sourceFile)) {
|
1977 | if (isExportsStatement(statement)) {
|
1978 | const exportDeclaration = this.extractBasicUmdExportDeclaration(statement);
|
1979 | if (!moduleMap.has(exportDeclaration.name)) {
|
1980 | moduleMap.set(exportDeclaration.name, exportDeclaration.declaration);
|
1981 | }
|
1982 | } else if (isWildcardReexportStatement(statement)) {
|
1983 | const reexports = this.extractUmdWildcardReexports(statement, sourceFile);
|
1984 | for (const reexport of reexports) {
|
1985 | moduleMap.set(reexport.name, reexport.declaration);
|
1986 | }
|
1987 | } else if (isDefinePropertyReexportStatement(statement)) {
|
1988 | const exportDeclaration = this.extractUmdDefinePropertyExportDeclaration(statement);
|
1989 | if (exportDeclaration !== null) {
|
1990 | moduleMap.set(exportDeclaration.name, exportDeclaration.declaration);
|
1991 | }
|
1992 | }
|
1993 | }
|
1994 | return moduleMap;
|
1995 | }
|
1996 | computeImportPath(param) {
|
1997 | const umdModule = this.getUmdModule(param.getSourceFile());
|
1998 | if (umdModule === null) {
|
1999 | return null;
|
2000 | }
|
2001 | const imports = getImportsOfUmdModule(umdModule);
|
2002 | if (imports === null) {
|
2003 | return null;
|
2004 | }
|
2005 | let importPath = null;
|
2006 | for (const i of imports) {
|
2007 | this.umdImportPaths.set(i.parameter, i.path);
|
2008 | if (i.parameter === param) {
|
2009 | importPath = i.path;
|
2010 | }
|
2011 | }
|
2012 | return importPath;
|
2013 | }
|
2014 | extractBasicUmdExportDeclaration(statement) {
|
2015 | var _a;
|
2016 | const name = statement.expression.left.name.text;
|
2017 | const exportExpression = skipAliases(statement.expression.right);
|
2018 | const declaration = (_a = this.getDeclarationOfExpression(exportExpression)) != null ? _a : {
|
2019 | kind: 1,
|
2020 | node: statement.expression.left,
|
2021 | implementation: statement.expression.right,
|
2022 | known: null,
|
2023 | viaModule: null
|
2024 | };
|
2025 | return { name, declaration };
|
2026 | }
|
2027 | extractUmdWildcardReexports(statement, containingFile) {
|
2028 | const reexportArg = statement.expression.arguments[0];
|
2029 | const requireCall = isRequireCall(reexportArg) ? reexportArg : ts6.isIdentifier(reexportArg) ? findRequireCallReference(reexportArg, this.checker) : null;
|
2030 | let importPath = null;
|
2031 | if (requireCall !== null) {
|
2032 | importPath = requireCall.arguments[0].text;
|
2033 | } else if (ts6.isIdentifier(reexportArg)) {
|
2034 | const importParameter = this.findUmdImportParameter(reexportArg);
|
2035 | importPath = importParameter && this.getUmdImportPath(importParameter);
|
2036 | }
|
2037 | if (importPath === null) {
|
2038 | return [];
|
2039 | }
|
2040 | const importedFile = this.resolveModuleName(importPath, containingFile);
|
2041 | if (importedFile === void 0) {
|
2042 | return [];
|
2043 | }
|
2044 | const importedExports = this.getExportsOfModule(importedFile);
|
2045 | if (importedExports === null) {
|
2046 | return [];
|
2047 | }
|
2048 | const viaModule = stripExtension(importedFile.fileName);
|
2049 | const reexports = [];
|
2050 | importedExports.forEach((decl, name) => reexports.push({ name, declaration: __spreadProps(__spreadValues({}, decl), { viaModule }) }));
|
2051 | return reexports;
|
2052 | }
|
2053 | extractUmdDefinePropertyExportDeclaration(statement) {
|
2054 | const args = statement.expression.arguments;
|
2055 | const name = args[1].text;
|
2056 | const getterFnExpression = extractGetterFnExpression(statement);
|
2057 | if (getterFnExpression === null) {
|
2058 | return null;
|
2059 | }
|
2060 | const declaration = this.getDeclarationOfExpression(getterFnExpression);
|
2061 | if (declaration !== null) {
|
2062 | return { name, declaration };
|
2063 | }
|
2064 | return {
|
2065 | name,
|
2066 | declaration: {
|
2067 | kind: 1,
|
2068 | node: args[1],
|
2069 | implementation: getterFnExpression,
|
2070 | known: null,
|
2071 | viaModule: null
|
2072 | }
|
2073 | };
|
2074 | }
|
2075 | findUmdImportParameter(id) {
|
2076 | const symbol = id && this.checker.getSymbolAtLocation(id) || null;
|
2077 | const declaration = symbol && symbol.valueDeclaration;
|
2078 | return declaration && ts6.isParameter(declaration) ? declaration : null;
|
2079 | }
|
2080 | getUmdDeclaration(id) {
|
2081 | const nsIdentifier = findNamespaceOfIdentifier(id);
|
2082 | if (nsIdentifier === null) {
|
2083 | return null;
|
2084 | }
|
2085 | if (nsIdentifier.parent.parent && isExportsAssignment(nsIdentifier.parent.parent)) {
|
2086 | const initializer = nsIdentifier.parent.parent.right;
|
2087 | if (ts6.isIdentifier(initializer)) {
|
2088 | return this.getDeclarationOfIdentifier(initializer);
|
2089 | }
|
2090 | return this.detectKnownDeclaration({
|
2091 | kind: 1,
|
2092 | node: nsIdentifier.parent.parent.left,
|
2093 | implementation: skipAliases(nsIdentifier.parent.parent.right),
|
2094 | viaModule: null,
|
2095 | known: null
|
2096 | });
|
2097 | }
|
2098 | const moduleDeclaration = this.getUmdModuleDeclaration(nsIdentifier);
|
2099 | if (moduleDeclaration === null || moduleDeclaration.node === null || !ts6.isSourceFile(moduleDeclaration.node)) {
|
2100 | return null;
|
2101 | }
|
2102 | const moduleExports = this.getExportsOfModule(moduleDeclaration.node);
|
2103 | if (moduleExports === null) {
|
2104 | return null;
|
2105 | }
|
2106 | const declaration = moduleExports.get(id.text);
|
2107 | if (!moduleExports.has(id.text)) {
|
2108 | return null;
|
2109 | }
|
2110 | const viaModule = declaration.viaModule === null ? moduleDeclaration.viaModule : declaration.viaModule;
|
2111 | return __spreadProps(__spreadValues({}, declaration), { viaModule, known: getTsHelperFnFromIdentifier(id) });
|
2112 | }
|
2113 | getExportsDeclaration(id) {
|
2114 | if (!isExportsIdentifier(id)) {
|
2115 | return null;
|
2116 | }
|
2117 | const exportsSymbol = this.checker.getSymbolsInScope(id, ts6.SymbolFlags.Variable).find((symbol) => symbol.name === "exports");
|
2118 | const node = (exportsSymbol == null ? void 0 : exportsSymbol.valueDeclaration) !== void 0 && !ts6.isFunctionExpression(exportsSymbol.valueDeclaration.parent) ? exportsSymbol.valueDeclaration : id.getSourceFile();
|
2119 | return {
|
2120 | kind: 0,
|
2121 | node,
|
2122 | viaModule: null,
|
2123 | known: null,
|
2124 | identity: null
|
2125 | };
|
2126 | }
|
2127 | getUmdModuleDeclaration(id) {
|
2128 | const importPath = this.getImportPathFromParameter(id) || this.getImportPathFromRequireCall(id);
|
2129 | if (importPath === null) {
|
2130 | return null;
|
2131 | }
|
2132 | const module = this.resolveModuleName(importPath, id.getSourceFile());
|
2133 | if (module === void 0) {
|
2134 | return null;
|
2135 | }
|
2136 | const viaModule = isExternalImport(importPath) ? importPath : null;
|
2137 | return { kind: 0, node: module, viaModule, known: null, identity: null };
|
2138 | }
|
2139 | getImportPathFromParameter(id) {
|
2140 | const importParameter = this.findUmdImportParameter(id);
|
2141 | if (importParameter === null) {
|
2142 | return null;
|
2143 | }
|
2144 | return this.getUmdImportPath(importParameter);
|
2145 | }
|
2146 | getImportPathFromRequireCall(id) {
|
2147 | const requireCall = findRequireCallReference(id, this.checker);
|
2148 | if (requireCall === null) {
|
2149 | return null;
|
2150 | }
|
2151 | return requireCall.arguments[0].text;
|
2152 | }
|
2153 | getDeclarationOfExpression(expression) {
|
2154 | const inner = getInnerClassDeclaration(expression);
|
2155 | if (inner !== null) {
|
2156 | const outer = getOuterNodeFromInnerDeclaration(inner);
|
2157 | if (outer !== null && isExportsAssignment(outer)) {
|
2158 | return {
|
2159 | kind: 1,
|
2160 | node: outer.left,
|
2161 | implementation: inner,
|
2162 | known: null,
|
2163 | viaModule: null
|
2164 | };
|
2165 | }
|
2166 | }
|
2167 | return super.getDeclarationOfExpression(expression);
|
2168 | }
|
2169 | resolveModuleName(moduleName, containingFile) {
|
2170 | if (this.compilerHost.resolveModuleNames) {
|
2171 | const moduleInfo = this.compilerHost.resolveModuleNames([moduleName], containingFile.fileName, void 0, void 0, this.program.getCompilerOptions())[0];
|
2172 | return moduleInfo && this.program.getSourceFile(absoluteFrom(moduleInfo.resolvedFileName));
|
2173 | } else {
|
2174 | const moduleInfo = ts6.resolveModuleName(moduleName, containingFile.fileName, this.program.getCompilerOptions(), this.compilerHost);
|
2175 | return moduleInfo.resolvedModule && this.program.getSourceFile(absoluteFrom(moduleInfo.resolvedModule.resolvedFileName));
|
2176 | }
|
2177 | }
|
2178 | };
|
2179 | function parseStatementForUmdModule(statement) {
|
2180 | const wrapper = getUmdWrapper(statement);
|
2181 | if (wrapper === null)
|
2182 | return null;
|
2183 | const factoryFnParamIndex = wrapper.fn.parameters.findIndex((parameter) => ts6.isIdentifier(parameter.name) && parameter.name.text === "factory");
|
2184 | if (factoryFnParamIndex === -1)
|
2185 | return null;
|
2186 | const factoryFn = stripParentheses(wrapper.call.arguments[factoryFnParamIndex]);
|
2187 | if (!factoryFn || !ts6.isFunctionExpression(factoryFn))
|
2188 | return null;
|
2189 | let factoryCalls = null;
|
2190 | return {
|
2191 | wrapperFn: wrapper.fn,
|
2192 | factoryFn,
|
2193 | get factoryCalls() {
|
2194 | if (factoryCalls === null) {
|
2195 | factoryCalls = parseUmdWrapperFunction(this.wrapperFn);
|
2196 | }
|
2197 | return factoryCalls;
|
2198 | }
|
2199 | };
|
2200 | }
|
2201 | function getUmdWrapper(statement) {
|
2202 | if (!ts6.isExpressionStatement(statement))
|
2203 | return null;
|
2204 | if (ts6.isParenthesizedExpression(statement.expression) && ts6.isCallExpression(statement.expression.expression) && ts6.isFunctionExpression(statement.expression.expression.expression)) {
|
2205 | const call = statement.expression.expression;
|
2206 | const fn = statement.expression.expression.expression;
|
2207 | return { call, fn };
|
2208 | }
|
2209 | if (ts6.isCallExpression(statement.expression) && ts6.isParenthesizedExpression(statement.expression.expression) && ts6.isFunctionExpression(statement.expression.expression.expression)) {
|
2210 | const call = statement.expression;
|
2211 | const fn = statement.expression.expression.expression;
|
2212 | return { call, fn };
|
2213 | }
|
2214 | return null;
|
2215 | }
|
2216 | function parseUmdWrapperFunction(wrapperFn) {
|
2217 | const stmt = wrapperFn.body.statements[0];
|
2218 | let conditionalFactoryCalls;
|
2219 | if (ts6.isExpressionStatement(stmt) && ts6.isConditionalExpression(stmt.expression)) {
|
2220 | conditionalFactoryCalls = extractFactoryCallsFromConditionalExpression(stmt.expression);
|
2221 | } else if (ts6.isIfStatement(stmt)) {
|
2222 | conditionalFactoryCalls = extractFactoryCallsFromIfStatement(stmt);
|
2223 | } else {
|
2224 | throw new Error("UMD wrapper body is not in a supported format (expected a conditional expression or if statement):\n" + wrapperFn.body.getText());
|
2225 | }
|
2226 | const amdDefine = getAmdDefineCall(conditionalFactoryCalls);
|
2227 | const commonJs = getCommonJsFactoryCall(conditionalFactoryCalls);
|
2228 | const commonJs2 = getCommonJs2FactoryCall(conditionalFactoryCalls);
|
2229 | const global = getGlobalFactoryCall(conditionalFactoryCalls);
|
2230 | const cjsCallForImports = commonJs2 || commonJs;
|
2231 | if (cjsCallForImports === null) {
|
2232 | throw new Error("Unable to find a CommonJS or CommonJS2 factory call inside the UMD wrapper function:\n" + stmt.getText());
|
2233 | }
|
2234 | return { amdDefine, commonJs, commonJs2, global, cjsCallForImports };
|
2235 | }
|
2236 | function extractFactoryCallsFromConditionalExpression(node) {
|
2237 | const factoryCalls = [];
|
2238 | let currentNode = node;
|
2239 | while (ts6.isConditionalExpression(currentNode)) {
|
2240 | if (!ts6.isBinaryExpression(currentNode.condition)) {
|
2241 | throw new Error("Condition inside UMD wrapper is not a binary expression:\n" + currentNode.condition.getText());
|
2242 | }
|
2243 | factoryCalls.push({
|
2244 | condition: currentNode.condition,
|
2245 | factoryCall: getFunctionCallFromExpression(currentNode.whenTrue)
|
2246 | });
|
2247 | currentNode = currentNode.whenFalse;
|
2248 | }
|
2249 | factoryCalls.push({
|
2250 | condition: null,
|
2251 | factoryCall: getFunctionCallFromExpression(currentNode)
|
2252 | });
|
2253 | return factoryCalls;
|
2254 | }
|
2255 | function extractFactoryCallsFromIfStatement(node) {
|
2256 | const factoryCalls = [];
|
2257 | let currentNode = node;
|
2258 | while (currentNode && ts6.isIfStatement(currentNode)) {
|
2259 | if (!ts6.isBinaryExpression(currentNode.expression)) {
|
2260 | throw new Error("Condition inside UMD wrapper is not a binary expression:\n" + currentNode.expression.getText());
|
2261 | }
|
2262 | if (!ts6.isExpressionStatement(currentNode.thenStatement)) {
|
2263 | throw new Error("Then-statement inside UMD wrapper is not an expression statement:\n" + currentNode.thenStatement.getText());
|
2264 | }
|
2265 | factoryCalls.push({
|
2266 | condition: currentNode.expression,
|
2267 | factoryCall: getFunctionCallFromExpression(currentNode.thenStatement.expression)
|
2268 | });
|
2269 | currentNode = currentNode.elseStatement;
|
2270 | }
|
2271 | if (currentNode) {
|
2272 | if (!ts6.isExpressionStatement(currentNode)) {
|
2273 | throw new Error("Else-statement inside UMD wrapper is not an expression statement:\n" + currentNode.getText());
|
2274 | }
|
2275 | factoryCalls.push({
|
2276 | condition: null,
|
2277 | factoryCall: getFunctionCallFromExpression(currentNode.expression)
|
2278 | });
|
2279 | }
|
2280 | return factoryCalls;
|
2281 | }
|
2282 | function getFunctionCallFromExpression(node) {
|
2283 | if (ts6.isParenthesizedExpression(node)) {
|
2284 | return getFunctionCallFromExpression(node.expression);
|
2285 | }
|
2286 | if (ts6.isBinaryExpression(node) && [ts6.SyntaxKind.CommaToken, ts6.SyntaxKind.EqualsToken].includes(node.operatorToken.kind)) {
|
2287 | return getFunctionCallFromExpression(node.right);
|
2288 | }
|
2289 | if (!ts6.isCallExpression(node)) {
|
2290 | throw new Error("Expression inside UMD wrapper is not a call expression:\n" + node.getText());
|
2291 | }
|
2292 | return node;
|
2293 | }
|
2294 | function getAmdDefineCall(calls) {
|
2295 | var _a;
|
2296 | const amdConditionalCall = calls.find((call) => {
|
2297 | var _a2;
|
2298 | return ((_a2 = call.condition) == null ? void 0 : _a2.operatorToken.kind) === ts6.SyntaxKind.AmpersandAmpersandToken && oneOfBinaryConditions(call.condition, (exp) => isTypeOf(exp, "define")) && ts6.isIdentifier(call.factoryCall.expression) && call.factoryCall.expression.text === "define";
|
2299 | });
|
2300 | return (_a = amdConditionalCall == null ? void 0 : amdConditionalCall.factoryCall) != null ? _a : null;
|
2301 | }
|
2302 | function getCommonJsFactoryCall(calls) {
|
2303 | var _a;
|
2304 | const cjsConditionalCall = calls.find((call) => {
|
2305 | var _a2;
|
2306 | return ((_a2 = call.condition) == null ? void 0 : _a2.operatorToken.kind) === ts6.SyntaxKind.EqualsEqualsEqualsToken && isTypeOf(call.condition, "exports") && ts6.isIdentifier(call.factoryCall.expression) && call.factoryCall.expression.text === "factory";
|
2307 | });
|
2308 | return (_a = cjsConditionalCall == null ? void 0 : cjsConditionalCall.factoryCall) != null ? _a : null;
|
2309 | }
|
2310 | function getCommonJs2FactoryCall(calls) {
|
2311 | var _a;
|
2312 | const cjs2ConditionalCall = calls.find((call) => {
|
2313 | var _a2;
|
2314 | return ((_a2 = call.condition) == null ? void 0 : _a2.operatorToken.kind) === ts6.SyntaxKind.AmpersandAmpersandToken && oneOfBinaryConditions(call.condition, (exp) => isTypeOf(exp, "exports", "module")) && ts6.isIdentifier(call.factoryCall.expression) && call.factoryCall.expression.text === "factory";
|
2315 | });
|
2316 | return (_a = cjs2ConditionalCall == null ? void 0 : cjs2ConditionalCall.factoryCall) != null ? _a : null;
|
2317 | }
|
2318 | function getGlobalFactoryCall(calls) {
|
2319 | var _a;
|
2320 | const globalConditionalCall = calls.find((call) => call.condition === null);
|
2321 | return (_a = globalConditionalCall == null ? void 0 : globalConditionalCall.factoryCall) != null ? _a : null;
|
2322 | }
|
2323 | function oneOfBinaryConditions(node, test) {
|
2324 | return test(node.left) || test(node.right);
|
2325 | }
|
2326 | function isTypeOf(node, ...types) {
|
2327 | return ts6.isBinaryExpression(node) && ts6.isTypeOfExpression(node.left) && ts6.isIdentifier(node.left.expression) && types.includes(node.left.expression.text);
|
2328 | }
|
2329 | function getImportsOfUmdModule(umdModule) {
|
2330 | const imports = [];
|
2331 | const factoryFnParams = umdModule.factoryFn.parameters;
|
2332 | const cjsFactoryCallArgs = umdModule.factoryCalls.cjsCallForImports.arguments;
|
2333 | for (let i = 0; i < factoryFnParams.length; i++) {
|
2334 | const arg = cjsFactoryCallArgs[i];
|
2335 | if (arg !== void 0 && isRequireCall(arg)) {
|
2336 | imports.push({
|
2337 | parameter: factoryFnParams[i],
|
2338 | path: arg.arguments[0].text
|
2339 | });
|
2340 | }
|
2341 | }
|
2342 | return imports;
|
2343 | }
|
2344 | function isExportsIdentifier(node) {
|
2345 | return ts6.isIdentifier(node) && node.text === "exports";
|
2346 | }
|
2347 |
|
2348 |
|
2349 | var SUPPORTED_FORMAT_PROPERTIES = ["fesm2015", "fesm5", "es2015", "esm2015", "esm5", "main", "module", "browser"];
|
2350 | var NO_ENTRY_POINT = "no-entry-point";
|
2351 | var IGNORED_ENTRY_POINT = "ignored-entry-point";
|
2352 | var INCOMPATIBLE_ENTRY_POINT = "incompatible-entry-point";
|
2353 | function getEntryPointInfo(fs, config, logger, packagePath, entryPointPath) {
|
2354 | const packagePackageJsonPath = fs.resolve(packagePath, "package.json");
|
2355 | const entryPointPackageJsonPath = fs.resolve(entryPointPath, "package.json");
|
2356 | const loadedPackagePackageJson = loadPackageJson(fs, packagePackageJsonPath);
|
2357 | const loadedEntryPointPackageJson = packagePackageJsonPath === entryPointPackageJsonPath ? loadedPackagePackageJson : loadPackageJson(fs, entryPointPackageJsonPath);
|
2358 | const { packageName, packageVersion } = getPackageNameAndVersion(fs, packagePath, loadedPackagePackageJson, loadedEntryPointPackageJson);
|
2359 | const repositoryUrl = getRepositoryUrl(loadedPackagePackageJson);
|
2360 | const packageConfig = config.getPackageConfig(packageName, packagePath, packageVersion);
|
2361 | const entryPointConfig = packageConfig.entryPoints.get(entryPointPath);
|
2362 | let entryPointPackageJson;
|
2363 | if (entryPointConfig === void 0) {
|
2364 | if (!fs.exists(entryPointPackageJsonPath)) {
|
2365 | return NO_ENTRY_POINT;
|
2366 | } else if (loadedEntryPointPackageJson === null) {
|
2367 | logger.warn(`Failed to read entry point info from invalid 'package.json' file: ${entryPointPackageJsonPath}`);
|
2368 | return INCOMPATIBLE_ENTRY_POINT;
|
2369 | } else {
|
2370 | entryPointPackageJson = loadedEntryPointPackageJson;
|
2371 | }
|
2372 | } else if (entryPointConfig.ignore === true) {
|
2373 | return IGNORED_ENTRY_POINT;
|
2374 | } else {
|
2375 | entryPointPackageJson = mergeConfigAndPackageJson(fs, loadedEntryPointPackageJson, entryPointConfig, packagePath, entryPointPath);
|
2376 | }
|
2377 | const typings = entryPointPackageJson.typings || entryPointPackageJson.types || guessTypingsFromPackageJson(fs, entryPointPath, entryPointPackageJson);
|
2378 | if (typeof typings !== "string") {
|
2379 | return INCOMPATIBLE_ENTRY_POINT;
|
2380 | }
|
2381 | const metadataPath = fs.resolve(entryPointPath, typings.replace(/\.d\.ts$/, "") + ".metadata.json");
|
2382 | const compiledByAngular = entryPointConfig !== void 0 || fs.exists(metadataPath);
|
2383 | const entryPointInfo = {
|
2384 | name: entryPointPackageJson.name,
|
2385 | path: entryPointPath,
|
2386 | packageName,
|
2387 | packagePath,
|
2388 | repositoryUrl,
|
2389 | packageJson: entryPointPackageJson,
|
2390 | typings: fs.resolve(entryPointPath, typings),
|
2391 | compiledByAngular,
|
2392 | ignoreMissingDependencies: entryPointConfig !== void 0 ? !!entryPointConfig.ignoreMissingDependencies : false,
|
2393 | generateDeepReexports: entryPointConfig !== void 0 ? !!entryPointConfig.generateDeepReexports : false
|
2394 | };
|
2395 | return entryPointInfo;
|
2396 | }
|
2397 | function isEntryPoint(result) {
|
2398 | return result !== NO_ENTRY_POINT && result !== INCOMPATIBLE_ENTRY_POINT && result !== IGNORED_ENTRY_POINT;
|
2399 | }
|
2400 | function getEntryPointFormat(fs, entryPoint, property2) {
|
2401 | switch (property2) {
|
2402 | case "fesm2015":
|
2403 | return "esm2015";
|
2404 | case "fesm5":
|
2405 | return "esm5";
|
2406 | case "es2015":
|
2407 | return "esm2015";
|
2408 | case "esm2015":
|
2409 | return "esm2015";
|
2410 | case "esm5":
|
2411 | return "esm5";
|
2412 | case "browser":
|
2413 | const browserFile = entryPoint.packageJson["browser"];
|
2414 | if (typeof browserFile !== "string") {
|
2415 | return void 0;
|
2416 | }
|
2417 | return sniffModuleFormat(fs, fs.join(entryPoint.path, browserFile));
|
2418 | case "main":
|
2419 | const mainFile = entryPoint.packageJson["main"];
|
2420 | if (mainFile === void 0) {
|
2421 | return void 0;
|
2422 | }
|
2423 | return sniffModuleFormat(fs, fs.join(entryPoint.path, mainFile));
|
2424 | case "module":
|
2425 | const moduleFilePath = entryPoint.packageJson["module"];
|
2426 | if (typeof moduleFilePath === "string" && moduleFilePath.includes("esm2015")) {
|
2427 | return `esm2015`;
|
2428 | }
|
2429 | return "esm5";
|
2430 | default:
|
2431 | return void 0;
|
2432 | }
|
2433 | }
|
2434 | function loadPackageJson(fs, packageJsonPath) {
|
2435 | try {
|
2436 | return JSON.parse(fs.readFile(packageJsonPath));
|
2437 | } catch {
|
2438 | return null;
|
2439 | }
|
2440 | }
|
2441 | function sniffModuleFormat(fs, sourceFilePath) {
|
2442 | const resolvedPath = resolveFileWithPostfixes(fs, sourceFilePath, ["", ".js", "/index.js"]);
|
2443 | if (resolvedPath === null) {
|
2444 | return void 0;
|
2445 | }
|
2446 | const sourceFile = ts7.createSourceFile(sourceFilePath, fs.readFile(resolvedPath), ts7.ScriptTarget.ES5);
|
2447 | if (sourceFile.statements.length === 0) {
|
2448 | return void 0;
|
2449 | }
|
2450 | if (ts7.isExternalModule(sourceFile)) {
|
2451 | return "esm5";
|
2452 | } else if (parseStatementForUmdModule(sourceFile.statements[0]) !== null) {
|
2453 | return "umd";
|
2454 | } else {
|
2455 | return "commonjs";
|
2456 | }
|
2457 | }
|
2458 | function mergeConfigAndPackageJson(fs, entryPointPackageJson, entryPointConfig, packagePath, entryPointPath) {
|
2459 | if (entryPointPackageJson !== null) {
|
2460 | return __spreadValues(__spreadValues({}, entryPointPackageJson), entryPointConfig.override);
|
2461 | } else {
|
2462 | const name = `${fs.basename(packagePath)}/${fs.relative(packagePath, entryPointPath)}`;
|
2463 | return __spreadValues({ name }, entryPointConfig.override);
|
2464 | }
|
2465 | }
|
2466 | function guessTypingsFromPackageJson(fs, entryPointPath, entryPointPackageJson) {
|
2467 | for (const prop of SUPPORTED_FORMAT_PROPERTIES) {
|
2468 | const field = entryPointPackageJson[prop];
|
2469 | if (typeof field !== "string") {
|
2470 | continue;
|
2471 | }
|
2472 | const relativeTypingsPath = field.replace(/\.js$/, ".d.ts");
|
2473 | const typingsPath = fs.resolve(entryPointPath, relativeTypingsPath);
|
2474 | if (fs.exists(typingsPath)) {
|
2475 | return typingsPath;
|
2476 | }
|
2477 | }
|
2478 | return null;
|
2479 | }
|
2480 | function getPackageNameAndVersion(fs, packagePath, packagePackageJson, entryPointPackageJson) {
|
2481 | var _a;
|
2482 | let packageName;
|
2483 | if (packagePackageJson !== null) {
|
2484 | packageName = packagePackageJson.name;
|
2485 | } else if (entryPointPackageJson !== null) {
|
2486 | packageName = /^(?:@[^/]+\/)?[^/]*/.exec(entryPointPackageJson.name)[0];
|
2487 | } else {
|
2488 | const lastSegment = fs.basename(packagePath);
|
2489 | const secondLastSegment = fs.basename(fs.dirname(packagePath));
|
2490 | packageName = secondLastSegment.startsWith("@") ? `${secondLastSegment}/${lastSegment}` : lastSegment;
|
2491 | }
|
2492 | return {
|
2493 | packageName,
|
2494 | packageVersion: (_a = packagePackageJson == null ? void 0 : packagePackageJson.version) != null ? _a : null
|
2495 | };
|
2496 | }
|
2497 | function getRepositoryUrl(packageJson) {
|
2498 | if ((packageJson == null ? void 0 : packageJson.repository) === void 0) {
|
2499 | return "";
|
2500 | }
|
2501 | if (typeof packageJson.repository === "string") {
|
2502 | return packageJson.repository;
|
2503 | }
|
2504 | return packageJson.repository.url;
|
2505 | }
|
2506 |
|
2507 |
|
2508 | var DtsProcessing;
|
2509 | (function(DtsProcessing2) {
|
2510 | DtsProcessing2[DtsProcessing2["Yes"] = 0] = "Yes";
|
2511 | DtsProcessing2[DtsProcessing2["No"] = 1] = "No";
|
2512 | DtsProcessing2[DtsProcessing2["Only"] = 2] = "Only";
|
2513 | })(DtsProcessing || (DtsProcessing = {}));
|
2514 | var TaskDependencies = Map;
|
2515 |
|
2516 |
|
2517 | import ts8 from "typescript";
|
2518 | function adjustElementAccessExports(sourceText) {
|
2519 | if (!/exports\[["']/.test(sourceText)) {
|
2520 | return sourceText;
|
2521 | }
|
2522 | const replacements = [];
|
2523 | const sf = ts8.createSourceFile("input.js", sourceText, ts8.ScriptTarget.ES5, false, ts8.ScriptKind.JS);
|
2524 | ts8.forEachChild(sf, function visitNode(node) {
|
2525 | if (ts8.isElementAccessExpression(node) && isExportsIdentifier2(node.expression) && ts8.isStringLiteral(node.argumentExpression) && isJsIdentifier(node.argumentExpression.text)) {
|
2526 | replacements.push({
|
2527 | start: node.getStart(sf),
|
2528 | end: node.getEnd(),
|
2529 | identifier: node.argumentExpression.text
|
2530 | });
|
2531 | }
|
2532 | ts8.forEachChild(node, visitNode);
|
2533 | });
|
2534 | replacements.sort((a, b) => a.start - b.start);
|
2535 | const parts = [];
|
2536 | let currentIndex = 0;
|
2537 | for (const replacement of replacements) {
|
2538 | parts.push(sourceText.substring(currentIndex, replacement.start));
|
2539 | parts.push(`exports. ${replacement.identifier} `);
|
2540 | currentIndex = replacement.end;
|
2541 | }
|
2542 | parts.push(sourceText.substring(currentIndex));
|
2543 | return parts.join("");
|
2544 | }
|
2545 | function isExportsIdentifier2(expr) {
|
2546 | return ts8.isIdentifier(expr) && expr.text === "exports";
|
2547 | }
|
2548 | var identifierPattern = /^(?!(?:do|if|in|for|let|new|try|var|case|else|enum|eval|false|null|this|true|void|with|break|catch|class|const|super|throw|while|yield|delete|export|import|public|return|static|switch|typeof|default|extends|finally|package|private|continue|debugger|function|arguments|interface|protected|implements|instanceof)$)[$A-Z\_a-z\xaa\xb5\xba\xc0-\xd6\xd8-\xf6\xf8-\u02c1\u02c6-\u02d1\u02e0-\u02e4\u02ec\u02ee\u0370-\u0374\u0376\u0377\u037a-\u037d\u0386\u0388-\u038a\u038c\u038e-\u03a1\u03a3-\u03f5\u03f7-\u0481\u048a-\u0527\u0531-\u0556\u0559\u0561-\u0587\u05d0-\u05ea\u05f0-\u05f2\u0620-\u064a\u066e\u066f\u0671-\u06d3\u06d5\u06e5\u06e6\u06ee\u06ef\u06fa-\u06fc\u06ff\u0710\u0712-\u072f\u074d-\u07a5\u07b1\u07ca-\u07ea\u07f4\u07f5\u07fa\u0800-\u0815\u081a\u0824\u0828\u0840-\u0858\u08a0\u08a2-\u08ac\u0904-\u0939\u093d\u0950\u0958-\u0961\u0971-\u0977\u0979-\u097f\u0985-\u098c\u098f\u0990\u0993-\u09a8\u09aa-\u09b0\u09b2\u09b6-\u09b9\u09bd\u09ce\u09dc\u09dd\u09df-\u09e1\u09f0\u09f1\u0a05-\u0a0a\u0a0f\u0a10\u0a13-\u0a28\u0a2a-\u0a30\u0a32\u0a33\u0a35\u0a36\u0a38\u0a39\u0a59-\u0a5c\u0a5e\u0a72-\u0a74\u0a85-\u0a8d\u0a8f-\u0a91\u0a93-\u0aa8\u0aaa-\u0ab0\u0ab2\u0ab3\u0ab5-\u0ab9\u0abd\u0ad0\u0ae0\u0ae1\u0b05-\u0b0c\u0b0f\u0b10\u0b13-\u0b28\u0b2a-\u0b30\u0b32\u0b33\u0b35-\u0b39\u0b3d\u0b5c\u0b5d\u0b5f-\u0b61\u0b71\u0b83\u0b85-\u0b8a\u0b8e-\u0b90\u0b92-\u0b95\u0b99\u0b9a\u0b9c\u0b9e\u0b9f\u0ba3\u0ba4\u0ba8-\u0baa\u0bae-\u0bb9\u0bd0\u0c05-\u0c0c\u0c0e-\u0c10\u0c12-\u0c28\u0c2a-\u0c33\u0c35-\u0c39\u0c3d\u0c58\u0c59\u0c60\u0c61\u0c85-\u0c8c\u0c8e-\u0c90\u0c92-\u0ca8\u0caa-\u0cb3\u0cb5-\u0cb9\u0cbd\u0cde\u0ce0\u0ce1\u0cf1\u0cf2\u0d05-\u0d0c\u0d0e-\u0d10\u0d12-\u0d3a\u0d3d\u0d4e\u0d60\u0d61\u0d7a-\u0d7f\u0d85-\u0d96\u0d9a-\u0db1\u0db3-\u0dbb\u0dbd\u0dc0-\u0dc6\u0e01-\u0e30\u0e32\u0e33\u0e40-\u0e46\u0e81\u0e82\u0e84\u0e87\u0e88\u0e8a\u0e8d\u0e94-\u0e97\u0e99-\u0e9f\u0ea1-\u0ea3\u0ea5\u0ea7\u0eaa\u0eab\u0ead-\u0eb0\u0eb2\u0eb3\u0ebd\u0ec0-\u0ec4\u0ec6\u0edc-\u0edf\u0f00\u0f40-\u0f47\u0f49-\u0f6c\u0f88-\u0f8c\u1000-\u102a\u103f\u1050-\u1055\u105a-\u105d\u1061\u1065\u1066\u106e-\u1070\u1075-\u1081\u108e\u10a0-\u10c5\u10c7\u10cd\u10d0-\u10fa\u10fc-\u1248\u124a-\u124d\u1250-\u1256\u1258\u125a-\u125d\u1260-\u1288\u128a-\u128d\u1290-\u12b0\u12b2-\u12b5\u12b8-\u12be\u12c0\u12c2-\u12c5\u12c8-\u12d6\u12d8-\u1310\u1312-\u1315\u1318-\u135a\u1380-\u138f\u13a0-\u13f4\u1401-\u166c\u166f-\u167f\u1681-\u169a\u16a0-\u16ea\u16ee-\u16f0\u1700-\u170c\u170e-\u1711\u1720-\u1731\u1740-\u1751\u1760-\u176c\u176e-\u1770\u1780-\u17b3\u17d7\u17dc\u1820-\u1877\u1880-\u18a8\u18aa\u18b0-\u18f5\u1900-\u191c\u1950-\u196d\u1970-\u1974\u1980-\u19ab\u19c1-\u19c7\u1a00-\u1a16\u1a20-\u1a54\u1aa7\u1b05-\u1b33\u1b45-\u1b4b\u1b83-\u1ba0\u1bae\u1baf\u1bba-\u1be5\u1c00-\u1c23\u1c4d-\u1c4f\u1c5a-\u1c7d\u1ce9-\u1cec\u1cee-\u1cf1\u1cf5\u1cf6\u1d00-\u1dbf\u1e00-\u1f15\u1f18-\u1f1d\u1f20-\u1f45\u1f48-\u1f4d\u1f50-\u1f57\u1f59\u1f5b\u1f5d\u1f5f-\u1f7d\u1f80-\u1fb4\u1fb6-\u1fbc\u1fbe\u1fc2-\u1fc4\u1fc6-\u1fcc\u1fd0-\u1fd3\u1fd6-\u1fdb\u1fe0-\u1fec\u1ff2-\u1ff4\u1ff6-\u1ffc\u2071\u207f\u2090-\u209c\u2102\u2107\u210a-\u2113\u2115\u2119-\u211d\u2124\u2126\u2128\u212a-\u212d\u212f-\u2139\u213c-\u213f\u2145-\u2149\u214e\u2160-\u2188\u2c00-\u2c2e\u2c30-\u2c5e\u2c60-\u2ce4\u2ceb-\u2cee\u2cf2\u2cf3\u2d00-\u2d25\u2d27\u2d2d\u2d30-\u2d67\u2d6f\u2d80-\u2d96\u2da0-\u2da6\u2da8-\u2dae\u2db0-\u2db6\u2db8-\u2dbe\u2dc0-\u2dc6\u2dc8-\u2dce\u2dd0-\u2dd6\u2dd8-\u2dde\u2e2f\u3005-\u3007\u3021-\u3029\u3031-\u3035\u3038-\u303c\u3041-\u3096\u309d-\u309f\u30a1-\u30fa\u30fc-\u30ff\u3105-\u312d\u3131-\u318e\u31a0-\u31ba\u31f0-\u31ff\u3400-\u4db5\u4e00-\u9fcc\ua000-\ua48c\ua4d0-\ua4fd\ua500-\ua60c\ua610-\ua61f\ua62a\ua62b\ua640-\ua66e\ua67f-\ua697\ua6a0-\ua6ef\ua717-\ua71f\ua722-\ua788\ua78b-\ua78e\ua790-\ua793\ua7a0-\ua7aa\ua7f8-\ua801\ua803-\ua805\ua807-\ua80a\ua80c-\ua822\ua840-\ua873\ua882-\ua8b3\ua8f2-\ua8f7\ua8fb\ua90a-\ua925\ua930-\ua946\ua960-\ua97c\ua984-\ua9b2\ua9cf\uaa00-\uaa28\uaa40-\uaa42\uaa44-\uaa4b\uaa60-\uaa76\uaa7a\uaa80-\uaaaf\uaab1\uaab5\uaab6\uaab9-\uaabd\uaac0\uaac2\uaadb-\uaadd\uaae0-\uaaea\uaaf2-\uaaf4\uab01-\uab06\uab09-\uab0e\uab11-\uab16\uab20-\uab26\uab28-\uab2e\uabc0-\uabe2\uac00-\ud7a3\ud7b0-\ud7c6\ud7cb-\ud7fb\uf900-\ufa6d\ufa70-\ufad9\ufb00-\ufb06\ufb13-\ufb17\ufb1d\ufb1f-\ufb28\ufb2a-\ufb36\ufb38-\ufb3c\ufb3e\ufb40\ufb41\ufb43\ufb44\ufb46-\ufbb1\ufbd3-\ufd3d\ufd50-\ufd8f\ufd92-\ufdc7\ufdf0-\ufdfb\ufe70-\ufe74\ufe76-\ufefc\uff21-\uff3a\uff41-\uff5a\uff66-\uffbe\uffc2-\uffc7\uffca-\uffcf\uffd2-\uffd7\uffda-\uffdc][$A-Z\_a-z\xaa\xb5\xba\xc0-\xd6\xd8-\xf6\xf8-\u02c1\u02c6-\u02d1\u02e0-\u02e4\u02ec\u02ee\u0370-\u0374\u0376\u0377\u037a-\u037d\u0386\u0388-\u038a\u038c\u038e-\u03a1\u03a3-\u03f5\u03f7-\u0481\u048a-\u0527\u0531-\u0556\u0559\u0561-\u0587\u05d0-\u05ea\u05f0-\u05f2\u0620-\u064a\u066e\u066f\u0671-\u06d3\u06d5\u06e5\u06e6\u06ee\u06ef\u06fa-\u06fc\u06ff\u0710\u0712-\u072f\u074d-\u07a5\u07b1\u07ca-\u07ea\u07f4\u07f5\u07fa\u0800-\u0815\u081a\u0824\u0828\u0840-\u0858\u08a0\u08a2-\u08ac\u0904-\u0939\u093d\u0950\u0958-\u0961\u0971-\u0977\u0979-\u097f\u0985-\u098c\u098f\u0990\u0993-\u09a8\u09aa-\u09b0\u09b2\u09b6-\u09b9\u09bd\u09ce\u09dc\u09dd\u09df-\u09e1\u09f0\u09f1\u0a05-\u0a0a\u0a0f\u0a10\u0a13-\u0a28\u0a2a-\u0a30\u0a32\u0a33\u0a35\u0a36\u0a38\u0a39\u0a59-\u0a5c\u0a5e\u0a72-\u0a74\u0a85-\u0a8d\u0a8f-\u0a91\u0a93-\u0aa8\u0aaa-\u0ab0\u0ab2\u0ab3\u0ab5-\u0ab9\u0abd\u0ad0\u0ae0\u0ae1\u0b05-\u0b0c\u0b0f\u0b10\u0b13-\u0b28\u0b2a-\u0b30\u0b32\u0b33\u0b35-\u0b39\u0b3d\u0b5c\u0b5d\u0b5f-\u0b61\u0b71\u0b83\u0b85-\u0b8a\u0b8e-\u0b90\u0b92-\u0b95\u0b99\u0b9a\u0b9c\u0b9e\u0b9f\u0ba3\u0ba4\u0ba8-\u0baa\u0bae-\u0bb9\u0bd0\u0c05-\u0c0c\u0c0e-\u0c10\u0c12-\u0c28\u0c2a-\u0c33\u0c35-\u0c39\u0c3d\u0c58\u0c59\u0c60\u0c61\u0c85-\u0c8c\u0c8e-\u0c90\u0c92-\u0ca8\u0caa-\u0cb3\u0cb5-\u0cb9\u0cbd\u0cde\u0ce0\u0ce1\u0cf1\u0cf2\u0d05-\u0d0c\u0d0e-\u0d10\u0d12-\u0d3a\u0d3d\u0d4e\u0d60\u0d61\u0d7a-\u0d7f\u0d85-\u0d96\u0d9a-\u0db1\u0db3-\u0dbb\u0dbd\u0dc0-\u0dc6\u0e01-\u0e30\u0e32\u0e33\u0e40-\u0e46\u0e81\u0e82\u0e84\u0e87\u0e88\u0e8a\u0e8d\u0e94-\u0e97\u0e99-\u0e9f\u0ea1-\u0ea3\u0ea5\u0ea7\u0eaa\u0eab\u0ead-\u0eb0\u0eb2\u0eb3\u0ebd\u0ec0-\u0ec4\u0ec6\u0edc-\u0edf\u0f00\u0f40-\u0f47\u0f49-\u0f6c\u0f88-\u0f8c\u1000-\u102a\u103f\u1050-\u1055\u105a-\u105d\u1061\u1065\u1066\u106e-\u1070\u1075-\u1081\u108e\u10a0-\u10c5\u10c7\u10cd\u10d0-\u10fa\u10fc-\u1248\u124a-\u124d\u1250-\u1256\u1258\u125a-\u125d\u1260-\u1288\u128a-\u128d\u1290-\u12b0\u12b2-\u12b5\u12b8-\u12be\u12c0\u12c2-\u12c5\u12c8-\u12d6\u12d8-\u1310\u1312-\u1315\u1318-\u135a\u1380-\u138f\u13a0-\u13f4\u1401-\u166c\u166f-\u167f\u1681-\u169a\u16a0-\u16ea\u16ee-\u16f0\u1700-\u170c\u170e-\u1711\u1720-\u1731\u1740-\u1751\u1760-\u176c\u176e-\u1770\u1780-\u17b3\u17d7\u17dc\u1820-\u1877\u1880-\u18a8\u18aa\u18b0-\u18f5\u1900-\u191c\u1950-\u196d\u1970-\u1974\u1980-\u19ab\u19c1-\u19c7\u1a00-\u1a16\u1a20-\u1a54\u1aa7\u1b05-\u1b33\u1b45-\u1b4b\u1b83-\u1ba0\u1bae\u1baf\u1bba-\u1be5\u1c00-\u1c23\u1c4d-\u1c4f\u1c5a-\u1c7d\u1ce9-\u1cec\u1cee-\u1cf1\u1cf5\u1cf6\u1d00-\u1dbf\u1e00-\u1f15\u1f18-\u1f1d\u1f20-\u1f45\u1f48-\u1f4d\u1f50-\u1f57\u1f59\u1f5b\u1f5d\u1f5f-\u1f7d\u1f80-\u1fb4\u1fb6-\u1fbc\u1fbe\u1fc2-\u1fc4\u1fc6-\u1fcc\u1fd0-\u1fd3\u1fd6-\u1fdb\u1fe0-\u1fec\u1ff2-\u1ff4\u1ff6-\u1ffc\u2071\u207f\u2090-\u209c\u2102\u2107\u210a-\u2113\u2115\u2119-\u211d\u2124\u2126\u2128\u212a-\u212d\u212f-\u2139\u213c-\u213f\u2145-\u2149\u214e\u2160-\u2188\u2c00-\u2c2e\u2c30-\u2c5e\u2c60-\u2ce4\u2ceb-\u2cee\u2cf2\u2cf3\u2d00-\u2d25\u2d27\u2d2d\u2d30-\u2d67\u2d6f\u2d80-\u2d96\u2da0-\u2da6\u2da8-\u2dae\u2db0-\u2db6\u2db8-\u2dbe\u2dc0-\u2dc6\u2dc8-\u2dce\u2dd0-\u2dd6\u2dd8-\u2dde\u2e2f\u3005-\u3007\u3021-\u3029\u3031-\u3035\u3038-\u303c\u3041-\u3096\u309d-\u309f\u30a1-\u30fa\u30fc-\u30ff\u3105-\u312d\u3131-\u318e\u31a0-\u31ba\u31f0-\u31ff\u3400-\u4db5\u4e00-\u9fcc\ua000-\ua48c\ua4d0-\ua4fd\ua500-\ua60c\ua610-\ua61f\ua62a\ua62b\ua640-\ua66e\ua67f-\ua697\ua6a0-\ua6ef\ua717-\ua71f\ua722-\ua788\ua78b-\ua78e\ua790-\ua793\ua7a0-\ua7aa\ua7f8-\ua801\ua803-\ua805\ua807-\ua80a\ua80c-\ua822\ua840-\ua873\ua882-\ua8b3\ua8f2-\ua8f7\ua8fb\ua90a-\ua925\ua930-\ua946\ua960-\ua97c\ua984-\ua9b2\ua9cf\uaa00-\uaa28\uaa40-\uaa42\uaa44-\uaa4b\uaa60-\uaa76\uaa7a\uaa80-\uaaaf\uaab1\uaab5\uaab6\uaab9-\uaabd\uaac0\uaac2\uaadb-\uaadd\uaae0-\uaaea\uaaf2-\uaaf4\uab01-\uab06\uab09-\uab0e\uab11-\uab16\uab20-\uab26\uab28-\uab2e\uabc0-\uabe2\uac00-\ud7a3\ud7b0-\ud7c6\ud7cb-\ud7fb\uf900-\ufa6d\ufa70-\ufad9\ufb00-\ufb06\ufb13-\ufb17\ufb1d\ufb1f-\ufb28\ufb2a-\ufb36\ufb38-\ufb3c\ufb3e\ufb40\ufb41\ufb43\ufb44\ufb46-\ufbb1\ufbd3-\ufd3d\ufd50-\ufd8f\ufd92-\ufdc7\ufdf0-\ufdfb\ufe70-\ufe74\ufe76-\ufefc\uff21-\uff3a\uff41-\uff5a\uff66-\uffbe\uffc2-\uffc7\uffca-\uffcf\uffd2-\uffd7\uffda-\uffdc0-9\u0300-\u036f\u0483-\u0487\u0591-\u05bd\u05bf\u05c1\u05c2\u05c4\u05c5\u05c7\u0610-\u061a\u064b-\u0669\u0670\u06d6-\u06dc\u06df-\u06e4\u06e7\u06e8\u06ea-\u06ed\u06f0-\u06f9\u0711\u0730-\u074a\u07a6-\u07b0\u07c0-\u07c9\u07eb-\u07f3\u0816-\u0819\u081b-\u0823\u0825-\u0827\u0829-\u082d\u0859-\u085b\u08e4-\u08fe\u0900-\u0903\u093a-\u093c\u093e-\u094f\u0951-\u0957\u0962\u0963\u0966-\u096f\u0981-\u0983\u09bc\u09be-\u09c4\u09c7\u09c8\u09cb-\u09cd\u09d7\u09e2\u09e3\u09e6-\u09ef\u0a01-\u0a03\u0a3c\u0a3e-\u0a42\u0a47\u0a48\u0a4b-\u0a4d\u0a51\u0a66-\u0a71\u0a75\u0a81-\u0a83\u0abc\u0abe-\u0ac5\u0ac7-\u0ac9\u0acb-\u0acd\u0ae2\u0ae3\u0ae6-\u0aef\u0b01-\u0b03\u0b3c\u0b3e-\u0b44\u0b47\u0b48\u0b4b-\u0b4d\u0b56\u0b57\u0b62\u0b63\u0b66-\u0b6f\u0b82\u0bbe-\u0bc2\u0bc6-\u0bc8\u0bca-\u0bcd\u0bd7\u0be6-\u0bef\u0c01-\u0c03\u0c3e-\u0c44\u0c46-\u0c48\u0c4a-\u0c4d\u0c55\u0c56\u0c62\u0c63\u0c66-\u0c6f\u0c82\u0c83\u0cbc\u0cbe-\u0cc4\u0cc6-\u0cc8\u0cca-\u0ccd\u0cd5\u0cd6\u0ce2\u0ce3\u0ce6-\u0cef\u0d02\u0d03\u0d3e-\u0d44\u0d46-\u0d48\u0d4a-\u0d4d\u0d57\u0d62\u0d63\u0d66-\u0d6f\u0d82\u0d83\u0dca\u0dcf-\u0dd4\u0dd6\u0dd8-\u0ddf\u0df2\u0df3\u0e31\u0e34-\u0e3a\u0e47-\u0e4e\u0e50-\u0e59\u0eb1\u0eb4-\u0eb9\u0ebb\u0ebc\u0ec8-\u0ecd\u0ed0-\u0ed9\u0f18\u0f19\u0f20-\u0f29\u0f35\u0f37\u0f39\u0f3e\u0f3f\u0f71-\u0f84\u0f86\u0f87\u0f8d-\u0f97\u0f99-\u0fbc\u0fc6\u102b-\u103e\u1040-\u1049\u1056-\u1059\u105e-\u1060\u1062-\u1064\u1067-\u106d\u1071-\u1074\u1082-\u108d\u108f-\u109d\u135d-\u135f\u1712-\u1714\u1732-\u1734\u1752\u1753\u1772\u1773\u17b4-\u17d3\u17dd\u17e0-\u17e9\u180b-\u180d\u1810-\u1819\u18a9\u1920-\u192b\u1930-\u193b\u1946-\u194f\u19b0-\u19c0\u19c8\u19c9\u19d0-\u19d9\u1a17-\u1a1b\u1a55-\u1a5e\u1a60-\u1a7c\u1a7f-\u1a89\u1a90-\u1a99\u1b00-\u1b04\u1b34-\u1b44\u1b50-\u1b59\u1b6b-\u1b73\u1b80-\u1b82\u1ba1-\u1bad\u1bb0-\u1bb9\u1be6-\u1bf3\u1c24-\u1c37\u1c40-\u1c49\u1c50-\u1c59\u1cd0-\u1cd2\u1cd4-\u1ce8\u1ced\u1cf2-\u1cf4\u1dc0-\u1de6\u1dfc-\u1dff\u200c\u200d\u203f\u2040\u2054\u20d0-\u20dc\u20e1\u20e5-\u20f0\u2cef-\u2cf1\u2d7f\u2de0-\u2dff\u302a-\u302f\u3099\u309a\ua620-\ua629\ua66f\ua674-\ua67d\ua69f\ua6f0\ua6f1\ua802\ua806\ua80b\ua823-\ua827\ua880\ua881\ua8b4-\ua8c4\ua8d0-\ua8d9\ua8e0-\ua8f1\ua900-\ua909\ua926-\ua92d\ua947-\ua953\ua980-\ua983\ua9b3-\ua9c0\ua9d0-\ua9d9\uaa29-\uaa36\uaa43\uaa4c\uaa4d\uaa50-\uaa59\uaa7b\uaab0\uaab2-\uaab4\uaab7\uaab8\uaabe\uaabf\uaac1\uaaeb-\uaaef\uaaf5\uaaf6\uabe3-\uabea\uabec\uabed\uabf0-\uabf9\ufb1e\ufe00-\ufe0f\ufe20-\ufe26\ufe33\ufe34\ufe4d-\ufe4f\uff10-\uff19\uff3f]*$/;
|
2549 | function isJsIdentifier(text) {
|
2550 | return identifierPattern.test(text);
|
2551 | }
|
2552 |
|
2553 |
|
2554 | import ts10 from "typescript";
|
2555 |
|
2556 |
|
2557 | import ts9 from "typescript";
|
2558 | function patchTsGetExpandoInitializer() {
|
2559 | if (isTs31778GetExpandoInitializerFixed()) {
|
2560 | return null;
|
2561 | }
|
2562 | const originalGetExpandoInitializer = ts9.getExpandoInitializer;
|
2563 | if (originalGetExpandoInitializer === void 0) {
|
2564 | throw makeUnsupportedTypeScriptError();
|
2565 | }
|
2566 | ts9.getExpandoInitializer = (initializer, isPrototypeAssignment) => {
|
2567 | if (ts9.isParenthesizedExpression(initializer) && ts9.isCallExpression(initializer.expression)) {
|
2568 | initializer = initializer.expression;
|
2569 | }
|
2570 | return originalGetExpandoInitializer(initializer, isPrototypeAssignment);
|
2571 | };
|
2572 | return originalGetExpandoInitializer;
|
2573 | }
|
2574 | function restoreGetExpandoInitializer(originalGetExpandoInitializer) {
|
2575 | if (originalGetExpandoInitializer !== null) {
|
2576 | ts9.getExpandoInitializer = originalGetExpandoInitializer;
|
2577 | }
|
2578 | }
|
2579 | var ts31778FixedResult = null;
|
2580 | function isTs31778GetExpandoInitializerFixed() {
|
2581 | if (ts31778FixedResult !== null) {
|
2582 | return ts31778FixedResult;
|
2583 | }
|
2584 | ts31778FixedResult = checkIfExpandoPropertyIsPresent();
|
2585 | if (!ts31778FixedResult) {
|
2586 | const originalGetExpandoInitializer = patchTsGetExpandoInitializer();
|
2587 | try {
|
2588 | const patchIsSuccessful = checkIfExpandoPropertyIsPresent();
|
2589 | if (!patchIsSuccessful) {
|
2590 | throw makeUnsupportedTypeScriptError();
|
2591 | }
|
2592 | } finally {
|
2593 | restoreGetExpandoInitializer(originalGetExpandoInitializer);
|
2594 | }
|
2595 | }
|
2596 | return ts31778FixedResult;
|
2597 | }
|
2598 | function checkIfExpandoPropertyIsPresent() {
|
2599 | const sourceText = `
|
2600 | (function() {
|
2601 | var A = (function() {
|
2602 | function A() {}
|
2603 | return A;
|
2604 | }());
|
2605 | A.expando = true;
|
2606 | }());`;
|
2607 | const sourceFile = ts9.createSourceFile("test.js", sourceText, ts9.ScriptTarget.ES5, true, ts9.ScriptKind.JS);
|
2608 | const host = {
|
2609 | getSourceFile() {
|
2610 | return sourceFile;
|
2611 | },
|
2612 | fileExists() {
|
2613 | return true;
|
2614 | },
|
2615 | readFile() {
|
2616 | return "";
|
2617 | },
|
2618 | writeFile() {
|
2619 | },
|
2620 | getDefaultLibFileName() {
|
2621 | return "";
|
2622 | },
|
2623 | getCurrentDirectory() {
|
2624 | return "";
|
2625 | },
|
2626 | getDirectories() {
|
2627 | return [];
|
2628 | },
|
2629 | getCanonicalFileName(fileName) {
|
2630 | return fileName;
|
2631 | },
|
2632 | useCaseSensitiveFileNames() {
|
2633 | return true;
|
2634 | },
|
2635 | getNewLine() {
|
2636 | return "\n";
|
2637 | }
|
2638 | };
|
2639 | const options = { noResolve: true, noLib: true, noEmit: true, allowJs: true };
|
2640 | const program = ts9.createProgram(["test.js"], options, host);
|
2641 | function visitor(node) {
|
2642 | if (ts9.isVariableDeclaration(node) && hasNameIdentifier(node) && node.name.text === "A") {
|
2643 | return node;
|
2644 | }
|
2645 | return ts9.forEachChild(node, visitor);
|
2646 | }
|
2647 | const declaration = ts9.forEachChild(sourceFile, visitor);
|
2648 | if (declaration === void 0) {
|
2649 | throw new Error("Unable to find declaration of outer A");
|
2650 | }
|
2651 | const symbol = program.getTypeChecker().getSymbolAtLocation(declaration.name);
|
2652 | if (symbol === void 0) {
|
2653 | throw new Error("Unable to resolve symbol of outer A");
|
2654 | }
|
2655 | return symbol.exports !== void 0 && symbol.exports.has("expando");
|
2656 | }
|
2657 | function makeUnsupportedTypeScriptError() {
|
2658 | return new Error("The TypeScript version used is not supported by ngcc.");
|
2659 | }
|
2660 |
|
2661 |
|
2662 | function makeBundleProgram(fs, isCore, pkg, path, r3FileName, options, host, additionalFiles = []) {
|
2663 | const r3SymbolsPath = isCore ? findR3SymbolsPath(fs, fs.dirname(path), r3FileName) : null;
|
2664 | let rootPaths = r3SymbolsPath ? [path, r3SymbolsPath, ...additionalFiles] : [path, ...additionalFiles];
|
2665 | const originalGetExpandoInitializer = patchTsGetExpandoInitializer();
|
2666 | const program = ts10.createProgram(rootPaths, options, host);
|
2667 | program.getTypeChecker();
|
2668 | restoreGetExpandoInitializer(originalGetExpandoInitializer);
|
2669 | const file = program.getSourceFile(path);
|
2670 | const r3SymbolsFile = r3SymbolsPath && program.getSourceFile(r3SymbolsPath) || null;
|
2671 | return { program, options, host, package: pkg, path, file, r3SymbolsPath, r3SymbolsFile };
|
2672 | }
|
2673 | function findR3SymbolsPath(fs, directory, filename) {
|
2674 | const r3SymbolsFilePath = fs.resolve(directory, filename);
|
2675 | if (fs.exists(r3SymbolsFilePath)) {
|
2676 | return r3SymbolsFilePath;
|
2677 | }
|
2678 | const subDirectories = fs.readdir(directory).filter((p) => !p.startsWith(".")).filter((p) => p !== "node_modules").filter((p) => {
|
2679 | const stat = fs.lstat(fs.resolve(directory, p));
|
2680 | return stat.isDirectory() && !stat.isSymbolicLink();
|
2681 | });
|
2682 | for (const subDirectory of subDirectories) {
|
2683 | const r3SymbolsFilePath2 = findR3SymbolsPath(fs, fs.resolve(directory, subDirectory), filename);
|
2684 | if (r3SymbolsFilePath2) {
|
2685 | return r3SymbolsFilePath2;
|
2686 | }
|
2687 | }
|
2688 | return null;
|
2689 | }
|
2690 |
|
2691 |
|
2692 | import ts11 from "typescript";
|
2693 | var NgccSourcesCompilerHost = class extends NgtscCompilerHost {
|
2694 | constructor(fs, options, cache, moduleResolutionCache, packagePath) {
|
2695 | super(fs, options);
|
2696 | this.cache = cache;
|
2697 | this.moduleResolutionCache = moduleResolutionCache;
|
2698 | this.packagePath = packagePath;
|
2699 | }
|
2700 | getSourceFile(fileName, languageVersion) {
|
2701 | return this.cache.getCachedSourceFile(fileName, languageVersion);
|
2702 | }
|
2703 | resolveModuleNames(moduleNames, containingFile, reusedNames, redirectedReference) {
|
2704 | return moduleNames.map((moduleName) => {
|
2705 | const { resolvedModule } = ts11.resolveModuleName(moduleName, containingFile, this.options, this, this.moduleResolutionCache, redirectedReference);
|
2706 | if ((resolvedModule == null ? void 0 : resolvedModule.extension) === ts11.Extension.Dts && containingFile.endsWith(".js") && isRelativePath(moduleName)) {
|
2707 | const jsFile = resolvedModule.resolvedFileName.replace(/\.d\.ts$/, ".js");
|
2708 | if (this.fileExists(jsFile)) {
|
2709 | return __spreadProps(__spreadValues({}, resolvedModule), { resolvedFileName: jsFile, extension: ts11.Extension.Js });
|
2710 | }
|
2711 | }
|
2712 | if ((resolvedModule == null ? void 0 : resolvedModule.extension) === ts11.Extension.Js && !isWithinPackage(this.packagePath, this.fs.resolve(resolvedModule.resolvedFileName))) {
|
2713 | return void 0;
|
2714 | }
|
2715 | return resolvedModule;
|
2716 | });
|
2717 | }
|
2718 | };
|
2719 | var NgccDtsCompilerHost = class extends NgtscCompilerHost {
|
2720 | constructor(fs, options, cache, moduleResolutionCache) {
|
2721 | super(fs, options);
|
2722 | this.cache = cache;
|
2723 | this.moduleResolutionCache = moduleResolutionCache;
|
2724 | }
|
2725 | getSourceFile(fileName, languageVersion) {
|
2726 | return this.cache.getCachedSourceFile(fileName, languageVersion);
|
2727 | }
|
2728 | resolveModuleNames(moduleNames, containingFile, reusedNames, redirectedReference) {
|
2729 | return moduleNames.map((moduleName) => {
|
2730 | const { resolvedModule } = ts11.resolveModuleName(moduleName, containingFile, this.options, this, this.moduleResolutionCache, redirectedReference);
|
2731 | return resolvedModule;
|
2732 | });
|
2733 | }
|
2734 | };
|
2735 |
|
2736 |
|
2737 | import ts12 from "typescript";
|
2738 | var SharedFileCache = class {
|
2739 | constructor(fs) {
|
2740 | this.fs = fs;
|
2741 | this.sfCache = new Map();
|
2742 | }
|
2743 | getCachedSourceFile(fileName) {
|
2744 | const absPath = this.fs.resolve(fileName);
|
2745 | if (isDefaultLibrary(absPath, this.fs)) {
|
2746 | return this.getStableCachedFile(absPath);
|
2747 | } else if (isAngularDts(absPath, this.fs)) {
|
2748 | return this.getVolatileCachedFile(absPath);
|
2749 | } else {
|
2750 | return void 0;
|
2751 | }
|
2752 | }
|
2753 | getStableCachedFile(absPath) {
|
2754 | if (!this.sfCache.has(absPath)) {
|
2755 | const content = readFile(absPath, this.fs);
|
2756 | if (content === void 0) {
|
2757 | return void 0;
|
2758 | }
|
2759 | const sf = ts12.createSourceFile(absPath, content, ts12.ScriptTarget.ES2015);
|
2760 | this.sfCache.set(absPath, sf);
|
2761 | }
|
2762 | return this.sfCache.get(absPath);
|
2763 | }
|
2764 | getVolatileCachedFile(absPath) {
|
2765 | const content = readFile(absPath, this.fs);
|
2766 | if (content === void 0) {
|
2767 | return void 0;
|
2768 | }
|
2769 | if (!this.sfCache.has(absPath) || this.sfCache.get(absPath).text !== content) {
|
2770 | const sf = ts12.createSourceFile(absPath, content, ts12.ScriptTarget.ES2015);
|
2771 | this.sfCache.set(absPath, sf);
|
2772 | }
|
2773 | return this.sfCache.get(absPath);
|
2774 | }
|
2775 | };
|
2776 | var DEFAULT_LIB_PATTERN = ["node_modules", "typescript", "lib", /^lib\..+\.d\.ts$/];
|
2777 | function isDefaultLibrary(absPath, fs) {
|
2778 | return isFile(absPath, DEFAULT_LIB_PATTERN, fs);
|
2779 | }
|
2780 | var ANGULAR_DTS_PATTERN = ["node_modules", "@angular", /./, /\.d\.ts$/];
|
2781 | function isAngularDts(absPath, fs) {
|
2782 | return isFile(absPath, ANGULAR_DTS_PATTERN, fs);
|
2783 | }
|
2784 | function isFile(path, segments, fs) {
|
2785 | for (let i = segments.length - 1; i >= 0; i--) {
|
2786 | const pattern = segments[i];
|
2787 | const segment = fs.basename(path);
|
2788 | if (typeof pattern === "string") {
|
2789 | if (pattern !== segment) {
|
2790 | return false;
|
2791 | }
|
2792 | } else {
|
2793 | if (!pattern.test(segment)) {
|
2794 | return false;
|
2795 | }
|
2796 | }
|
2797 | path = fs.dirname(path);
|
2798 | }
|
2799 | return true;
|
2800 | }
|
2801 | var EntryPointFileCache = class {
|
2802 | constructor(fs, sharedFileCache, processSourceText) {
|
2803 | this.fs = fs;
|
2804 | this.sharedFileCache = sharedFileCache;
|
2805 | this.processSourceText = processSourceText;
|
2806 | this.sfCache = new Map();
|
2807 | }
|
2808 | getCachedSourceFile(fileName, languageVersion) {
|
2809 | const staticSf = this.sharedFileCache.getCachedSourceFile(fileName);
|
2810 | if (staticSf !== void 0) {
|
2811 | return staticSf;
|
2812 | }
|
2813 | const absPath = this.fs.resolve(fileName);
|
2814 | if (this.sfCache.has(absPath)) {
|
2815 | return this.sfCache.get(absPath);
|
2816 | }
|
2817 | const content = readFile(absPath, this.fs);
|
2818 | if (content === void 0) {
|
2819 | return void 0;
|
2820 | }
|
2821 | const processed = this.processSourceText(content);
|
2822 | const sf = ts12.createSourceFile(fileName, processed, languageVersion);
|
2823 | this.sfCache.set(absPath, sf);
|
2824 | return sf;
|
2825 | }
|
2826 | };
|
2827 | function readFile(absPath, fs) {
|
2828 | if (!fs.exists(absPath) || !fs.stat(absPath).isFile()) {
|
2829 | return void 0;
|
2830 | }
|
2831 | return fs.readFile(absPath);
|
2832 | }
|
2833 | function createModuleResolutionCache(fs) {
|
2834 | return ts12.createModuleResolutionCache(fs.pwd(), (fileName) => {
|
2835 | return fs.isCaseSensitive() ? fileName : fileName.toLowerCase();
|
2836 | });
|
2837 | }
|
2838 |
|
2839 |
|
2840 | function createSourceTextProcessor(format) {
|
2841 | if (format === "umd" || format === "commonjs") {
|
2842 | return adjustElementAccessExports;
|
2843 | } else {
|
2844 | return (sourceText) => sourceText;
|
2845 | }
|
2846 | }
|
2847 | function makeEntryPointBundle(fs, entryPoint, sharedFileCache, moduleResolutionCache, formatPath, isCore, format, dtsProcessing, pathMappings, mirrorDtsFromSrc = false, enableI18nLegacyMessageIdFormat = true) {
|
2848 | const rootDir = entryPoint.packagePath;
|
2849 | const options = __spreadValues({ allowJs: true, maxNodeModuleJsDepth: Infinity, rootDir }, pathMappings);
|
2850 | const processSourceText = createSourceTextProcessor(format);
|
2851 | const entryPointCache = new EntryPointFileCache(fs, sharedFileCache, processSourceText);
|
2852 | const dtsHost = new NgccDtsCompilerHost(fs, options, entryPointCache, moduleResolutionCache);
|
2853 | const srcHost = new NgccSourcesCompilerHost(fs, options, entryPointCache, moduleResolutionCache, entryPoint.packagePath);
|
2854 | const absFormatPath = fs.resolve(entryPoint.path, formatPath);
|
2855 | const typingsPath = fs.resolve(entryPoint.path, entryPoint.typings);
|
2856 | const src = makeBundleProgram(fs, isCore, entryPoint.packagePath, absFormatPath, "r3_symbols.js", options, srcHost);
|
2857 | const additionalDtsFiles = dtsProcessing !== DtsProcessing.No && mirrorDtsFromSrc ? computePotentialDtsFilesFromJsFiles(fs, src.program, absFormatPath, typingsPath) : [];
|
2858 | const dts = dtsProcessing !== DtsProcessing.No ? makeBundleProgram(fs, isCore, entryPoint.packagePath, typingsPath, "r3_symbols.d.ts", __spreadProps(__spreadValues({}, options), { allowJs: false }), dtsHost, additionalDtsFiles) : null;
|
2859 | const isFlatCore = isCore && src.r3SymbolsFile === null;
|
2860 | return {
|
2861 | entryPoint,
|
2862 | format,
|
2863 | rootDirs: [rootDir],
|
2864 | isCore,
|
2865 | isFlatCore,
|
2866 | src,
|
2867 | dts,
|
2868 | dtsProcessing,
|
2869 | enableI18nLegacyMessageIdFormat
|
2870 | };
|
2871 | }
|
2872 | function computePotentialDtsFilesFromJsFiles(fs, srcProgram, formatPath, typingsPath) {
|
2873 | const formatRoot = fs.dirname(formatPath);
|
2874 | const typingsRoot = fs.dirname(typingsPath);
|
2875 | const additionalFiles = [];
|
2876 | for (const sf of srcProgram.getSourceFiles()) {
|
2877 | if (!sf.fileName.endsWith(".js")) {
|
2878 | continue;
|
2879 | }
|
2880 | const mirroredDtsPath = fs.resolve(typingsRoot, fs.relative(formatRoot, sf.fileName.replace(/\.js$/, ".d.ts")));
|
2881 | if (fs.exists(mirroredDtsPath)) {
|
2882 | additionalFiles.push(mirroredDtsPath);
|
2883 | }
|
2884 | }
|
2885 | return additionalFiles;
|
2886 | }
|
2887 |
|
2888 |
|
2889 | import ts22 from "typescript";
|
2890 |
|
2891 |
|
2892 | import { ConstantPool } from "@angular/compiler";
|
2893 |
|
2894 |
|
2895 | import ts13 from "typescript";
|
2896 | function isClassDeclaration(clazz) {
|
2897 | return isNamedClassDeclaration(clazz) || isNamedFunctionDeclaration(clazz) || isNamedVariableDeclaration(clazz);
|
2898 | }
|
2899 | function hasDirectiveDecorator(host, clazz) {
|
2900 | const ref = new Reference(clazz);
|
2901 | return host.metadata.getDirectiveMetadata(ref) !== null;
|
2902 | }
|
2903 | function hasPipeDecorator(host, clazz) {
|
2904 | const ref = new Reference(clazz);
|
2905 | return host.metadata.getPipeMetadata(ref) !== null;
|
2906 | }
|
2907 | function hasConstructor(host, clazz) {
|
2908 | return host.reflectionHost.getConstructorParameters(clazz) !== null;
|
2909 | }
|
2910 | function createDirectiveDecorator(clazz, metadata) {
|
2911 | const args = [];
|
2912 | if (metadata !== void 0) {
|
2913 | const metaArgs = [];
|
2914 | if (metadata.selector !== null) {
|
2915 | metaArgs.push(property("selector", metadata.selector));
|
2916 | }
|
2917 | if (metadata.exportAs !== null) {
|
2918 | metaArgs.push(property("exportAs", metadata.exportAs.join(", ")));
|
2919 | }
|
2920 | args.push(reifySourceFile(ts13.createObjectLiteral(metaArgs)));
|
2921 | }
|
2922 | return {
|
2923 | name: "Directive",
|
2924 | identifier: null,
|
2925 | import: { name: "Directive", from: "@angular/core" },
|
2926 | node: null,
|
2927 | synthesizedFor: clazz.name,
|
2928 | args
|
2929 | };
|
2930 | }
|
2931 | function createComponentDecorator(clazz, metadata) {
|
2932 | const metaArgs = [
|
2933 | property("template", "")
|
2934 | ];
|
2935 | if (metadata.selector !== null) {
|
2936 | metaArgs.push(property("selector", metadata.selector));
|
2937 | }
|
2938 | if (metadata.exportAs !== null) {
|
2939 | metaArgs.push(property("exportAs", metadata.exportAs.join(", ")));
|
2940 | }
|
2941 | return {
|
2942 | name: "Component",
|
2943 | identifier: null,
|
2944 | import: { name: "Component", from: "@angular/core" },
|
2945 | node: null,
|
2946 | synthesizedFor: clazz.name,
|
2947 | args: [
|
2948 | reifySourceFile(ts13.createObjectLiteral(metaArgs))
|
2949 | ]
|
2950 | };
|
2951 | }
|
2952 | function createInjectableDecorator(clazz) {
|
2953 | return {
|
2954 | name: "Injectable",
|
2955 | identifier: null,
|
2956 | import: { name: "Injectable", from: "@angular/core" },
|
2957 | node: null,
|
2958 | synthesizedFor: clazz.name,
|
2959 | args: []
|
2960 | };
|
2961 | }
|
2962 | function property(name, value) {
|
2963 | return ts13.createPropertyAssignment(name, ts13.createStringLiteral(value));
|
2964 | }
|
2965 | var EMPTY_SF = ts13.createSourceFile("(empty)", "", ts13.ScriptTarget.Latest);
|
2966 | function reifySourceFile(expr) {
|
2967 | const printer = ts13.createPrinter();
|
2968 | const exprText = printer.printNode(ts13.EmitHint.Unspecified, expr, EMPTY_SF);
|
2969 | const sf = ts13.createSourceFile("(synthetic)", `const expr = ${exprText};`, ts13.ScriptTarget.Latest, true, ts13.ScriptKind.JS);
|
2970 | const stmt = sf.statements[0];
|
2971 | if (!ts13.isVariableStatement(stmt)) {
|
2972 | throw new Error(`Expected VariableStatement, got ${ts13.SyntaxKind[stmt.kind]}`);
|
2973 | }
|
2974 | return stmt.declarationList.declarations[0].initializer;
|
2975 | }
|
2976 |
|
2977 |
|
2978 | var MissingInjectableMigration = class {
|
2979 | apply(clazz, host) {
|
2980 | const decorators = host.reflectionHost.getDecoratorsOfDeclaration(clazz);
|
2981 | if (decorators === null) {
|
2982 | return null;
|
2983 | }
|
2984 | for (const decorator of decorators) {
|
2985 | const name = getAngularCoreDecoratorName(decorator);
|
2986 | if (name === "NgModule") {
|
2987 | migrateNgModuleProviders(decorator, host);
|
2988 | } else if (name === "Directive") {
|
2989 | migrateDirectiveProviders(decorator, host, false);
|
2990 | } else if (name === "Component") {
|
2991 | migrateDirectiveProviders(decorator, host, true);
|
2992 | }
|
2993 | }
|
2994 | return null;
|
2995 | }
|
2996 | };
|
2997 | function migrateNgModuleProviders(decorator, host) {
|
2998 | if (decorator.args === null || decorator.args.length !== 1) {
|
2999 | return;
|
3000 | }
|
3001 | const metadata = host.evaluator.evaluate(decorator.args[0], forwardRefResolver);
|
3002 | if (!(metadata instanceof Map)) {
|
3003 | return;
|
3004 | }
|
3005 | migrateProviders(metadata, "providers", host);
|
3006 | }
|
3007 | function migrateDirectiveProviders(decorator, host, isComponent) {
|
3008 | if (decorator.args === null || decorator.args.length !== 1) {
|
3009 | return;
|
3010 | }
|
3011 | const metadata = host.evaluator.evaluate(decorator.args[0], forwardRefResolver);
|
3012 | if (!(metadata instanceof Map)) {
|
3013 | return;
|
3014 | }
|
3015 | migrateProviders(metadata, "providers", host);
|
3016 | if (isComponent) {
|
3017 | migrateProviders(metadata, "viewProviders", host);
|
3018 | }
|
3019 | }
|
3020 | function migrateProviders(metadata, field, host) {
|
3021 | if (!metadata.has(field)) {
|
3022 | return;
|
3023 | }
|
3024 | const providers = metadata.get(field);
|
3025 | if (!Array.isArray(providers)) {
|
3026 | return;
|
3027 | }
|
3028 | for (const provider of providers) {
|
3029 | migrateProvider(provider, host);
|
3030 | }
|
3031 | }
|
3032 | function migrateProvider(provider, host) {
|
3033 | if (provider instanceof Map) {
|
3034 | if (!provider.has("provide") || provider.has("useValue") || provider.has("useFactory") || provider.has("useExisting")) {
|
3035 | return;
|
3036 | }
|
3037 | if (provider.has("useClass")) {
|
3038 | if (!provider.has("deps")) {
|
3039 | migrateProviderClass(provider.get("useClass"), host);
|
3040 | }
|
3041 | } else {
|
3042 | migrateProviderClass(provider.get("provide"), host);
|
3043 | }
|
3044 | } else if (Array.isArray(provider)) {
|
3045 | for (const v of provider) {
|
3046 | migrateProvider(v, host);
|
3047 | }
|
3048 | } else {
|
3049 | migrateProviderClass(provider, host);
|
3050 | }
|
3051 | }
|
3052 | function migrateProviderClass(provider, host) {
|
3053 | if (!(provider instanceof Reference)) {
|
3054 | return;
|
3055 | }
|
3056 | const clazz = provider.node;
|
3057 | if (isClassDeclaration(clazz) && host.isInScope(clazz) && needsInjectableDecorator(clazz, host)) {
|
3058 | host.injectSyntheticDecorator(clazz, createInjectableDecorator(clazz));
|
3059 | }
|
3060 | }
|
3061 | var NO_MIGRATE_DECORATORS = new Set(["Injectable", "Directive", "Component", "Pipe"]);
|
3062 | function needsInjectableDecorator(clazz, host) {
|
3063 | const decorators = host.getAllDecorators(clazz);
|
3064 | if (decorators === null) {
|
3065 | return true;
|
3066 | }
|
3067 | for (const decorator of decorators) {
|
3068 | const name = getAngularCoreDecoratorName(decorator);
|
3069 | if (name !== null && NO_MIGRATE_DECORATORS.has(name)) {
|
3070 | return false;
|
3071 | }
|
3072 | }
|
3073 | return true;
|
3074 | }
|
3075 | function getAngularCoreDecoratorName(decorator) {
|
3076 | if (decorator.import === null || decorator.import.from !== "@angular/core") {
|
3077 | return null;
|
3078 | }
|
3079 | return decorator.import.name;
|
3080 | }
|
3081 |
|
3082 |
|
3083 | var UndecoratedChildMigration = class {
|
3084 | apply(clazz, host) {
|
3085 | const moduleMeta = host.metadata.getNgModuleMetadata(new Reference(clazz));
|
3086 | if (moduleMeta === null) {
|
3087 | return null;
|
3088 | }
|
3089 | for (const decl of moduleMeta.declarations) {
|
3090 | this.maybeMigrate(decl, host);
|
3091 | }
|
3092 | return null;
|
3093 | }
|
3094 | maybeMigrate(ref, host) {
|
3095 | if (hasDirectiveDecorator(host, ref.node) || hasPipeDecorator(host, ref.node)) {
|
3096 | return;
|
3097 | }
|
3098 | const baseRef = readBaseClass(ref.node, host.reflectionHost, host.evaluator);
|
3099 | if (baseRef === null) {
|
3100 | return;
|
3101 | } else if (baseRef === "dynamic") {
|
3102 | return;
|
3103 | }
|
3104 | this.maybeMigrate(baseRef, host);
|
3105 | const baseMeta = host.metadata.getDirectiveMetadata(baseRef);
|
3106 | if (baseMeta === null) {
|
3107 | return;
|
3108 | }
|
3109 | if (baseMeta.isComponent) {
|
3110 | host.injectSyntheticDecorator(ref.node, createComponentDecorator(ref.node, baseMeta), HandlerFlags.FULL_INHERITANCE);
|
3111 | } else {
|
3112 | host.injectSyntheticDecorator(ref.node, createDirectiveDecorator(ref.node, baseMeta), HandlerFlags.FULL_INHERITANCE);
|
3113 | }
|
3114 | }
|
3115 | };
|
3116 |
|
3117 |
|
3118 | var UndecoratedParentMigration = class {
|
3119 | apply(clazz, host) {
|
3120 | if (!hasDirectiveDecorator(host, clazz) || hasConstructor(host, clazz)) {
|
3121 | return null;
|
3122 | }
|
3123 | let baseClazzRef = determineBaseClass(clazz, host);
|
3124 | while (baseClazzRef !== null) {
|
3125 | const baseClazz = baseClazzRef.node;
|
3126 | if (hasDirectiveDecorator(host, baseClazz) || !host.isInScope(baseClazz)) {
|
3127 | break;
|
3128 | }
|
3129 | host.injectSyntheticDecorator(baseClazz, createDirectiveDecorator(baseClazz));
|
3130 | if (hasConstructor(host, baseClazz)) {
|
3131 | break;
|
3132 | }
|
3133 | baseClazzRef = determineBaseClass(baseClazz, host);
|
3134 | }
|
3135 | return null;
|
3136 | }
|
3137 | };
|
3138 | function determineBaseClass(clazz, host) {
|
3139 | const baseClassExpr = host.reflectionHost.getBaseClassExpression(clazz);
|
3140 | if (baseClassExpr === null) {
|
3141 | return null;
|
3142 | }
|
3143 | const baseClass = host.evaluator.evaluate(baseClassExpr);
|
3144 | if (!(baseClass instanceof Reference) || !isClassDeclaration(baseClass.node)) {
|
3145 | return null;
|
3146 | }
|
3147 | return baseClass;
|
3148 | }
|
3149 |
|
3150 |
|
3151 | import ts14 from "typescript";
|
3152 | var DefaultMigrationHost = class {
|
3153 | constructor(reflectionHost, metadata, evaluator, compiler, entryPointPath) {
|
3154 | this.reflectionHost = reflectionHost;
|
3155 | this.metadata = metadata;
|
3156 | this.evaluator = evaluator;
|
3157 | this.compiler = compiler;
|
3158 | this.entryPointPath = entryPointPath;
|
3159 | }
|
3160 | injectSyntheticDecorator(clazz, decorator, flags) {
|
3161 | const migratedTraits = this.compiler.injectSyntheticDecorator(clazz, decorator, flags);
|
3162 | for (const trait of migratedTraits) {
|
3163 | if ((trait.state === TraitState.Analyzed || trait.state === TraitState.Resolved) && trait.analysisDiagnostics !== null) {
|
3164 | trait.analysisDiagnostics = trait.analysisDiagnostics.map((diag) => createMigrationDiagnostic(diag, clazz, decorator));
|
3165 | }
|
3166 | if (trait.state === TraitState.Resolved && trait.resolveDiagnostics !== null) {
|
3167 | trait.resolveDiagnostics = trait.resolveDiagnostics.map((diag) => createMigrationDiagnostic(diag, clazz, decorator));
|
3168 | }
|
3169 | }
|
3170 | }
|
3171 | getAllDecorators(clazz) {
|
3172 | return this.compiler.getAllDecorators(clazz);
|
3173 | }
|
3174 | isInScope(clazz) {
|
3175 | return isWithinPackage(this.entryPointPath, absoluteFromSourceFile(clazz.getSourceFile()));
|
3176 | }
|
3177 | };
|
3178 | function createMigrationDiagnostic(diagnostic, source, decorator) {
|
3179 | const clone = __spreadValues({}, diagnostic);
|
3180 | const chain = [{
|
3181 | messageText: `Occurs for @${decorator.name} decorator inserted by an automatic migration`,
|
3182 | category: ts14.DiagnosticCategory.Message,
|
3183 | code: 0
|
3184 | }];
|
3185 | if (decorator.args !== null) {
|
3186 | const args = decorator.args.map((arg) => arg.getText()).join(", ");
|
3187 | chain.push({
|
3188 | messageText: `@${decorator.name}(${args})`,
|
3189 | category: ts14.DiagnosticCategory.Message,
|
3190 | code: 0
|
3191 | });
|
3192 | }
|
3193 | if (typeof clone.messageText === "string") {
|
3194 | clone.messageText = {
|
3195 | messageText: clone.messageText,
|
3196 | category: diagnostic.category,
|
3197 | code: diagnostic.code,
|
3198 | next: chain
|
3199 | };
|
3200 | } else {
|
3201 | if (clone.messageText.next === void 0) {
|
3202 | clone.messageText.next = chain;
|
3203 | } else {
|
3204 | clone.messageText.next.push(...chain);
|
3205 | }
|
3206 | }
|
3207 | return clone;
|
3208 | }
|
3209 |
|
3210 |
|
3211 | var NgccTraitCompiler = class extends TraitCompiler {
|
3212 | constructor(handlers, ngccReflector) {
|
3213 | super(handlers, ngccReflector, NOOP_PERF_RECORDER, new NoIncrementalBuild(), true, CompilationMode.FULL, new DtsTransformRegistry(), null, { isShim, isResource: () => false });
|
3214 | this.ngccReflector = ngccReflector;
|
3215 | }
|
3216 | get analyzedFiles() {
|
3217 | return Array.from(this.fileToClasses.keys());
|
3218 | }
|
3219 | analyzeFile(sf) {
|
3220 | const ngccClassSymbols = this.ngccReflector.findClassSymbols(sf);
|
3221 | for (const classSymbol of ngccClassSymbols) {
|
3222 | this.analyzeClass(classSymbol.declaration.valueDeclaration, null);
|
3223 | }
|
3224 | return void 0;
|
3225 | }
|
3226 | injectSyntheticDecorator(clazz, decorator, flags) {
|
3227 | const migratedTraits = this.detectTraits(clazz, [decorator]);
|
3228 | if (migratedTraits === null) {
|
3229 | return [];
|
3230 | }
|
3231 | for (const trait of migratedTraits) {
|
3232 | this.analyzeTrait(clazz, trait, flags);
|
3233 | }
|
3234 | return migratedTraits;
|
3235 | }
|
3236 | getAllDecorators(clazz) {
|
3237 | const record = this.recordFor(clazz);
|
3238 | if (record === null) {
|
3239 | return null;
|
3240 | }
|
3241 | return record.traits.map((trait) => trait.detected.decorator).filter(isDefined);
|
3242 | }
|
3243 | };
|
3244 | var NoIncrementalBuild = class {
|
3245 | priorAnalysisFor(sf) {
|
3246 | return null;
|
3247 | }
|
3248 | priorTypeCheckingResultsFor() {
|
3249 | return null;
|
3250 | }
|
3251 | recordSuccessfulTypeCheck() {
|
3252 | }
|
3253 | };
|
3254 |
|
3255 |
|
3256 | var DecorationAnalyses = Map;
|
3257 |
|
3258 |
|
3259 | var NgccResourceLoader = class {
|
3260 | constructor(fs) {
|
3261 | this.fs = fs;
|
3262 | this.canPreload = false;
|
3263 | this.canPreprocess = false;
|
3264 | }
|
3265 | preload() {
|
3266 | throw new Error("Not implemented.");
|
3267 | }
|
3268 | preprocessInline() {
|
3269 | throw new Error("Not implemented.");
|
3270 | }
|
3271 | load(url) {
|
3272 | return this.fs.readFile(this.fs.resolve(url));
|
3273 | }
|
3274 | resolve(url, containingFile) {
|
3275 | return this.fs.resolve(this.fs.dirname(containingFile), url);
|
3276 | }
|
3277 | };
|
3278 | var DecorationAnalyzer = class {
|
3279 | constructor(fs, bundle, reflectionHost, referencesRegistry, diagnosticHandler = () => {
|
3280 | }, tsConfig = null) {
|
3281 | this.fs = fs;
|
3282 | this.bundle = bundle;
|
3283 | this.reflectionHost = reflectionHost;
|
3284 | this.referencesRegistry = referencesRegistry;
|
3285 | this.diagnosticHandler = diagnosticHandler;
|
3286 | this.tsConfig = tsConfig;
|
3287 | this.program = this.bundle.src.program;
|
3288 | this.options = this.bundle.src.options;
|
3289 | this.host = this.bundle.src.host;
|
3290 | this.typeChecker = this.bundle.src.program.getTypeChecker();
|
3291 | this.rootDirs = this.bundle.rootDirs;
|
3292 | this.packagePath = this.bundle.entryPoint.packagePath;
|
3293 | this.isCore = this.bundle.isCore;
|
3294 | this.compilerOptions = this.tsConfig !== null ? this.tsConfig.options : {};
|
3295 | this.moduleResolver = new ModuleResolver(this.program, this.options, this.host, null);
|
3296 | this.resourceManager = new NgccResourceLoader(this.fs);
|
3297 | this.metaRegistry = new LocalMetadataRegistry();
|
3298 | this.dtsMetaReader = new DtsMetadataReader(this.typeChecker, this.reflectionHost);
|
3299 | this.fullMetaReader = new CompoundMetadataReader([this.metaRegistry, this.dtsMetaReader]);
|
3300 | this.refEmitter = new ReferenceEmitter([
|
3301 | new LocalIdentifierStrategy(),
|
3302 | new AbsoluteModuleStrategy(this.program, this.typeChecker, this.moduleResolver, this.reflectionHost),
|
3303 | new LogicalProjectStrategy(this.reflectionHost, new LogicalFileSystem(this.rootDirs, this.host))
|
3304 | ]);
|
3305 | this.aliasingHost = this.bundle.entryPoint.generateDeepReexports ? new PrivateExportAliasingHost(this.reflectionHost) : null;
|
3306 | this.dtsModuleScopeResolver = new MetadataDtsModuleScopeResolver(this.dtsMetaReader, this.aliasingHost);
|
3307 | this.scopeRegistry = new LocalModuleScopeRegistry(this.metaRegistry, this.dtsModuleScopeResolver, this.refEmitter, this.aliasingHost);
|
3308 | this.fullRegistry = new CompoundMetadataRegistry([this.metaRegistry, this.scopeRegistry]);
|
3309 | this.evaluator = new PartialEvaluator(this.reflectionHost, this.typeChecker, null);
|
3310 | this.importGraph = new ImportGraph(this.typeChecker, NOOP_PERF_RECORDER);
|
3311 | this.cycleAnalyzer = new CycleAnalyzer(this.importGraph);
|
3312 | this.injectableRegistry = new InjectableClassRegistry(this.reflectionHost);
|
3313 | this.typeCheckScopeRegistry = new TypeCheckScopeRegistry(this.scopeRegistry, this.fullMetaReader);
|
3314 | this.handlers = [
|
3315 | new ComponentDecoratorHandler(this.reflectionHost, this.evaluator, this.fullRegistry, this.fullMetaReader, this.scopeRegistry, this.scopeRegistry, this.typeCheckScopeRegistry, new ResourceRegistry(), this.isCore, this.resourceManager, this.rootDirs, !!this.compilerOptions.preserveWhitespaces, true, this.bundle.enableI18nLegacyMessageIdFormat, false, false, this.moduleResolver, this.cycleAnalyzer, 0, this.refEmitter, NOOP_DEPENDENCY_TRACKER, this.injectableRegistry, null, !!this.compilerOptions.annotateForClosureCompiler, NOOP_PERF_RECORDER),
|
3316 | new DirectiveDecoratorHandler(this.reflectionHost, this.evaluator, this.fullRegistry, this.scopeRegistry, this.fullMetaReader, this.injectableRegistry, this.isCore, null, !!this.compilerOptions.annotateForClosureCompiler, true, NOOP_PERF_RECORDER),
|
3317 | new PipeDecoratorHandler(this.reflectionHost, this.evaluator, this.metaRegistry, this.scopeRegistry, this.injectableRegistry, this.isCore, NOOP_PERF_RECORDER),
|
3318 | new InjectableDecoratorHandler(this.reflectionHost, this.isCore, false, this.injectableRegistry, NOOP_PERF_RECORDER, false),
|
3319 | new NgModuleDecoratorHandler(this.reflectionHost, this.evaluator, this.fullMetaReader, this.fullRegistry, this.scopeRegistry, this.referencesRegistry, this.isCore, this.refEmitter, null, !!this.compilerOptions.annotateForClosureCompiler, this.injectableRegistry, NOOP_PERF_RECORDER)
|
3320 | ];
|
3321 | this.compiler = new NgccTraitCompiler(this.handlers, this.reflectionHost);
|
3322 | this.migrations = [
|
3323 | new UndecoratedParentMigration(),
|
3324 | new UndecoratedChildMigration(),
|
3325 | new MissingInjectableMigration()
|
3326 | ];
|
3327 | }
|
3328 | analyzeProgram() {
|
3329 | for (const sourceFile of this.program.getSourceFiles()) {
|
3330 | if (!sourceFile.isDeclarationFile && isWithinPackage(this.packagePath, absoluteFromSourceFile(sourceFile))) {
|
3331 | this.compiler.analyzeFile(sourceFile);
|
3332 | }
|
3333 | }
|
3334 | this.applyMigrations();
|
3335 | this.compiler.resolve();
|
3336 | this.reportDiagnostics();
|
3337 | const decorationAnalyses = new DecorationAnalyses();
|
3338 | for (const analyzedFile of this.compiler.analyzedFiles) {
|
3339 | const compiledFile = this.compileFile(analyzedFile);
|
3340 | decorationAnalyses.set(compiledFile.sourceFile, compiledFile);
|
3341 | }
|
3342 | return decorationAnalyses;
|
3343 | }
|
3344 | applyMigrations() {
|
3345 | const migrationHost = new DefaultMigrationHost(this.reflectionHost, this.fullMetaReader, this.evaluator, this.compiler, this.bundle.entryPoint.path);
|
3346 | this.migrations.forEach((migration) => {
|
3347 | this.compiler.analyzedFiles.forEach((analyzedFile) => {
|
3348 | const records = this.compiler.recordsFor(analyzedFile);
|
3349 | if (records === null) {
|
3350 | throw new Error("Assertion error: file to migrate must have records.");
|
3351 | }
|
3352 | records.forEach((record) => {
|
3353 | const addDiagnostic = (diagnostic) => {
|
3354 | if (record.metaDiagnostics === null) {
|
3355 | record.metaDiagnostics = [];
|
3356 | }
|
3357 | record.metaDiagnostics.push(diagnostic);
|
3358 | };
|
3359 | try {
|
3360 | const result = migration.apply(record.node, migrationHost);
|
3361 | if (result !== null) {
|
3362 | addDiagnostic(result);
|
3363 | }
|
3364 | } catch (e) {
|
3365 | if (isFatalDiagnosticError(e)) {
|
3366 | addDiagnostic(e.toDiagnostic());
|
3367 | } else {
|
3368 | throw e;
|
3369 | }
|
3370 | }
|
3371 | });
|
3372 | });
|
3373 | });
|
3374 | }
|
3375 | reportDiagnostics() {
|
3376 | this.compiler.diagnostics.forEach(this.diagnosticHandler);
|
3377 | }
|
3378 | compileFile(sourceFile) {
|
3379 | const constantPool = new ConstantPool();
|
3380 | const records = this.compiler.recordsFor(sourceFile);
|
3381 | if (records === null) {
|
3382 | throw new Error("Assertion error: file to compile must have records.");
|
3383 | }
|
3384 | const compiledClasses = [];
|
3385 | for (const record of records) {
|
3386 | const compilation = this.compiler.compile(record.node, constantPool);
|
3387 | if (compilation === null) {
|
3388 | continue;
|
3389 | }
|
3390 | compiledClasses.push({
|
3391 | name: record.node.name.text,
|
3392 | decorators: this.compiler.getAllDecorators(record.node),
|
3393 | declaration: record.node,
|
3394 | compilation
|
3395 | });
|
3396 | }
|
3397 | const reexports = this.getReexportsForSourceFile(sourceFile);
|
3398 | return { constantPool, sourceFile, compiledClasses, reexports };
|
3399 | }
|
3400 | getReexportsForSourceFile(sf) {
|
3401 | const exportStatements = this.compiler.exportStatements;
|
3402 | if (!exportStatements.has(sf.fileName)) {
|
3403 | return [];
|
3404 | }
|
3405 | const exports = exportStatements.get(sf.fileName);
|
3406 | const reexports = [];
|
3407 | exports.forEach(([fromModule, symbolName], asAlias) => {
|
3408 | reexports.push({ asAlias, fromModule, symbolName });
|
3409 | });
|
3410 | return reexports;
|
3411 | }
|
3412 | };
|
3413 |
|
3414 |
|
3415 | import ts15 from "typescript";
|
3416 | var ModuleWithProvidersAnalyses = Map;
|
3417 | var ModuleWithProvidersAnalyzer = class {
|
3418 | constructor(host, typeChecker, referencesRegistry, processDts) {
|
3419 | this.host = host;
|
3420 | this.typeChecker = typeChecker;
|
3421 | this.referencesRegistry = referencesRegistry;
|
3422 | this.processDts = processDts;
|
3423 | this.evaluator = new PartialEvaluator(this.host, this.typeChecker, null);
|
3424 | }
|
3425 | analyzeProgram(program) {
|
3426 | const analyses = new ModuleWithProvidersAnalyses();
|
3427 | const rootFiles = this.getRootFiles(program);
|
3428 | rootFiles.forEach((f) => {
|
3429 | const fns = this.getModuleWithProvidersFunctions(f);
|
3430 | fns && fns.forEach((fn) => {
|
3431 | if (fn.ngModule.bestGuessOwningModule === null) {
|
3432 | this.referencesRegistry.add(fn.ngModule.node, new Reference(fn.ngModule.node));
|
3433 | }
|
3434 | if (this.processDts) {
|
3435 | const dtsFn = this.getDtsModuleWithProvidersFunction(fn);
|
3436 | const dtsFnType = dtsFn.declaration.type;
|
3437 | const typeParam = dtsFnType && ts15.isTypeReferenceNode(dtsFnType) && dtsFnType.typeArguments && dtsFnType.typeArguments[0] || null;
|
3438 | if (!typeParam || isAnyKeyword(typeParam)) {
|
3439 | const dtsFile = dtsFn.declaration.getSourceFile();
|
3440 | const analysis = analyses.has(dtsFile) ? analyses.get(dtsFile) : [];
|
3441 | analysis.push(dtsFn);
|
3442 | analyses.set(dtsFile, analysis);
|
3443 | }
|
3444 | }
|
3445 | });
|
3446 | });
|
3447 | return analyses;
|
3448 | }
|
3449 | getRootFiles(program) {
|
3450 | return program.getRootFileNames().map((f) => program.getSourceFile(f)).filter(isDefined);
|
3451 | }
|
3452 | getModuleWithProvidersFunctions(f) {
|
3453 | const exports = this.host.getExportsOfModule(f);
|
3454 | if (!exports)
|
3455 | return [];
|
3456 | const infos = [];
|
3457 | exports.forEach((declaration) => {
|
3458 | if (declaration.node === null) {
|
3459 | return;
|
3460 | }
|
3461 | if (this.host.isClass(declaration.node)) {
|
3462 | this.host.getMembersOfClass(declaration.node).forEach((member) => {
|
3463 | if (member.isStatic) {
|
3464 | const info = this.parseForModuleWithProviders(member.name, member.node, member.implementation, declaration.node);
|
3465 | if (info) {
|
3466 | infos.push(info);
|
3467 | }
|
3468 | }
|
3469 | });
|
3470 | } else {
|
3471 | if (hasNameIdentifier(declaration.node)) {
|
3472 | const info = this.parseForModuleWithProviders(declaration.node.name.text, declaration.node);
|
3473 | if (info) {
|
3474 | infos.push(info);
|
3475 | }
|
3476 | }
|
3477 | }
|
3478 | });
|
3479 | return infos;
|
3480 | }
|
3481 | parseForModuleWithProviders(name, node, implementation = node, container = null) {
|
3482 | if (implementation === null || !ts15.isFunctionDeclaration(implementation) && !ts15.isMethodDeclaration(implementation) && !ts15.isFunctionExpression(implementation)) {
|
3483 | return null;
|
3484 | }
|
3485 | const declaration = implementation;
|
3486 | const definition = this.host.getDefinitionOfFunction(declaration);
|
3487 | if (definition === null) {
|
3488 | return null;
|
3489 | }
|
3490 | const body = definition.body;
|
3491 | if (body === null || body.length === 0) {
|
3492 | return null;
|
3493 | }
|
3494 | const lastStatement = body[body.length - 1];
|
3495 | if (!ts15.isReturnStatement(lastStatement) || lastStatement.expression === void 0) {
|
3496 | return null;
|
3497 | }
|
3498 | const result = this.evaluator.evaluate(lastStatement.expression);
|
3499 | if (!(result instanceof Map) || !result.has("ngModule")) {
|
3500 | return null;
|
3501 | }
|
3502 | const ngModuleRef = result.get("ngModule");
|
3503 | if (!(ngModuleRef instanceof Reference)) {
|
3504 | return null;
|
3505 | }
|
3506 | if (!isNamedClassDeclaration(ngModuleRef.node) && !isNamedVariableDeclaration(ngModuleRef.node)) {
|
3507 | throw new Error(`The identity given by ${ngModuleRef.debugName} referenced in "${declaration.getText()}" doesn't appear to be a "class" declaration.`);
|
3508 | }
|
3509 | const ngModule = ngModuleRef;
|
3510 | return { name, ngModule, declaration, container };
|
3511 | }
|
3512 | getDtsModuleWithProvidersFunction(fn) {
|
3513 | let dtsFn = null;
|
3514 | const containerClass = fn.container && this.host.getClassSymbol(fn.container);
|
3515 | if (containerClass) {
|
3516 | const dtsClass = this.host.getDtsDeclaration(containerClass.declaration.valueDeclaration);
|
3517 | dtsFn = dtsClass && ts15.isClassDeclaration(dtsClass) ? dtsClass.members.find((member) => ts15.isMethodDeclaration(member) && ts15.isIdentifier(member.name) && member.name.text === fn.name) : null;
|
3518 | } else {
|
3519 | dtsFn = this.host.getDtsDeclaration(fn.declaration);
|
3520 | }
|
3521 | if (!dtsFn) {
|
3522 | throw new Error(`Matching type declaration for ${fn.declaration.getText()} is missing`);
|
3523 | }
|
3524 | if (!isFunctionOrMethod(dtsFn)) {
|
3525 | throw new Error(`Matching type declaration for ${fn.declaration.getText()} is not a function: ${dtsFn.getText()}`);
|
3526 | }
|
3527 | const container = containerClass ? containerClass.declaration.valueDeclaration : null;
|
3528 | const ngModule = this.resolveNgModuleReference(fn);
|
3529 | return { name: fn.name, container, declaration: dtsFn, ngModule };
|
3530 | }
|
3531 | resolveNgModuleReference(fn) {
|
3532 | const ngModule = fn.ngModule;
|
3533 | if (ngModule.bestGuessOwningModule !== null) {
|
3534 | return ngModule;
|
3535 | }
|
3536 | const dtsNgModule = this.host.getDtsDeclaration(ngModule.node);
|
3537 | if (!dtsNgModule) {
|
3538 | throw new Error(`No typings declaration can be found for the referenced NgModule class in ${fn.declaration.getText()}.`);
|
3539 | }
|
3540 | if (!isNamedClassDeclaration(dtsNgModule)) {
|
3541 | throw new Error(`The referenced NgModule in ${fn.declaration.getText()} is not a named class declaration in the typings program; instead we get ${dtsNgModule.getText()}`);
|
3542 | }
|
3543 | return new Reference(dtsNgModule, null);
|
3544 | }
|
3545 | };
|
3546 | function isFunctionOrMethod(declaration) {
|
3547 | return ts15.isFunctionDeclaration(declaration) || ts15.isMethodDeclaration(declaration);
|
3548 | }
|
3549 | function isAnyKeyword(typeParam) {
|
3550 | return typeParam.kind === ts15.SyntaxKind.AnyKeyword;
|
3551 | }
|
3552 |
|
3553 |
|
3554 | var NgccReferencesRegistry = class {
|
3555 | constructor(host) {
|
3556 | this.host = host;
|
3557 | this.map = new Map();
|
3558 | }
|
3559 | add(source, ...references) {
|
3560 | references.forEach((ref) => {
|
3561 | if (ref.bestGuessOwningModule === null && hasNameIdentifier(ref.node)) {
|
3562 | const declaration = this.host.getDeclarationOfIdentifier(ref.node.name);
|
3563 | if (declaration && hasNameIdentifier(declaration.node)) {
|
3564 | this.map.set(declaration.node.name, declaration);
|
3565 | }
|
3566 | }
|
3567 | });
|
3568 | }
|
3569 | getDeclarationMap() {
|
3570 | return this.map;
|
3571 | }
|
3572 | };
|
3573 |
|
3574 |
|
3575 | var PrivateDeclarationsAnalyzer = class {
|
3576 | constructor(host, referencesRegistry) {
|
3577 | this.host = host;
|
3578 | this.referencesRegistry = referencesRegistry;
|
3579 | }
|
3580 | analyzeProgram(program) {
|
3581 | const rootFiles = this.getRootFiles(program);
|
3582 | return this.getPrivateDeclarations(rootFiles, this.referencesRegistry.getDeclarationMap());
|
3583 | }
|
3584 | getRootFiles(program) {
|
3585 | return program.getRootFileNames().map((f) => program.getSourceFile(f)).filter(isDefined);
|
3586 | }
|
3587 | getPrivateDeclarations(rootFiles, declarations) {
|
3588 | const privateDeclarations = new Map(declarations);
|
3589 | rootFiles.forEach((f) => {
|
3590 | const exports = this.host.getExportsOfModule(f);
|
3591 | if (exports) {
|
3592 | exports.forEach((declaration, exportedName) => {
|
3593 | if (declaration.node !== null && hasNameIdentifier(declaration.node)) {
|
3594 | if (privateDeclarations.has(declaration.node.name)) {
|
3595 | const privateDeclaration = privateDeclarations.get(declaration.node.name);
|
3596 | if (privateDeclaration.node !== declaration.node) {
|
3597 | throw new Error(`${declaration.node.name.text} is declared multiple times.`);
|
3598 | }
|
3599 | privateDeclarations.delete(declaration.node.name);
|
3600 | }
|
3601 | }
|
3602 | });
|
3603 | }
|
3604 | });
|
3605 | return Array.from(privateDeclarations.keys()).map((id) => {
|
3606 | const from = absoluteFromSourceFile(id.getSourceFile());
|
3607 | const declaration = privateDeclarations.get(id);
|
3608 | const dtsDeclaration = this.host.getDtsDeclaration(declaration.node);
|
3609 | const dtsFrom = dtsDeclaration && absoluteFromSourceFile(dtsDeclaration.getSourceFile());
|
3610 | return { identifier: id.text, from, dtsFrom };
|
3611 | });
|
3612 | }
|
3613 | };
|
3614 |
|
3615 |
|
3616 | import ts16 from "typescript";
|
3617 | var CommonJsReflectionHost = class extends Esm5ReflectionHost {
|
3618 | constructor(logger, isCore, src, dts = null) {
|
3619 | super(logger, isCore, src, dts);
|
3620 | this.commonJsExports = new FactoryMap((sf) => this.computeExportsOfCommonJsModule(sf));
|
3621 | this.topLevelHelperCalls = new FactoryMap((helperName) => new FactoryMap((sf) => sf.statements.map((stmt) => this.getHelperCall(stmt, [helperName])).filter(isDefined)));
|
3622 | this.program = src.program;
|
3623 | this.compilerHost = src.host;
|
3624 | }
|
3625 | getImportOfIdentifier(id) {
|
3626 | const requireCall = this.findCommonJsImport(id);
|
3627 | if (requireCall === null) {
|
3628 | return null;
|
3629 | }
|
3630 | return { from: requireCall.arguments[0].text, name: id.text };
|
3631 | }
|
3632 | getDeclarationOfIdentifier(id) {
|
3633 | return this.getCommonJsModuleDeclaration(id) || super.getDeclarationOfIdentifier(id);
|
3634 | }
|
3635 | getExportsOfModule(module) {
|
3636 | return super.getExportsOfModule(module) || this.commonJsExports.get(module.getSourceFile());
|
3637 | }
|
3638 | getHelperCallsForClass(classSymbol, helperNames) {
|
3639 | const esm5HelperCalls = super.getHelperCallsForClass(classSymbol, helperNames);
|
3640 | if (esm5HelperCalls.length > 0) {
|
3641 | return esm5HelperCalls;
|
3642 | } else {
|
3643 | const sourceFile = classSymbol.declaration.valueDeclaration.getSourceFile();
|
3644 | return this.getTopLevelHelperCalls(sourceFile, helperNames);
|
3645 | }
|
3646 | }
|
3647 | getTopLevelHelperCalls(sourceFile, helperNames) {
|
3648 | const calls = [];
|
3649 | helperNames.forEach((helperName) => {
|
3650 | const helperCallsMap = this.topLevelHelperCalls.get(helperName);
|
3651 | calls.push(...helperCallsMap.get(sourceFile));
|
3652 | });
|
3653 | return calls;
|
3654 | }
|
3655 | computeExportsOfCommonJsModule(sourceFile) {
|
3656 | const moduleMap = new Map();
|
3657 | for (const statement of this.getModuleStatements(sourceFile)) {
|
3658 | if (isExportsStatement(statement)) {
|
3659 | const exportDeclaration = this.extractBasicCommonJsExportDeclaration(statement);
|
3660 | moduleMap.set(exportDeclaration.name, exportDeclaration.declaration);
|
3661 | } else if (isWildcardReexportStatement(statement)) {
|
3662 | const reexports = this.extractCommonJsWildcardReexports(statement, sourceFile);
|
3663 | for (const reexport of reexports) {
|
3664 | moduleMap.set(reexport.name, reexport.declaration);
|
3665 | }
|
3666 | } else if (isDefinePropertyReexportStatement(statement)) {
|
3667 | const exportDeclaration = this.extractCommonJsDefinePropertyExportDeclaration(statement);
|
3668 | if (exportDeclaration !== null) {
|
3669 | moduleMap.set(exportDeclaration.name, exportDeclaration.declaration);
|
3670 | }
|
3671 | }
|
3672 | }
|
3673 | return moduleMap;
|
3674 | }
|
3675 | extractBasicCommonJsExportDeclaration(statement) {
|
3676 | var _a;
|
3677 | const exportExpression = skipAliases(statement.expression.right);
|
3678 | const node = statement.expression.left;
|
3679 | const declaration = (_a = this.getDeclarationOfExpression(exportExpression)) != null ? _a : {
|
3680 | kind: 1,
|
3681 | node,
|
3682 | implementation: exportExpression,
|
3683 | known: null,
|
3684 | viaModule: null
|
3685 | };
|
3686 | return { name: node.name.text, declaration };
|
3687 | }
|
3688 | extractCommonJsWildcardReexports(statement, containingFile) {
|
3689 | const reexportArg = statement.expression.arguments[0];
|
3690 | const requireCall = isRequireCall(reexportArg) ? reexportArg : ts16.isIdentifier(reexportArg) ? findRequireCallReference(reexportArg, this.checker) : null;
|
3691 | if (requireCall === null) {
|
3692 | return [];
|
3693 | }
|
3694 | const importPath = requireCall.arguments[0].text;
|
3695 | const importedFile = this.resolveModuleName(importPath, containingFile);
|
3696 | if (importedFile === void 0) {
|
3697 | return [];
|
3698 | }
|
3699 | const importedExports = this.getExportsOfModule(importedFile);
|
3700 | if (importedExports === null) {
|
3701 | return [];
|
3702 | }
|
3703 | const viaModule = isExternalImport(importPath) ? importPath : null;
|
3704 | const reexports = [];
|
3705 | importedExports.forEach((declaration, name) => {
|
3706 | if (viaModule !== null && declaration.viaModule === null) {
|
3707 | declaration = __spreadProps(__spreadValues({}, declaration), { viaModule });
|
3708 | }
|
3709 | reexports.push({ name, declaration });
|
3710 | });
|
3711 | return reexports;
|
3712 | }
|
3713 | extractCommonJsDefinePropertyExportDeclaration(statement) {
|
3714 | const args = statement.expression.arguments;
|
3715 | const name = args[1].text;
|
3716 | const getterFnExpression = extractGetterFnExpression(statement);
|
3717 | if (getterFnExpression === null) {
|
3718 | return null;
|
3719 | }
|
3720 | const declaration = this.getDeclarationOfExpression(getterFnExpression);
|
3721 | if (declaration !== null) {
|
3722 | return { name, declaration };
|
3723 | }
|
3724 | return {
|
3725 | name,
|
3726 | declaration: {
|
3727 | kind: 1,
|
3728 | node: args[1],
|
3729 | implementation: getterFnExpression,
|
3730 | known: null,
|
3731 | viaModule: null
|
3732 | }
|
3733 | };
|
3734 | }
|
3735 | findCommonJsImport(id) {
|
3736 | const nsIdentifier = findNamespaceOfIdentifier(id);
|
3737 | return nsIdentifier && findRequireCallReference(nsIdentifier, this.checker);
|
3738 | }
|
3739 | getCommonJsModuleDeclaration(id) {
|
3740 | const requireCall = findRequireCallReference(id, this.checker);
|
3741 | if (requireCall === null) {
|
3742 | return null;
|
3743 | }
|
3744 | const importPath = requireCall.arguments[0].text;
|
3745 | const module = this.resolveModuleName(importPath, id.getSourceFile());
|
3746 | if (module === void 0) {
|
3747 | return null;
|
3748 | }
|
3749 | const viaModule = isExternalImport(importPath) ? importPath : null;
|
3750 | return { node: module, known: null, viaModule, identity: null, kind: 0 };
|
3751 | }
|
3752 | getDeclarationOfExpression(expression) {
|
3753 | const inner = getInnerClassDeclaration(expression);
|
3754 | if (inner !== null) {
|
3755 | const outer = getOuterNodeFromInnerDeclaration(inner);
|
3756 | if (outer !== null && isExportsAssignment(outer)) {
|
3757 | return {
|
3758 | kind: 1,
|
3759 | node: outer.left,
|
3760 | implementation: inner,
|
3761 | known: null,
|
3762 | viaModule: null
|
3763 | };
|
3764 | }
|
3765 | }
|
3766 | return super.getDeclarationOfExpression(expression);
|
3767 | }
|
3768 | resolveModuleName(moduleName, containingFile) {
|
3769 | if (this.compilerHost.resolveModuleNames) {
|
3770 | const moduleInfo = this.compilerHost.resolveModuleNames([moduleName], containingFile.fileName, void 0, void 0, this.program.getCompilerOptions())[0];
|
3771 | return moduleInfo && this.program.getSourceFile(absoluteFrom(moduleInfo.resolvedFileName));
|
3772 | } else {
|
3773 | const moduleInfo = ts16.resolveModuleName(moduleName, containingFile.fileName, this.program.getCompilerOptions(), this.compilerHost);
|
3774 | return moduleInfo.resolvedModule && this.program.getSourceFile(absoluteFrom(moduleInfo.resolvedModule.resolvedFileName));
|
3775 | }
|
3776 | }
|
3777 | };
|
3778 |
|
3779 |
|
3780 | var DelegatingReflectionHost = class {
|
3781 | constructor(tsHost, ngccHost) {
|
3782 | this.tsHost = tsHost;
|
3783 | this.ngccHost = ngccHost;
|
3784 | }
|
3785 | getConstructorParameters(clazz) {
|
3786 | if (isFromDtsFile(clazz)) {
|
3787 | return this.tsHost.getConstructorParameters(clazz);
|
3788 | }
|
3789 | return this.ngccHost.getConstructorParameters(clazz);
|
3790 | }
|
3791 | getDeclarationOfIdentifier(id) {
|
3792 | if (isFromDtsFile(id)) {
|
3793 | const declaration = this.tsHost.getDeclarationOfIdentifier(id);
|
3794 | return declaration !== null ? this.detectKnownDeclaration(declaration) : null;
|
3795 | }
|
3796 | return this.ngccHost.getDeclarationOfIdentifier(id);
|
3797 | }
|
3798 | getDecoratorsOfDeclaration(declaration) {
|
3799 | if (isFromDtsFile(declaration)) {
|
3800 | return this.tsHost.getDecoratorsOfDeclaration(declaration);
|
3801 | }
|
3802 | return this.ngccHost.getDecoratorsOfDeclaration(declaration);
|
3803 | }
|
3804 | getDefinitionOfFunction(fn) {
|
3805 | if (isFromDtsFile(fn)) {
|
3806 | return this.tsHost.getDefinitionOfFunction(fn);
|
3807 | }
|
3808 | return this.ngccHost.getDefinitionOfFunction(fn);
|
3809 | }
|
3810 | getDtsDeclaration(declaration) {
|
3811 | if (isFromDtsFile(declaration)) {
|
3812 | return this.tsHost.getDtsDeclaration(declaration);
|
3813 | }
|
3814 | return this.ngccHost.getDtsDeclaration(declaration);
|
3815 | }
|
3816 | getExportsOfModule(module) {
|
3817 | if (isFromDtsFile(module)) {
|
3818 | const exportMap = this.tsHost.getExportsOfModule(module);
|
3819 | if (exportMap !== null) {
|
3820 | exportMap.forEach((decl) => this.detectKnownDeclaration(decl));
|
3821 | }
|
3822 | return exportMap;
|
3823 | }
|
3824 | return this.ngccHost.getExportsOfModule(module);
|
3825 | }
|
3826 | getGenericArityOfClass(clazz) {
|
3827 | if (isFromDtsFile(clazz)) {
|
3828 | return this.tsHost.getGenericArityOfClass(clazz);
|
3829 | }
|
3830 | return this.ngccHost.getGenericArityOfClass(clazz);
|
3831 | }
|
3832 | getImportOfIdentifier(id) {
|
3833 | if (isFromDtsFile(id)) {
|
3834 | return this.tsHost.getImportOfIdentifier(id);
|
3835 | }
|
3836 | return this.ngccHost.getImportOfIdentifier(id);
|
3837 | }
|
3838 | getInternalNameOfClass(clazz) {
|
3839 | if (isFromDtsFile(clazz)) {
|
3840 | return this.tsHost.getInternalNameOfClass(clazz);
|
3841 | }
|
3842 | return this.ngccHost.getInternalNameOfClass(clazz);
|
3843 | }
|
3844 | getAdjacentNameOfClass(clazz) {
|
3845 | if (isFromDtsFile(clazz)) {
|
3846 | return this.tsHost.getAdjacentNameOfClass(clazz);
|
3847 | }
|
3848 | return this.ngccHost.getAdjacentNameOfClass(clazz);
|
3849 | }
|
3850 | getMembersOfClass(clazz) {
|
3851 | if (isFromDtsFile(clazz)) {
|
3852 | return this.tsHost.getMembersOfClass(clazz);
|
3853 | }
|
3854 | return this.ngccHost.getMembersOfClass(clazz);
|
3855 | }
|
3856 | getVariableValue(declaration) {
|
3857 | if (isFromDtsFile(declaration)) {
|
3858 | return this.tsHost.getVariableValue(declaration);
|
3859 | }
|
3860 | return this.ngccHost.getVariableValue(declaration);
|
3861 | }
|
3862 | hasBaseClass(clazz) {
|
3863 | if (isFromDtsFile(clazz)) {
|
3864 | return this.tsHost.hasBaseClass(clazz);
|
3865 | }
|
3866 | return this.ngccHost.hasBaseClass(clazz);
|
3867 | }
|
3868 | getBaseClassExpression(clazz) {
|
3869 | if (isFromDtsFile(clazz)) {
|
3870 | return this.tsHost.getBaseClassExpression(clazz);
|
3871 | }
|
3872 | return this.ngccHost.getBaseClassExpression(clazz);
|
3873 | }
|
3874 | isClass(node) {
|
3875 | if (isFromDtsFile(node)) {
|
3876 | return this.tsHost.isClass(node);
|
3877 | }
|
3878 | return this.ngccHost.isClass(node);
|
3879 | }
|
3880 | findClassSymbols(sourceFile) {
|
3881 | return this.ngccHost.findClassSymbols(sourceFile);
|
3882 | }
|
3883 | getClassSymbol(node) {
|
3884 | return this.ngccHost.getClassSymbol(node);
|
3885 | }
|
3886 | getDecoratorsOfSymbol(symbol) {
|
3887 | return this.ngccHost.getDecoratorsOfSymbol(symbol);
|
3888 | }
|
3889 | getEndOfClass(classSymbol) {
|
3890 | return this.ngccHost.getEndOfClass(classSymbol);
|
3891 | }
|
3892 | detectKnownDeclaration(decl) {
|
3893 | return this.ngccHost.detectKnownDeclaration(decl);
|
3894 | }
|
3895 | isStaticallyExported(decl) {
|
3896 | return this.ngccHost.isStaticallyExported(decl);
|
3897 | }
|
3898 | };
|
3899 |
|
3900 |
|
3901 | import ts19 from "typescript";
|
3902 |
|
3903 |
|
3904 | import ts18 from "typescript";
|
3905 |
|
3906 |
|
3907 | import ts17 from "typescript";
|
3908 |
|
3909 |
|
3910 | var NgccFlatImportRewriter = class {
|
3911 | shouldImportSymbol(symbol, specifier) {
|
3912 | if (specifier === "@angular/core") {
|
3913 | return false;
|
3914 | } else {
|
3915 | return true;
|
3916 | }
|
3917 | }
|
3918 | rewriteSymbol(symbol, specifier) {
|
3919 | if (specifier === "@angular/core") {
|
3920 | return validateAndRewriteCoreSymbol(symbol);
|
3921 | } else {
|
3922 | return symbol;
|
3923 | }
|
3924 | }
|
3925 | rewriteSpecifier(originalModulePath, inContextOfFile) {
|
3926 | return originalModulePath;
|
3927 | }
|
3928 | };
|
3929 |
|
3930 |
|
3931 | function getImportRewriter(r3SymbolsFile, isCore, isFlat) {
|
3932 | if (isCore && isFlat) {
|
3933 | return new NgccFlatImportRewriter();
|
3934 | } else if (isCore) {
|
3935 | return new R3SymbolsImportRewriter(r3SymbolsFile.fileName);
|
3936 | } else {
|
3937 | return new NoopImportRewriter();
|
3938 | }
|
3939 | }
|
3940 | function stripExtension2(filePath) {
|
3941 | return filePath.replace(/\.(js|d\.ts)$/, "");
|
3942 | }
|
3943 |
|
3944 |
|
3945 | var EsmRenderingFormatter = class {
|
3946 | constructor(fs, host, isCore) {
|
3947 | this.fs = fs;
|
3948 | this.host = host;
|
3949 | this.isCore = isCore;
|
3950 | this.printer = ts17.createPrinter({ newLine: ts17.NewLineKind.LineFeed });
|
3951 | }
|
3952 | addImports(output, imports, sf) {
|
3953 | if (imports.length === 0) {
|
3954 | return;
|
3955 | }
|
3956 | const insertionPoint = this.findEndOfImports(sf);
|
3957 | const renderedImports = imports.map((i) => `import * as ${i.qualifier.text} from '${i.specifier}';
|
3958 | `).join("");
|
3959 | output.appendLeft(insertionPoint, renderedImports);
|
3960 | }
|
3961 | addExports(output, entryPointBasePath, exports, importManager, file) {
|
3962 | exports.forEach((e) => {
|
3963 | let exportFrom = "";
|
3964 | const isDtsFile = isDtsPath(entryPointBasePath);
|
3965 | const from = isDtsFile ? e.dtsFrom : e.from;
|
3966 | if (from) {
|
3967 | const basePath = stripExtension2(from);
|
3968 | const relativePath = this.fs.relative(this.fs.dirname(entryPointBasePath), basePath);
|
3969 | const relativeImport = toRelativeImport(relativePath);
|
3970 | exportFrom = entryPointBasePath !== basePath ? ` from '${relativeImport}'` : "";
|
3971 | }
|
3972 | const exportStr = `
|
3973 | export {${e.identifier}}${exportFrom};`;
|
3974 | output.append(exportStr);
|
3975 | });
|
3976 | }
|
3977 | addDirectExports(output, exports, importManager, file) {
|
3978 | for (const e of exports) {
|
3979 | const exportStatement = `
|
3980 | export {${e.symbolName} as ${e.asAlias}} from '${e.fromModule}';`;
|
3981 | output.append(exportStatement);
|
3982 | }
|
3983 | }
|
3984 | addConstants(output, constants, file) {
|
3985 | if (constants === "") {
|
3986 | return;
|
3987 | }
|
3988 | const insertionPoint = this.findEndOfImports(file);
|
3989 | output.appendRight(insertionPoint, "\n" + constants + "\n");
|
3990 | }
|
3991 | addDefinitions(output, compiledClass, definitions) {
|
3992 | const classSymbol = this.host.getClassSymbol(compiledClass.declaration);
|
3993 | if (!classSymbol) {
|
3994 | throw new Error(`Compiled class does not have a valid symbol: ${compiledClass.name}`);
|
3995 | }
|
3996 | const declarationStatement = getContainingStatement(classSymbol.implementation.valueDeclaration);
|
3997 | const insertionPoint = declarationStatement.getEnd();
|
3998 | output.appendLeft(insertionPoint, "\n" + definitions);
|
3999 | }
|
4000 | addAdjacentStatements(output, compiledClass, statements) {
|
4001 | const classSymbol = this.host.getClassSymbol(compiledClass.declaration);
|
4002 | if (!classSymbol) {
|
4003 | throw new Error(`Compiled class does not have a valid symbol: ${compiledClass.name}`);
|
4004 | }
|
4005 | const endOfClass = this.host.getEndOfClass(classSymbol);
|
4006 | output.appendLeft(endOfClass.getEnd(), "\n" + statements);
|
4007 | }
|
4008 | removeDecorators(output, decoratorsToRemove) {
|
4009 | decoratorsToRemove.forEach((nodesToRemove, containerNode) => {
|
4010 | if (ts17.isArrayLiteralExpression(containerNode)) {
|
4011 | const items = containerNode.elements;
|
4012 | if (items.length === nodesToRemove.length) {
|
4013 | const statement = findStatement(containerNode);
|
4014 | if (statement) {
|
4015 | if (ts17.isExpressionStatement(statement)) {
|
4016 | output.remove(statement.getFullStart(), statement.getEnd());
|
4017 | } else if (ts17.isReturnStatement(statement) && statement.expression && isAssignment2(statement.expression)) {
|
4018 | const startOfRemoval = statement.expression.left.getEnd();
|
4019 | const endOfRemoval = getEndExceptSemicolon(statement);
|
4020 | output.remove(startOfRemoval, endOfRemoval);
|
4021 | }
|
4022 | }
|
4023 | } else {
|
4024 | nodesToRemove.forEach((node) => {
|
4025 | const nextSibling = getNextSiblingInArray(node, items);
|
4026 | let end;
|
4027 | if (nextSibling !== null && output.slice(nextSibling.getFullStart() - 1, nextSibling.getFullStart()) === ",") {
|
4028 | end = nextSibling.getFullStart() - 1 + nextSibling.getLeadingTriviaWidth();
|
4029 | } else if (output.slice(node.getEnd(), node.getEnd() + 1) === ",") {
|
4030 | end = node.getEnd() + 1;
|
4031 | } else {
|
4032 | end = node.getEnd();
|
4033 | }
|
4034 | output.remove(node.getFullStart(), end);
|
4035 | });
|
4036 | }
|
4037 | }
|
4038 | });
|
4039 | }
|
4040 | addModuleWithProvidersParams(outputText, moduleWithProviders, importManager) {
|
4041 | moduleWithProviders.forEach((info) => {
|
4042 | const ngModuleName = info.ngModule.node.name.text;
|
4043 | const declarationFile = absoluteFromSourceFile(info.declaration.getSourceFile());
|
4044 | const ngModuleFile = absoluteFromSourceFile(info.ngModule.node.getSourceFile());
|
4045 | const relativePath = this.fs.relative(this.fs.dirname(declarationFile), ngModuleFile);
|
4046 | const relativeImport = toRelativeImport(relativePath);
|
4047 | const importPath = info.ngModule.ownedByModuleGuess || (declarationFile !== ngModuleFile ? stripExtension2(relativeImport) : null);
|
4048 | const ngModule = generateImportString(importManager, importPath, ngModuleName);
|
4049 | if (info.declaration.type) {
|
4050 | const typeName = info.declaration.type && ts17.isTypeReferenceNode(info.declaration.type) ? info.declaration.type.typeName : null;
|
4051 | if (this.isCoreModuleWithProvidersType(typeName)) {
|
4052 | outputText.overwrite(info.declaration.type.getStart(), info.declaration.type.getEnd(), `ModuleWithProviders<${ngModule}>`);
|
4053 | } else {
|
4054 | const originalTypeString = info.declaration.type.getText();
|
4055 | outputText.overwrite(info.declaration.type.getStart(), info.declaration.type.getEnd(), `(${originalTypeString})&{ngModule:${ngModule}}`);
|
4056 | }
|
4057 | } else {
|
4058 | const lastToken = info.declaration.getLastToken();
|
4059 | const insertPoint = lastToken && lastToken.kind === ts17.SyntaxKind.SemicolonToken ? lastToken.getStart() : info.declaration.getEnd();
|
4060 | outputText.appendLeft(insertPoint, `: ${generateImportString(importManager, "@angular/core", "ModuleWithProviders")}<${ngModule}>`);
|
4061 | }
|
4062 | });
|
4063 | }
|
4064 | printStatement(stmt, sourceFile, importManager) {
|
4065 | const node = translateStatement(stmt, importManager);
|
4066 | const code = this.printer.printNode(ts17.EmitHint.Unspecified, node, sourceFile);
|
4067 | return code;
|
4068 | }
|
4069 | findEndOfImports(sf) {
|
4070 | for (const stmt of sf.statements) {
|
4071 | if (!ts17.isImportDeclaration(stmt) && !ts17.isImportEqualsDeclaration(stmt) && !ts17.isNamespaceImport(stmt)) {
|
4072 | return stmt.getStart();
|
4073 | }
|
4074 | }
|
4075 | return 0;
|
4076 | }
|
4077 | isCoreModuleWithProvidersType(typeName) {
|
4078 | const id = typeName && ts17.isIdentifier(typeName) ? this.host.getImportOfIdentifier(typeName) : null;
|
4079 | return id && id.name === "ModuleWithProviders" && (this.isCore || id.from === "@angular/core");
|
4080 | }
|
4081 | };
|
4082 | function findStatement(node) {
|
4083 | while (node) {
|
4084 | if (ts17.isExpressionStatement(node) || ts17.isReturnStatement(node)) {
|
4085 | return node;
|
4086 | }
|
4087 | node = node.parent;
|
4088 | }
|
4089 | return void 0;
|
4090 | }
|
4091 | function generateImportString(importManager, importPath, importName) {
|
4092 | const importAs = importPath ? importManager.generateNamedImport(importPath, importName) : null;
|
4093 | return importAs && importAs.moduleImport ? `${importAs.moduleImport.text}.${importAs.symbol}` : `${importName}`;
|
4094 | }
|
4095 | function getNextSiblingInArray(node, array) {
|
4096 | const index = array.indexOf(node);
|
4097 | return index !== -1 && array.length > index + 1 ? array[index + 1] : null;
|
4098 | }
|
4099 | function getEndExceptSemicolon(statement) {
|
4100 | const lastToken = statement.getLastToken();
|
4101 | return lastToken && lastToken.kind === ts17.SyntaxKind.SemicolonToken ? statement.getEnd() - 1 : statement.getEnd();
|
4102 | }
|
4103 |
|
4104 |
|
4105 | var Esm5RenderingFormatter = class extends EsmRenderingFormatter {
|
4106 | addDefinitions(output, compiledClass, definitions) {
|
4107 | const classSymbol = this.host.getClassSymbol(compiledClass.declaration);
|
4108 | if (!classSymbol) {
|
4109 | throw new Error(`Compiled class "${compiledClass.name}" in "${compiledClass.declaration.getSourceFile().fileName}" does not have a valid syntax.
|
4110 | Expected an ES5 IIFE wrapped function. But got:
|
4111 | ` + compiledClass.declaration.getText());
|
4112 | }
|
4113 | const declarationStatement = getContainingStatement(classSymbol.implementation.valueDeclaration);
|
4114 | const iifeBody = declarationStatement.parent;
|
4115 | if (!iifeBody || !ts18.isBlock(iifeBody)) {
|
4116 | throw new Error(`Compiled class declaration is not inside an IIFE: ${compiledClass.name} in ${compiledClass.declaration.getSourceFile().fileName}`);
|
4117 | }
|
4118 | const returnStatement = iifeBody.statements.find(ts18.isReturnStatement);
|
4119 | if (!returnStatement) {
|
4120 | throw new Error(`Compiled class wrapper IIFE does not have a return statement: ${compiledClass.name} in ${compiledClass.declaration.getSourceFile().fileName}`);
|
4121 | }
|
4122 | const insertionPoint = returnStatement.getFullStart();
|
4123 | output.appendLeft(insertionPoint, "\n" + definitions);
|
4124 | }
|
4125 | printStatement(stmt, sourceFile, importManager) {
|
4126 | const node = translateStatement(stmt, importManager, { downlevelTaggedTemplates: true, downlevelVariableDeclarations: true });
|
4127 | const code = this.printer.printNode(ts18.EmitHint.Unspecified, node, sourceFile);
|
4128 | return code;
|
4129 | }
|
4130 | };
|
4131 |
|
4132 |
|
4133 | var CommonJsRenderingFormatter = class extends Esm5RenderingFormatter {
|
4134 | constructor(fs, commonJsHost, isCore) {
|
4135 | super(fs, commonJsHost, isCore);
|
4136 | this.commonJsHost = commonJsHost;
|
4137 | }
|
4138 | addImports(output, imports, file) {
|
4139 | if (imports.length === 0) {
|
4140 | return;
|
4141 | }
|
4142 | const insertionPoint = this.findEndOfImports(file);
|
4143 | const renderedImports = imports.map((i) => `var ${i.qualifier.text} = require('${i.specifier}');
|
4144 | `).join("");
|
4145 | output.appendLeft(insertionPoint, renderedImports);
|
4146 | }
|
4147 | addExports(output, entryPointBasePath, exports, importManager, file) {
|
4148 | exports.forEach((e) => {
|
4149 | const basePath = stripExtension2(e.from);
|
4150 | const relativePath = "./" + this.fs.relative(this.fs.dirname(entryPointBasePath), basePath);
|
4151 | const namedImport = entryPointBasePath !== basePath ? importManager.generateNamedImport(relativePath, e.identifier) : { symbol: e.identifier, moduleImport: null };
|
4152 | const importNamespace = namedImport.moduleImport ? `${namedImport.moduleImport.text}.` : "";
|
4153 | const exportStr = `
|
4154 | exports.${e.identifier} = ${importNamespace}${namedImport.symbol};`;
|
4155 | output.append(exportStr);
|
4156 | });
|
4157 | }
|
4158 | addDirectExports(output, exports, importManager, file) {
|
4159 | for (const e of exports) {
|
4160 | const namedImport = importManager.generateNamedImport(e.fromModule, e.symbolName);
|
4161 | const importNamespace = namedImport.moduleImport ? `${namedImport.moduleImport.text}.` : "";
|
4162 | const exportStr = `
|
4163 | exports.${e.asAlias} = ${importNamespace}${namedImport.symbol};`;
|
4164 | output.append(exportStr);
|
4165 | }
|
4166 | }
|
4167 | findEndOfImports(sf) {
|
4168 | for (const statement of sf.statements) {
|
4169 | if (ts19.isExpressionStatement(statement) && isRequireCall(statement.expression)) {
|
4170 | continue;
|
4171 | }
|
4172 | const declarations = ts19.isVariableStatement(statement) ? Array.from(statement.declarationList.declarations) : [];
|
4173 | if (declarations.some((d) => !d.initializer || !isRequireCall(d.initializer))) {
|
4174 | return statement.getStart();
|
4175 | }
|
4176 | }
|
4177 | return 0;
|
4178 | }
|
4179 | };
|
4180 |
|
4181 |
|
4182 | import MagicString from "magic-string";
|
4183 | import ts20 from "typescript";
|
4184 |
|
4185 |
|
4186 | var IMPORT_PREFIX = "\u0275ngcc";
|
4187 | var NGCC_TIMED_OUT_EXIT_CODE = 177;
|
4188 |
|
4189 |
|
4190 | import mapHelpers from "convert-source-map";
|
4191 | function renderSourceAndMap(logger, fs, sourceFile, generatedMagicString) {
|
4192 | var _a;
|
4193 | const sourceFilePath = absoluteFromSourceFile(sourceFile);
|
4194 | const sourceMapPath = absoluteFrom(`${sourceFilePath}.map`);
|
4195 | const generatedContent = generatedMagicString.toString();
|
4196 | const generatedMap = generatedMagicString.generateMap({ file: sourceFilePath, source: sourceFilePath, includeContent: true });
|
4197 | try {
|
4198 | const loader = new SourceFileLoader(fs, logger, {});
|
4199 | const generatedFile = loader.loadSourceFile(sourceFilePath, generatedContent, { map: generatedMap, mapPath: sourceMapPath });
|
4200 | const rawMergedMap = generatedFile.renderFlattenedSourceMap();
|
4201 | const mergedMap = mapHelpers.fromObject(rawMergedMap);
|
4202 | const originalFile = loader.loadSourceFile(sourceFilePath, generatedMagicString.original);
|
4203 | if (originalFile.rawMap === null && !sourceFile.isDeclarationFile || ((_a = originalFile.rawMap) == null ? void 0 : _a.origin) === ContentOrigin.Inline) {
|
4204 | return [
|
4205 | { path: sourceFilePath, contents: `${generatedFile.contents}
|
4206 | ${mergedMap.toComment()}` }
|
4207 | ];
|
4208 | }
|
4209 | const sourceMapComment = mapHelpers.generateMapFileComment(`${fs.basename(sourceFilePath)}.map`);
|
4210 | return [
|
4211 | { path: sourceFilePath, contents: `${generatedFile.contents}
|
4212 | ${sourceMapComment}` },
|
4213 | { path: sourceMapPath, contents: mergedMap.toJSON() }
|
4214 | ];
|
4215 | } catch (e) {
|
4216 | logger.error(`Error when flattening the source-map "${sourceMapPath}" for "${sourceFilePath}": ${e.toString()}`);
|
4217 | return [
|
4218 | { path: sourceFilePath, contents: generatedContent },
|
4219 | { path: sourceMapPath, contents: mapHelpers.fromObject(generatedMap).toJSON() }
|
4220 | ];
|
4221 | }
|
4222 | }
|
4223 |
|
4224 |
|
4225 | var DtsRenderInfo = class {
|
4226 | constructor() {
|
4227 | this.classInfo = [];
|
4228 | this.moduleWithProviders = [];
|
4229 | this.privateExports = [];
|
4230 | this.reexports = [];
|
4231 | }
|
4232 | };
|
4233 | var DtsRenderer = class {
|
4234 | constructor(dtsFormatter, fs, logger, host, bundle) {
|
4235 | this.dtsFormatter = dtsFormatter;
|
4236 | this.fs = fs;
|
4237 | this.logger = logger;
|
4238 | this.host = host;
|
4239 | this.bundle = bundle;
|
4240 | }
|
4241 | renderProgram(decorationAnalyses, privateDeclarationsAnalyses, moduleWithProvidersAnalyses) {
|
4242 | const renderedFiles = [];
|
4243 | if (this.bundle.dts) {
|
4244 | const dtsFiles = this.getTypingsFilesToRender(decorationAnalyses, privateDeclarationsAnalyses, moduleWithProvidersAnalyses);
|
4245 | if (!dtsFiles.has(this.bundle.dts.file)) {
|
4246 | dtsFiles.set(this.bundle.dts.file, new DtsRenderInfo());
|
4247 | }
|
4248 | dtsFiles.forEach((renderInfo, file) => renderedFiles.push(...this.renderDtsFile(file, renderInfo)));
|
4249 | }
|
4250 | return renderedFiles;
|
4251 | }
|
4252 | renderDtsFile(dtsFile, renderInfo) {
|
4253 | const outputText = new MagicString(dtsFile.text);
|
4254 | const printer = ts20.createPrinter();
|
4255 | const importManager = new ImportManager(getImportRewriter(this.bundle.dts.r3SymbolsFile, this.bundle.isCore, false), IMPORT_PREFIX);
|
4256 | renderInfo.classInfo.forEach((dtsClass) => {
|
4257 | const endOfClass = dtsClass.dtsDeclaration.getEnd();
|
4258 | dtsClass.compilation.forEach((declaration) => {
|
4259 | const type = translateType(declaration.type, importManager);
|
4260 | markForEmitAsSingleLine(type);
|
4261 | const typeStr = printer.printNode(ts20.EmitHint.Unspecified, type, dtsFile);
|
4262 | const newStatement = ` static ${declaration.name}: ${typeStr};
|
4263 | `;
|
4264 | outputText.appendRight(endOfClass - 1, newStatement);
|
4265 | });
|
4266 | });
|
4267 | if (renderInfo.reexports.length > 0) {
|
4268 | for (const e of renderInfo.reexports) {
|
4269 | const newStatement = `
|
4270 | export {${e.symbolName} as ${e.asAlias}} from '${e.fromModule}';`;
|
4271 | outputText.append(newStatement);
|
4272 | }
|
4273 | }
|
4274 | this.dtsFormatter.addModuleWithProvidersParams(outputText, renderInfo.moduleWithProviders, importManager);
|
4275 | this.dtsFormatter.addExports(outputText, dtsFile.fileName, renderInfo.privateExports, importManager, dtsFile);
|
4276 | this.dtsFormatter.addImports(outputText, importManager.getAllImports(dtsFile.fileName), dtsFile);
|
4277 | return renderSourceAndMap(this.logger, this.fs, dtsFile, outputText);
|
4278 | }
|
4279 | getTypingsFilesToRender(decorationAnalyses, privateDeclarationsAnalyses, moduleWithProvidersAnalyses) {
|
4280 | const dtsMap = new Map();
|
4281 | decorationAnalyses.forEach((compiledFile) => {
|
4282 | let appliedReexports = false;
|
4283 | compiledFile.compiledClasses.forEach((compiledClass) => {
|
4284 | const dtsDeclaration = this.host.getDtsDeclaration(compiledClass.declaration);
|
4285 | if (dtsDeclaration) {
|
4286 | const dtsFile = dtsDeclaration.getSourceFile();
|
4287 | const renderInfo = dtsMap.has(dtsFile) ? dtsMap.get(dtsFile) : new DtsRenderInfo();
|
4288 | renderInfo.classInfo.push({ dtsDeclaration, compilation: compiledClass.compilation });
|
4289 | if (!appliedReexports && compiledClass.declaration.getSourceFile().fileName === dtsFile.fileName.replace(/\.d\.ts$/, ".js")) {
|
4290 | renderInfo.reexports.push(...compiledFile.reexports);
|
4291 | appliedReexports = true;
|
4292 | }
|
4293 | dtsMap.set(dtsFile, renderInfo);
|
4294 | }
|
4295 | });
|
4296 | });
|
4297 | if (moduleWithProvidersAnalyses !== null) {
|
4298 | moduleWithProvidersAnalyses.forEach((moduleWithProvidersToFix, dtsFile) => {
|
4299 | const renderInfo = dtsMap.has(dtsFile) ? dtsMap.get(dtsFile) : new DtsRenderInfo();
|
4300 | renderInfo.moduleWithProviders = moduleWithProvidersToFix;
|
4301 | dtsMap.set(dtsFile, renderInfo);
|
4302 | });
|
4303 | }
|
4304 | if (privateDeclarationsAnalyses.length) {
|
4305 | privateDeclarationsAnalyses.forEach((e) => {
|
4306 | if (!e.dtsFrom) {
|
4307 | throw new Error(`There is no typings path for ${e.identifier} in ${e.from}.
|
4308 | We need to add an export for this class to a .d.ts typings file because Angular compiler needs to be able to reference this class in compiled code, such as templates.
|
4309 | The simplest fix for this is to ensure that this class is exported from the package's entry-point.`);
|
4310 | }
|
4311 | });
|
4312 | const dtsEntryPoint = this.bundle.dts.file;
|
4313 | const renderInfo = dtsMap.has(dtsEntryPoint) ? dtsMap.get(dtsEntryPoint) : new DtsRenderInfo();
|
4314 | renderInfo.privateExports = privateDeclarationsAnalyses;
|
4315 | dtsMap.set(dtsEntryPoint, renderInfo);
|
4316 | }
|
4317 | return dtsMap;
|
4318 | }
|
4319 | };
|
4320 | function markForEmitAsSingleLine(node) {
|
4321 | ts20.setEmitFlags(node, ts20.EmitFlags.SingleLine);
|
4322 | ts20.forEachChild(node, markForEmitAsSingleLine);
|
4323 | }
|
4324 |
|
4325 |
|
4326 | import { jsDocComment, WrappedNodeExpr, WritePropExpr } from "@angular/compiler";
|
4327 | import MagicString2 from "magic-string";
|
4328 |
|
4329 |
|
4330 | var RedundantDecoratorMap = Map;
|
4331 |
|
4332 |
|
4333 | var Renderer = class {
|
4334 | constructor(host, srcFormatter, fs, logger, bundle, tsConfig = null) {
|
4335 | this.host = host;
|
4336 | this.srcFormatter = srcFormatter;
|
4337 | this.fs = fs;
|
4338 | this.logger = logger;
|
4339 | this.bundle = bundle;
|
4340 | this.tsConfig = tsConfig;
|
4341 | }
|
4342 | renderProgram(decorationAnalyses, privateDeclarationsAnalyses) {
|
4343 | const renderedFiles = [];
|
4344 | this.bundle.src.program.getSourceFiles().forEach((sourceFile) => {
|
4345 | if (decorationAnalyses.has(sourceFile) || sourceFile === this.bundle.src.file) {
|
4346 | const compiledFile = decorationAnalyses.get(sourceFile);
|
4347 | renderedFiles.push(...this.renderFile(sourceFile, compiledFile, privateDeclarationsAnalyses));
|
4348 | }
|
4349 | });
|
4350 | return renderedFiles;
|
4351 | }
|
4352 | renderFile(sourceFile, compiledFile, privateDeclarationsAnalyses) {
|
4353 | const isEntryPoint2 = sourceFile === this.bundle.src.file;
|
4354 | const outputText = new MagicString2(sourceFile.text);
|
4355 | const importManager = new ImportManager(getImportRewriter(this.bundle.src.r3SymbolsFile, this.bundle.isCore, this.bundle.isFlatCore), IMPORT_PREFIX);
|
4356 | if (compiledFile) {
|
4357 | const decoratorsToRemove = this.computeDecoratorsToRemove(compiledFile.compiledClasses);
|
4358 | this.srcFormatter.removeDecorators(outputText, decoratorsToRemove);
|
4359 | compiledFile.compiledClasses.forEach((clazz) => {
|
4360 | var _a;
|
4361 | const renderedDefinition = this.renderDefinitions(compiledFile.sourceFile, clazz, importManager, !!((_a = this.tsConfig) == null ? void 0 : _a.options.annotateForClosureCompiler));
|
4362 | this.srcFormatter.addDefinitions(outputText, clazz, renderedDefinition);
|
4363 | const renderedStatements = this.renderAdjacentStatements(compiledFile.sourceFile, clazz, importManager);
|
4364 | this.srcFormatter.addAdjacentStatements(outputText, clazz, renderedStatements);
|
4365 | });
|
4366 | if (!isEntryPoint2 && compiledFile.reexports.length > 0) {
|
4367 | this.srcFormatter.addDirectExports(outputText, compiledFile.reexports, importManager, compiledFile.sourceFile);
|
4368 | }
|
4369 | this.srcFormatter.addConstants(outputText, renderConstantPool(this.srcFormatter, compiledFile.sourceFile, compiledFile.constantPool, importManager), compiledFile.sourceFile);
|
4370 | }
|
4371 | if (isEntryPoint2) {
|
4372 | const entryPointBasePath = stripExtension2(this.bundle.src.path);
|
4373 | this.srcFormatter.addExports(outputText, entryPointBasePath, privateDeclarationsAnalyses, importManager, sourceFile);
|
4374 | }
|
4375 | if (isEntryPoint2 || compiledFile) {
|
4376 | this.srcFormatter.addImports(outputText, importManager.getAllImports(sourceFile.fileName), sourceFile);
|
4377 | }
|
4378 | if (compiledFile || isEntryPoint2) {
|
4379 | return renderSourceAndMap(this.logger, this.fs, sourceFile, outputText);
|
4380 | } else {
|
4381 | return [];
|
4382 | }
|
4383 | }
|
4384 | computeDecoratorsToRemove(classes) {
|
4385 | const decoratorsToRemove = new RedundantDecoratorMap();
|
4386 | classes.forEach((clazz) => {
|
4387 | if (clazz.decorators === null) {
|
4388 | return;
|
4389 | }
|
4390 | clazz.decorators.forEach((dec) => {
|
4391 | if (dec.node === null) {
|
4392 | return;
|
4393 | }
|
4394 | const decoratorArray = dec.node.parent;
|
4395 | if (!decoratorsToRemove.has(decoratorArray)) {
|
4396 | decoratorsToRemove.set(decoratorArray, [dec.node]);
|
4397 | } else {
|
4398 | decoratorsToRemove.get(decoratorArray).push(dec.node);
|
4399 | }
|
4400 | });
|
4401 | });
|
4402 | return decoratorsToRemove;
|
4403 | }
|
4404 | renderDefinitions(sourceFile, compiledClass, imports, annotateForClosureCompiler) {
|
4405 | const name = this.host.getInternalNameOfClass(compiledClass.declaration);
|
4406 | const leadingComment = annotateForClosureCompiler ? jsDocComment([{ tagName: "nocollapse" }]) : void 0;
|
4407 | const statements = compiledClass.compilation.map((c) => createAssignmentStatement(name, c.name, c.initializer, leadingComment));
|
4408 | return this.renderStatements(sourceFile, statements, imports);
|
4409 | }
|
4410 | renderAdjacentStatements(sourceFile, compiledClass, imports) {
|
4411 | const statements = [];
|
4412 | for (const c of compiledClass.compilation) {
|
4413 | statements.push(...c.statements);
|
4414 | }
|
4415 | return this.renderStatements(sourceFile, statements, imports);
|
4416 | }
|
4417 | renderStatements(sourceFile, statements, imports) {
|
4418 | const printStatement = (stmt) => this.srcFormatter.printStatement(stmt, sourceFile, imports);
|
4419 | return statements.map(printStatement).join("\n");
|
4420 | }
|
4421 | };
|
4422 | function renderConstantPool(formatter, sourceFile, constantPool, imports) {
|
4423 | const printStatement = (stmt) => formatter.printStatement(stmt, sourceFile, imports);
|
4424 | return constantPool.statements.map(printStatement).join("\n");
|
4425 | }
|
4426 | function createAssignmentStatement(receiverName, propName, initializer, leadingComment) {
|
4427 | const receiver = new WrappedNodeExpr(receiverName);
|
4428 | const statement = new WritePropExpr(receiver, propName, initializer, void 0, void 0).toStmt();
|
4429 | if (leadingComment !== void 0) {
|
4430 | statement.addLeadingComment(leadingComment);
|
4431 | }
|
4432 | return statement;
|
4433 | }
|
4434 |
|
4435 |
|
4436 | import ts21 from "typescript";
|
4437 | var UmdRenderingFormatter = class extends Esm5RenderingFormatter {
|
4438 | constructor(fs, umdHost, isCore) {
|
4439 | super(fs, umdHost, isCore);
|
4440 | this.umdHost = umdHost;
|
4441 | }
|
4442 | addImports(output, imports, file) {
|
4443 | if (imports.length === 0) {
|
4444 | return;
|
4445 | }
|
4446 | const umdModule = this.umdHost.getUmdModule(file);
|
4447 | if (!umdModule) {
|
4448 | return;
|
4449 | }
|
4450 | const { factoryFn, factoryCalls } = umdModule;
|
4451 | renderCommonJsDependencies(output, factoryCalls.commonJs, imports);
|
4452 | renderCommonJsDependencies(output, factoryCalls.commonJs2, imports);
|
4453 | renderAmdDependencies(output, factoryCalls.amdDefine, imports);
|
4454 | renderGlobalDependencies(output, factoryCalls.global, imports);
|
4455 | renderFactoryParameters(output, factoryFn, imports);
|
4456 | }
|
4457 | addExports(output, entryPointBasePath, exports, importManager, file) {
|
4458 | const umdModule = this.umdHost.getUmdModule(file);
|
4459 | if (!umdModule) {
|
4460 | return;
|
4461 | }
|
4462 | const factoryFunction = umdModule.factoryFn;
|
4463 | const lastStatement = factoryFunction.body.statements[factoryFunction.body.statements.length - 1];
|
4464 | const insertionPoint = lastStatement ? lastStatement.getEnd() : factoryFunction.body.getEnd() - 1;
|
4465 | exports.forEach((e) => {
|
4466 | const basePath = stripExtension2(e.from);
|
4467 | const relativePath = "./" + this.fs.relative(this.fs.dirname(entryPointBasePath), basePath);
|
4468 | const namedImport = entryPointBasePath !== basePath ? importManager.generateNamedImport(relativePath, e.identifier) : { symbol: e.identifier, moduleImport: null };
|
4469 | const importNamespace = namedImport.moduleImport ? `${namedImport.moduleImport.text}.` : "";
|
4470 | const exportStr = `
|
4471 | exports.${e.identifier} = ${importNamespace}${namedImport.symbol};`;
|
4472 | output.appendRight(insertionPoint, exportStr);
|
4473 | });
|
4474 | }
|
4475 | addDirectExports(output, exports, importManager, file) {
|
4476 | const umdModule = this.umdHost.getUmdModule(file);
|
4477 | if (!umdModule) {
|
4478 | return;
|
4479 | }
|
4480 | const factoryFunction = umdModule.factoryFn;
|
4481 | const lastStatement = factoryFunction.body.statements[factoryFunction.body.statements.length - 1];
|
4482 | const insertionPoint = lastStatement ? lastStatement.getEnd() : factoryFunction.body.getEnd() - 1;
|
4483 | for (const e of exports) {
|
4484 | const namedImport = importManager.generateNamedImport(e.fromModule, e.symbolName);
|
4485 | const importNamespace = namedImport.moduleImport ? `${namedImport.moduleImport.text}.` : "";
|
4486 | const exportStr = `
|
4487 | exports.${e.asAlias} = ${importNamespace}${namedImport.symbol};`;
|
4488 | output.appendRight(insertionPoint, exportStr);
|
4489 | }
|
4490 | }
|
4491 | addConstants(output, constants, file) {
|
4492 | if (constants === "") {
|
4493 | return;
|
4494 | }
|
4495 | const umdModule = this.umdHost.getUmdModule(file);
|
4496 | if (!umdModule) {
|
4497 | return;
|
4498 | }
|
4499 | const factoryFunction = umdModule.factoryFn;
|
4500 | const firstStatement = factoryFunction.body.statements[0];
|
4501 | const insertionPoint = firstStatement ? firstStatement.getStart() : factoryFunction.body.getStart() + 1;
|
4502 | output.appendLeft(insertionPoint, "\n" + constants + "\n");
|
4503 | }
|
4504 | };
|
4505 | function renderCommonJsDependencies(output, factoryCall, imports) {
|
4506 | if (factoryCall === null) {
|
4507 | return;
|
4508 | }
|
4509 | const injectionPoint = factoryCall.arguments.length > 0 ? factoryCall.arguments[0].getFullStart() : factoryCall.getEnd() - 1;
|
4510 | const importString = imports.map((i) => `require('${i.specifier}')`).join(",");
|
4511 | output.appendLeft(injectionPoint, importString + (factoryCall.arguments.length > 0 ? "," : ""));
|
4512 | }
|
4513 | function renderAmdDependencies(output, amdDefineCall, imports) {
|
4514 | if (amdDefineCall === null) {
|
4515 | return;
|
4516 | }
|
4517 | const importString = imports.map((i) => `'${i.specifier}'`).join(",");
|
4518 | const factoryIndex = amdDefineCall.arguments.length - 1;
|
4519 | const dependencyArray = amdDefineCall.arguments[factoryIndex - 1];
|
4520 | if (dependencyArray === void 0 || !ts21.isArrayLiteralExpression(dependencyArray)) {
|
4521 | const injectionPoint = amdDefineCall.arguments[factoryIndex].getFullStart();
|
4522 | output.appendLeft(injectionPoint, `[${importString}],`);
|
4523 | } else {
|
4524 | const injectionPoint = dependencyArray.elements.length > 0 ? dependencyArray.elements[0].getFullStart() : dependencyArray.getEnd() - 1;
|
4525 | output.appendLeft(injectionPoint, importString + (dependencyArray.elements.length > 0 ? "," : ""));
|
4526 | }
|
4527 | }
|
4528 | function renderGlobalDependencies(output, factoryCall, imports) {
|
4529 | if (factoryCall === null) {
|
4530 | return;
|
4531 | }
|
4532 | const injectionPoint = factoryCall.arguments.length > 0 ? factoryCall.arguments[0].getFullStart() : factoryCall.getEnd() - 1;
|
4533 | const importString = imports.map((i) => `global.${getGlobalIdentifier(i)}`).join(",");
|
4534 | output.appendLeft(injectionPoint, importString + (factoryCall.arguments.length > 0 ? "," : ""));
|
4535 | }
|
4536 | function renderFactoryParameters(output, factoryFunction, imports) {
|
4537 | const parameters = factoryFunction.parameters;
|
4538 | const parameterString = imports.map((i) => i.qualifier.text).join(",");
|
4539 | if (parameters.length > 0) {
|
4540 | const injectionPoint = parameters[0].getFullStart();
|
4541 | output.appendLeft(injectionPoint, parameterString + ",");
|
4542 | } else {
|
4543 | const injectionPoint = factoryFunction.getStart() + factoryFunction.getText().indexOf("()") + 1;
|
4544 | output.appendLeft(injectionPoint, parameterString);
|
4545 | }
|
4546 | }
|
4547 | function getGlobalIdentifier(i) {
|
4548 | return i.specifier.replace(/^@angular\//, "ng.").replace(/^@/, "").replace(/\//g, ".").replace(/[-_]+(.?)/g, (_, c) => c.toUpperCase()).replace(/^./, (c) => c.toLowerCase());
|
4549 | }
|
4550 |
|
4551 |
|
4552 | var Transformer = class {
|
4553 | constructor(fs, logger, tsConfig = null) {
|
4554 | this.fs = fs;
|
4555 | this.logger = logger;
|
4556 | this.tsConfig = tsConfig;
|
4557 | }
|
4558 | transform(bundle) {
|
4559 | const ngccReflectionHost = this.getHost(bundle);
|
4560 | const tsReflectionHost = new TypeScriptReflectionHost(bundle.src.program.getTypeChecker());
|
4561 | const reflectionHost = new DelegatingReflectionHost(tsReflectionHost, ngccReflectionHost);
|
4562 | const { decorationAnalyses, privateDeclarationsAnalyses, moduleWithProvidersAnalyses, diagnostics } = this.analyzeProgram(reflectionHost, bundle);
|
4563 | if (hasErrors(diagnostics)) {
|
4564 | return { success: false, diagnostics };
|
4565 | }
|
4566 | let renderedFiles = [];
|
4567 | if (bundle.dtsProcessing !== DtsProcessing.Only) {
|
4568 | const srcFormatter = this.getRenderingFormatter(ngccReflectionHost, bundle);
|
4569 | const renderer = new Renderer(reflectionHost, srcFormatter, this.fs, this.logger, bundle, this.tsConfig);
|
4570 | renderedFiles = renderer.renderProgram(decorationAnalyses, privateDeclarationsAnalyses);
|
4571 | }
|
4572 | if (bundle.dts) {
|
4573 | const dtsFormatter = new EsmRenderingFormatter(this.fs, reflectionHost, bundle.isCore);
|
4574 | const dtsRenderer = new DtsRenderer(dtsFormatter, this.fs, this.logger, reflectionHost, bundle);
|
4575 | const renderedDtsFiles = dtsRenderer.renderProgram(decorationAnalyses, privateDeclarationsAnalyses, moduleWithProvidersAnalyses);
|
4576 | renderedFiles = renderedFiles.concat(renderedDtsFiles);
|
4577 | }
|
4578 | return { success: true, diagnostics, transformedFiles: renderedFiles };
|
4579 | }
|
4580 | getHost(bundle) {
|
4581 | switch (bundle.format) {
|
4582 | case "esm2015":
|
4583 | return new Esm2015ReflectionHost(this.logger, bundle.isCore, bundle.src, bundle.dts);
|
4584 | case "esm5":
|
4585 | return new Esm5ReflectionHost(this.logger, bundle.isCore, bundle.src, bundle.dts);
|
4586 | case "umd":
|
4587 | return new UmdReflectionHost(this.logger, bundle.isCore, bundle.src, bundle.dts);
|
4588 | case "commonjs":
|
4589 | return new CommonJsReflectionHost(this.logger, bundle.isCore, bundle.src, bundle.dts);
|
4590 | default:
|
4591 | throw new Error(`Reflection host for "${bundle.format}" not yet implemented.`);
|
4592 | }
|
4593 | }
|
4594 | getRenderingFormatter(host, bundle) {
|
4595 | switch (bundle.format) {
|
4596 | case "esm2015":
|
4597 | return new EsmRenderingFormatter(this.fs, host, bundle.isCore);
|
4598 | case "esm5":
|
4599 | return new Esm5RenderingFormatter(this.fs, host, bundle.isCore);
|
4600 | case "umd":
|
4601 | if (!(host instanceof UmdReflectionHost)) {
|
4602 | throw new Error("UmdRenderer requires a UmdReflectionHost");
|
4603 | }
|
4604 | return new UmdRenderingFormatter(this.fs, host, bundle.isCore);
|
4605 | case "commonjs":
|
4606 | return new CommonJsRenderingFormatter(this.fs, host, bundle.isCore);
|
4607 | default:
|
4608 | throw new Error(`Renderer for "${bundle.format}" not yet implemented.`);
|
4609 | }
|
4610 | }
|
4611 | analyzeProgram(reflectionHost, bundle) {
|
4612 | const referencesRegistry = new NgccReferencesRegistry(reflectionHost);
|
4613 | const diagnostics = [];
|
4614 | const decorationAnalyzer = new DecorationAnalyzer(this.fs, bundle, reflectionHost, referencesRegistry, (diagnostic) => diagnostics.push(diagnostic), this.tsConfig);
|
4615 | const decorationAnalyses = decorationAnalyzer.analyzeProgram();
|
4616 | const moduleWithProvidersAnalyzer = new ModuleWithProvidersAnalyzer(reflectionHost, bundle.src.program.getTypeChecker(), referencesRegistry, bundle.dts !== null);
|
4617 | const moduleWithProvidersAnalyses = moduleWithProvidersAnalyzer && moduleWithProvidersAnalyzer.analyzeProgram(bundle.src.program);
|
4618 | const privateDeclarationsAnalyzer = new PrivateDeclarationsAnalyzer(reflectionHost, referencesRegistry);
|
4619 | const privateDeclarationsAnalyses = privateDeclarationsAnalyzer.analyzeProgram(bundle.src.program);
|
4620 | return {
|
4621 | decorationAnalyses,
|
4622 | privateDeclarationsAnalyses,
|
4623 | moduleWithProvidersAnalyses,
|
4624 | diagnostics
|
4625 | };
|
4626 | }
|
4627 | };
|
4628 | function hasErrors(diagnostics) {
|
4629 | return diagnostics.some((d) => d.category === ts22.DiagnosticCategory.Error);
|
4630 | }
|
4631 |
|
4632 |
|
4633 | function getCreateCompileFn(fileSystem, logger, fileWriter, enableI18nLegacyMessageIdFormat, tsConfig, pathMappings) {
|
4634 | return (beforeWritingFiles, onTaskCompleted) => {
|
4635 | const transformer = new Transformer(fileSystem, logger, tsConfig);
|
4636 | const sharedFileCache = new SharedFileCache(fileSystem);
|
4637 | const moduleResolutionCache = createModuleResolutionCache(fileSystem);
|
4638 | return (task) => {
|
4639 | const { entryPoint, formatProperty, formatPropertiesToMarkAsProcessed, processDts } = task;
|
4640 | const isCore = entryPoint.name === "@angular/core";
|
4641 | const packageJson = entryPoint.packageJson;
|
4642 | const formatPath = packageJson[formatProperty];
|
4643 | const format = getEntryPointFormat(fileSystem, entryPoint, formatProperty);
|
4644 | if (!formatPath || !format) {
|
4645 | onTaskCompleted(task, 1, `property \`${formatProperty}\` pointing to a missing or empty file: ${formatPath}`);
|
4646 | return;
|
4647 | }
|
4648 | logger.info(`- ${entryPoint.name} [${formatProperty}/${format}] (${entryPoint.repositoryUrl})`);
|
4649 | const bundle = makeEntryPointBundle(fileSystem, entryPoint, sharedFileCache, moduleResolutionCache, formatPath, isCore, format, processDts, pathMappings, true, enableI18nLegacyMessageIdFormat);
|
4650 | const result = transformer.transform(bundle);
|
4651 | if (result.success) {
|
4652 | if (result.diagnostics.length > 0) {
|
4653 | logger.warn(replaceTsWithNgInErrors(ts23.formatDiagnosticsWithColorAndContext(result.diagnostics, bundle.src.host)));
|
4654 | }
|
4655 | const writeBundle = () => {
|
4656 | fileWriter.writeBundle(bundle, result.transformedFiles, formatPropertiesToMarkAsProcessed);
|
4657 | logger.debug(` Successfully compiled ${entryPoint.name} : ${formatProperty}`);
|
4658 | onTaskCompleted(task, 0, null);
|
4659 | };
|
4660 | const beforeWritingResult = beforeWritingFiles(result.transformedFiles);
|
4661 | return beforeWritingResult instanceof Promise ? beforeWritingResult.then(writeBundle) : writeBundle();
|
4662 | } else {
|
4663 | const errors = replaceTsWithNgInErrors(ts23.formatDiagnosticsWithColorAndContext(result.diagnostics, bundle.src.host));
|
4664 | onTaskCompleted(task, 1, `compilation errors:
|
4665 | ${errors}`);
|
4666 | }
|
4667 | };
|
4668 | };
|
4669 | }
|
4670 |
|
4671 |
|
4672 | import * as os from "os";
|
4673 |
|
4674 |
|
4675 | function getPathMappingsFromTsConfig(fs, tsConfig, projectPath) {
|
4676 | if (tsConfig !== null && tsConfig.options.baseUrl !== void 0 && tsConfig.options.paths !== void 0) {
|
4677 | return {
|
4678 | baseUrl: fs.resolve(projectPath, tsConfig.options.baseUrl),
|
4679 | paths: tsConfig.options.paths
|
4680 | };
|
4681 | }
|
4682 | }
|
4683 |
|
4684 |
|
4685 | var NGCC_BACKUP_EXTENSION = ".__ivy_ngcc_bak";
|
4686 | var InPlaceFileWriter = class {
|
4687 | constructor(fs, logger, errorOnFailedEntryPoint) {
|
4688 | this.fs = fs;
|
4689 | this.logger = logger;
|
4690 | this.errorOnFailedEntryPoint = errorOnFailedEntryPoint;
|
4691 | }
|
4692 | writeBundle(_bundle, transformedFiles, _formatProperties) {
|
4693 | transformedFiles.forEach((file) => this.writeFileAndBackup(file));
|
4694 | }
|
4695 | revertBundle(_entryPoint, transformedFilePaths, _formatProperties) {
|
4696 | for (const filePath of transformedFilePaths) {
|
4697 | this.revertFileAndBackup(filePath);
|
4698 | }
|
4699 | }
|
4700 | writeFileAndBackup(file) {
|
4701 | this.fs.ensureDir(dirname(file.path));
|
4702 | const backPath = absoluteFrom(`${file.path}${NGCC_BACKUP_EXTENSION}`);
|
4703 | if (this.fs.exists(backPath)) {
|
4704 | if (this.errorOnFailedEntryPoint) {
|
4705 | throw new Error(`Tried to overwrite ${backPath} with an ngcc back up file, which is disallowed.`);
|
4706 | } else {
|
4707 | this.logger.error(`Tried to write ${backPath} with an ngcc back up file but it already exists so not writing, nor backing up, ${file.path}.
|
4708 | This error may be caused by one of the following:
|
4709 | * two or more entry-points overlap and ngcc has been asked to process some files more than once.
|
4710 | In this case, you should check other entry-points in this package
|
4711 | and set up a config to ignore any that you are not using.
|
4712 | * a previous run of ngcc was killed in the middle of processing, in a way that cannot be recovered.
|
4713 | In this case, you should try cleaning the node_modules directory and any dist directories that contain local libraries. Then try again.`);
|
4714 | }
|
4715 | } else {
|
4716 | if (this.fs.exists(file.path)) {
|
4717 | this.fs.moveFile(file.path, backPath);
|
4718 | }
|
4719 | this.fs.writeFile(file.path, file.contents);
|
4720 | }
|
4721 | }
|
4722 | revertFileAndBackup(filePath) {
|
4723 | if (this.fs.exists(filePath)) {
|
4724 | this.fs.removeFile(filePath);
|
4725 | const backPath = absoluteFrom(`${filePath}${NGCC_BACKUP_EXTENSION}`);
|
4726 | if (this.fs.exists(backPath)) {
|
4727 | this.fs.moveFile(backPath, filePath);
|
4728 | }
|
4729 | }
|
4730 | }
|
4731 | };
|
4732 |
|
4733 |
|
4734 | var NGCC_DIRECTORY = "__ivy_ngcc__";
|
4735 | var NGCC_PROPERTY_EXTENSION = "_ivy_ngcc";
|
4736 | var NewEntryPointFileWriter = class extends InPlaceFileWriter {
|
4737 | constructor(fs, logger, errorOnFailedEntryPoint, pkgJsonUpdater) {
|
4738 | super(fs, logger, errorOnFailedEntryPoint);
|
4739 | this.pkgJsonUpdater = pkgJsonUpdater;
|
4740 | }
|
4741 | writeBundle(bundle, transformedFiles, formatProperties) {
|
4742 | const entryPoint = bundle.entryPoint;
|
4743 | const ngccFolder = this.fs.join(entryPoint.packagePath, NGCC_DIRECTORY);
|
4744 | this.copyBundle(bundle, entryPoint.packagePath, ngccFolder, transformedFiles);
|
4745 | transformedFiles.forEach((file) => this.writeFile(file, entryPoint.packagePath, ngccFolder));
|
4746 | this.updatePackageJson(entryPoint, formatProperties, ngccFolder);
|
4747 | }
|
4748 | revertBundle(entryPoint, transformedFilePaths, formatProperties) {
|
4749 | for (const filePath of transformedFilePaths) {
|
4750 | this.revertFile(filePath, entryPoint.packagePath);
|
4751 | }
|
4752 | this.revertPackageJson(entryPoint, formatProperties);
|
4753 | }
|
4754 | copyBundle(bundle, packagePath, ngccFolder, transformedFiles) {
|
4755 | const doNotCopy = new Set(transformedFiles.map((f) => f.path));
|
4756 | bundle.src.program.getSourceFiles().forEach((sourceFile) => {
|
4757 | const originalPath = absoluteFromSourceFile(sourceFile);
|
4758 | if (doNotCopy.has(originalPath)) {
|
4759 | return;
|
4760 | }
|
4761 | const relativePath = this.fs.relative(packagePath, originalPath);
|
4762 | const isInsidePackage = isLocalRelativePath(relativePath);
|
4763 | if (!sourceFile.isDeclarationFile && isInsidePackage) {
|
4764 | const newPath = this.fs.resolve(ngccFolder, relativePath);
|
4765 | this.fs.ensureDir(this.fs.dirname(newPath));
|
4766 | this.fs.copyFile(originalPath, newPath);
|
4767 | this.copyAndUpdateSourceMap(originalPath, newPath);
|
4768 | }
|
4769 | });
|
4770 | }
|
4771 | copyAndUpdateSourceMap(originalSrcPath, newSrcPath) {
|
4772 | var _a;
|
4773 | const sourceMapPath = originalSrcPath + ".map";
|
4774 | if (this.fs.exists(sourceMapPath)) {
|
4775 | try {
|
4776 | const sourceMap = JSON.parse(this.fs.readFile(sourceMapPath));
|
4777 | const newSourceMapPath = newSrcPath + ".map";
|
4778 | const relativePath = this.fs.relative(this.fs.dirname(newSourceMapPath), this.fs.dirname(sourceMapPath));
|
4779 | sourceMap.sourceRoot = this.fs.join(relativePath, sourceMap.sourceRoot || ".");
|
4780 | this.fs.ensureDir(this.fs.dirname(newSourceMapPath));
|
4781 | this.fs.writeFile(newSourceMapPath, JSON.stringify(sourceMap));
|
4782 | } catch (e) {
|
4783 | this.logger.warn(`Failed to process source-map at ${sourceMapPath}`);
|
4784 | this.logger.warn((_a = e.message) != null ? _a : e);
|
4785 | }
|
4786 | }
|
4787 | }
|
4788 | writeFile(file, packagePath, ngccFolder) {
|
4789 | if (isDtsPath(file.path.replace(/\.map$/, ""))) {
|
4790 | super.writeFileAndBackup(file);
|
4791 | } else {
|
4792 | const relativePath = this.fs.relative(packagePath, file.path);
|
4793 | const newFilePath = this.fs.resolve(ngccFolder, relativePath);
|
4794 | this.fs.ensureDir(this.fs.dirname(newFilePath));
|
4795 | this.fs.writeFile(newFilePath, file.contents);
|
4796 | }
|
4797 | }
|
4798 | revertFile(filePath, packagePath) {
|
4799 | if (isDtsPath(filePath.replace(/\.map$/, ""))) {
|
4800 | super.revertFileAndBackup(filePath);
|
4801 | } else if (this.fs.exists(filePath)) {
|
4802 | const relativePath = this.fs.relative(packagePath, filePath);
|
4803 | const newFilePath = this.fs.resolve(packagePath, NGCC_DIRECTORY, relativePath);
|
4804 | this.fs.removeFile(newFilePath);
|
4805 | }
|
4806 | }
|
4807 | updatePackageJson(entryPoint, formatProperties, ngccFolder) {
|
4808 | if (formatProperties.length === 0) {
|
4809 | return;
|
4810 | }
|
4811 | const packageJson = entryPoint.packageJson;
|
4812 | const packageJsonPath = this.fs.join(entryPoint.path, "package.json");
|
4813 | const oldFormatProp = formatProperties[0];
|
4814 | const oldFormatPath = packageJson[oldFormatProp];
|
4815 | const oldAbsFormatPath = this.fs.resolve(entryPoint.path, oldFormatPath);
|
4816 | const newAbsFormatPath = this.fs.resolve(ngccFolder, this.fs.relative(entryPoint.packagePath, oldAbsFormatPath));
|
4817 | const newFormatPath = this.fs.relative(entryPoint.path, newAbsFormatPath);
|
4818 | const update = this.pkgJsonUpdater.createUpdate();
|
4819 | for (const formatProperty of formatProperties) {
|
4820 | if (packageJson[formatProperty] !== oldFormatPath) {
|
4821 | throw new Error(`Unable to update '${packageJsonPath}': Format properties (${formatProperties.join(", ")}) map to more than one format-path.`);
|
4822 | }
|
4823 | update.addChange([`${formatProperty}${NGCC_PROPERTY_EXTENSION}`], newFormatPath, { before: formatProperty });
|
4824 | }
|
4825 | update.writeChanges(packageJsonPath, packageJson);
|
4826 | }
|
4827 | revertPackageJson(entryPoint, formatProperties) {
|
4828 | if (formatProperties.length === 0) {
|
4829 | return;
|
4830 | }
|
4831 | const packageJson = entryPoint.packageJson;
|
4832 | const packageJsonPath = this.fs.join(entryPoint.path, "package.json");
|
4833 | const update = this.pkgJsonUpdater.createUpdate();
|
4834 | for (const formatProperty of formatProperties) {
|
4835 | update.addChange([`${formatProperty}${NGCC_PROPERTY_EXTENSION}`], void 0);
|
4836 | }
|
4837 | update.writeChanges(packageJsonPath, packageJson);
|
4838 | }
|
4839 | };
|
4840 |
|
4841 |
|
4842 | function getSharedSetup(options) {
|
4843 | const fileSystem = getFileSystem();
|
4844 | const absBasePath = absoluteFrom(options.basePath);
|
4845 | const projectPath = fileSystem.dirname(absBasePath);
|
4846 | const tsConfig = options.tsConfigPath !== null ? getTsConfig(options.tsConfigPath || projectPath) : null;
|
4847 | let { basePath, targetEntryPointPath, propertiesToConsider = SUPPORTED_FORMAT_PROPERTIES, typingsOnly = false, compileAllFormats = true, createNewEntryPointFormats = false, logger = new ConsoleLogger(LogLevel.info), pathMappings = getPathMappingsFromTsConfig(fileSystem, tsConfig, projectPath), async = false, errorOnFailedEntryPoint = false, enableI18nLegacyMessageIdFormat = true, invalidateEntryPointManifest = false, tsConfigPath } = options;
|
4848 | if (!!targetEntryPointPath) {
|
4849 | errorOnFailedEntryPoint = true;
|
4850 | }
|
4851 | if (typingsOnly) {
|
4852 | compileAllFormats = false;
|
4853 | }
|
4854 | checkForSolutionStyleTsConfig(fileSystem, logger, projectPath, options.tsConfigPath, tsConfig);
|
4855 | return {
|
4856 | basePath,
|
4857 | targetEntryPointPath,
|
4858 | propertiesToConsider,
|
4859 | typingsOnly,
|
4860 | compileAllFormats,
|
4861 | createNewEntryPointFormats,
|
4862 | logger,
|
4863 | pathMappings,
|
4864 | async,
|
4865 | errorOnFailedEntryPoint,
|
4866 | enableI18nLegacyMessageIdFormat,
|
4867 | invalidateEntryPointManifest,
|
4868 | tsConfigPath,
|
4869 | fileSystem,
|
4870 | absBasePath,
|
4871 | projectPath,
|
4872 | tsConfig,
|
4873 | getFileWriter: (pkgJsonUpdater) => createNewEntryPointFormats ? new NewEntryPointFileWriter(fileSystem, logger, errorOnFailedEntryPoint, pkgJsonUpdater) : new InPlaceFileWriter(fileSystem, logger, errorOnFailedEntryPoint)
|
4874 | };
|
4875 | }
|
4876 | var tsConfigCache = null;
|
4877 | var tsConfigPathCache = null;
|
4878 | function getTsConfig(tsConfigPath) {
|
4879 | if (tsConfigPath !== tsConfigPathCache) {
|
4880 | tsConfigPathCache = tsConfigPath;
|
4881 | tsConfigCache = readConfiguration(tsConfigPath);
|
4882 | }
|
4883 | return tsConfigCache;
|
4884 | }
|
4885 | function clearTsConfigCache() {
|
4886 | tsConfigPathCache = null;
|
4887 | tsConfigCache = null;
|
4888 | }
|
4889 | function checkForSolutionStyleTsConfig(fileSystem, logger, projectPath, tsConfigPath, tsConfig) {
|
4890 | if (tsConfigPath !== null && !tsConfigPath && tsConfig !== null && tsConfig.rootNames.length === 0 && tsConfig.projectReferences !== void 0 && tsConfig.projectReferences.length > 0) {
|
4891 | logger.warn(`The inferred tsconfig file "${tsConfig.project}" appears to be "solution-style" since it contains no root files but does contain project references.
|
4892 | This is probably not wanted, since ngcc is unable to infer settings like "paths" mappings from such a file.
|
4893 | Perhaps you should have explicitly specified one of the referenced projects using the --tsconfig option. For example:
|
4894 |
|
4895 | ` + tsConfig.projectReferences.map((ref) => ` ngcc ... --tsconfig "${ref.originalPath}"
|
4896 | `).join("") + `
|
4897 | Find out more about solution-style tsconfig at https://devblogs.microsoft.com/typescript/announcing-typescript-3-9/#solution-style-tsconfig.
|
4898 | If you did intend to use this file, then you can hide this warning by providing it explicitly:
|
4899 |
|
4900 | ngcc ... --tsconfig "${fileSystem.relative(projectPath, tsConfig.project)}"`);
|
4901 | }
|
4902 | }
|
4903 | function getMaxNumberOfWorkers() {
|
4904 | const maxWorkers = process.env.NGCC_MAX_WORKERS;
|
4905 | if (maxWorkers === void 0) {
|
4906 | return Math.max(1, Math.min(4, os.cpus().length - 1));
|
4907 | }
|
4908 | const numericMaxWorkers = +maxWorkers.trim();
|
4909 | if (!Number.isInteger(numericMaxWorkers)) {
|
4910 | throw new Error("NGCC_MAX_WORKERS should be an integer.");
|
4911 | } else if (numericMaxWorkers < 1) {
|
4912 | throw new Error("NGCC_MAX_WORKERS should be at least 1.");
|
4913 | }
|
4914 | return numericMaxWorkers;
|
4915 | }
|
4916 |
|
4917 |
|
4918 | var stringifyTask = (task) => `{entryPoint: ${task.entryPoint.name}, formatProperty: ${task.formatProperty}, processDts: ${DtsProcessing[task.processDts]}}`;
|
4919 | function computeTaskDependencies(tasks, graph) {
|
4920 | const dependencies = new TaskDependencies();
|
4921 | const candidateDependencies = new Map();
|
4922 | tasks.forEach((task) => {
|
4923 | const entryPointPath = task.entryPoint.path;
|
4924 | const deps = graph.dependenciesOf(entryPointPath);
|
4925 | const taskDependencies = deps.filter((dep) => candidateDependencies.has(dep)).map((dep) => candidateDependencies.get(dep));
|
4926 | if (taskDependencies.length > 0) {
|
4927 | for (const dependency of taskDependencies) {
|
4928 | const taskDependents = getDependentsSet(dependencies, dependency);
|
4929 | taskDependents.add(task);
|
4930 | }
|
4931 | }
|
4932 | if (task.processDts !== DtsProcessing.No) {
|
4933 | if (candidateDependencies.has(entryPointPath)) {
|
4934 | const otherTask = candidateDependencies.get(entryPointPath);
|
4935 | throw new Error(`Invariant violated: Multiple tasks are assigned generating typings for '${entryPointPath}':
|
4936 | - ${stringifyTask(otherTask)}
|
4937 | - ${stringifyTask(task)}`);
|
4938 | }
|
4939 | candidateDependencies.set(entryPointPath, task);
|
4940 | } else {
|
4941 | if (candidateDependencies.has(entryPointPath)) {
|
4942 | const typingsTask = candidateDependencies.get(entryPointPath);
|
4943 | const typingsTaskDependents = getDependentsSet(dependencies, typingsTask);
|
4944 | typingsTaskDependents.add(task);
|
4945 | }
|
4946 | }
|
4947 | });
|
4948 | return dependencies;
|
4949 | }
|
4950 | function getDependentsSet(map, task) {
|
4951 | if (!map.has(task)) {
|
4952 | map.set(task, new Set());
|
4953 | }
|
4954 | return map.get(task);
|
4955 | }
|
4956 | function getBlockedTasks(dependencies) {
|
4957 | const blockedTasks = new Map();
|
4958 | for (const [dependency, dependents] of dependencies) {
|
4959 | for (const dependent of dependents) {
|
4960 | const dependentSet = getDependentsSet(blockedTasks, dependent);
|
4961 | dependentSet.add(dependency);
|
4962 | }
|
4963 | }
|
4964 | return blockedTasks;
|
4965 | }
|
4966 | function sortTasksByPriority(tasks, dependencies) {
|
4967 | const priorityPerTask = new Map();
|
4968 | const computePriority = (task, idx) => [dependencies.has(task) ? dependencies.get(task).size : 0, idx];
|
4969 | tasks.forEach((task, i) => priorityPerTask.set(task, computePriority(task, i)));
|
4970 | return tasks.slice().sort((task1, task2) => {
|
4971 | const [p1, idx1] = priorityPerTask.get(task1);
|
4972 | const [p2, idx2] = priorityPerTask.get(task2);
|
4973 | return p2 - p1 || idx1 - idx2;
|
4974 | });
|
4975 | }
|
4976 |
|
4977 |
|
4978 | import cluster from "cluster";
|
4979 | var Deferred = class {
|
4980 | constructor() {
|
4981 | this.promise = new Promise((resolve, reject) => {
|
4982 | this.resolve = resolve;
|
4983 | this.reject = reject;
|
4984 | });
|
4985 | }
|
4986 | };
|
4987 | var sendMessageToMaster = (msg) => {
|
4988 | if (cluster.isMaster) {
|
4989 | throw new Error("Unable to send message to the master process: Already on the master process.");
|
4990 | }
|
4991 | return new Promise((resolve, reject) => {
|
4992 | if (process.send === void 0) {
|
4993 | throw new Error("Unable to send message to the master process: Missing `process.send()`.");
|
4994 | }
|
4995 | process.send(msg, (err) => err === null ? resolve() : reject(err));
|
4996 | });
|
4997 | };
|
4998 | var sendMessageToWorker = (workerId, msg) => {
|
4999 | if (!cluster.isMaster) {
|
5000 | throw new Error("Unable to send message to worker process: Sender is not the master process.");
|
5001 | }
|
5002 | const worker = cluster.workers[workerId];
|
5003 | if (worker === void 0 || worker.isDead() || !worker.isConnected()) {
|
5004 | throw new Error("Unable to send message to worker process: Recipient does not exist or has disconnected.");
|
5005 | }
|
5006 | return new Promise((resolve, reject) => {
|
5007 | worker.send(msg, (err) => err === null ? resolve() : reject(err));
|
5008 | });
|
5009 | };
|
5010 |
|
5011 |
|
5012 | var PackageJsonUpdate = class {
|
5013 | constructor(writeChangesImpl) {
|
5014 | this.writeChangesImpl = writeChangesImpl;
|
5015 | this.changes = [];
|
5016 | this.applied = false;
|
5017 | }
|
5018 | addChange(propertyPath, value, positioning = "unimportant") {
|
5019 | this.ensureNotApplied();
|
5020 | this.changes.push([propertyPath, value, positioning]);
|
5021 | return this;
|
5022 | }
|
5023 | writeChanges(packageJsonPath, parsedJson) {
|
5024 | this.ensureNotApplied();
|
5025 | this.writeChangesImpl(this.changes, packageJsonPath, parsedJson);
|
5026 | this.applied = true;
|
5027 | }
|
5028 | ensureNotApplied() {
|
5029 | if (this.applied) {
|
5030 | throw new Error("Trying to apply a `PackageJsonUpdate` that has already been applied.");
|
5031 | }
|
5032 | }
|
5033 | };
|
5034 | var DirectPackageJsonUpdater = class {
|
5035 | constructor(fs) {
|
5036 | this.fs = fs;
|
5037 | }
|
5038 | createUpdate() {
|
5039 | return new PackageJsonUpdate((...args) => this.writeChanges(...args));
|
5040 | }
|
5041 | writeChanges(changes, packageJsonPath, preExistingParsedJson) {
|
5042 | if (changes.length === 0) {
|
5043 | throw new Error(`No changes to write to '${packageJsonPath}'.`);
|
5044 | }
|
5045 | const parsedJson = this.fs.exists(packageJsonPath) ? JSON.parse(this.fs.readFile(packageJsonPath)) : {};
|
5046 | for (const [propPath, value, positioning] of changes) {
|
5047 | if (propPath.length === 0) {
|
5048 | throw new Error(`Missing property path for writing value to '${packageJsonPath}'.`);
|
5049 | }
|
5050 | applyChange(parsedJson, propPath, value, positioning);
|
5051 | if (preExistingParsedJson) {
|
5052 | applyChange(preExistingParsedJson, propPath, value, "unimportant");
|
5053 | }
|
5054 | }
|
5055 | this.fs.ensureDir(dirname(packageJsonPath));
|
5056 | this.fs.writeFile(packageJsonPath, `${JSON.stringify(parsedJson, null, 2)}
|
5057 | `);
|
5058 | }
|
5059 | };
|
5060 | function applyChange(ctx, propPath, value, positioning) {
|
5061 | const lastPropIdx = propPath.length - 1;
|
5062 | const lastProp = propPath[lastPropIdx];
|
5063 | for (let i = 0; i < lastPropIdx; i++) {
|
5064 | const key = propPath[i];
|
5065 | const newCtx = ctx.hasOwnProperty(key) ? ctx[key] : ctx[key] = {};
|
5066 | if (typeof newCtx !== "object" || newCtx === null || Array.isArray(newCtx)) {
|
5067 | throw new Error(`Property path '${propPath.join(".")}' does not point to an object.`);
|
5068 | }
|
5069 | ctx = newCtx;
|
5070 | }
|
5071 | ctx[lastProp] = value;
|
5072 | positionProperty(ctx, lastProp, positioning);
|
5073 | }
|
5074 | function movePropBefore(ctx, prop, isNextProp) {
|
5075 | const allProps = Object.keys(ctx);
|
5076 | const otherProps = allProps.filter((p) => p !== prop);
|
5077 | const nextPropIdx = otherProps.findIndex(isNextProp);
|
5078 | const propsToShift = nextPropIdx === -1 ? [] : otherProps.slice(nextPropIdx);
|
5079 | movePropToEnd(ctx, prop);
|
5080 | propsToShift.forEach((p) => movePropToEnd(ctx, p));
|
5081 | }
|
5082 | function movePropToEnd(ctx, prop) {
|
5083 | const value = ctx[prop];
|
5084 | delete ctx[prop];
|
5085 | ctx[prop] = value;
|
5086 | }
|
5087 | function positionProperty(ctx, prop, positioning) {
|
5088 | switch (positioning) {
|
5089 | case "alphabetic":
|
5090 | movePropBefore(ctx, prop, (p) => p > prop);
|
5091 | break;
|
5092 | case "unimportant":
|
5093 | break;
|
5094 | default:
|
5095 | if (typeof positioning !== "object" || positioning.before === void 0) {
|
5096 | throw new Error(`Unknown positioning (${JSON.stringify(positioning)}) for property '${prop}'.`);
|
5097 | }
|
5098 | movePropBefore(ctx, prop, (p) => p === positioning.before);
|
5099 | break;
|
5100 | }
|
5101 | }
|
5102 |
|
5103 | export {
|
5104 | isWildcardReexportStatement,
|
5105 | isRequireCall,
|
5106 | isRelativePath,
|
5107 | resolveFileWithPostfixes,
|
5108 | parseStatementForUmdModule,
|
5109 | getImportsOfUmdModule,
|
5110 | SUPPORTED_FORMAT_PROPERTIES,
|
5111 | NO_ENTRY_POINT,
|
5112 | IGNORED_ENTRY_POINT,
|
5113 | INCOMPATIBLE_ENTRY_POINT,
|
5114 | getEntryPointInfo,
|
5115 | isEntryPoint,
|
5116 | getEntryPointFormat,
|
5117 | NGCC_BACKUP_EXTENSION,
|
5118 | NGCC_DIRECTORY,
|
5119 | NGCC_PROPERTY_EXTENSION,
|
5120 | getPathMappingsFromTsConfig,
|
5121 | DtsProcessing,
|
5122 | stringifyTask,
|
5123 | computeTaskDependencies,
|
5124 | getBlockedTasks,
|
5125 | sortTasksByPriority,
|
5126 | Deferred,
|
5127 | sendMessageToMaster,
|
5128 | sendMessageToWorker,
|
5129 | NGCC_TIMED_OUT_EXIT_CODE,
|
5130 | getCreateCompileFn,
|
5131 | getSharedSetup,
|
5132 | clearTsConfigCache,
|
5133 | getMaxNumberOfWorkers,
|
5134 | PackageJsonUpdate,
|
5135 | DirectPackageJsonUpdater,
|
5136 | applyChange
|
5137 | };
|
5138 |
|
5139 |
|
5140 |
|
5141 |
|
5142 |
|
5143 |
|
5144 |
|
5145 |
|