@angular-wave/angular.ts 0.0.8 → 0.0.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@angular-wave/angular.ts",
3
3
  "license": "MIT",
4
- "version": "0.0.8",
4
+ "version": "0.0.9",
5
5
  "type": "module",
6
6
  "main": "dist/angular-ts.cjs.js",
7
7
  "module": "dist/angular-ts.esm.js",
package/rollup.config.js CHANGED
@@ -15,7 +15,7 @@ export default [
15
15
  plugins: [resolve(), commonjs(), terser()],
16
16
  },
17
17
 
18
- // CommonJS (for Node) and ES module (for bundlers) build.
18
+ // ES module (for bundlers) build.
19
19
  // (We could have three entries in the configuration array
20
20
  // instead of two, but it's quicker to generate multiple
21
21
  // builds from a single configuration where possible, using
@@ -24,10 +24,7 @@ export default [
24
24
  {
25
25
  input: 'src/index.js',
26
26
  external: ['ms'],
27
- output: [
28
- { file: pkg.main, format: 'cjs' },
29
- { file: pkg.module, format: 'es' },
30
- ],
27
+ output: { file: pkg.module, format: 'es' },
31
28
  plugins: [terser()],
32
29
  },
33
30
  ];
@@ -37,11 +37,15 @@ import { PREFIX_REGEXP, ALIASED_ATTR } from "../constants";
37
37
  import { createEventDirective } from "../directive/events";
38
38
  import { CACHE, EXPANDO } from "./cache";
39
39
 
40
+ /**
41
+ * Function that aggregates all linking fns for a compilation root (nodeList)
42
+ * @typedef {Function} CompositeLinkFn
43
+ */
44
+
40
45
  const $compileMinErr = minErr("$compile");
41
46
 
42
- function UNINITIALIZED_VALUE() {}
43
- const _UNINITIALIZED_VALUE = new UNINITIALIZED_VALUE();
44
- let config = { TTL: 10 };
47
+ const _UNINITIALIZED_VALUE = new Object();
48
+ let TTL = 10;
45
49
 
46
50
  /**
47
51
  * @ngdoc provider
@@ -54,7 +58,6 @@ $CompileProvider.$inject = ["$provide", "$$sanitizeUriProvider"];
54
58
  export function $CompileProvider($provide, $$sanitizeUriProvider) {
55
59
  const hasDirectives = {};
56
60
  const Suffix = "Directive";
57
- const CLASS_DIRECTIVE_REGEXP = /(([\w-]+)(?::([^;]+))?;?)/;
58
61
  const ALL_OR_NOTHING_ATTRS = {
59
62
  ngSrc: true,
60
63
  ngSrcset: true,
@@ -209,7 +212,7 @@ export function $CompileProvider($provide, $$sanitizeUriProvider) {
209
212
  * are the factories.
210
213
  * @param {Function|Array} directiveFactory An injectable directive factory function. See the
211
214
  * {@link guide/directive directive guide} and the {@link $compile compile API} for more info.
212
- * @returns {ng.$compileProvider} Self for chaining.
215
+ * @returns {ng.ICompileProvider} Self for chaining.
213
216
  */
214
217
  this.directive = function registerDirective(name, directiveFactory) {
215
218
  assertArg(name, "name");
@@ -252,7 +255,7 @@ export function $CompileProvider($provide, $$sanitizeUriProvider) {
252
255
  }
253
256
  hasDirectives[name].push(directiveFactory);
254
257
  } else {
255
- forEach(name, reverseParams(registerDirective));
258
+ Object.entries(name).forEach(([k, v]) => registerDirective(k, v));
256
259
  }
257
260
  return this;
258
261
  };
