malinajs 0.7.2-a6 → 0.7.2-a8
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/CHANGELOG.md +1 -0
- package/malina.js +82 -47
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
package/malina.js
CHANGED
|
@@ -1351,27 +1351,40 @@
|
|
|
1351
1351
|
if(r.probe('/>') || r.probe('>')) break;
|
|
1352
1352
|
} else if(r.end()) break;
|
|
1353
1353
|
let start = r.index;
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1354
|
+
if(r.probe('{*')) {
|
|
1355
|
+
const {raw} = parseBinding(r);
|
|
1356
|
+
result.push({name: raw, content: raw});
|
|
1357
|
+
} else if(r.probe('*{')) {
|
|
1358
|
+
r.read();
|
|
1359
|
+
let {raw} = parseBinding(r);
|
|
1360
|
+
raw = '*' + raw;
|
|
1361
|
+
result.push({name: raw, content: raw});
|
|
1362
|
+
} else if(r.probe('{...')) {
|
|
1363
|
+
let {raw} = parseBinding(r);
|
|
1364
|
+
result.push({name: raw, content: raw});
|
|
1365
|
+
} else {
|
|
1366
|
+
let name = r.readAttribute();
|
|
1367
|
+
assert(name, 'Wrong syntax');
|
|
1368
|
+
if(r.readIf('=')) {
|
|
1369
|
+
if(r.probe('{')) {
|
|
1370
|
+
const {raw} = parseBinding(r);
|
|
1371
|
+
result.push({name, value: raw, raw, content: r.sub(start)});
|
|
1372
|
+
} else if(r.probeQuote()) {
|
|
1373
|
+
const raw = r.readString();
|
|
1374
|
+
const value = raw.substring(1, raw.length - 1);
|
|
1375
|
+
result.push({name, value, raw, content: r.sub(start)});
|
|
1376
|
+
} else {
|
|
1377
|
+
const value = r.readIf(/^\S+/);
|
|
1378
|
+
result.push({name, value, raw: value, content: r.sub(start)});
|
|
1379
|
+
}
|
|
1364
1380
|
} else {
|
|
1365
|
-
|
|
1381
|
+
let value;
|
|
1382
|
+
if(name[0] == '{' && last(name) == '}' && !name.startsWith('{...')) {
|
|
1383
|
+
value = name;
|
|
1384
|
+
name = unwrapExp(name);
|
|
1385
|
+
}
|
|
1366
1386
|
result.push({name, value, raw: value, content: r.sub(start)});
|
|
1367
1387
|
}
|
|
1368
|
-
} else {
|
|
1369
|
-
let value;
|
|
1370
|
-
if(name[0] == '{' && last(name) == '}' && !name.startsWith('{...')) {
|
|
1371
|
-
value = name;
|
|
1372
|
-
name = unwrapExp(name);
|
|
1373
|
-
}
|
|
1374
|
-
result.push({name, value, raw: value, content: r.sub(start)});
|
|
1375
1388
|
}
|
|
1376
1389
|
}
|
|
1377
1390
|
|
|
@@ -2174,7 +2187,13 @@
|
|
|
2174
2187
|
if(n.name == 'malina' && !option.malinaElement) {
|
|
2175
2188
|
let b;
|
|
2176
2189
|
if(n.elArg == 'portal') b = this.attachPortal(n);
|
|
2177
|
-
else b = this.attachHead(n);
|
|
2190
|
+
else if(['window', 'body', 'head'].includes(n.elArg)) b = this.attachHead(n);
|
|
2191
|
+
else if(n.elArg == 'self') {
|
|
2192
|
+
this.glob.$$selfComponent.$value();
|
|
2193
|
+
const label = requireLabel();
|
|
2194
|
+
let component = this.makeComponent(n, {self: true});
|
|
2195
|
+
binds.push(insertComponent(component, label));
|
|
2196
|
+
} else throw 'Wrong tag';
|
|
2178
2197
|
b && binds.push(b);
|
|
2179
2198
|
return;
|
|
2180
2199
|
}
|
|
@@ -2194,23 +2213,7 @@
|
|
|
2194
2213
|
} else {
|
|
2195
2214
|
const label = requireLabel();
|
|
2196
2215
|
let component = this.makeComponent(n);
|
|
2197
|
-
binds.push(
|
|
2198
|
-
component: component.bind,
|
|
2199
|
-
reference: component.reference,
|
|
2200
|
-
label
|
|
2201
|
-
}, (ctx, n) => {
|
|
2202
|
-
if(n.reference) {
|
|
2203
|
-
ctx.write(true, `${n.reference} = `);
|
|
2204
|
-
ctx.add(n.component);
|
|
2205
|
-
if(n.label.node) ctx.write(true, `$runtime.insertBlock(${n.label.name}, ${n.reference});`);
|
|
2206
|
-
else ctx.write(true, `$runtime.addBlock(${n.label.name}, ${n.reference});`);
|
|
2207
|
-
} else {
|
|
2208
|
-
if(n.label.node) ctx.write(true, `$runtime.insertBlock(${n.label.name}, `);
|
|
2209
|
-
else ctx.write(true, `$runtime.addBlock(${n.label.name}, `);
|
|
2210
|
-
ctx.add(n.component);
|
|
2211
|
-
ctx.write(');');
|
|
2212
|
-
}
|
|
2213
|
-
}));
|
|
2216
|
+
binds.push(insertComponent(component, label));
|
|
2214
2217
|
}
|
|
2215
2218
|
} else {
|
|
2216
2219
|
if(isRoot) requireFragment = true;
|
|
@@ -2306,7 +2309,7 @@
|
|
|
2306
2309
|
go(n, false, el);
|
|
2307
2310
|
}
|
|
2308
2311
|
} else if(n.type === 'block') {
|
|
2309
|
-
if(n.name == 'keep
|
|
2312
|
+
if(n.name == 'keep') {
|
|
2310
2313
|
if(isRoot) requireFragment = true;
|
|
2311
2314
|
binds.push(xNode('attach-fragment', {
|
|
2312
2315
|
label: requireLabel(),
|
|
@@ -2631,6 +2634,26 @@
|
|
|
2631
2634
|
throw e;
|
|
2632
2635
|
}
|
|
2633
2636
|
|
|
2637
|
+
function insertComponent(component, label) {
|
|
2638
|
+
return xNode('insert-component', {
|
|
2639
|
+
component: component.bind,
|
|
2640
|
+
reference: component.reference,
|
|
2641
|
+
label
|
|
2642
|
+
}, (ctx, n) => {
|
|
2643
|
+
if(n.reference) {
|
|
2644
|
+
ctx.write(true, `${n.reference} = `);
|
|
2645
|
+
ctx.add(n.component);
|
|
2646
|
+
if(n.label.node) ctx.write(true, `$runtime.insertBlock(${n.label.name}, ${n.reference});`);
|
|
2647
|
+
else ctx.write(true, `$runtime.addBlock(${n.label.name}, ${n.reference});`);
|
|
2648
|
+
} else {
|
|
2649
|
+
if(n.label.node) ctx.write(true, `$runtime.insertBlock(${n.label.name}, `);
|
|
2650
|
+
else ctx.write(true, `$runtime.addBlock(${n.label.name}, `);
|
|
2651
|
+
ctx.add(n.component);
|
|
2652
|
+
ctx.write(');');
|
|
2653
|
+
}
|
|
2654
|
+
})
|
|
2655
|
+
}
|
|
2656
|
+
|
|
2634
2657
|
var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
|
|
2635
2658
|
|
|
2636
2659
|
function createCommonjsModule(fn, basedir, module) {
|
|
@@ -4869,7 +4892,7 @@
|
|
|
4869
4892
|
return result;
|
|
4870
4893
|
};
|
|
4871
4894
|
|
|
4872
|
-
function makeComponent(node) {
|
|
4895
|
+
function makeComponent(node, option={}) {
|
|
4873
4896
|
let propList = node.attributes;
|
|
4874
4897
|
|
|
4875
4898
|
this.require('$context');
|
|
@@ -4879,8 +4902,8 @@
|
|
|
4879
4902
|
let slotBlocks = [];
|
|
4880
4903
|
let anchorBlocks = [];
|
|
4881
4904
|
|
|
4882
|
-
let componentName = node.name;
|
|
4883
|
-
if(componentName != 'component' && this.config.autoimport) {
|
|
4905
|
+
let componentName = option.self ? '$$selfComponent' : node.name;
|
|
4906
|
+
if(componentName != 'component' && this.config.autoimport && !option.self) {
|
|
4884
4907
|
let imported = this.script.autoimport[componentName] || this.script.importedNames.includes(componentName) ||
|
|
4885
4908
|
this.script.rootVariables[componentName] || this.script.rootFunctions[componentName];
|
|
4886
4909
|
|
|
@@ -6712,7 +6735,7 @@
|
|
|
6712
6735
|
}
|
|
6713
6736
|
|
|
6714
6737
|
let key = null;
|
|
6715
|
-
let args = node.value.substr(
|
|
6738
|
+
let args = node.value.substr(6);
|
|
6716
6739
|
if(args) {
|
|
6717
6740
|
args = parseAttibutes(args);
|
|
6718
6741
|
const a = args.find(a => a.name == 'key');
|
|
@@ -6737,7 +6760,7 @@
|
|
|
6737
6760
|
});
|
|
6738
6761
|
}
|
|
6739
6762
|
|
|
6740
|
-
const version = '0.7.2-
|
|
6763
|
+
const version = '0.7.2-a8';
|
|
6741
6764
|
|
|
6742
6765
|
|
|
6743
6766
|
async function compile(source, config = {}) {
|
|
@@ -6792,7 +6815,8 @@
|
|
|
6792
6815
|
rootCD: xNode('root-cd', false),
|
|
6793
6816
|
apply: xNode('apply', false),
|
|
6794
6817
|
componentFn: xNode('componentFn', false),
|
|
6795
|
-
$onMount: xNode('$onMount', false)
|
|
6818
|
+
$onMount: xNode('$onMount', false),
|
|
6819
|
+
$$selfComponent: xNode('$$selfComponent', false)
|
|
6796
6820
|
},
|
|
6797
6821
|
require: function(...args) {
|
|
6798
6822
|
for(let name of args) {
|
|
@@ -6889,10 +6913,21 @@
|
|
|
6889
6913
|
$compile: [ctx.module.head, ctx.module.code, ctx.module.body, ctx.glob.rootCD],
|
|
6890
6914
|
name: config.name,
|
|
6891
6915
|
componentFn: ctx.glob.componentFn
|
|
6892
|
-
}, (
|
|
6893
|
-
if(config.exportDefault)
|
|
6894
|
-
|
|
6895
|
-
|
|
6916
|
+
}, (ctx2, n) => {
|
|
6917
|
+
if(config.exportDefault) {
|
|
6918
|
+
if(ctx.glob.$$selfComponent.value) {
|
|
6919
|
+
ctx2.write(true, 'const $$selfComponent = ');
|
|
6920
|
+
ctx2.add(n.componentFn);
|
|
6921
|
+
ctx2.write(true, 'export default $$selfComponent;');
|
|
6922
|
+
} else {
|
|
6923
|
+
ctx2.write(true, 'export default ');
|
|
6924
|
+
ctx2.add(n.componentFn);
|
|
6925
|
+
}
|
|
6926
|
+
} else {
|
|
6927
|
+
assert(!ctx.glob.$$selfComponent.value, 'Not supported');
|
|
6928
|
+
ctx2.write(true, `const ${n.name} = `);
|
|
6929
|
+
ctx2.add(n.componentFn);
|
|
6930
|
+
}
|
|
6896
6931
|
}));
|
|
6897
6932
|
|
|
6898
6933
|
ctx.result = xBuild(result);
|