UNPKG

23 kBJavaScriptView Raw
1/**
2 * @license Angular v8.2.14
3 * (c) 2010-2019 Google LLC. https://angular.io/
4 * License: MIT
5 */
6
7(function (global, factory) {
8 typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/compiler')) :
9 typeof define === 'function' && define.amd ? define('@angular/compiler/testing', ['exports', '@angular/compiler'], factory) :
10 (global = global || self, factory((global.ng = global.ng || {}, global.ng.compiler = global.ng.compiler || {}, global.ng.compiler.testing = {}), global.ng.compiler));
11}(this, function (exports, compiler) { 'use strict';
12
13 /*! *****************************************************************************
14 Copyright (c) Microsoft Corporation. All rights reserved.
15 Licensed under the Apache License, Version 2.0 (the "License"); you may not use
16 this file except in compliance with the License. You may obtain a copy of the
17 License at http://www.apache.org/licenses/LICENSE-2.0
18
19 THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
20 KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
21 WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
22 MERCHANTABLITY OR NON-INFRINGEMENT.
23
24 See the Apache Version 2.0 License for specific language governing permissions
25 and limitations under the License.
26 ***************************************************************************** */
27 /* global Reflect, Promise */
28
29 var extendStatics = function(d, b) {
30 extendStatics = Object.setPrototypeOf ||
31 ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
32 function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
33 return extendStatics(d, b);
34 };
35
36 function __extends(d, b) {
37 extendStatics(d, b);
38 function __() { this.constructor = d; }
39 d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
40 }
41
42 var __assign = function() {
43 __assign = Object.assign || function __assign(t) {
44 for (var s, i = 1, n = arguments.length; i < n; i++) {
45 s = arguments[i];
46 for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
47 }
48 return t;
49 };
50 return __assign.apply(this, arguments);
51 };
52
53 function __rest(s, e) {
54 var t = {};
55 for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
56 t[p] = s[p];
57 if (s != null && typeof Object.getOwnPropertySymbols === "function")
58 for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) if (e.indexOf(p[i]) < 0)
59 t[p[i]] = s[p[i]];
60 return t;
61 }
62
63 function __decorate(decorators, target, key, desc) {
64 var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
65 if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
66 else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
67 return c > 3 && r && Object.defineProperty(target, key, r), r;
68 }
69
70 function __param(paramIndex, decorator) {
71 return function (target, key) { decorator(target, key, paramIndex); }
72 }
73
74 function __metadata(metadataKey, metadataValue) {
75 if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(metadataKey, metadataValue);
76 }
77
78 function __awaiter(thisArg, _arguments, P, generator) {
79 return new (P || (P = Promise))(function (resolve, reject) {
80 function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
81 function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
82 function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
83 step((generator = generator.apply(thisArg, _arguments || [])).next());
84 });
85 }
86
87 function __generator(thisArg, body) {
88 var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
89 return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
90 function verb(n) { return function (v) { return step([n, v]); }; }
91 function step(op) {
92 if (f) throw new TypeError("Generator is already executing.");
93 while (_) try {
94 if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
95 if (y = 0, t) op = [op[0] & 2, t.value];
96 switch (op[0]) {
97 case 0: case 1: t = op; break;
98 case 4: _.label++; return { value: op[1], done: false };
99 case 5: _.label++; y = op[1]; op = [0]; continue;
100 case 7: op = _.ops.pop(); _.trys.pop(); continue;
101 default:
102 if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
103 if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
104 if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
105 if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
106 if (t[2]) _.ops.pop();
107 _.trys.pop(); continue;
108 }
109 op = body.call(thisArg, _);
110 } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
111 if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
112 }
113 }
114
115 function __exportStar(m, exports) {
116 for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
117 }
118
119 function __values(o) {
120 var m = typeof Symbol === "function" && o[Symbol.iterator], i = 0;
121 if (m) return m.call(o);
122 return {
123 next: function () {
124 if (o && i >= o.length) o = void 0;
125 return { value: o && o[i++], done: !o };
126 }
127 };
128 }
129
130 function __read(o, n) {
131 var m = typeof Symbol === "function" && o[Symbol.iterator];
132 if (!m) return o;
133 var i = m.call(o), r, ar = [], e;
134 try {
135 while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
136 }
137 catch (error) { e = { error: error }; }
138 finally {
139 try {
140 if (r && !r.done && (m = i["return"])) m.call(i);
141 }
142 finally { if (e) throw e.error; }
143 }
144 return ar;
145 }
146
147 function __spread() {
148 for (var ar = [], i = 0; i < arguments.length; i++)
149 ar = ar.concat(__read(arguments[i]));
150 return ar;
151 }
152
153 function __await(v) {
154 return this instanceof __await ? (this.v = v, this) : new __await(v);
155 }
156
157 function __asyncGenerator(thisArg, _arguments, generator) {
158 if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
159 var g = generator.apply(thisArg, _arguments || []), i, q = [];
160 return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i;
161 function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }
162 function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }
163 function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
164 function fulfill(value) { resume("next", value); }
165 function reject(value) { resume("throw", value); }
166 function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }
167 }
168
169 function __asyncDelegator(o) {
170 var i, p;
171 return i = {}, verb("next"), verb("throw", function (e) { throw e; }), verb("return"), i[Symbol.iterator] = function () { return this; }, i;
172 function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: n === "return" } : f ? f(v) : v; } : f; }
173 }
174
175 function __asyncValues(o) {
176 if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
177 var m = o[Symbol.asyncIterator], i;
178 return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
179 function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
180 function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
181 }
182
183 function __makeTemplateObject(cooked, raw) {
184 if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; }
185 return cooked;
186 };
187
188 function __importStar(mod) {
189 if (mod && mod.__esModule) return mod;
190 var result = {};
191 if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
192 result.default = mod;
193 return result;
194 }
195
196 function __importDefault(mod) {
197 return (mod && mod.__esModule) ? mod : { default: mod };
198 }
199
200 /**
201 * @license
202 * Copyright Google Inc. All Rights Reserved.
203 *
204 * Use of this source code is governed by an MIT-style license that can be
205 * found in the LICENSE file at https://angular.io/license
206 */
207 /**
208 * A mock implementation of {@link ResourceLoader} that allows outgoing requests to be mocked
209 * and responded to within a single test, without going to the network.
210 */
211 var MockResourceLoader = /** @class */ (function (_super) {
212 __extends(MockResourceLoader, _super);
213 function MockResourceLoader() {
214 var _this = _super !== null && _super.apply(this, arguments) || this;
215 _this._expectations = [];
216 _this._definitions = new Map();
217 _this._requests = [];
218 return _this;
219 }
220 MockResourceLoader.prototype.get = function (url) {
221 var request = new _PendingRequest(url);
222 this._requests.push(request);
223 return request.getPromise();
224 };
225 MockResourceLoader.prototype.hasPendingRequests = function () { return !!this._requests.length; };
226 /**
227 * Add an expectation for the given URL. Incoming requests will be checked against
228 * the next expectation (in FIFO order). The `verifyNoOutstandingExpectations` method
229 * can be used to check if any expectations have not yet been met.
230 *
231 * The response given will be returned if the expectation matches.
232 */
233 MockResourceLoader.prototype.expect = function (url, response) {
234 var expectation = new _Expectation(url, response);
235 this._expectations.push(expectation);
236 };
237 /**
238 * Add a definition for the given URL to return the given response. Unlike expectations,
239 * definitions have no order and will satisfy any matching request at any time. Also
240 * unlike expectations, unused definitions do not cause `verifyNoOutstandingExpectations`
241 * to return an error.
242 */
243 MockResourceLoader.prototype.when = function (url, response) { this._definitions.set(url, response); };
244 /**
245 * Process pending requests and verify there are no outstanding expectations. Also fails
246 * if no requests are pending.
247 */
248 MockResourceLoader.prototype.flush = function () {
249 if (this._requests.length === 0) {
250 throw new Error('No pending requests to flush');
251 }
252 do {
253 this._processRequest(this._requests.shift());
254 } while (this._requests.length > 0);
255 this.verifyNoOutstandingExpectations();
256 };
257 /**
258 * Throw an exception if any expectations have not been satisfied.
259 */
260 MockResourceLoader.prototype.verifyNoOutstandingExpectations = function () {
261 if (this._expectations.length === 0)
262 return;
263 var urls = [];
264 for (var i = 0; i < this._expectations.length; i++) {
265 var expectation = this._expectations[i];
266 urls.push(expectation.url);
267 }
268 throw new Error("Unsatisfied requests: " + urls.join(', '));
269 };
270 MockResourceLoader.prototype._processRequest = function (request) {
271 var url = request.url;
272 if (this._expectations.length > 0) {
273 var expectation = this._expectations[0];
274 if (expectation.url == url) {
275 remove(this._expectations, expectation);
276 request.complete(expectation.response);
277 return;
278 }
279 }
280 if (this._definitions.has(url)) {
281 var response = this._definitions.get(url);
282 request.complete(response == null ? null : response);
283 return;
284 }
285 throw new Error("Unexpected request " + url);
286 };
287 return MockResourceLoader;
288 }(compiler.ResourceLoader));
289 var _PendingRequest = /** @class */ (function () {
290 function _PendingRequest(url) {
291 var _this = this;
292 this.url = url;
293 this.promise = new Promise(function (res, rej) {
294 _this.resolve = res;
295 _this.reject = rej;
296 });
297 }
298 _PendingRequest.prototype.complete = function (response) {
299 if (response == null) {
300 this.reject("Failed to load " + this.url);
301 }
302 else {
303 this.resolve(response);
304 }
305 };
306 _PendingRequest.prototype.getPromise = function () { return this.promise; };
307 return _PendingRequest;
308 }());
309 var _Expectation = /** @class */ (function () {
310 function _Expectation(url, response) {
311 this.url = url;
312 this.response = response;
313 }
314 return _Expectation;
315 }());
316 function remove(list, el) {
317 var index = list.indexOf(el);
318 if (index > -1) {
319 list.splice(index, 1);
320 }
321 }
322
323 /**
324 * @license
325 * Copyright Google Inc. All Rights Reserved.
326 *
327 * Use of this source code is governed by an MIT-style license that can be
328 * found in the LICENSE file at https://angular.io/license
329 */
330 var MockSchemaRegistry = /** @class */ (function () {
331 function MockSchemaRegistry(existingProperties, attrPropMapping, existingElements, invalidProperties, invalidAttributes) {
332 this.existingProperties = existingProperties;
333 this.attrPropMapping = attrPropMapping;
334 this.existingElements = existingElements;
335 this.invalidProperties = invalidProperties;
336 this.invalidAttributes = invalidAttributes;
337 }
338 MockSchemaRegistry.prototype.hasProperty = function (tagName, property, schemas) {
339 var value = this.existingProperties[property];
340 return value === void 0 ? true : value;
341 };
342 MockSchemaRegistry.prototype.hasElement = function (tagName, schemaMetas) {
343 var value = this.existingElements[tagName.toLowerCase()];
344 return value === void 0 ? true : value;
345 };
346 MockSchemaRegistry.prototype.allKnownElementNames = function () { return Object.keys(this.existingElements); };
347 MockSchemaRegistry.prototype.securityContext = function (selector, property, isAttribute) {
348 return compiler.core.SecurityContext.NONE;
349 };
350 MockSchemaRegistry.prototype.getMappedPropName = function (attrName) { return this.attrPropMapping[attrName] || attrName; };
351 MockSchemaRegistry.prototype.getDefaultComponentElementName = function () { return 'ng-component'; };
352 MockSchemaRegistry.prototype.validateProperty = function (name) {
353 if (this.invalidProperties.indexOf(name) > -1) {
354 return { error: true, msg: "Binding to property '" + name + "' is disallowed for security reasons" };
355 }
356 else {
357 return { error: false };
358 }
359 };
360 MockSchemaRegistry.prototype.validateAttribute = function (name) {
361 if (this.invalidAttributes.indexOf(name) > -1) {
362 return {
363 error: true,
364 msg: "Binding to attribute '" + name + "' is disallowed for security reasons"
365 };
366 }
367 else {
368 return { error: false };
369 }
370 };
371 MockSchemaRegistry.prototype.normalizeAnimationStyleProperty = function (propName) { return propName; };
372 MockSchemaRegistry.prototype.normalizeAnimationStyleValue = function (camelCaseProp, userProvidedProp, val) {
373 return { error: null, value: val.toString() };
374 };
375 return MockSchemaRegistry;
376 }());
377
378 /**
379 * An implementation of {@link DirectiveResolver} that allows overriding
380 * various properties of directives.
381 */
382 var MockDirectiveResolver = /** @class */ (function (_super) {
383 __extends(MockDirectiveResolver, _super);
384 function MockDirectiveResolver(reflector) {
385 var _this = _super.call(this, reflector) || this;
386 _this._directives = new Map();
387 return _this;
388 }
389 MockDirectiveResolver.prototype.resolve = function (type, throwIfNotFound) {
390 if (throwIfNotFound === void 0) { throwIfNotFound = true; }
391 return this._directives.get(type) || _super.prototype.resolve.call(this, type, throwIfNotFound);
392 };
393 /**
394 * Overrides the {@link core.Directive} for a directive.
395 */
396 MockDirectiveResolver.prototype.setDirective = function (type, metadata) {
397 this._directives.set(type, metadata);
398 };
399 return MockDirectiveResolver;
400 }(compiler.DirectiveResolver));
401
402 /**
403 * @license
404 * Copyright Google Inc. All Rights Reserved.
405 *
406 * Use of this source code is governed by an MIT-style license that can be
407 * found in the LICENSE file at https://angular.io/license
408 */
409 var MockNgModuleResolver = /** @class */ (function (_super) {
410 __extends(MockNgModuleResolver, _super);
411 function MockNgModuleResolver(reflector) {
412 var _this = _super.call(this, reflector) || this;
413 _this._ngModules = new Map();
414 return _this;
415 }
416 /**
417 * Overrides the {@link NgModule} for a module.
418 */
419 MockNgModuleResolver.prototype.setNgModule = function (type, metadata) {
420 this._ngModules.set(type, metadata);
421 };
422 /**
423 * Returns the {@link NgModule} for a module:
424 * - Set the {@link NgModule} to the overridden view when it exists or fallback to the
425 * default
426 * `NgModuleResolver`, see `setNgModule`.
427 */
428 MockNgModuleResolver.prototype.resolve = function (type, throwIfNotFound) {
429 if (throwIfNotFound === void 0) { throwIfNotFound = true; }
430 return this._ngModules.get(type) || _super.prototype.resolve.call(this, type, throwIfNotFound);
431 };
432 return MockNgModuleResolver;
433 }(compiler.NgModuleResolver));
434
435 /**
436 * @license
437 * Copyright Google Inc. All Rights Reserved.
438 *
439 * Use of this source code is governed by an MIT-style license that can be
440 * found in the LICENSE file at https://angular.io/license
441 */
442 var MockPipeResolver = /** @class */ (function (_super) {
443 __extends(MockPipeResolver, _super);
444 function MockPipeResolver(refector) {
445 var _this = _super.call(this, refector) || this;
446 _this._pipes = new Map();
447 return _this;
448 }
449 /**
450 * Overrides the {@link Pipe} for a pipe.
451 */
452 MockPipeResolver.prototype.setPipe = function (type, metadata) { this._pipes.set(type, metadata); };
453 /**
454 * Returns the {@link Pipe} for a pipe:
455 * - Set the {@link Pipe} to the overridden view when it exists or fallback to the
456 * default
457 * `PipeResolver`, see `setPipe`.
458 */
459 MockPipeResolver.prototype.resolve = function (type, throwIfNotFound) {
460 if (throwIfNotFound === void 0) { throwIfNotFound = true; }
461 var metadata = this._pipes.get(type);
462 if (!metadata) {
463 metadata = _super.prototype.resolve.call(this, type, throwIfNotFound);
464 }
465 return metadata;
466 };
467 return MockPipeResolver;
468 }(compiler.PipeResolver));
469
470 /**
471 * @license
472 * Copyright Google Inc. All Rights Reserved.
473 *
474 * Use of this source code is governed by an MIT-style license that can be
475 * found in the LICENSE file at https://angular.io/license
476 */
477
478 /**
479 * @license
480 * Copyright Google Inc. All Rights Reserved.
481 *
482 * Use of this source code is governed by an MIT-style license that can be
483 * found in the LICENSE file at https://angular.io/license
484 */
485 // This file only reexports content of the `src` folder. Keep it that way.
486
487 /**
488 * @license
489 * Copyright Google Inc. All Rights Reserved.
490 *
491 * Use of this source code is governed by an MIT-style license that can be
492 * found in the LICENSE file at https://angular.io/license
493 */
494
495 /**
496 * Generated bundle index. Do not edit.
497 */
498
499 exports.MockResourceLoader = MockResourceLoader;
500 exports.MockSchemaRegistry = MockSchemaRegistry;
501 exports.MockDirectiveResolver = MockDirectiveResolver;
502 exports.MockNgModuleResolver = MockNgModuleResolver;
503 exports.MockPipeResolver = MockPipeResolver;
504
505 Object.defineProperty(exports, '__esModule', { value: true });
506
507}));
508//# sourceMappingURL=compiler-testing.umd.js.map