malinajs 0.7.13 → 0.7.14

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 (2) hide show
  1. package/malina.js +42 -34
  2. package/package.json +1 -1
package/malina.js CHANGED
@@ -21,7 +21,7 @@
21
21
  let prev = current_context;
22
22
  try {
23
23
  current_context = context;
24
- return fn();
24
+ return fn.call(context);
25
25
  } finally {
26
26
  current_context = prev;
27
27
  }
@@ -610,14 +610,10 @@
610
610
  });
611
611
  }
612
612
 
613
- let className = {};
614
- node.class.forEach(sel => {
615
- if(sel.$selector) sel = get_context().css.resolve(sel);
616
- className[sel] = true;
617
- });
618
- className = Object.keys(className).join(' ');
619
- if(className) ctx.write(` class="${className}"`);
620
-
613
+ if (node.class.size) {
614
+ ctx.add(get_context().css.resolveAsNode(node.class, [' class="', '"']));
615
+ }
616
+
621
617
  if(node.children.length) {
622
618
  ctx.write('>');
623
619
  node.children.forEach(n => ctx.build(n));
@@ -2372,13 +2368,13 @@
2372
2368
  ctx.writeLine(`${elName}.setAttribute('${a.name}', \`${Q(a.value)}\`);`);
2373
2369
  });
2374
2370
  }));
2371
+
2375
2372
  binds.push(xNode('bindClasses', { el }, (ctx, n) => {
2376
2373
  let el = n.el;
2374
+ if (!el.class.size) return;
2377
2375
  let elName = el.bindName();
2378
- if(el.class.size) {
2379
- let className = Array.from(el.class.values()).join(' ');
2380
- ctx.writeLine(`${elName}.className += ' ${className}';`);
2381
- }
2376
+ ctx.add(this.css.resolveAsNode(el.class, [`${elName}.className += ' `, `';`]));
2377
+ ctx.write(true);
2382
2378
  }));
2383
2379
  }
2384
2380
  bindTail.forEach(b => binds.push(b));
@@ -4839,6 +4835,18 @@
4839
4835
  return sel.local;
4840
4836
  };
4841
4837
 
4838
+ self.resolveAsNode = function(classList, wrap) {
4839
+ return xNode('resolve-class', { classList, wrap }, (ctx, n) => {
4840
+ let className = {};
4841
+ n.classList.forEach(sel => {
4842
+ if(sel.$selector) sel = this.resolve(sel);
4843
+ className[sel] = true;
4844
+ });
4845
+ className = Object.keys(className).join(' ');
4846
+ if(className) ctx.write(`${n.wrap[0]}${className}${n.wrap[1]}`);
4847
+ });
4848
+ };
4849
+
4842
4850
  self.getContent = function() {
4843
4851
  removeBlocks.forEach(node => {
4844
4852
  let i = node.parent.children.indexOf(node);
@@ -6879,7 +6887,7 @@
6879
6887
  });
6880
6888
  }
6881
6889
 
6882
- const version = '0.7.13';
6890
+ const version = '0.7.14';
6883
6891
 
6884
6892
 
6885
6893
  async function compile(source, config = {}) {
@@ -6983,7 +6991,7 @@
6983
6991
  }
6984
6992
  };
6985
6993
 
6986
- use_context(ctx, () => setup.call(ctx));
6994
+ use_context(ctx, setup);
6987
6995
 
6988
6996
  await hook(ctx, 'dom:before');
6989
6997
  ctx.parseHTML();
@@ -7010,7 +7018,7 @@
7010
7018
  await hook(ctx, 'js:before');
7011
7019
  ctx.js_parse();
7012
7020
  await hook(ctx, 'js');
7013
- use_context(ctx, () => ctx.js_transform());
7021
+ use_context(ctx, ctx.js_transform);
7014
7022
  await hook(ctx, 'js:after');
7015
7023
 
7016
7024
  await hook(ctx, 'css:before');
@@ -7019,38 +7027,38 @@
7019
7027
  await hook(ctx, 'css');
7020
7028
 
7021
7029
  await hook(ctx, 'runtime:before');
7022
- use_context(ctx, () => ctx.buildRuntime());
7030
+ use_context(ctx, ctx.buildRuntime);
7023
7031
  await hook(ctx, 'runtime');
7024
7032
 
7025
7033
  await hook(ctx, 'build:before');
7026
7034
 
7027
- use_context(ctx, () => {
7028
- const result = ctx.result = xNode('block');
7035
+ use_context(ctx, function() {
7036
+ const result = this.result = xNode('block');
7029
7037
  result.push('import * as $runtime from \'malinajs/runtime.js\';');
7030
7038
  result.push('import { $watch, $tick } from \'malinajs/runtime.js\';');
7031
- result.push(ctx.module.top);
7039
+ result.push(this.module.top);
7032
7040
  result.push(xNode('componentFn-wrapper', {
7033
- $compile: [ctx.module.head, ctx.module.code, ctx.module.body, ctx.glob.rootCD],
7041
+ $compile: [this.module.head, this.module.code, this.module.body, this.glob.rootCD],
7034
7042
  name: config.name,
7035
- componentFn: ctx.glob.componentFn
7036
- }, (ctx2, n) => {
7043
+ componentFn: this.glob.componentFn
7044
+ }, (ctx, n) => {
7037
7045
  if(config.exportDefault) {
7038
- if(ctx.glob.$$selfComponent.value) {
7039
- ctx2.write(true, 'const $$selfComponent = ');
7040
- ctx2.add(n.componentFn);
7041
- ctx2.write(true, 'export default $$selfComponent;');
7046
+ if(this.glob.$$selfComponent.value) {
7047
+ ctx.write(true, 'const $$selfComponent = ');
7048
+ ctx.add(n.componentFn);
7049
+ ctx.write(true, 'export default $$selfComponent;');
7042
7050
  } else {
7043
- ctx2.write(true, 'export default ');
7044
- ctx2.add(n.componentFn);
7051
+ ctx.write(true, 'export default ');
7052
+ ctx.add(n.componentFn);
7045
7053
  }
7046
7054
  } else {
7047
- assert(!ctx.glob.$$selfComponent.value, 'Not supported');
7048
- ctx2.write(true, `const ${n.name} = `);
7049
- ctx2.add(n.componentFn);
7055
+ assert(!this.glob.$$selfComponent.value, 'Not supported');
7056
+ ctx.write(true, `const ${n.name} = `);
7057
+ ctx.add(n.componentFn);
7050
7058
  }
7051
7059
  }));
7052
7060
 
7053
- ctx.result = xBuild(result);
7061
+ this.result = xBuild(result);
7054
7062
  });
7055
7063
 
7056
7064
  await hook(ctx, 'build');
@@ -7061,7 +7069,7 @@
7061
7069
  async function hook(ctx, name) {
7062
7070
  for(let i = 0; i < ctx.config.plugins.length; i++) {
7063
7071
  const fn = ctx.config.plugins[i][name];
7064
- if(fn) await use_context(ctx, () => fn(ctx));
7072
+ if(fn) await use_context(ctx, () => fn.call(ctx, ctx));
7065
7073
  }
7066
7074
  }
7067
7075
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "malinajs",
3
- "version": "0.7.13",
3
+ "version": "0.7.14",
4
4
  "license": "MIT",
5
5
  "scripts": {
6
6
  "build": "npm run build_runtime && rollup -c",