@wavemaker/angular-codegen 11.1.0-next.24309 → 11.1.0-next.24312

Sign up to get free protection for your applications and to get access to all the features.
@@ -41328,9 +41328,12 @@ class ASTCompiler {
41328
41328
  cleanup() {
41329
41329
  this.ast = this.cAst = this.stmts = this.cStmts = this.declarations = this.pipes = this.pipeNameVsIsPureMap = undefined;
41330
41330
  }
41331
- compile() {
41331
+ compile(defOnly) {
41332
41332
  this.extendCtxWithLocals();
41333
41333
  this.addReturnStmt(this.build(this.ast));
41334
+ if (defOnly) {
41335
+ return { fnBody: this.fnBody(), fnArgs: this.fnArgs(), pipes: this.pipes };
41336
+ }
41334
41337
  const fn = new Function(this.fnArgs(), this.fnBody());
41335
41338
  let boundFn;
41336
41339
  if (this.exprType === ExpressionType$1.Binding) {
@@ -41349,13 +41352,27 @@ const nullPipe = () => {
41349
41352
  transform: noop$1$1
41350
41353
  };
41351
41354
  };
41355
+ let _cspEnabled;
41356
+ const isCSPEnabled = () => {
41357
+ if (typeof _cspEnabled !== 'undefined') {
41358
+ return _cspEnabled;
41359
+ }
41360
+ try {
41361
+ new Function();
41362
+ _cspEnabled = false;
41363
+ }
41364
+ catch (e) {
41365
+ _cspEnabled = true;
41366
+ }
41367
+ return _cspEnabled;
41368
+ };
41352
41369
  let pipeProvider;
41353
41370
  var ExpressionType$1;
41354
41371
  (function (ExpressionType$$1) {
41355
41372
  ExpressionType$$1[ExpressionType$$1["Binding"] = 0] = "Binding";
41356
41373
  ExpressionType$$1[ExpressionType$$1["Action"] = 1] = "Action";
41357
41374
  })(ExpressionType$1 || (ExpressionType$1 = {}));
41358
- function $parseExpr(expr) {
41375
+ function $parseExpr(expr, defOnly) {
41359
41376
  if (!pipeProvider) {
41360
41377
  console.log('set pipe provider');
41361
41378
  return noop$1$1;
@@ -41374,51 +41391,89 @@ function $parseExpr(expr) {
41374
41391
  if (fn) {
41375
41392
  return fn;
41376
41393
  }
41377
- const parser = new Parser$1(new Lexer);
41378
- const ast = parser.parseBinding(expr, '', 0);
41379
41394
  let boundFn;
41380
- if (ast.errors.length) {
41381
- fn = noop$1$1;
41382
- boundFn = fn;
41383
- }
41384
- else {
41385
- const pipeNameVsIsPureMap = pipeProvider.getPipeNameVsIsPureMap();
41386
- const astCompiler = new ASTCompiler(ast.ast, ExpressionType$1.Binding, pipeNameVsIsPureMap);
41387
- fn = astCompiler.compile();
41388
- if (fn.usedPipes.length) {
41389
- const pipeArgs = [];
41390
- let hasPurePipe = false;
41391
- for (const [pipeName] of fn.usedPipes) {
41392
- const pipeInfo = pipeProvider.meta(pipeName);
41393
- let pipeInstance;
41394
- if (!pipeInfo) {
41395
- pipeInstance = nullPipe;
41395
+ if (!defOnly) {
41396
+ boundFn = getFnForBindExpr(expr);
41397
+ }
41398
+ // fallback to generate function in runtime. This will break if CSP is enabled
41399
+ if (!boundFn) {
41400
+ // If CSP enabled, function def not found from the generated fn expressions for the page.
41401
+ // Handle bind expressions used internally inside WM components. e.g. wmAnchor used inside nav.comp.html
41402
+ if (isCSPEnabled()) {
41403
+ boundFn = function (ctx, locals) {
41404
+ // handle internal bindings for wm widgets used inside a component
41405
+ let _ctx = Object.assign({}, locals);
41406
+ Object.setPrototypeOf(_ctx, ctx);
41407
+ return _.get(_ctx, expr);
41408
+ };
41409
+ }
41410
+ else {
41411
+ const parser = new Parser$1(new Lexer);
41412
+ const ast = parser.parseBinding(expr, '', 0);
41413
+ if (ast.errors.length) {
41414
+ fn = noop$1$1;
41415
+ boundFn = fn;
41416
+ }
41417
+ else {
41418
+ const pipeNameVsIsPureMap = pipeProvider.getPipeNameVsIsPureMap();
41419
+ const astCompiler = new ASTCompiler(ast.ast, ExpressionType$1.Binding, pipeNameVsIsPureMap);
41420
+ fn = astCompiler.compile(defOnly);
41421
+ if (defOnly) {
41422
+ return fn;
41423
+ }
41424
+ if (fn.usedPipes.length) {
41425
+ const pipeArgs = [];
41426
+ let hasPurePipe = false;
41427
+ for (const [pipeName] of fn.usedPipes) {
41428
+ const pipeInfo = pipeProvider.meta(pipeName);
41429
+ let pipeInstance;
41430
+ if (!pipeInfo) {
41431
+ pipeInstance = nullPipe;
41432
+ }
41433
+ else {
41434
+ if (pipeInfo.pure) {
41435
+ hasPurePipe = true;
41436
+ pipeInstance = purePipes.get(pipeName);
41437
+ }
41438
+ if (!pipeInstance) {
41439
+ pipeInstance = pipeProvider.getInstance(pipeName);
41440
+ }
41441
+ if (pipeInfo.pure) {
41442
+ purePipes.set(pipeName, pipeInstance);
41443
+ }
41444
+ }
41445
+ pipeArgs.push(pipeInstance);
41446
+ }
41447
+ pipeArgs.unshift(hasPurePipe ? new Map() : undefined);
41448
+ boundFn = fn.bind(undefined, ...pipeArgs);
41396
41449
  }
41397
41450
  else {
41398
- if (pipeInfo.pure) {
41399
- hasPurePipe = true;
41400
- pipeInstance = purePipes.get(pipeName);
41401
- }
41402
- if (!pipeInstance) {
41403
- pipeInstance = pipeProvider.getInstance(pipeName);
41404
- }
41405
- if (pipeInfo.pure) {
41406
- purePipes.set(pipeName, pipeInstance);
41407
- }
41451
+ boundFn = fn.bind(undefined, undefined);
41408
41452
  }
41409
- pipeArgs.push(pipeInstance);
41410
41453
  }
41411
- pipeArgs.unshift(hasPurePipe ? new Map() : undefined);
41412
- boundFn = fn.bind(undefined, ...pipeArgs);
41413
- }
41414
- else {
41415
- boundFn = fn.bind(undefined, undefined);
41416
41454
  }
41417
41455
  }
41418
41456
  exprFnCache.set(expr, boundFn);
41419
41457
  return boundFn;
41420
41458
  }
41421
- function $parseEvent(expr) {
41459
+ function simpleFunctionEvaluator(expr, ctx, locals) {
41460
+ let _ctx = Object.assign({}, locals);
41461
+ Object.setPrototypeOf(_ctx, ctx);
41462
+ let parts = expr.split('(');
41463
+ let fnName = parts[0];
41464
+ let computedFn = _.get(ctx, fnName);
41465
+ if (computedFn) {
41466
+ let args = parts[1].replace(')', '');
41467
+ args = args.split(',');
41468
+ let computedArgs = [];
41469
+ args.forEach((arg) => {
41470
+ arg = arg && arg.trim();
41471
+ computedArgs.push(_.get(_ctx, arg));
41472
+ });
41473
+ return computedFn.bind(_ctx)(...computedArgs);
41474
+ }
41475
+ }
41476
+ function $parseEvent(expr, defOnly) {
41422
41477
  if (!isString$1(expr)) {
41423
41478
  return noop$1$1;
41424
41479
  }
@@ -41430,16 +41485,80 @@ function $parseEvent(expr) {
41430
41485
  if (fn) {
41431
41486
  return fn;
41432
41487
  }
41433
- const parser = new Parser$1(new Lexer);
41434
- const ast = parser.parseAction(expr, '', 0);
41435
- if (ast.errors.length) {
41436
- return noop$1$1;
41488
+ if (!defOnly) {
41489
+ fn = getFnForEventExpr(expr);
41490
+ }
41491
+ // fallback to generate function in runtime. This will break if CSP is enabled
41492
+ if (!fn) {
41493
+ if (isCSPEnabled()) {
41494
+ fn = simpleFunctionEvaluator.bind(undefined, expr);
41495
+ }
41496
+ else {
41497
+ const parser = new Parser$1(new Lexer);
41498
+ const ast = parser.parseAction(expr, '', 0);
41499
+ if (ast.errors.length) {
41500
+ return noop$1$1;
41501
+ }
41502
+ const astCompiler = new ASTCompiler(ast.ast, ExpressionType$1.Action);
41503
+ fn = astCompiler.compile(defOnly);
41504
+ }
41437
41505
  }
41438
- const astCompiler = new ASTCompiler(ast.ast, ExpressionType$1.Action);
41439
- fn = astCompiler.compile();
41440
41506
  eventFnCache.set(expr, fn);
41441
41507
  return fn;
41442
41508
  }
41509
+ const fnNameMap = new Map();
41510
+ const getFnByExpr = (expr) => fnNameMap.get(expr);
41511
+ const fnExecutor = (expr, exprType) => {
41512
+ let fn = getFnByExpr(expr);
41513
+ if (!fn) {
41514
+ return;
41515
+ }
41516
+ const usedPipes = fn.usedPipes || [];
41517
+ if (exprType === ExpressionType$1.Binding) {
41518
+ fn = fn.bind(undefined, plus, minus, isDef, getPurePipeVal);
41519
+ }
41520
+ else {
41521
+ fn = fn.bind(undefined, plus, minus, isDef);
41522
+ }
41523
+ if (usedPipes.length) {
41524
+ const pipeArgs = [];
41525
+ let hasPurePipe = false;
41526
+ for (const [pipeName] of usedPipes) {
41527
+ const pipeInfo = pipeProvider.meta(pipeName);
41528
+ let pipeInstance;
41529
+ if (!pipeInfo) {
41530
+ pipeInstance = nullPipe;
41531
+ }
41532
+ else {
41533
+ if (pipeInfo.pure) {
41534
+ hasPurePipe = true;
41535
+ pipeInstance = purePipes.get(pipeName);
41536
+ }
41537
+ if (!pipeInstance) {
41538
+ pipeInstance = pipeProvider.getInstance(pipeName);
41539
+ }
41540
+ if (pipeInfo.pure) {
41541
+ purePipes.set(pipeName, pipeInstance);
41542
+ }
41543
+ }
41544
+ pipeArgs.push(pipeInstance);
41545
+ }
41546
+ pipeArgs.unshift(hasPurePipe ? new Map() : undefined);
41547
+ fn = fn.bind(undefined, ...pipeArgs);
41548
+ }
41549
+ else {
41550
+ if (exprType === ExpressionType$1.Binding) {
41551
+ fn = fn.bind(undefined, undefined);
41552
+ }
41553
+ }
41554
+ return fn;
41555
+ };
41556
+ const getFnForBindExpr = (expr) => {
41557
+ return fnExecutor(expr, ExpressionType$1.Binding);
41558
+ };
41559
+ const getFnForEventExpr = (expr) => {
41560
+ return fnExecutor(expr, ExpressionType$1.Action);
41561
+ };
41443
41562
 
41444
41563
  const registry = new Map();
41445
41564
  const watchIdGenerator = new IDGenerator('watch-id-');
@@ -42280,10 +42399,26 @@ const loadScript = (url, loadViaScriptTag, cacheable = false) => __awaiter$1(voi
42280
42399
  return Promise.resolve();
42281
42400
  }
42282
42401
  if (loadViaScriptTag) {
42283
- return fetchContent('text', _url, false, text => {
42284
- const script = document.createElement('script');
42285
- script.textContent = text;
42286
- document.head.appendChild(script);
42402
+ return new Promise((resolve, reject) => {
42403
+ let script = document.createElement('script');
42404
+ script.type = 'text/javascript';
42405
+ script.src = _url;
42406
+ script.async = false;
42407
+ if (script.readyState) { //IE
42408
+ script.onreadystatechange = () => {
42409
+ if (script.readyState === "loaded" || script.readyState === "complete") {
42410
+ script.onreadystatechange = null;
42411
+ resolve(true);
42412
+ }
42413
+ };
42414
+ }
42415
+ else { //Other browsers
42416
+ script.onload = () => {
42417
+ resolve(true);
42418
+ };
42419
+ }
42420
+ script.onerror = (error) => reject(error);
42421
+ document.getElementsByTagName('head')[0].appendChild(script);
42287
42422
  });
42288
42423
  }
42289
42424
  else if (cacheable) {
@@ -42299,13 +42434,6 @@ const loadScript = (url, loadViaScriptTag, cacheable = false) => __awaiter$1(voi
42299
42434
  .done(response => response)
42300
42435
  .fail(reason => reason);
42301
42436
  }
42302
- // return fetch(_url)
42303
- // .then(response => response.text())
42304
- // .then(text => {
42305
- // const script = document.createElement('script');
42306
- // script.textContent = text;
42307
- // document.head.appendChild(script);
42308
- // });
42309
42437
  });
42310
42438
  const loadScripts = (urls = [], loadViaScriptTag = true) => __awaiter$1(void 0, void 0, void 0, function* () {
42311
42439
  for (const url of urls) {
@@ -42335,7 +42463,8 @@ const setSessionStorageItem = (key, value) => {
42335
42463
  * @param key string
42336
42464
  */
42337
42465
  const getSessionStorageItem = key => {
42338
- let item = window.sessionStorage.getItem(_WM_APP_PROJECT.id);
42466
+ // sanity check for this to work with ng-codegen
42467
+ let item = window && window.sessionStorage && window.sessionStorage.getItem(_WM_APP_PROJECT.id);
42339
42468
  if (item) {
42340
42469
  item = JSON.parse(item);
42341
42470
  return item[key];
@@ -42559,6 +42688,7 @@ const processFilterExpBindNode = (context, filterExpressions) => {
42559
42688
  const filter$ = new Subject();
42560
42689
  const bindFilExpObj = (obj, targetNodeKey) => {
42561
42690
  if (stringStartsWith(obj[targetNodeKey], 'bind:')) {
42691
+ // [Todo-CSP]: needs a check, where is this used
42562
42692
  destroyFn($watch(obj[targetNodeKey].replace('bind:', ''), context, {}, (newVal, oldVal) => {
42563
42693
  if ((newVal === oldVal && _.isUndefined(newVal)) || (_.isUndefined(newVal) && !_.isUndefined(oldVal))) {
42564
42694
  return;
@@ -42802,6 +42932,7 @@ const triggerItemAction = (scope, item) => {
42802
42932
  const linkTarget = item.target;
42803
42933
  if (itemAction) {
42804
42934
  if (!scope.itemActionFn) {
42935
+ //[Todo-CSP]: This will not work as function will be dynamic
42805
42936
  scope.itemActionFn = $parseEvent(itemAction);
42806
42937
  }
42807
42938
  scope.itemActionFn(scope.userDefinedExecutionContext, Object.create(item));
@@ -44517,7 +44648,7 @@ const getRequiredProviders = (nodeDef, providers, nodeAttrs) => {
44517
44648
  }
44518
44649
  });
44519
44650
  };
44520
- const ɵ11 = getRequiredProviders;
44651
+ const ɵ11$1 = getRequiredProviders;
44521
44652
  const DIMENSION_PROPS = ['padding', 'borderwidth', 'margin'];
44522
44653
  const SEPARATOR = ' ', UNSET = 'unset';
44523
44654
  const setDimensionProp = (cssObj, key, nv) => {
@@ -44552,7 +44683,7 @@ const setDimensionProp = (cssObj, key, nv) => {
44552
44683
  cssObj[cssKey] = nv;
44553
44684
  }
44554
44685
  };
44555
- const ɵ12 = setDimensionProp;
44686
+ const ɵ12$1 = setDimensionProp;
44556
44687
  const processDimensionAttributes = attrMap => {
44557
44688
  const attrKeys = Array.from(attrMap.keys());
44558
44689
  attrKeys.forEach((attrKey) => {
@@ -47705,8 +47836,8 @@ exports.transpile = transpile;
47705
47836
  exports.ɵ0 = ɵ0$h;
47706
47837
  exports.ɵ1 = ɵ1$5;
47707
47838
  exports.ɵ10 = ɵ10$1;
47708
- exports.ɵ11 = ɵ11;
47709
- exports.ɵ12 = ɵ12;
47839
+ exports.ɵ11 = ɵ11$1;
47840
+ exports.ɵ12 = ɵ12$1;
47710
47841
  exports.ɵ13 = ɵ13;
47711
47842
  exports.ɵ14 = ɵ14;
47712
47843
  exports.ɵ2 = ɵ2$4;