@wavemaker/angular-codegen 11.0.3-next.23393 → 11.0.3-next.23394

Sign up to get free protection for your applications and to get access to all the features.
@@ -38622,9 +38622,12 @@ class ASTCompiler {
38622
38622
  cleanup() {
38623
38623
  this.ast = this.cAst = this.stmts = this.cStmts = this.declarations = this.pipes = this.pipeNameVsIsPureMap = undefined;
38624
38624
  }
38625
- compile() {
38625
+ compile(defOnly) {
38626
38626
  this.extendCtxWithLocals();
38627
38627
  this.addReturnStmt(this.build(this.ast));
38628
+ if (defOnly) {
38629
+ return { fnBody: this.fnBody(), fnArgs: this.fnArgs(), pipes: this.pipes };
38630
+ }
38628
38631
  const fn = new Function(this.fnArgs(), this.fnBody());
38629
38632
  let boundFn;
38630
38633
  if (this.exprType === ExpressionType$1.Binding) {
@@ -38643,13 +38646,27 @@ const nullPipe = () => {
38643
38646
  transform: noop$1$1
38644
38647
  };
38645
38648
  };
38649
+ let _cspEnabled;
38650
+ const isCSPEnabled = () => {
38651
+ if (typeof _cspEnabled !== 'undefined') {
38652
+ return _cspEnabled;
38653
+ }
38654
+ try {
38655
+ new Function();
38656
+ _cspEnabled = false;
38657
+ }
38658
+ catch (e) {
38659
+ _cspEnabled = true;
38660
+ }
38661
+ return _cspEnabled;
38662
+ };
38646
38663
  let pipeProvider;
38647
38664
  var ExpressionType$1;
38648
38665
  (function (ExpressionType$$1) {
38649
38666
  ExpressionType$$1[ExpressionType$$1["Binding"] = 0] = "Binding";
38650
38667
  ExpressionType$$1[ExpressionType$$1["Action"] = 1] = "Action";
38651
38668
  })(ExpressionType$1 || (ExpressionType$1 = {}));
38652
- function $parseExpr(expr) {
38669
+ function $parseExpr(expr, defOnly) {
38653
38670
  if (!pipeProvider) {
38654
38671
  console.log('set pipe provider');
38655
38672
  return noop$1$1;
@@ -38668,51 +38685,89 @@ function $parseExpr(expr) {
38668
38685
  if (fn) {
38669
38686
  return fn;
38670
38687
  }
38671
- const parser = new Parser$1(new Lexer);
38672
- const ast = parser.parseBinding(expr, '', 0);
38673
38688
  let boundFn;
38674
- if (ast.errors.length) {
38675
- fn = noop$1$1;
38676
- boundFn = fn;
38677
- }
38678
- else {
38679
- const pipeNameVsIsPureMap = pipeProvider.getPipeNameVsIsPureMap();
38680
- const astCompiler = new ASTCompiler(ast.ast, ExpressionType$1.Binding, pipeNameVsIsPureMap);
38681
- fn = astCompiler.compile();
38682
- if (fn.usedPipes.length) {
38683
- const pipeArgs = [];
38684
- let hasPurePipe = false;
38685
- for (const [pipeName] of fn.usedPipes) {
38686
- const pipeInfo = pipeProvider.meta(pipeName);
38687
- let pipeInstance;
38688
- if (!pipeInfo) {
38689
- pipeInstance = nullPipe;
38689
+ if (!defOnly) {
38690
+ boundFn = getFnForBindExpr(expr);
38691
+ }
38692
+ // fallback to generate function in runtime. This will break if CSP is enabled
38693
+ if (!boundFn) {
38694
+ // If CSP enabled, function def not found from the generated fn expressions for the page.
38695
+ // Handle bind expressions used internally inside WM components. e.g. wmAnchor used inside nav.comp.html
38696
+ if (isCSPEnabled()) {
38697
+ boundFn = function (ctx, locals) {
38698
+ // handle internal bindings for wm widgets used inside a component
38699
+ let _ctx = Object.assign({}, locals);
38700
+ Object.setPrototypeOf(_ctx, ctx);
38701
+ return _.get(_ctx, expr);
38702
+ };
38703
+ }
38704
+ else {
38705
+ const parser = new Parser$1(new Lexer);
38706
+ const ast = parser.parseBinding(expr, '', 0);
38707
+ if (ast.errors.length) {
38708
+ fn = noop$1$1;
38709
+ boundFn = fn;
38710
+ }
38711
+ else {
38712
+ const pipeNameVsIsPureMap = pipeProvider.getPipeNameVsIsPureMap();
38713
+ const astCompiler = new ASTCompiler(ast.ast, ExpressionType$1.Binding, pipeNameVsIsPureMap);
38714
+ fn = astCompiler.compile(defOnly);
38715
+ if (defOnly) {
38716
+ return fn;
38717
+ }
38718
+ if (fn.usedPipes.length) {
38719
+ const pipeArgs = [];
38720
+ let hasPurePipe = false;
38721
+ for (const [pipeName] of fn.usedPipes) {
38722
+ const pipeInfo = pipeProvider.meta(pipeName);
38723
+ let pipeInstance;
38724
+ if (!pipeInfo) {
38725
+ pipeInstance = nullPipe;
38726
+ }
38727
+ else {
38728
+ if (pipeInfo.pure) {
38729
+ hasPurePipe = true;
38730
+ pipeInstance = purePipes.get(pipeName);
38731
+ }
38732
+ if (!pipeInstance) {
38733
+ pipeInstance = pipeProvider.getInstance(pipeName);
38734
+ }
38735
+ if (pipeInfo.pure) {
38736
+ purePipes.set(pipeName, pipeInstance);
38737
+ }
38738
+ }
38739
+ pipeArgs.push(pipeInstance);
38740
+ }
38741
+ pipeArgs.unshift(hasPurePipe ? new Map() : undefined);
38742
+ boundFn = fn.bind(undefined, ...pipeArgs);
38690
38743
  }
38691
38744
  else {
38692
- if (pipeInfo.pure) {
38693
- hasPurePipe = true;
38694
- pipeInstance = purePipes.get(pipeName);
38695
- }
38696
- if (!pipeInstance) {
38697
- pipeInstance = pipeProvider.getInstance(pipeName);
38698
- }
38699
- if (pipeInfo.pure) {
38700
- purePipes.set(pipeName, pipeInstance);
38701
- }
38745
+ boundFn = fn.bind(undefined, undefined);
38702
38746
  }
38703
- pipeArgs.push(pipeInstance);
38704
38747
  }
38705
- pipeArgs.unshift(hasPurePipe ? new Map() : undefined);
38706
- boundFn = fn.bind(undefined, ...pipeArgs);
38707
- }
38708
- else {
38709
- boundFn = fn.bind(undefined, undefined);
38710
38748
  }
38711
38749
  }
38712
38750
  exprFnCache.set(expr, boundFn);
38713
38751
  return boundFn;
38714
38752
  }
38715
- function $parseEvent(expr) {
38753
+ function simpleFunctionEvaluator(expr, ctx, locals) {
38754
+ let _ctx = Object.assign({}, locals);
38755
+ Object.setPrototypeOf(_ctx, ctx);
38756
+ let parts = expr.split('(');
38757
+ let fnName = parts[0];
38758
+ let computedFn = _.get(ctx, fnName);
38759
+ if (computedFn) {
38760
+ let args = parts[1].replace(')', '');
38761
+ args = args.split(',');
38762
+ let computedArgs = [];
38763
+ args.forEach((arg) => {
38764
+ arg = arg && arg.trim();
38765
+ computedArgs.push(_.get(_ctx, arg));
38766
+ });
38767
+ return computedFn.bind(_ctx)(...computedArgs);
38768
+ }
38769
+ }
38770
+ function $parseEvent(expr, defOnly) {
38716
38771
  if (!isString$1(expr)) {
38717
38772
  return noop$1$1;
38718
38773
  }
@@ -38724,16 +38779,80 @@ function $parseEvent(expr) {
38724
38779
  if (fn) {
38725
38780
  return fn;
38726
38781
  }
38727
- const parser = new Parser$1(new Lexer);
38728
- const ast = parser.parseAction(expr, '', 0);
38729
- if (ast.errors.length) {
38730
- return noop$1$1;
38782
+ if (!defOnly) {
38783
+ fn = getFnForEventExpr(expr);
38784
+ }
38785
+ // fallback to generate function in runtime. This will break if CSP is enabled
38786
+ if (!fn) {
38787
+ if (isCSPEnabled()) {
38788
+ fn = simpleFunctionEvaluator.bind(undefined, expr);
38789
+ }
38790
+ else {
38791
+ const parser = new Parser$1(new Lexer);
38792
+ const ast = parser.parseAction(expr, '', 0);
38793
+ if (ast.errors.length) {
38794
+ return noop$1$1;
38795
+ }
38796
+ const astCompiler = new ASTCompiler(ast.ast, ExpressionType$1.Action);
38797
+ fn = astCompiler.compile(defOnly);
38798
+ }
38731
38799
  }
38732
- const astCompiler = new ASTCompiler(ast.ast, ExpressionType$1.Action);
38733
- fn = astCompiler.compile();
38734
38800
  eventFnCache.set(expr, fn);
38735
38801
  return fn;
38736
38802
  }
38803
+ const fnNameMap = new Map();
38804
+ const getFnByExpr = (expr) => fnNameMap.get(expr);
38805
+ const fnExecutor = (expr, exprType) => {
38806
+ let fn = getFnByExpr(expr);
38807
+ if (!fn) {
38808
+ return;
38809
+ }
38810
+ const usedPipes = fn.usedPipes || [];
38811
+ if (exprType === ExpressionType$1.Binding) {
38812
+ fn = fn.bind(undefined, plus, minus, isDef, getPurePipeVal);
38813
+ }
38814
+ else {
38815
+ fn = fn.bind(undefined, plus, minus, isDef);
38816
+ }
38817
+ if (usedPipes.length) {
38818
+ const pipeArgs = [];
38819
+ let hasPurePipe = false;
38820
+ for (const [pipeName] of usedPipes) {
38821
+ const pipeInfo = pipeProvider.meta(pipeName);
38822
+ let pipeInstance;
38823
+ if (!pipeInfo) {
38824
+ pipeInstance = nullPipe;
38825
+ }
38826
+ else {
38827
+ if (pipeInfo.pure) {
38828
+ hasPurePipe = true;
38829
+ pipeInstance = purePipes.get(pipeName);
38830
+ }
38831
+ if (!pipeInstance) {
38832
+ pipeInstance = pipeProvider.getInstance(pipeName);
38833
+ }
38834
+ if (pipeInfo.pure) {
38835
+ purePipes.set(pipeName, pipeInstance);
38836
+ }
38837
+ }
38838
+ pipeArgs.push(pipeInstance);
38839
+ }
38840
+ pipeArgs.unshift(hasPurePipe ? new Map() : undefined);
38841
+ fn = fn.bind(undefined, ...pipeArgs);
38842
+ }
38843
+ else {
38844
+ if (exprType === ExpressionType$1.Binding) {
38845
+ fn = fn.bind(undefined, undefined);
38846
+ }
38847
+ }
38848
+ return fn;
38849
+ };
38850
+ const getFnForBindExpr = (expr) => {
38851
+ return fnExecutor(expr, ExpressionType$1.Binding);
38852
+ };
38853
+ const getFnForEventExpr = (expr) => {
38854
+ return fnExecutor(expr, ExpressionType$1.Action);
38855
+ };
38737
38856
 
38738
38857
  const registry = new Map();
38739
38858
  const watchIdGenerator = new IDGenerator('watch-id-');
@@ -39574,10 +39693,26 @@ const loadScript = (url, loadViaScriptTag, cacheable = false) => __awaiter$1(voi
39574
39693
  return Promise.resolve();
39575
39694
  }
39576
39695
  if (loadViaScriptTag) {
39577
- return fetchContent('text', _url, false, text => {
39578
- const script = document.createElement('script');
39579
- script.textContent = text;
39580
- document.head.appendChild(script);
39696
+ return new Promise((resolve, reject) => {
39697
+ let script = document.createElement('script');
39698
+ script.type = 'text/javascript';
39699
+ script.src = _url;
39700
+ script.async = false;
39701
+ if (script.readyState) { //IE
39702
+ script.onreadystatechange = () => {
39703
+ if (script.readyState === "loaded" || script.readyState === "complete") {
39704
+ script.onreadystatechange = null;
39705
+ resolve(true);
39706
+ }
39707
+ };
39708
+ }
39709
+ else { //Other browsers
39710
+ script.onload = () => {
39711
+ resolve(true);
39712
+ };
39713
+ }
39714
+ script.onerror = (error) => reject(error);
39715
+ document.getElementsByTagName('head')[0].appendChild(script);
39581
39716
  });
39582
39717
  }
39583
39718
  else if (cacheable) {
@@ -39593,13 +39728,6 @@ const loadScript = (url, loadViaScriptTag, cacheable = false) => __awaiter$1(voi
39593
39728
  .done(response => response)
39594
39729
  .fail(reason => reason);
39595
39730
  }
39596
- // return fetch(_url)
39597
- // .then(response => response.text())
39598
- // .then(text => {
39599
- // const script = document.createElement('script');
39600
- // script.textContent = text;
39601
- // document.head.appendChild(script);
39602
- // });
39603
39731
  });
39604
39732
  const loadScripts = (urls = [], loadViaScriptTag = true) => __awaiter$1(void 0, void 0, void 0, function* () {
39605
39733
  for (const url of urls) {
@@ -39629,7 +39757,8 @@ const setSessionStorageItem = (key, value) => {
39629
39757
  * @param key string
39630
39758
  */
39631
39759
  const getSessionStorageItem = key => {
39632
- let item = window.sessionStorage.getItem(_WM_APP_PROJECT.id);
39760
+ // sanity check for this to work with ng-codegen
39761
+ let item = window && window.sessionStorage && window.sessionStorage.getItem(_WM_APP_PROJECT.id);
39633
39762
  if (item) {
39634
39763
  item = JSON.parse(item);
39635
39764
  return item[key];
@@ -39853,6 +39982,7 @@ const processFilterExpBindNode = (context, filterExpressions) => {
39853
39982
  const filter$ = new Subject();
39854
39983
  const bindFilExpObj = (obj, targetNodeKey) => {
39855
39984
  if (stringStartsWith(obj[targetNodeKey], 'bind:')) {
39985
+ // [Todo-CSP]: needs a check, where is this used
39856
39986
  destroyFn($watch(obj[targetNodeKey].replace('bind:', ''), context, {}, (newVal, oldVal) => {
39857
39987
  if ((newVal === oldVal && _.isUndefined(newVal)) || (_.isUndefined(newVal) && !_.isUndefined(oldVal))) {
39858
39988
  return;
@@ -40096,6 +40226,7 @@ const triggerItemAction = (scope, item) => {
40096
40226
  const linkTarget = item.target;
40097
40227
  if (itemAction) {
40098
40228
  if (!scope.itemActionFn) {
40229
+ //[Todo-CSP]: This will not work as function will be dynamic
40099
40230
  scope.itemActionFn = $parseEvent(itemAction);
40100
40231
  }
40101
40232
  scope.itemActionFn(scope.userDefinedExecutionContext, Object.create(item));
@@ -41811,7 +41942,7 @@ const getRequiredProviders = (nodeDef, providers, nodeAttrs) => {
41811
41942
  }
41812
41943
  });
41813
41944
  };
41814
- const ɵ11 = getRequiredProviders;
41945
+ const ɵ11$1 = getRequiredProviders;
41815
41946
  const DIMENSION_PROPS = ['padding', 'borderwidth', 'margin'];
41816
41947
  const SEPARATOR = ' ', UNSET = 'unset';
41817
41948
  const setDimensionProp = (cssObj, key, nv) => {
@@ -41846,7 +41977,7 @@ const setDimensionProp = (cssObj, key, nv) => {
41846
41977
  cssObj[cssKey] = nv;
41847
41978
  }
41848
41979
  };
41849
- const ɵ12 = setDimensionProp;
41980
+ const ɵ12$1 = setDimensionProp;
41850
41981
  const processDimensionAttributes = attrMap => {
41851
41982
  const attrKeys = Array.from(attrMap.keys());
41852
41983
  attrKeys.forEach((attrKey) => {
@@ -44999,8 +45130,8 @@ exports.transpile = transpile;
44999
45130
  exports.ɵ0 = ɵ0$h;
45000
45131
  exports.ɵ1 = ɵ1$5;
45001
45132
  exports.ɵ10 = ɵ10$1;
45002
- exports.ɵ11 = ɵ11;
45003
- exports.ɵ12 = ɵ12;
45133
+ exports.ɵ11 = ɵ11$1;
45134
+ exports.ɵ12 = ɵ12$1;
45004
45135
  exports.ɵ13 = ɵ13;
45005
45136
  exports.ɵ14 = ɵ14;
45006
45137
  exports.ɵ2 = ɵ2$4;