source: trip-planner-front/node_modules/@angular/compiler/src/output/js_emitter.js@ 571e0df

Last change on this file since 571e0df was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 11.8 KB
Line 
1(function (factory) {
2 if (typeof module === "object" && typeof module.exports === "object") {
3 var v = factory(require, exports);
4 if (v !== undefined) module.exports = v;
5 }
6 else if (typeof define === "function" && define.amd) {
7 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);
8 }
9})(function (require, exports) {
10 "use strict";
11 Object.defineProperty(exports, "__esModule", { value: true });
12 exports.JavaScriptEmitter = void 0;
13 var tslib_1 = require("tslib");
14 /**
15 * @license
16 * Copyright Google LLC All Rights Reserved.
17 *
18 * Use of this source code is governed by an MIT-style license that can be
19 * found in the LICENSE file at https://angular.io/license
20 */
21 var abstract_emitter_1 = require("@angular/compiler/src/output/abstract_emitter");
22 var abstract_js_emitter_1 = require("@angular/compiler/src/output/abstract_js_emitter");
23 var o = require("@angular/compiler/src/output/output_ast");
24 var JavaScriptEmitter = /** @class */ (function () {
25 function JavaScriptEmitter() {
26 }
27 JavaScriptEmitter.prototype.emitStatements = function (genFilePath, stmts, preamble) {
28 if (preamble === void 0) { preamble = ''; }
29 var converter = new JsEmitterVisitor();
30 var ctx = abstract_emitter_1.EmitterVisitorContext.createRoot();
31 converter.visitAllStatements(stmts, ctx);
32 var preambleLines = preamble ? preamble.split('\n') : [];
33 converter.importsWithPrefixes.forEach(function (prefix, importedModuleName) {
34 // Note: can't write the real word for import as it screws up system.js auto detection...
35 preambleLines.push("var " + prefix + " = req" +
36 ("uire('" + importedModuleName + "');"));
37 });
38 var sm = ctx.toSourceMapGenerator(genFilePath, preambleLines.length).toJsComment();
39 var lines = tslib_1.__spreadArray(tslib_1.__spreadArray([], tslib_1.__read(preambleLines)), [ctx.toSource(), sm]);
40 if (sm) {
41 // always add a newline at the end, as some tools have bugs without it.
42 lines.push('');
43 }
44 return lines.join('\n');
45 };
46 return JavaScriptEmitter;
47 }());
48 exports.JavaScriptEmitter = JavaScriptEmitter;
49 var JsEmitterVisitor = /** @class */ (function (_super) {
50 tslib_1.__extends(JsEmitterVisitor, _super);
51 function JsEmitterVisitor() {
52 var _this = _super !== null && _super.apply(this, arguments) || this;
53 _this.importsWithPrefixes = new Map();
54 return _this;
55 }
56 JsEmitterVisitor.prototype.visitExternalExpr = function (ast, ctx) {
57 var _a = ast.value, name = _a.name, moduleName = _a.moduleName;
58 if (moduleName) {
59 var prefix = this.importsWithPrefixes.get(moduleName);
60 if (prefix == null) {
61 prefix = "i" + this.importsWithPrefixes.size;
62 this.importsWithPrefixes.set(moduleName, prefix);
63 }
64 ctx.print(ast, prefix + ".");
65 }
66 ctx.print(ast, name);
67 return null;
68 };
69 JsEmitterVisitor.prototype.visitDeclareVarStmt = function (stmt, ctx) {
70 _super.prototype.visitDeclareVarStmt.call(this, stmt, ctx);
71 if (stmt.hasModifier(o.StmtModifier.Exported)) {
72 ctx.println(stmt, exportVar(stmt.name));
73 }
74 return null;
75 };
76 JsEmitterVisitor.prototype.visitDeclareFunctionStmt = function (stmt, ctx) {
77 _super.prototype.visitDeclareFunctionStmt.call(this, stmt, ctx);
78 if (stmt.hasModifier(o.StmtModifier.Exported)) {
79 ctx.println(stmt, exportVar(stmt.name));
80 }
81 return null;
82 };
83 JsEmitterVisitor.prototype.visitDeclareClassStmt = function (stmt, ctx) {
84 _super.prototype.visitDeclareClassStmt.call(this, stmt, ctx);
85 if (stmt.hasModifier(o.StmtModifier.Exported)) {
86 ctx.println(stmt, exportVar(stmt.name));
87 }
88 return null;
89 };
90 return JsEmitterVisitor;
91 }(abstract_js_emitter_1.AbstractJsEmitterVisitor));
92 function exportVar(varName) {
93 return "Object.defineProperty(exports, '" + varName + "', { get: function() { return " + varName + "; }});";
94 }
95});
96//# sourceMappingURL=data:application/json;base64,eyJ2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m5hbWUpKTtcbiAgICB9XG4gICAgcmV0dXJuIG51bGw7XG4gIH1cbiAgb3ZlcnJpZGUgdmlzaXREZWNsYXJlRnVuY3Rpb25TdG10KHN0bXQ6IG8uRGVjbGFyZUZ1bmN0aW9uU3RtdCwgY3R4OiBFbWl0dGVyVmlzaXRvckNvbnRleHQpOiBhbnkge1xuICAgIHN1cGVyLnZpc2l0RGVjbGFyZUZ1bmN0aW9uU3RtdChzdG10LCBjdHgpO1xuICAgIGlmIChzdG10Lmhhc01vZGlmaWVyKG8uU3RtdE1vZGlmaWVyLkV4cG9ydGVkKSkge1xuICAgICAgY3R4LnByaW50bG4oc3RtdCwgZXhwb3J0VmFyKHN0bXQubmFtZSkpO1xuICAgIH1cbiAgICByZXR1cm4gbnVsbDtcbiAgfVxuICBvdmVycmlkZSB2aXNpdERlY2xhcmVDbGFzc1N0bXQoc3RtdDogby5DbGFzc1N0bXQsIGN0eDogRW1pdHRlclZpc2l0b3JDb250ZXh0KTogYW55IHtcbiAgICBzdXBlci52aXNpdERlY2xhcmVDbGFzc1N0bXQoc3RtdCwgY3R4KTtcbiAgICBpZiAoc3RtdC5oYXNNb2RpZmllcihvLlN0bXRNb2RpZmllci5FeHBvcnRlZCkpIHtcbiAgICAgIGN0eC5wcmludGxuKHN0bXQsIGV4cG9ydFZhcihzdG10Lm5hbWUpKTtcbiAgICB9XG4gICAgcmV0dXJuIG51bGw7XG4gIH1cbn1cblxuZnVuY3Rpb24gZXhwb3J0VmFyKHZhck5hbWU6IHN0cmluZyk6IHN0cmluZyB7XG4gIHJldHVybiBgT2JqZWN0LmRlZmluZVByb3BlcnR5KGV4cG9ydHMsICcke3Zhck5hbWV9JywgeyBnZXQ6IGZ1bmN0aW9uKCkgeyByZXR1cm4gJHt2YXJOYW1lfTsgfX0pO2A7XG59XG4iXX0=
Note: See TracBrowser for help on using the repository browser.