source: trip-planner-front/node_modules/@angular/compiler/src/output/output_jit.js@ ceaed42

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

initial commit

  • Property mode set to 100644
File size: 22.8 KB
Line 
1/**
2 * @license
3 * Copyright Google LLC All Rights Reserved.
4 *
5 * Use of this source code is governed by an MIT-style license that can be
6 * found in the LICENSE file at https://angular.io/license
7 */
8(function (factory) {
9 if (typeof module === "object" && typeof module.exports === "object") {
10 var v = factory(require, exports);
11 if (v !== undefined) module.exports = v;
12 }
13 else if (typeof define === "function" && define.amd) {
14 define("@angular/compiler/src/output/output_jit", ["require", "exports", "tslib", "@angular/compiler/src/parse_util", "@angular/compiler/src/output/abstract_emitter", "@angular/compiler/src/output/abstract_js_emitter", "@angular/compiler/src/output/output_ast", "@angular/compiler/src/output/output_jit_trusted_types"], factory);
15 }
16})(function (require, exports) {
17 "use strict";
18 Object.defineProperty(exports, "__esModule", { value: true });
19 exports.JitEmitterVisitor = exports.JitEvaluator = void 0;
20 var tslib_1 = require("tslib");
21 var parse_util_1 = require("@angular/compiler/src/parse_util");
22 var abstract_emitter_1 = require("@angular/compiler/src/output/abstract_emitter");
23 var abstract_js_emitter_1 = require("@angular/compiler/src/output/abstract_js_emitter");
24 var o = require("@angular/compiler/src/output/output_ast");
25 var output_jit_trusted_types_1 = require("@angular/compiler/src/output/output_jit_trusted_types");
26 /**
27 * A helper class to manage the evaluation of JIT generated code.
28 */
29 var JitEvaluator = /** @class */ (function () {
30 function JitEvaluator() {
31 }
32 /**
33 *
34 * @param sourceUrl The URL of the generated code.
35 * @param statements An array of Angular statement AST nodes to be evaluated.
36 * @param reflector A helper used when converting the statements to executable code.
37 * @param createSourceMaps If true then create a source-map for the generated code and include it
38 * inline as a source-map comment.
39 * @returns A map of all the variables in the generated code.
40 */
41 JitEvaluator.prototype.evaluateStatements = function (sourceUrl, statements, reflector, createSourceMaps) {
42 var converter = new JitEmitterVisitor(reflector);
43 var ctx = abstract_emitter_1.EmitterVisitorContext.createRoot();
44 // Ensure generated code is in strict mode
45 if (statements.length > 0 && !isUseStrictStatement(statements[0])) {
46 statements = tslib_1.__spreadArray([
47 o.literal('use strict').toStmt()
48 ], tslib_1.__read(statements));
49 }
50 converter.visitAllStatements(statements, ctx);
51 converter.createReturnStmt(ctx);
52 return this.evaluateCode(sourceUrl, ctx, converter.getArgs(), createSourceMaps);
53 };
54 /**
55 * Evaluate a piece of JIT generated code.
56 * @param sourceUrl The URL of this generated code.
57 * @param ctx A context object that contains an AST of the code to be evaluated.
58 * @param vars A map containing the names and values of variables that the evaluated code might
59 * reference.
60 * @param createSourceMap If true then create a source-map for the generated code and include it
61 * inline as a source-map comment.
62 * @returns The result of evaluating the code.
63 */
64 JitEvaluator.prototype.evaluateCode = function (sourceUrl, ctx, vars, createSourceMap) {
65 var fnBody = "\"use strict\";" + ctx.toSource() + "\n//# sourceURL=" + sourceUrl;
66 var fnArgNames = [];
67 var fnArgValues = [];
68 for (var argName in vars) {
69 fnArgValues.push(vars[argName]);
70 fnArgNames.push(argName);
71 }
72 if (createSourceMap) {
73 // using `new Function(...)` generates a header, 1 line of no arguments, 2 lines otherwise
74 // E.g. ```
75 // function anonymous(a,b,c
76 // /**/) { ... }```
77 // We don't want to hard code this fact, so we auto detect it via an empty function first.
78 var emptyFn = output_jit_trusted_types_1.newTrustedFunctionForJIT.apply(void 0, tslib_1.__spreadArray([], tslib_1.__read(fnArgNames.concat('return null;')))).toString();
79 var headerLines = emptyFn.slice(0, emptyFn.indexOf('return null;')).split('\n').length - 1;
80 fnBody += "\n" + ctx.toSourceMapGenerator(sourceUrl, headerLines).toJsComment();
81 }
82 var fn = output_jit_trusted_types_1.newTrustedFunctionForJIT.apply(void 0, tslib_1.__spreadArray([], tslib_1.__read(fnArgNames.concat(fnBody))));
83 return this.executeFunction(fn, fnArgValues);
84 };
85 /**
86 * Execute a JIT generated function by calling it.
87 *
88 * This method can be overridden in tests to capture the functions that are generated
89 * by this `JitEvaluator` class.
90 *
91 * @param fn A function to execute.
92 * @param args The arguments to pass to the function being executed.
93 * @returns The return value of the executed function.
94 */
95 JitEvaluator.prototype.executeFunction = function (fn, args) {
96 return fn.apply(void 0, tslib_1.__spreadArray([], tslib_1.__read(args)));
97 };
98 return JitEvaluator;
99 }());
100 exports.JitEvaluator = JitEvaluator;
101 /**
102 * An Angular AST visitor that converts AST nodes into executable JavaScript code.
103 */
104 var JitEmitterVisitor = /** @class */ (function (_super) {
105 tslib_1.__extends(JitEmitterVisitor, _super);
106 function JitEmitterVisitor(reflector) {
107 var _this = _super.call(this) || this;
108 _this.reflector = reflector;
109 _this._evalArgNames = [];
110 _this._evalArgValues = [];
111 _this._evalExportedVars = [];
112 return _this;
113 }
114 JitEmitterVisitor.prototype.createReturnStmt = function (ctx) {
115 var stmt = new o.ReturnStatement(new o.LiteralMapExpr(this._evalExportedVars.map(function (resultVar) { return new o.LiteralMapEntry(resultVar, o.variable(resultVar), false); })));
116 stmt.visitStatement(this, ctx);
117 };
118 JitEmitterVisitor.prototype.getArgs = function () {
119 var result = {};
120 for (var i = 0; i < this._evalArgNames.length; i++) {
121 result[this._evalArgNames[i]] = this._evalArgValues[i];
122 }
123 return result;
124 };
125 JitEmitterVisitor.prototype.visitExternalExpr = function (ast, ctx) {
126 this._emitReferenceToExternal(ast, this.reflector.resolveExternalReference(ast.value), ctx);
127 return null;
128 };
129 JitEmitterVisitor.prototype.visitWrappedNodeExpr = function (ast, ctx) {
130 this._emitReferenceToExternal(ast, ast.node, ctx);
131 return null;
132 };
133 JitEmitterVisitor.prototype.visitDeclareVarStmt = function (stmt, ctx) {
134 if (stmt.hasModifier(o.StmtModifier.Exported)) {
135 this._evalExportedVars.push(stmt.name);
136 }
137 return _super.prototype.visitDeclareVarStmt.call(this, stmt, ctx);
138 };
139 JitEmitterVisitor.prototype.visitDeclareFunctionStmt = function (stmt, ctx) {
140 if (stmt.hasModifier(o.StmtModifier.Exported)) {
141 this._evalExportedVars.push(stmt.name);
142 }
143 return _super.prototype.visitDeclareFunctionStmt.call(this, stmt, ctx);
144 };
145 JitEmitterVisitor.prototype.visitDeclareClassStmt = function (stmt, ctx) {
146 if (stmt.hasModifier(o.StmtModifier.Exported)) {
147 this._evalExportedVars.push(stmt.name);
148 }
149 return _super.prototype.visitDeclareClassStmt.call(this, stmt, ctx);
150 };
151 JitEmitterVisitor.prototype._emitReferenceToExternal = function (ast, value, ctx) {
152 var id = this._evalArgValues.indexOf(value);
153 if (id === -1) {
154 id = this._evalArgValues.length;
155 this._evalArgValues.push(value);
156 var name_1 = parse_util_1.identifierName({ reference: value }) || 'val';
157 this._evalArgNames.push("jit_" + name_1 + "_" + id);
158 }
159 ctx.print(ast, this._evalArgNames[id]);
160 };
161 return JitEmitterVisitor;
162 }(abstract_js_emitter_1.AbstractJsEmitterVisitor));
163 exports.JitEmitterVisitor = JitEmitterVisitor;
164 function isUseStrictStatement(statement) {
165 return statement.isEquivalent(o.literal('use strict').toStmt());
166 }
167});
168//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoib3V0cHV0X2ppdC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uLy4uLy4uLy4uLy4uL3BhY2thZ2VzL2NvbXBpbGVyL3NyYy9vdXRwdXQvb3V0cHV0X2ppdC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQTs7Ozs7O0dBTUc7Ozs7Ozs7Ozs7Ozs7O0lBR0gsK0RBQTZDO0lBRTdDLGtGQUF5RDtJQUN6RCx3RkFBK0Q7SUFDL0QsMkRBQWtDO0lBQ2xDLGtHQUFvRTtJQUVwRTs7T0FFRztJQUNIO1FBQUE7UUEwRUEsQ0FBQztRQXpFQzs7Ozs7Ozs7V0FRRztRQUNILHlDQUFrQixHQUFsQixVQUNJLFNBQWlCLEVBQUUsVUFBeUIsRUFBRSxTQUEyQixFQUN6RSxnQkFBeUI7WUFDM0IsSUFBTSxTQUFTLE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