(function (factory) { if (typeof module === "object" && typeof module.exports === "object") { var v = factory(require, exports); if (v !== undefined) module.exports = v; } else if (typeof define === "function" && define.amd) { define("@angular/compiler-cli/ngcc/src/rendering/renderer", ["require", "exports", "tslib", "@angular/compiler", "magic-string", "@angular/compiler-cli/src/ngtsc/translator", "@angular/compiler-cli/ngcc/src/constants", "@angular/compiler-cli/ngcc/src/rendering/rendering_formatter", "@angular/compiler-cli/ngcc/src/rendering/source_maps", "@angular/compiler-cli/ngcc/src/rendering/utils"], factory); } })(function (require, exports) { "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.renderConstantPool = exports.Renderer = void 0; var tslib_1 = require("tslib"); /** * @license * Copyright Google LLC All Rights Reserved. * * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://angular.io/license */ var compiler_1 = require("@angular/compiler"); var magic_string_1 = require("magic-string"); var translator_1 = require("@angular/compiler-cli/src/ngtsc/translator"); var constants_1 = require("@angular/compiler-cli/ngcc/src/constants"); var rendering_formatter_1 = require("@angular/compiler-cli/ngcc/src/rendering/rendering_formatter"); var source_maps_1 = require("@angular/compiler-cli/ngcc/src/rendering/source_maps"); var utils_1 = require("@angular/compiler-cli/ngcc/src/rendering/utils"); /** * A base-class for rendering an `AnalyzedFile`. * * Package formats have output files that must be rendered differently. Concrete sub-classes must * implement the `addImports`, `addDefinitions` and `removeDecorators` abstract methods. */ var Renderer = /** @class */ (function () { function Renderer(host, srcFormatter, fs, logger, bundle, tsConfig) { if (tsConfig === void 0) { tsConfig = null; } this.host = host; this.srcFormatter = srcFormatter; this.fs = fs; this.logger = logger; this.bundle = bundle; this.tsConfig = tsConfig; } Renderer.prototype.renderProgram = function (decorationAnalyses, switchMarkerAnalyses, privateDeclarationsAnalyses) { var _this = this; var renderedFiles = []; // Transform the source files. this.bundle.src.program.getSourceFiles().forEach(function (sourceFile) { if (decorationAnalyses.has(sourceFile) || switchMarkerAnalyses.has(sourceFile) || sourceFile === _this.bundle.src.file) { var compiledFile = decorationAnalyses.get(sourceFile); var switchMarkerAnalysis = switchMarkerAnalyses.get(sourceFile); renderedFiles.push.apply(renderedFiles, tslib_1.__spreadArray([], tslib_1.__read(_this.renderFile(sourceFile, compiledFile, switchMarkerAnalysis, privateDeclarationsAnalyses)))); } }); return renderedFiles; }; /** * Render the source code and source-map for an Analyzed file. * @param compiledFile The analyzed file to render. * @param targetPath The absolute path where the rendered file will be written. */ Renderer.prototype.renderFile = function (sourceFile, compiledFile, switchMarkerAnalysis, privateDeclarationsAnalyses) { var _this = this; var isEntryPoint = sourceFile === this.bundle.src.file; var outputText = new magic_string_1.default(sourceFile.text); if (switchMarkerAnalysis) { this.srcFormatter.rewriteSwitchableDeclarations(outputText, switchMarkerAnalysis.sourceFile, switchMarkerAnalysis.declarations); } var importManager = new translator_1.ImportManager(utils_1.getImportRewriter(this.bundle.src.r3SymbolsFile, this.bundle.isCore, this.bundle.isFlatCore), constants_1.IMPORT_PREFIX); if (compiledFile) { // TODO: remove constructor param metadata and property decorators (we need info from the // handlers to do this) var decoratorsToRemove = this.computeDecoratorsToRemove(compiledFile.compiledClasses); this.srcFormatter.removeDecorators(outputText, decoratorsToRemove); compiledFile.compiledClasses.forEach(function (clazz) { var _a; var renderedDefinition = _this.renderDefinitions(compiledFile.sourceFile, clazz, importManager, !!((_a = _this.tsConfig) === null || _a === void 0 ? void 0 : _a.options.annotateForClosureCompiler)); _this.srcFormatter.addDefinitions(outputText, clazz, renderedDefinition); var renderedStatements = _this.renderAdjacentStatements(compiledFile.sourceFile, clazz, importManager); _this.srcFormatter.addAdjacentStatements(outputText, clazz, renderedStatements); }); if (!isEntryPoint && compiledFile.reexports.length > 0) { this.srcFormatter.addDirectExports(outputText, compiledFile.reexports, importManager, compiledFile.sourceFile); } this.srcFormatter.addConstants(outputText, renderConstantPool(this.srcFormatter, compiledFile.sourceFile, compiledFile.constantPool, importManager), compiledFile.sourceFile); } // Add exports to the entry-point file if (isEntryPoint) { var entryPointBasePath = utils_1.stripExtension(this.bundle.src.path); this.srcFormatter.addExports(outputText, entryPointBasePath, privateDeclarationsAnalyses, importManager, sourceFile); } if (isEntryPoint || compiledFile) { this.srcFormatter.addImports(outputText, importManager.getAllImports(sourceFile.fileName), sourceFile); } if (compiledFile || switchMarkerAnalysis || isEntryPoint) { return source_maps_1.renderSourceAndMap(this.logger, this.fs, sourceFile, outputText); } else { return []; } }; /** * From the given list of classes, computes a map of decorators that should be removed. * The decorators to remove are keyed by their container node, such that we can tell if * we should remove the entire decorator property. * @param classes The list of classes that may have decorators to remove. * @returns A map of decorators to remove, keyed by their container node. */ Renderer.prototype.computeDecoratorsToRemove = function (classes) { var decoratorsToRemove = new rendering_formatter_1.RedundantDecoratorMap(); classes.forEach(function (clazz) { if (clazz.decorators === null) { return; } clazz.decorators.forEach(function (dec) { if (dec.node === null) { return; } var decoratorArray = dec.node.parent; if (!decoratorsToRemove.has(decoratorArray)) { decoratorsToRemove.set(decoratorArray, [dec.node]); } else { decoratorsToRemove.get(decoratorArray).push(dec.node); } }); }); return decoratorsToRemove; }; /** * Render the definitions as source code for the given class. * @param sourceFile The file containing the class to process. * @param clazz The class whose definitions are to be rendered. * @param compilation The results of analyzing the class - this is used to generate the rendered * definitions. * @param imports An object that tracks the imports that are needed by the rendered definitions. */ Renderer.prototype.renderDefinitions = function (sourceFile, compiledClass, imports, annotateForClosureCompiler) { var name = this.host.getInternalNameOfClass(compiledClass.declaration); var leadingComment = annotateForClosureCompiler ? compiler_1.jsDocComment([{ tagName: 'nocollapse' }]) : undefined; var statements = compiledClass.compilation.map(function (c) { return createAssignmentStatement(name, c.name, c.initializer, leadingComment); }); return this.renderStatements(sourceFile, statements, imports); }; /** * Render the adjacent statements as source code for the given class. * @param sourceFile The file containing the class to process. * @param clazz The class whose statements are to be rendered. * @param compilation The results of analyzing the class - this is used to generate the rendered * definitions. * @param imports An object that tracks the imports that are needed by the rendered definitions. */ Renderer.prototype.renderAdjacentStatements = function (sourceFile, compiledClass, imports) { var e_1, _a; var statements = []; try { for (var _b = tslib_1.__values(compiledClass.compilation), _c = _b.next(); !_c.done; _c = _b.next()) { var c = _c.value; statements.push.apply(statements, tslib_1.__spreadArray([], tslib_1.__read(c.statements))); } } catch (e_1_1) { e_1 = { error: e_1_1 }; } finally { try { if (_c && !_c.done && (_a = _b.return)) _a.call(_b); } finally { if (e_1) throw e_1.error; } } return this.renderStatements(sourceFile, statements, imports); }; Renderer.prototype.renderStatements = function (sourceFile, statements, imports) { var _this = this; var printStatement = function (stmt) { return _this.srcFormatter.printStatement(stmt, sourceFile, imports); }; return statements.map(printStatement).join('\n'); }; return Renderer; }()); exports.Renderer = Renderer; /** * Render the constant pool as source code for the given class. */ function renderConstantPool(formatter, sourceFile, constantPool, imports) { var printStatement = function (stmt) { return formatter.printStatement(stmt, sourceFile, imports); }; return constantPool.statements.map(printStatement).join('\n'); } exports.renderConstantPool = renderConstantPool; /** * Create an Angular AST statement node that contains the assignment of the * compiled decorator to be applied to the class. * @param analyzedClass The info about the class whose statement we want to create. */ function createAssignmentStatement(receiverName, propName, initializer, leadingComment) { var receiver = new compiler_1.WrappedNodeExpr(receiverName); var statement = new compiler_1.WritePropExpr(receiver, propName, initializer, /* type */ undefined, /* sourceSpan */ undefined) .toStmt(); if (leadingComment !== undefined) { statement.addLeadingComment(leadingComment); } return statement; } }); //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoicmVuZGVyZXIuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi8uLi8uLi8uLi8uLi8uLi9wYWNrYWdlcy9jb21waWxlci1jbGkvbmdjYy9zcmMvcmVuZGVyaW5nL3JlbmRlcmVyLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7Ozs7Ozs7Ozs7Ozs7SUFBQTs7Ozs7O09BTUc7SUFDSCw4Q0FBb0k7SUFDcEksNkNBQXVDO0lBS3ZDLHlFQUE0RDtJQUs1RCxzRUFBMkM7SUFJM0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