malinajs 0.7.11 → 0.7.13

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.
Files changed (3) hide show
  1. package/malina.js +73 -46
  2. package/package.json +1 -1
  3. package/runtime.js +5 -4
package/malina.js CHANGED
@@ -1,12 +1,14 @@
1
1
  (function (global, factory) {
2
2
  typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('acorn'), require('astring'), require('css-tree')) :
3
3
  typeof define === 'function' && define.amd ? define(['exports', 'acorn', 'astring', 'css-tree'], factory) :
4
- (global = global || self, factory(global.malina = {}, global.acorn, global.astring, global['css-tree']));
5
- }(this, (function (exports, acorn, astring, csstree) { 'use strict';
4
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.malina = {}, global.acorn, global.astring, global["css-tree"]));
5
+ })(this, (function (exports, acorn, astring, csstree) { 'use strict';
6
6
 
7
- acorn = acorn && Object.prototype.hasOwnProperty.call(acorn, 'default') ? acorn['default'] : acorn;
8
- astring = astring && Object.prototype.hasOwnProperty.call(astring, 'default') ? astring['default'] : astring;
9
- csstree = csstree && Object.prototype.hasOwnProperty.call(csstree, 'default') ? csstree['default'] : csstree;
7
+ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
8
+
9
+ var acorn__default = /*#__PURE__*/_interopDefaultLegacy(acorn);
10
+ var astring__default = /*#__PURE__*/_interopDefaultLegacy(astring);
11
+ var csstree__default = /*#__PURE__*/_interopDefaultLegacy(csstree);
10
12
 
11
13
  let current_context;
12
14
 
@@ -72,7 +74,7 @@
72
74
  function detectExpressionType(name) {
73
75
  if(isSimpleName(name)) return 'identifier';
74
76
 
75
- let ast = acorn.parse(name, { allowReturnOutsideFunction: true, ecmaVersion: 'latest' });
77
+ let ast = acorn__default["default"].parse(name, { allowReturnOutsideFunction: true, ecmaVersion: 'latest' });
76
78
 
77
79
  function checkIdentificator(body) {
78
80
  if(body.length != 1) return;
@@ -139,7 +141,7 @@
139
141
 
140
142
 
141
143
  const extractKeywords = (exp) => {
142
- let ast = acorn.parse(exp, { sourceType: 'module', ecmaVersion: 'latest' });
144
+ let ast = acorn__default["default"].parse(exp, { sourceType: 'module', ecmaVersion: 'latest' });
143
145
 
144
146
  const keys = new Set();
145
147
  const rec = (n) => {
@@ -197,8 +199,8 @@
197
199
 
198
200
  const parseJS = (exp, option) => {
199
201
  let self = {};
200
- if(option === true) self.ast = acorn.parse(exp, { ecmaVersion: 'latest' });
201
- else self.ast = acorn.parseExpressionAt(exp, 0, { ecmaVersion: 'latest' });
202
+ if(option === true) self.ast = acorn__default["default"].parse(exp, { ecmaVersion: 'latest' });
203
+ else self.ast = acorn__default["default"].parseExpressionAt(exp, 0, { ecmaVersion: 'latest' });
202
204
 
203
205
  self.transform = function(fn) {
204
206
  const rec = (n, pk) => {
@@ -229,7 +231,7 @@
229
231
  };
230
232
 
231
233
  self.build = function(data) {
232
- return astring.generate(data || self.ast, { indent: '', lineEnd: '' });
234
+ return astring__default["default"].generate(data || self.ast, { indent: '', lineEnd: '' });
233
235
  };
234
236
  return self;
235
237
  };
@@ -404,6 +406,18 @@
404
406
  xNode(data, handler)
405
407
  xNode(handler)
406
408
  xNode(xNode, data, handler)
409
+
410
+ $wait - wait for a node be processed
411
+ $hold - hold a node from processing
412
+
413
+ xNode('name', {
414
+ $wait: ['apply', 'rootCD', anotherNode],
415
+ $hold: ['apply', 'anotherNode']
416
+ }, (ctx, node) => {
417
+ this.inuse.apply // check if apply is used
418
+ this.inuse.rootCD // check if rootCD is used
419
+ node.$wait[0].value // check value of first node in $wait
420
+ })
407
421
  */
408
422
  if(_type instanceof xNode) {
409
423
  let n = _type;
@@ -963,17 +977,17 @@
963
977
  const reader = new Reader(source);
964
978
 
965
979
  const readScript = (reader) => {
966
- class ScriptParser extends acorn.Parser {
980
+ class ScriptParser extends acorn__default["default"].Parser {
967
981
  readToken_lt_gt(code) {
968
982
  if (this.input.slice(this.pos, this.pos + 9) == '</script>') {
969
- return this.finishToken(acorn.tokTypes.eof);
983
+ return this.finishToken(acorn__default["default"].tokTypes.eof);
970
984
  }
971
985
  return super.readToken_lt_gt(code);
972
986
  }
973
987
 
974
988
  scan() {
975
989
  this.nextToken();
976
- while (this.type !== acorn.tokTypes.eof) {
990
+ while (this.type !== acorn__default["default"].tokTypes.eof) {
977
991
  this.parseStatement(null, true, null);
978
992
  }
979
993
  return this.end;
@@ -1219,7 +1233,7 @@
1219
1233
  elArg = reader.read(/^[^\s>/]+/);
1220
1234
  }
1221
1235
 
1222
- let attributes = parseAttibutes(reader, {closedByTag: true});
1236
+ let attributes = parseAttibutes$1(reader, {closedByTag: true});
1223
1237
 
1224
1238
  let closedTag = false;
1225
1239
  if(reader.readIf('/>')) closedTag = true;
@@ -1370,7 +1384,7 @@
1370
1384
  };
1371
1385
 
1372
1386
 
1373
- const parseAttibutes = (source, option={}) => {
1387
+ const parseAttibutes$1 = (source, option={}) => {
1374
1388
  const r = new Reader(source);
1375
1389
  let result = [];
1376
1390
 
@@ -1450,7 +1464,7 @@
1450
1464
  if(isBlockComment) return;
1451
1465
  this.script.comments.push({ start, end, value });
1452
1466
  };
1453
- this.script.ast = acorn.parse(source, { sourceType: 'module', ecmaVersion: 'latest', onComment });
1467
+ this.script.ast = acorn__default["default"].parse(source, { sourceType: 'module', ecmaVersion: 'latest', onComment });
1454
1468
 
1455
1469
  if(source.includes('$props')) this.require('$props');
1456
1470
  if(source.includes('$attributes')) this.require('$attributes');
@@ -1631,10 +1645,10 @@
1631
1645
  target = ex.left.name;
1632
1646
  if(!(target in rootVariables)) resultBody.push(makeVariable(target));
1633
1647
  } else if(ex.left.type == 'MemberExpression') {
1634
- target = astring.generate(ex.left);
1648
+ target = astring__default["default"].generate(ex.left);
1635
1649
  } else throw 'Error';
1636
1650
  assertExpression(ex.right);
1637
- const exp = astring.generate(ex.right);
1651
+ const exp = astring__default["default"].generate(ex.right);
1638
1652
  watchers.push(xNode('watch-assign', {
1639
1653
  $wait: ['apply'],
1640
1654
  target,
@@ -1646,7 +1660,7 @@
1646
1660
  } else if(n.body.expression.type == 'SequenceExpression') {
1647
1661
  const ex = n.body.expression.expressions;
1648
1662
  const handler = last(ex);
1649
- let callback = astring.generate(handler);
1663
+ let callback = astring__default["default"].generate(handler);
1650
1664
  if(handler.type == 'ArrowFunctionExpression' || handler.type == 'FunctionExpression') ; else if(detectExpressionType(callback) == 'identifier') {
1651
1665
  callback = `(v) => { ${callback}(v); }`;
1652
1666
  } else {
@@ -1657,7 +1671,7 @@
1657
1671
  assertExpression(ex[0]);
1658
1672
  watchers.push(xNode('watch-expression', {
1659
1673
  $wait: ['apply'],
1660
- exp: astring.generate(ex[0]),
1674
+ exp: astring__default["default"].generate(ex[0]),
1661
1675
  callback
1662
1676
  }, (ctx, n) => {
1663
1677
  if(this.inuse.apply) {
@@ -1676,7 +1690,7 @@
1676
1690
 
1677
1691
  watchers.push(xNode('watch-expression', {
1678
1692
  $wait: ['apply'],
1679
- exp: astring.generate(exp),
1693
+ exp: astring__default["default"].generate(exp),
1680
1694
  callback
1681
1695
  }, (ctx, n) => {
1682
1696
  if(this.inuse.apply) ctx.write(true, `$watch(() => ${n.exp}, ($args) => { (${n.callback}).apply(null, $args); }, {cmp: $runtime.deepComparator(1)});`);
@@ -1735,7 +1749,7 @@
1735
1749
  if(d.init.type == 'Literal') {
1736
1750
  p.value = d.init.raw;
1737
1751
  } else {
1738
- p.value = astring.generate(d.init);
1752
+ p.value = astring__default["default"].generate(d.init);
1739
1753
  }
1740
1754
  }
1741
1755
  result.props.push(p);
@@ -1867,12 +1881,12 @@
1867
1881
  if(statement.type != 'Raw') state.write(lineEnd);
1868
1882
  }
1869
1883
  }
1870
- }, astring.baseGenerator);
1884
+ }, astring__default["default"].baseGenerator);
1871
1885
 
1872
1886
 
1873
1887
  xNode.init.ast = (ctx, node) => {
1874
1888
  if(!node.body.length) return;
1875
- let code = astring.generate({
1889
+ let code = astring__default["default"].generate({
1876
1890
  type: 'CustomBlock',
1877
1891
  body: node.body
1878
1892
  }, { generator, startingIndentLevel: 0 });
@@ -4555,7 +4569,7 @@
4555
4569
 
4556
4570
  const selector2str = (sel) => {
4557
4571
  if(!sel.children) sel = { type: 'Selector', children: sel };
4558
- return csstree.generate(sel);
4572
+ return csstree__default["default"].generate(sel);
4559
4573
  };
4560
4574
 
4561
4575
  const convertAst = (node, parent) => {
@@ -4570,7 +4584,7 @@
4570
4584
  };
4571
4585
 
4572
4586
  const parseCSS = (content, option) => {
4573
- let ast = csstree.parse(content, option);
4587
+ let ast = csstree__default["default"].parse(content, option);
4574
4588
  return convertAst(ast, null);
4575
4589
  };
4576
4590
 
@@ -4591,7 +4605,7 @@
4591
4605
  let ast = parseCSS(styleNode.content);
4592
4606
  astList.push(ast);
4593
4607
 
4594
- csstree.walk(ast, function(node) {
4608
+ csstree__default["default"].walk(ast, function(node) {
4595
4609
  if(node.type == 'Declaration') {
4596
4610
  if(node.property == 'animation' || node.property == 'animation-name') {
4597
4611
  let c = node.value.children[0];
@@ -4832,7 +4846,7 @@
4832
4846
  });
4833
4847
  resolveHashes();
4834
4848
 
4835
- return astList.map(ast => csstree.generate(ast)).join('');
4849
+ return astList.map(ast => csstree__default["default"].generate(ast)).join('');
4836
4850
  };
4837
4851
  }
4838
4852
 
@@ -5107,8 +5121,7 @@
5107
5121
  if(name[0] == '#') {
5108
5122
  assert(!value, 'Wrong ref');
5109
5123
  name = name.substring(1);
5110
- assert(isSimpleName(name), name);
5111
- this.checkRootName(name);
5124
+ assert(detectExpressionType(name) == 'identifier', name);
5112
5125
  reference = name;
5113
5126
  return;
5114
5127
  } else if(name[0] == ':' || name.startsWith('bind:')) {
@@ -6015,19 +6028,26 @@
6015
6028
  if(block.singleBlock) {
6016
6029
  itemBlock = xNode('each-component', {
6017
6030
  block: block.singleBlock,
6031
+ reference: block.reference,
6018
6032
  rebind,
6019
6033
  itemName,
6020
6034
  indexName
6021
6035
  }, (ctx, n) => {
6022
6036
  ctx.write(`$runtime.makeEachSingleBlock((${n.itemName}`);
6023
- if(n.indexName) ctx.write(`, ${n.indexName}`);
6037
+ if (n.indexName) ctx.write(`, ${n.indexName}`);
6024
6038
  ctx.write(') => [');
6025
6039
  ctx.indent++;
6026
6040
  ctx.write(true);
6027
- if(n.rebind) ctx.add(n.rebind);
6041
+ if (n.rebind) ctx.add(n.rebind);
6028
6042
  else ctx.write('null');
6029
6043
  ctx.write(',', true);
6030
- ctx.add(n.block);
6044
+ if (n.reference) {
6045
+ ctx.write(true, `(${n.reference} = `);
6046
+ ctx.add(n.block);
6047
+ ctx.write(')', true);
6048
+ } else {
6049
+ ctx.add(n.block);
6050
+ }
6031
6051
  ctx.indent--;
6032
6052
  ctx.write(true, '])');
6033
6053
  });
@@ -6294,7 +6314,7 @@
6294
6314
  }
6295
6315
 
6296
6316
 
6297
- function parseAttibutes$1(attributes) {
6317
+ function parseAttibutes(attributes) {
6298
6318
  let props = [];
6299
6319
  let events = [];
6300
6320
  let forwardAllEvents;
@@ -6339,7 +6359,7 @@
6339
6359
  let slot = null;
6340
6360
  if(node.body?.length) slot = this.buildBlock({ body: trimEmptyNodes(node.body) }, { inline: true });
6341
6361
 
6342
- let { props, events, forwardAllEvents, staticProps } = parseAttibutes$1.call(this, node.attributes);
6362
+ let { props, events, forwardAllEvents, staticProps } = parseAttibutes.call(this, node.attributes);
6343
6363
 
6344
6364
  return xNode('call-fragment', {
6345
6365
  $compile: [slot?.source],
@@ -6439,7 +6459,7 @@
6439
6459
  // assert(!data.slot.template.svg, 'SVG is not supported for exported fragment');
6440
6460
  }
6441
6461
 
6442
- let pa = parseAttibutes$1.call(this, node.attributes);
6462
+ let pa = parseAttibutes.call(this, node.attributes);
6443
6463
  data = { ...pa, ...data };
6444
6464
 
6445
6465
  return xNode('attach-exported-fragment', data, (ctx, n) => {
@@ -6456,13 +6476,20 @@
6456
6476
  ctx.add(n.slot.template);
6457
6477
  ctx.write(')');
6458
6478
  } else {
6459
- ctx.write('$runtime.makeBlockBound(');
6460
- ctx.add(n.slot.template);
6461
- ctx.write(', ($parentElement) => {', true);
6462
- ctx.indent++;
6463
- ctx.add(n.slot.source);
6464
- ctx.indent--;
6465
- ctx.write(true, '})');
6479
+ ctx.add(xNode('make-block', {
6480
+ $wait: ['apply'],
6481
+ template: n.slot.template,
6482
+ source: n.slot.source
6483
+ }, (ctx, n) => {
6484
+ if(this.inuse.apply) ctx.write('$runtime.makeBlockBound(');
6485
+ else ctx.write('$runtime.makeBlock(');
6486
+ ctx.add(n.template);
6487
+ ctx.write(', ($parentElement) => {', true);
6488
+ ctx.indent++;
6489
+ ctx.add(n.source);
6490
+ ctx.indent--;
6491
+ ctx.write(true, '})');
6492
+ }));
6466
6493
  }
6467
6494
  } else missed = ', null';
6468
6495
 
@@ -6829,7 +6856,7 @@
6829
6856
  let key = null;
6830
6857
  let args = node.value.substr(6);
6831
6858
  if(args) {
6832
- args = parseAttibutes(args);
6859
+ args = parseAttibutes$1(args);
6833
6860
  const a = args.find(a => a.name == 'key');
6834
6861
  if(a) {
6835
6862
  let value = a.value;
@@ -6852,7 +6879,7 @@
6852
6879
  });
6853
6880
  }
6854
6881
 
6855
- const version = '0.7.11';
6882
+ const version = '0.7.13';
6856
6883
 
6857
6884
 
6858
6885
  async function compile(source, config = {}) {
@@ -7113,5 +7140,5 @@
7113
7140
 
7114
7141
  Object.defineProperty(exports, '__esModule', { value: true });
7115
7142
 
7116
- })));
7143
+ }));
7117
7144
  //# sourceMappingURL=malina.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "malinajs",
3
- "version": "0.7.11",
3
+ "version": "0.7.13",
4
4
  "license": "MIT",
5
5
  "scripts": {
6
6
  "build": "npm run build_runtime && rollup -c",
package/runtime.js CHANGED
@@ -178,11 +178,13 @@ const keyComparator = (w, value) => {
178
178
 
179
179
 
180
180
  const fire = w => {
181
- if(w.cmp) w.cmp(w, w.fn());
181
+ let value = w.fn();
182
+ if(w.cmp) w.cmp(w, value);
182
183
  else {
183
- w.value = w.fn();
184
+ w.value = value;
184
185
  w.cb(w.value);
185
186
  }
187
+ return value;
186
188
  };
187
189
 
188
190
  function $digest($cd, flag) {
@@ -373,8 +375,7 @@ const callComponentDyn = (component, context, option = {}, propFn, cmp, setter,
373
375
  $component.$push?.(value);
374
376
  $component.$apply?.();
375
377
  }, { value: {}, idle: true, cmp });
376
- fire(parentWatch);
377
- option.props = parentWatch.value;
378
+ option.props = fire(parentWatch);
378
379
  }
379
380
 
380
381
  if(classFn) {