(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/src/output/js_emitter", ["require", "exports", "tslib", "@angular/compiler/src/output/abstract_emitter", "@angular/compiler/src/output/abstract_js_emitter", "@angular/compiler/src/output/output_ast"], factory); } })(function (require, exports) { "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.JavaScriptEmitter = 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 abstract_emitter_1 = require("@angular/compiler/src/output/abstract_emitter"); var abstract_js_emitter_1 = require("@angular/compiler/src/output/abstract_js_emitter"); var o = require("@angular/compiler/src/output/output_ast"); var JavaScriptEmitter = /** @class */ (function () { function JavaScriptEmitter() { } JavaScriptEmitter.prototype.emitStatements = function (genFilePath, stmts, preamble) { if (preamble === void 0) { preamble = ''; } var converter = new JsEmitterVisitor(); var ctx = abstract_emitter_1.EmitterVisitorContext.createRoot(); converter.visitAllStatements(stmts, ctx); var preambleLines = preamble ? preamble.split('\n') : []; converter.importsWithPrefixes.forEach(function (prefix, importedModuleName) { // Note: can't write the real word for import as it screws up system.js auto detection... preambleLines.push("var " + prefix + " = req" + ("uire('" + importedModuleName + "');")); }); var sm = ctx.toSourceMapGenerator(genFilePath, preambleLines.length).toJsComment(); var lines = tslib_1.__spreadArray(tslib_1.__spreadArray([], tslib_1.__read(preambleLines)), [ctx.toSource(), sm]); if (sm) { // always add a newline at the end, as some tools have bugs without it. lines.push(''); } return lines.join('\n'); }; return JavaScriptEmitter; }()); exports.JavaScriptEmitter = JavaScriptEmitter; var JsEmitterVisitor = /** @class */ (function (_super) { tslib_1.__extends(JsEmitterVisitor, _super); function JsEmitterVisitor() { var _this = _super !== null && _super.apply(this, arguments) || this; _this.importsWithPrefixes = new Map(); return _this; } JsEmitterVisitor.prototype.visitExternalExpr = function (ast, ctx) { var _a = ast.value, name = _a.name, moduleName = _a.moduleName; if (moduleName) { var prefix = this.importsWithPrefixes.get(moduleName); if (prefix == null) { prefix = "i" + this.importsWithPrefixes.size; this.importsWithPrefixes.set(moduleName, prefix); } ctx.print(ast, prefix + "."); } ctx.print(ast, name); return null; }; JsEmitterVisitor.prototype.visitDeclareVarStmt = function (stmt, ctx) { _super.prototype.visitDeclareVarStmt.call(this, stmt, ctx); if (stmt.hasModifier(o.StmtModifier.Exported)) { ctx.println(stmt, exportVar(stmt.name)); } return null; }; JsEmitterVisitor.prototype.visitDeclareFunctionStmt = function (stmt, ctx) { _super.prototype.visitDeclareFunctionStmt.call(this, stmt, ctx); if (stmt.hasModifier(o.StmtModifier.Exported)) { ctx.println(stmt, exportVar(stmt.name)); } return null; }; JsEmitterVisitor.prototype.visitDeclareClassStmt = function (stmt, ctx) { _super.prototype.visitDeclareClassStmt.call(this, stmt, ctx); if (stmt.hasModifier(o.StmtModifier.Exported)) { ctx.println(stmt, exportVar(stmt.name)); } return null; }; return JsEmitterVisitor; }(abstract_js_emitter_1.AbstractJsEmitterVisitor)); function exportVar(varName) { return "Object.defineProperty(exports, '" + varName + "', { get: function() { return " + varName + "; }});"; } }); //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoianNfZW1pdHRlci5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uLy4uLy4uLy4uLy4uL3BhY2thZ2VzL2NvbXBpbGVyL3NyYy9vdXRwdXQvanNfZW1pdHRlci50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7Ozs7Ozs7Ozs7O0lBQUE7Ozs7OztPQU1HO0lBQ0gsa0ZBQXdFO0lBQ3hFLHdGQUErRDtJQUMvRCwyREFBa0M7SUFFbEM7UUFBQTtRQXNCQSxDQUFDO1FBckJDLDBDQUFjLEdBQWQsVUFBZSxXQUFtQixFQUFFLEtBQW9CLEVBQUUsUUFBcUI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