compiler-testing.umd.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350
  1. /**
  2. * @license Angular v8.1.0
  3. * (c) 2010-2019 Google LLC. https://angular.io/
  4. * License: MIT
  5. */
  6. (function (global, factory) {
  7. typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/compiler')) :
  8. typeof define === 'function' && define.amd ? define('@angular/compiler/testing', ['exports', '@angular/compiler'], factory) :
  9. (global = global || self, factory((global.ng = global.ng || {}, global.ng.compiler = global.ng.compiler || {}, global.ng.compiler.testing = {}), global.ng.compiler));
  10. }(this, function (exports, compiler) { 'use strict';
  11. /*! *****************************************************************************
  12. Copyright (c) Microsoft Corporation. All rights reserved.
  13. Licensed under the Apache License, Version 2.0 (the "License"); you may not use
  14. this file except in compliance with the License. You may obtain a copy of the
  15. License at http://www.apache.org/licenses/LICENSE-2.0
  16. THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  17. KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
  18. WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
  19. MERCHANTABLITY OR NON-INFRINGEMENT.
  20. See the Apache Version 2.0 License for specific language governing permissions
  21. and limitations under the License.
  22. ***************************************************************************** */
  23. /* global Reflect, Promise */
  24. var extendStatics = function(d, b) {
  25. extendStatics = Object.setPrototypeOf ||
  26. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  27. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  28. return extendStatics(d, b);
  29. };
  30. function __extends(d, b) {
  31. extendStatics(d, b);
  32. function __() { this.constructor = d; }
  33. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  34. }
  35. /**
  36. * @license
  37. * Copyright Google Inc. All Rights Reserved.
  38. *
  39. * Use of this source code is governed by an MIT-style license that can be
  40. * found in the LICENSE file at https://angular.io/license
  41. */
  42. /**
  43. * A mock implementation of {@link ResourceLoader} that allows outgoing requests to be mocked
  44. * and responded to within a single test, without going to the network.
  45. */
  46. var MockResourceLoader = /** @class */ (function (_super) {
  47. __extends(MockResourceLoader, _super);
  48. function MockResourceLoader() {
  49. var _this = _super !== null && _super.apply(this, arguments) || this;
  50. _this._expectations = [];
  51. _this._definitions = new Map();
  52. _this._requests = [];
  53. return _this;
  54. }
  55. MockResourceLoader.prototype.get = function (url) {
  56. var request = new _PendingRequest(url);
  57. this._requests.push(request);
  58. return request.getPromise();
  59. };
  60. MockResourceLoader.prototype.hasPendingRequests = function () { return !!this._requests.length; };
  61. /**
  62. * Add an expectation for the given URL. Incoming requests will be checked against
  63. * the next expectation (in FIFO order). The `verifyNoOutstandingExpectations` method
  64. * can be used to check if any expectations have not yet been met.
  65. *
  66. * The response given will be returned if the expectation matches.
  67. */
  68. MockResourceLoader.prototype.expect = function (url, response) {
  69. var expectation = new _Expectation(url, response);
  70. this._expectations.push(expectation);
  71. };
  72. /**
  73. * Add a definition for the given URL to return the given response. Unlike expectations,
  74. * definitions have no order and will satisfy any matching request at any time. Also
  75. * unlike expectations, unused definitions do not cause `verifyNoOutstandingExpectations`
  76. * to return an error.
  77. */
  78. MockResourceLoader.prototype.when = function (url, response) { this._definitions.set(url, response); };
  79. /**
  80. * Process pending requests and verify there are no outstanding expectations. Also fails
  81. * if no requests are pending.
  82. */
  83. MockResourceLoader.prototype.flush = function () {
  84. if (this._requests.length === 0) {
  85. throw new Error('No pending requests to flush');
  86. }
  87. do {
  88. this._processRequest(this._requests.shift());
  89. } while (this._requests.length > 0);
  90. this.verifyNoOutstandingExpectations();
  91. };
  92. /**
  93. * Throw an exception if any expectations have not been satisfied.
  94. */
  95. MockResourceLoader.prototype.verifyNoOutstandingExpectations = function () {
  96. if (this._expectations.length === 0)
  97. return;
  98. var urls = [];
  99. for (var i = 0; i < this._expectations.length; i++) {
  100. var expectation = this._expectations[i];
  101. urls.push(expectation.url);
  102. }
  103. throw new Error("Unsatisfied requests: " + urls.join(', '));
  104. };
  105. MockResourceLoader.prototype._processRequest = function (request) {
  106. var url = request.url;
  107. if (this._expectations.length > 0) {
  108. var expectation = this._expectations[0];
  109. if (expectation.url == url) {
  110. remove(this._expectations, expectation);
  111. request.complete(expectation.response);
  112. return;
  113. }
  114. }
  115. if (this._definitions.has(url)) {
  116. var response = this._definitions.get(url);
  117. request.complete(response == null ? null : response);
  118. return;
  119. }
  120. throw new Error("Unexpected request " + url);
  121. };
  122. return MockResourceLoader;
  123. }(compiler.ResourceLoader));
  124. var _PendingRequest = /** @class */ (function () {
  125. function _PendingRequest(url) {
  126. var _this = this;
  127. this.url = url;
  128. this.promise = new Promise(function (res, rej) {
  129. _this.resolve = res;
  130. _this.reject = rej;
  131. });
  132. }
  133. _PendingRequest.prototype.complete = function (response) {
  134. if (response == null) {
  135. this.reject("Failed to load " + this.url);
  136. }
  137. else {
  138. this.resolve(response);
  139. }
  140. };
  141. _PendingRequest.prototype.getPromise = function () { return this.promise; };
  142. return _PendingRequest;
  143. }());
  144. var _Expectation = /** @class */ (function () {
  145. function _Expectation(url, response) {
  146. this.url = url;
  147. this.response = response;
  148. }
  149. return _Expectation;
  150. }());
  151. function remove(list, el) {
  152. var index = list.indexOf(el);
  153. if (index > -1) {
  154. list.splice(index, 1);
  155. }
  156. }
  157. /**
  158. * @license
  159. * Copyright Google Inc. All Rights Reserved.
  160. *
  161. * Use of this source code is governed by an MIT-style license that can be
  162. * found in the LICENSE file at https://angular.io/license
  163. */
  164. var MockSchemaRegistry = /** @class */ (function () {
  165. function MockSchemaRegistry(existingProperties, attrPropMapping, existingElements, invalidProperties, invalidAttributes) {
  166. this.existingProperties = existingProperties;
  167. this.attrPropMapping = attrPropMapping;
  168. this.existingElements = existingElements;
  169. this.invalidProperties = invalidProperties;
  170. this.invalidAttributes = invalidAttributes;
  171. }
  172. MockSchemaRegistry.prototype.hasProperty = function (tagName, property, schemas) {
  173. var value = this.existingProperties[property];
  174. return value === void 0 ? true : value;
  175. };
  176. MockSchemaRegistry.prototype.hasElement = function (tagName, schemaMetas) {
  177. var value = this.existingElements[tagName.toLowerCase()];
  178. return value === void 0 ? true : value;
  179. };
  180. MockSchemaRegistry.prototype.allKnownElementNames = function () { return Object.keys(this.existingElements); };
  181. MockSchemaRegistry.prototype.securityContext = function (selector, property, isAttribute) {
  182. return compiler.core.SecurityContext.NONE;
  183. };
  184. MockSchemaRegistry.prototype.getMappedPropName = function (attrName) { return this.attrPropMapping[attrName] || attrName; };
  185. MockSchemaRegistry.prototype.getDefaultComponentElementName = function () { return 'ng-component'; };
  186. MockSchemaRegistry.prototype.validateProperty = function (name) {
  187. if (this.invalidProperties.indexOf(name) > -1) {
  188. return { error: true, msg: "Binding to property '" + name + "' is disallowed for security reasons" };
  189. }
  190. else {
  191. return { error: false };
  192. }
  193. };
  194. MockSchemaRegistry.prototype.validateAttribute = function (name) {
  195. if (this.invalidAttributes.indexOf(name) > -1) {
  196. return {
  197. error: true,
  198. msg: "Binding to attribute '" + name + "' is disallowed for security reasons"
  199. };
  200. }
  201. else {
  202. return { error: false };
  203. }
  204. };
  205. MockSchemaRegistry.prototype.normalizeAnimationStyleProperty = function (propName) { return propName; };
  206. MockSchemaRegistry.prototype.normalizeAnimationStyleValue = function (camelCaseProp, userProvidedProp, val) {
  207. return { error: null, value: val.toString() };
  208. };
  209. return MockSchemaRegistry;
  210. }());
  211. /**
  212. * An implementation of {@link DirectiveResolver} that allows overriding
  213. * various properties of directives.
  214. */
  215. var MockDirectiveResolver = /** @class */ (function (_super) {
  216. __extends(MockDirectiveResolver, _super);
  217. function MockDirectiveResolver(reflector) {
  218. var _this = _super.call(this, reflector) || this;
  219. _this._directives = new Map();
  220. return _this;
  221. }
  222. MockDirectiveResolver.prototype.resolve = function (type, throwIfNotFound) {
  223. if (throwIfNotFound === void 0) { throwIfNotFound = true; }
  224. return this._directives.get(type) || _super.prototype.resolve.call(this, type, throwIfNotFound);
  225. };
  226. /**
  227. * Overrides the {@link core.Directive} for a directive.
  228. */
  229. MockDirectiveResolver.prototype.setDirective = function (type, metadata) {
  230. this._directives.set(type, metadata);
  231. };
  232. return MockDirectiveResolver;
  233. }(compiler.DirectiveResolver));
  234. /**
  235. * @license
  236. * Copyright Google Inc. All Rights Reserved.
  237. *
  238. * Use of this source code is governed by an MIT-style license that can be
  239. * found in the LICENSE file at https://angular.io/license
  240. */
  241. var MockNgModuleResolver = /** @class */ (function (_super) {
  242. __extends(MockNgModuleResolver, _super);
  243. function MockNgModuleResolver(reflector) {
  244. var _this = _super.call(this, reflector) || this;
  245. _this._ngModules = new Map();
  246. return _this;
  247. }
  248. /**
  249. * Overrides the {@link NgModule} for a module.
  250. */
  251. MockNgModuleResolver.prototype.setNgModule = function (type, metadata) {
  252. this._ngModules.set(type, metadata);
  253. };
  254. /**
  255. * Returns the {@link NgModule} for a module:
  256. * - Set the {@link NgModule} to the overridden view when it exists or fallback to the
  257. * default
  258. * `NgModuleResolver`, see `setNgModule`.
  259. */
  260. MockNgModuleResolver.prototype.resolve = function (type, throwIfNotFound) {
  261. if (throwIfNotFound === void 0) { throwIfNotFound = true; }
  262. return this._ngModules.get(type) || _super.prototype.resolve.call(this, type, throwIfNotFound);
  263. };
  264. return MockNgModuleResolver;
  265. }(compiler.NgModuleResolver));
  266. /**
  267. * @license
  268. * Copyright Google Inc. All Rights Reserved.
  269. *
  270. * Use of this source code is governed by an MIT-style license that can be
  271. * found in the LICENSE file at https://angular.io/license
  272. */
  273. var MockPipeResolver = /** @class */ (function (_super) {
  274. __extends(MockPipeResolver, _super);
  275. function MockPipeResolver(refector) {
  276. var _this = _super.call(this, refector) || this;
  277. _this._pipes = new Map();
  278. return _this;
  279. }
  280. /**
  281. * Overrides the {@link Pipe} for a pipe.
  282. */
  283. MockPipeResolver.prototype.setPipe = function (type, metadata) { this._pipes.set(type, metadata); };
  284. /**
  285. * Returns the {@link Pipe} for a pipe:
  286. * - Set the {@link Pipe} to the overridden view when it exists or fallback to the
  287. * default
  288. * `PipeResolver`, see `setPipe`.
  289. */
  290. MockPipeResolver.prototype.resolve = function (type, throwIfNotFound) {
  291. if (throwIfNotFound === void 0) { throwIfNotFound = true; }
  292. var metadata = this._pipes.get(type);
  293. if (!metadata) {
  294. metadata = _super.prototype.resolve.call(this, type, throwIfNotFound);
  295. }
  296. return metadata;
  297. };
  298. return MockPipeResolver;
  299. }(compiler.PipeResolver));
  300. /**
  301. * @license
  302. * Copyright Google Inc. All Rights Reserved.
  303. *
  304. * Use of this source code is governed by an MIT-style license that can be
  305. * found in the LICENSE file at https://angular.io/license
  306. */
  307. /**
  308. * @license
  309. * Copyright Google Inc. All Rights Reserved.
  310. *
  311. * Use of this source code is governed by an MIT-style license that can be
  312. * found in the LICENSE file at https://angular.io/license
  313. */
  314. // This file only reexports content of the `src` folder. Keep it that way.
  315. /**
  316. * @license
  317. * Copyright Google Inc. All Rights Reserved.
  318. *
  319. * Use of this source code is governed by an MIT-style license that can be
  320. * found in the LICENSE file at https://angular.io/license
  321. */
  322. /**
  323. * Generated bundle index. Do not edit.
  324. */
  325. exports.MockResourceLoader = MockResourceLoader;
  326. exports.MockSchemaRegistry = MockSchemaRegistry;
  327. exports.MockDirectiveResolver = MockDirectiveResolver;
  328. exports.MockNgModuleResolver = MockNgModuleResolver;
  329. exports.MockPipeResolver = MockPipeResolver;
  330. Object.defineProperty(exports, '__esModule', { value: true });
  331. }));
  332. //# sourceMappingURL=compiler-testing.umd.js.map