@@ -427,7 +430,7 @@ export function $CompileProvider($provide, $$sanitizeUriProvider) {
427
430
  * the absolute url is prefixed with `'unsafe:'` string and only then is it written into the DOM.
428
431
  *
429
432
  * @param {RegExp=} regexp New regexp to trust urls with.
430
- * @returns {RegExp|ng.$compileProvider} Current RegExp if called without value or self for
433
+ * @returns {RegExp|ng.ICompileProvider} Current RegExp if called without value or self for
431
434
  * chaining otherwise.
432
435
  */
433
436
  this.aHrefSanitizationTrustedUrlList = function (regexp) {
@@ -455,7 +458,7 @@ export function $CompileProvider($provide, $$sanitizeUriProvider) {
455
458
  * the absolute url is prefixed with `'unsafe:'` string and only then is it written into the DOM.
456
459
  *
457
460
  * @param {RegExp=} regexp New regexp to trust urls with.
458
- * @returns {RegExp|ng.$compileProvider} Current RegExp if called without value or self for
461
+ * @returns {RegExp|ng.ICompileProvider} Current RegExp if called without value or self for
459
462
  * chaining otherwise.
460
463
  */
461
464
  this.imgSrcSanitizationTrustedUrlList = function (regexp) {
@@ -528,34 +531,6 @@ export function $CompileProvider($provide, $$sanitizeUriProvider) {
528
531
  return strictComponentBindingsEnabled;
529
532
  };
530
533
 
531
- /**
532
- * @ngdoc method
533
- * @name $compileProvider#onChangesTtl
534
- * @description
535
- *
536
- * Sets the number of times `$onChanges` hooks can trigger new changes before giving up and
537
- * assuming that the model is unstable.
538
- *
539
- * The current default is 10 iterations.
540
- *
541
- * In complex applications it's possible that dependencies between `$onChanges` hooks and bindings will result
542
- * in several iterations of calls to these hooks. However if an application needs more than the default 10
543
- * iterations to stabilize then you should investigate what is causing the model to continuously change during
544
- * the `$onChanges` hook execution.
545
- *
546
- * Increasing the TTL could have performance implications, so you should not change it without proper justification.
547
- *
548
- * @param {number} limit The number of `$onChanges` hook iterations.
549
- * @returns {number|object} the current limit (or `this` if called as a setter for chaining)
550
- */
551
- this.onChangesTtl = function (value) {
552
- if (arguments.length) {
553
- config.TTL = value;
554
- return this;
555
- }
556
- return config.TTL;
557
- };
558
-
559
534
  /**
560
535
  * The security context of DOM Properties.
561
536
  * @private
@@ -686,13 +661,13 @@ export function $CompileProvider($provide, $$sanitizeUriProvider) {
686
661
  // This function is called in a $$postDigest to trigger all the onChanges hooks in a single digest
687
662
  function flushOnChangesQueue() {
688
663
  try {
689
- if (!--config.TTL) {
664
+ if (!--TTL) {
690
665
  // We have hit the TTL limit so reset everything
691
666
  onChangesQueue = undefined;
692
667
  throw $compileMinErr(
693
668
  "infchng",
694
669
  "{0} $onChanges() iterations reached. Aborting!\n",
695
- config.TTL,
670
+ TTL,
696
671
  );
697
672
  }
698
673
  // We must run this hook in an apply since the $$postDigest runs outside apply
@@ -708,7 +683,7 @@ export function $CompileProvider($provide, $$sanitizeUriProvider) {
708
683
  onChangesQueue = undefined;
709
684
  });
710
685
  } finally {
711
- config.TTL++;
686
+ TTL++;
712
687
  }
713
688
  }
714
689
 
@@ -767,25 +742,20 @@ export function $CompileProvider($provide, $$sanitizeUriProvider) {
767
742
  return result;
768
743
  }
769
744
 
770
- function Attributes(element, attributesToCopy) {
771
- if (attributesToCopy) {
772
- const keys = Object.keys(attributesToCopy);
773
- let i;
774
- let l;
775
- let key;
776
-
777
- for (i = 0, l = keys.length; i < l; i++) {
778
- key = keys[i];
779
- this[key] = attributesToCopy[key];
745
+ class Attributes {
746
+ constructor(element, attributesToCopy) {
747
+ if (attributesToCopy) {
748
+ const keys = Object.keys(attributesToCopy);
749
+ for (let i = 0, l = keys.length; i < l; i++) {
750
+ const key = keys[i];
751
+ this[key] = attributesToCopy[key];
752
+ }
753
+ } else {
754
+ this.$attr = {};
780
755
  }
781
- } else {
782
- this.$attr = {};
756
+ this.$$element = element;
783
757
  }
784
758
 
785
- this.$$element = element;
786
- }
787
-
788
- Attributes.prototype = {
789
759
  /**
790
760
  * @ngdoc method
791
761
  * @name $compile.directive.Attributes#$normalize
@@ -801,7 +771,7 @@ export function $CompileProvider($provide, $$sanitizeUriProvider) {
801
771
  *
802
772
  * @param {string} name Name to normalize
803
773
  */
804
- $normalize: directiveNormalize,
774
+ $normalize = directiveNormalize;
805
775
 
806
776
  /**
807
777
  * @ngdoc method
@@ -818,7 +788,7 @@ export function $CompileProvider($provide, $$sanitizeUriProvider) {
818
788
  if (classVal && classVal.length > 0) {
819
789
  $animate.addClass(this.$$element, classVal);
820
790
  }
821
- },
791
+ }
822
792
 
823
793
  /**
824
794
  * @ngdoc method
@@ -835,7 +805,7 @@ export function $CompileProvider($provide, $$sanitizeUriProvider) {
835
805
  if (classVal && classVal.length > 0) {
836
806
  $animate.removeClass(this.$$element, classVal);
837
807
  }
838
- },
808
+ }
839
809
 
840
810
  /**
841
811
  * @ngdoc method
@@ -859,7 +829,7 @@ export function $CompileProvider($provide, $$sanitizeUriProvider) {
859
829
  if (toRemove && toRemove.length) {
860
830
  $animate.removeClass(this.$$element, toRemove);
861
831
  }
862
- },
832
+ }
863
833
 
864
834
  /**
865
835
  * Set a normalized attribute on the element in a way such that all directives
@@ -910,6 +880,7 @@ export function $CompileProvider($provide, $$sanitizeUriProvider) {
910
880
  if (writeAttr !== false) {
911
881
  if (value === null || isUndefined(value)) {
912
882
  this.$$element[0].removeAttribute(attrName);
883
+ //
913
884
  } else if (SIMPLE_ATTR_NAME.test(attrName)) {
914
885
  // jQuery skips special boolean attrs treatment in XML nodes for
915
886
  // historical reasons and hence AngularJS cannot freely call
@@ -937,9 +908,9 @@ export function $CompileProvider($provide, $$sanitizeUriProvider) {
937
908
  }
938
909
  });
939
910
  }
940
- },
911
+ }
941
912
 
942
- /**
913
+ /**
943
914
  * @ngdoc method
944
915
  * @name $compile.directive.Attributes#$observe
945
916
  * @kind function
@@ -959,28 +930,27 @@ export function $CompileProvider($provide, $$sanitizeUriProvider) {
959
930
  * @returns {function()} Returns a deregistration function for this observer.
960
931
  */
961
932
  $observe(key, fn) {
962
- const attrs = this;
963
933
  const $$observers =
964
- attrs.$$observers || (attrs.$$observers = createMap());
934
+ this.$$observers || (this.$$observers = createMap());
965
935
  const listeners = $$observers[key] || ($$observers[key] = []);
966
936
 
967
937
  listeners.push(fn);
968
938
  $rootScope.$evalAsync(() => {
969
939
  if (
970
940
  !listeners.$$inter &&
971
- Object.prototype.hasOwnProperty.call(attrs, key) &&
972
- !isUndefined(attrs[key])
941
+ Object.prototype.hasOwnProperty.call(this, key) &&
942
+ !isUndefined(this[key])
973
943
  ) {
974
944
  // no one registered attribute interpolation function, so lets call it manually
975
- fn(attrs[key]);
945
+ fn(this[key]);
976
946
  }
977
947
  });
978
948
 
979
949
  return function () {
980
950
  arrayRemove(listeners, fn);
981
951
  };
982
- },
983
- };
952
+ }
953
+ }
984
954
 
985
955
  function setSpecialAttr(element, attrName, value) {
986
956
  // Attributes names that do not start with letters (such as `(click)`) cannot be set using `setAttribute`
@@ -995,15 +965,6 @@ export function $CompileProvider($provide, $$sanitizeUriProvider) {
995
965
  element.attributes.setNamedItem(attribute);
996
966
  }
997
967
 
998
- function safeAddClass($element, className) {
999
- try {
1000
- $element[0].classList.add(className);
1001
- } catch (e) {
1002
- // ignore, since it means that we are trying to set class on
1003
- // SVG element, where class name is read-only.
1004
- }
1005
- }
1006
-
1007
968
  const startSymbol = $interpolate.startSymbol();
1008
969
  const endSymbol = $interpolate.endSymbol();
1009
970
  const denormalizeTemplate =
@@ -1018,7 +979,7 @@ export function $CompileProvider($provide, $$sanitizeUriProvider) {
1018
979
  const MULTI_ELEMENT_DIR_RE = /^(.+)Start$/;
1019
980
 
1020
981
  compile.$$addScopeInfo = debugInfoEnabled
1021
- ? function $$addScopeInfo($element, scope, isolated, noTemplate) {
982
+ ? ($element, scope, isolated, noTemplate) => {
1022
983
  const dataName = isolated
1023
984
  ? noTemplate
1024
985
  ? "$isolateScopeNoTemplate"
@@ -1028,19 +989,19 @@ export function $CompileProvider($provide, $$sanitizeUriProvider) {
1028
989
  }
1029
990
  : () => {};
1030
991
 
1031
- compile.$$createComment = function (directiveName, comment) {
1032
- let content = "";
1033
- if (debugInfoEnabled) {
1034
- content = ` ${directiveName || ""}: `;
1035
- if (comment) content += `${comment} `;
1036
- }
1037
- return window.document.createComment(content);
1038
- };
1039
-
1040
992
  return compile;
1041
993
 
1042
994
  //= ===============================
1043
995
 
996
+ /**
997
+ *
998
+ * @param {string|NodeList} $compileNodes
999
+ * @param {*} transcludeFn
1000
+ * @param {*} maxPriority
1001
+ * @param {*} ignoreDirective
1002
+ * @param {*} previousCompileContext
1003
+ * @returns
1004
+ */
1044
1005
  function compile(
1045
1006
  $compileNodes,
1046
1007
  transcludeFn,
@@ -1051,8 +1012,13 @@ export function $CompileProvider($provide, $$sanitizeUriProvider) {
1051
1012
  if (!($compileNodes instanceof jqLite)) {
1052
1013
  // jquery always rewraps, whereas we need to preserve the original selector so that we can
1053
1014
  // modify it.
1015
+
1054
1016
  $compileNodes = jqLite($compileNodes);
1055
1017
  }
1018
+
1019
+ /**
1020
+ * @type {CompositeLinkFn}
1021
+ */
1056
1022
  let compositeLinkFn = compileNodes(
1057
1023
  $compileNodes,
1058
1024
  transcludeFn,
@@ -1168,7 +1134,7 @@ export function $CompileProvider($provide, $$sanitizeUriProvider) {
1168
1134
  * function, which is the a linking function for the node.
1169
1135
  *
1170
1136
  * @param {NodeList} nodeList an array of nodes or NodeList to compile
1171
- * @param {function(angular.Scope, cloneAttachFn=)} transcludeFn A linking function, where the
1137
+ * @param {function(ng.IScope, cloneAttachFn=)} transcludeFn A linking function, where the
1172
1138
  * scope argument is auto-generated to the new child of the transcluded parent scope.
1173
1139
  * @param {Element=} $rootElement If the nodeList is the root of the compilation tree then
1174
1140
  * the rootElement must be set the jqLite collection of the compile root. This is
@@ -1268,8 +1234,7 @@ export function $CompileProvider($provide, $$sanitizeUriProvider) {
1268
1234
  if (nodeLinkFnFound) {
1269
1235
  // copy nodeList so that if a nodeLinkFn removes or adds an element at this DOM level our
1270
1236
  // offsets don't get screwed up
1271
- const nodeListLength = nodeList.length;
1272
- stableNodeList = new Array(nodeListLength);
1237
+ stableNodeList = new Array(nodeList.length);
1273
1238
 
1274
1239
  // create a sparse array by only copying the elements which have a linkFn
1275
1240
  for (i = 0; i < linkFns.length; i += 3) {
@@ -1378,7 +1343,7 @@ export function $CompileProvider($provide, $$sanitizeUriProvider) {
1378
1343
  * Looks for directives on the given node and adds them to the directive collection which is
1379
1344
  * sorted.
1380
1345
  *
1381
- * @param node Node to search.
1346
+ * @param {Element} node Node to search.
1382
1347
  * @param directives An array to which the directives are added to. This array is sorted before
1383
1348
  * the function returns.
1384
1349
  * @param attrs The shared attrs object which is used to populate the normalized attributes.
@@ -1393,9 +1358,7 @@ export function $CompileProvider($provide, $$sanitizeUriProvider) {
1393
1358
  ) {
1394
1359
  const { nodeType } = node;
1395
1360
  const attrsMap = attrs.$attr;
1396
- let match;
1397
1361
  let nodeName;
1398
- let className;
1399
1362
 
1400
1363
  switch (nodeType) {
1401
1364
  case Node.ELEMENT_NODE /* Element */:
@@ -1528,9 +1491,9 @@ export function $CompileProvider($provide, $$sanitizeUriProvider) {
1528
1491
  /**
1529
1492
  * Given a node with a directive-start it collects all of the siblings until it finds
1530
1493
  * directive-end.
1531
- * @param node
1532
- * @param attrStart
1533
- * @param attrEnd
1494
+ * @param {Element} node
1495
+ * @param {string} attrStart
1496
+ * @param {string} attrEnd
1534
1497
  * @returns {*}
1535
1498
  */
1536
1499
  function groupScan(node, attrStart, attrEnd) {
@@ -1551,7 +1514,7 @@ export function $CompileProvider($provide, $$sanitizeUriProvider) {
1551
1514
  if (node.hasAttribute(attrEnd)) depth--;
1552
1515
  }
1553
1516
  nodes.push(node);
1554
- node = node.nextSibling;
1517
+ node = /** @type {Element} */ (node.nextSibling);
1555
1518
  } while (depth > 0);
1556
1519
  } else {
1557
1520
  nodes.push(node);
@@ -1801,10 +1764,7 @@ export function $CompileProvider($provide, $$sanitizeUriProvider) {
1801
1764
  terminalPriority = directive.priority;
1802
1765
  $template = $compileNode;
1803
1766
  $compileNode = templateAttrs.$$element = jqLite(
1804
- compile.$$createComment(
1805
- directiveName,
1806
- templateAttrs[directiveName],
1807
- ),
1767
+ document.createComment(""),
1808
1768
  );
1809
1769
  compileNode = $compileNode[0];
1810
1770
  replaceWith(jqCollection, sliceArgs($template), compileNode);
@@ -2528,8 +2488,6 @@ export function $CompileProvider($provide, $$sanitizeUriProvider) {
2528
2488
  *
2529
2489
  * * `E`: element name
2530
2490
  * * `A': attribute
2531
- * * `C`: class
2532
- * * `M`: comment
2533
2491
  * @returns {boolean} true if directive was added.
2534
2492
  */
2535
2493
  function addDirective(
@@ -2782,7 +2740,14 @@ export function $CompileProvider($provide, $$sanitizeUriProvider) {
2782
2740
  );
2783
2741
 
2784
2742
  // Copy in CSS classes from original node
2785
- safeAddClass(jqLite(linkNode), oldClasses);
2743
+ try {
2744
+ if (oldClasses !== "") {
2745
+ linkNode.classList.add(oldClasses);
2746
+ }
2747
+ } catch (e) {
2748
+ // ignore, since it means that we are trying to set class on
2749
+ // SVG element, where class name is read-only.
2750
+ }
2786
2751
  }
2787
2752
  if (afterTemplateNodeLinkFn.transcludeOnThisElement) {
2788
2753
  childBoundTranscludeFn = createBoundTranscludeFn(
@@ -80,8 +80,7 @@ import { getBlockNodes } from "../jqLite";
80
80
  */
81
81
  export const ngIfDirective = [
82
82
  "$animate",
83
- "$compile",
84
- ($animate, $compile) => ({
83
+ ($animate) => ({
85
84
  multiElement: true,
86
85
  transclude: "element",
87
86
  priority: 600,
@@ -97,11 +96,7 @@ export const ngIfDirective = [
97
96
  if (!childScope) {
98
97
  $transclude((clone, newScope) => {
99
98
  childScope = newScope;
100
- // eslint-disable-next-line no-plusplus, no-param-reassign
101
- clone[clone.length++] = $compile.$$createComment(
102
- "end ngIf",
103
- $attr.ngIf,
104
- );
99
+ clone[clone.length++] = document.createComment("");
105
100
  // Note: We only need the first/last node of the cloned nodes.
106
101
  // However, we need to keep the reference to the jqlite wrapper as it might be changed later
107
102
  // by a directive with templateUrl when its template arrives.