malinajs 0.6.48 → 0.6.52
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/compile.js +17 -9
- package/malina-esbuild.js +4 -10
- package/malina.js +18 -10
- package/package.json +1 -1
- package/runtime.js +2 -2
package/compile.js
CHANGED
|
@@ -24,10 +24,10 @@ function toCamelCase(name) {
|
|
|
24
24
|
});
|
|
25
25
|
}
|
|
26
26
|
function Q(s) {
|
|
27
|
-
return s.replace(
|
|
27
|
+
return s.replace(/\\/g, '\\\\').replace(/`/g, '\\`');
|
|
28
28
|
}
|
|
29
29
|
function Q2(s) {
|
|
30
|
-
return s.replace(
|
|
30
|
+
return s.replace(/\\/g, '\\\\').replace(/`/g, '\\`').replace(/\n/g, '\\n');
|
|
31
31
|
}
|
|
32
32
|
function unwrapExp(e) {
|
|
33
33
|
assert(e, 'Empty expression');
|
|
@@ -4023,8 +4023,10 @@ function makeDom(data) {
|
|
|
4023
4023
|
//if(e.name[0].match(/[A-Z]/)) return;
|
|
4024
4024
|
let n = new Node(e.name, {__node: e});
|
|
4025
4025
|
e.attributes.forEach(a => {
|
|
4026
|
-
if(a.name == 'class')
|
|
4027
|
-
|
|
4026
|
+
if(a.name == 'class') {
|
|
4027
|
+
if(a.value != null) n.className += ' ' + a.value;
|
|
4028
|
+
n.attributes[a.name] = a.value;
|
|
4029
|
+
} else if(a.name == 'id') n.attributes.id = n.id = a.value;
|
|
4028
4030
|
else if(a.name.startsWith('class:')) {
|
|
4029
4031
|
n.className += ' ' + a.name.substring(6);
|
|
4030
4032
|
} else n.attributes[a.name] = a.value;
|
|
@@ -4066,6 +4068,10 @@ Node.prototype.getAttribute = function(n) {
|
|
|
4066
4068
|
return this.attributes[n];
|
|
4067
4069
|
};
|
|
4068
4070
|
|
|
4071
|
+
Node.prototype.hasAttribute = function(n) {
|
|
4072
|
+
return n in this.attributes;
|
|
4073
|
+
};
|
|
4074
|
+
|
|
4069
4075
|
Node.prototype.appendChild = function(n) {
|
|
4070
4076
|
n.parentElement = this;
|
|
4071
4077
|
this.childNodes.push(n);
|
|
@@ -4291,6 +4297,7 @@ function makeComponent(node, element) {
|
|
|
4291
4297
|
let value = prop.value;
|
|
4292
4298
|
if(name == '@@') {
|
|
4293
4299
|
forwardAllEvents = true;
|
|
4300
|
+
this.require('$events');
|
|
4294
4301
|
return false;
|
|
4295
4302
|
} else if(name == 'this') {
|
|
4296
4303
|
dynamicComponent = unwrapExp(value);
|
|
@@ -4559,6 +4566,7 @@ function bindProp(prop, node, element) {
|
|
|
4559
4566
|
// spread operator
|
|
4560
4567
|
name = name.substring(3);
|
|
4561
4568
|
assert(detectExpressionType(name) == 'identifier');
|
|
4569
|
+
this.detectDependency(name);
|
|
4562
4570
|
return node.spreading.push(`...${name}`);
|
|
4563
4571
|
} else {
|
|
4564
4572
|
prop.value = prop.name;
|
|
@@ -5345,7 +5353,7 @@ function makeFragment(node) {
|
|
|
5345
5353
|
svg: block.svg
|
|
5346
5354
|
})
|
|
5347
5355
|
}, (ctx, n) => {
|
|
5348
|
-
ctx.write(true, `function $fragment_${n.name}($cd, label, $props, $events, $$fragmentSlot) {\n`);
|
|
5356
|
+
ctx.write(true, `function $fragment_${n.name}($cd, $$label, $props, $events, $$fragmentSlot) {\n`);
|
|
5349
5357
|
ctx.indent++;
|
|
5350
5358
|
|
|
5351
5359
|
if(n.props?.length) {
|
|
@@ -5360,7 +5368,7 @@ function makeFragment(node) {
|
|
|
5360
5368
|
|
|
5361
5369
|
ctx.build(n.template);
|
|
5362
5370
|
ctx.build(n.source);
|
|
5363
|
-
ctx.writeLine(`$runtime.insertAfter(label, $parentElement);`);
|
|
5371
|
+
ctx.writeLine(`$runtime.insertAfter($$label, $parentElement);`);
|
|
5364
5372
|
|
|
5365
5373
|
ctx.indent--;
|
|
5366
5374
|
ctx.writeLine('}');
|
|
@@ -5483,15 +5491,15 @@ function attachFragment(node, element) {
|
|
|
5483
5491
|
ctx.write(missed, ',\n');
|
|
5484
5492
|
missed = '';
|
|
5485
5493
|
if(n.slot.source) {
|
|
5486
|
-
ctx.writeLine(`($cd, label) => {`);
|
|
5494
|
+
ctx.writeLine(`($cd, $$label) => {`);
|
|
5487
5495
|
ctx.goIndent(() => {
|
|
5488
5496
|
ctx.build(n.slot.template);
|
|
5489
5497
|
ctx.build(n.slot.source);
|
|
5490
|
-
ctx.writeLine(`$runtime.insertAfter(label, $parentElement);`);
|
|
5498
|
+
ctx.writeLine(`$runtime.insertAfter($$label, $parentElement);`);
|
|
5491
5499
|
});
|
|
5492
5500
|
ctx.write(true, `}`);
|
|
5493
5501
|
} else {
|
|
5494
|
-
ctx.write(true, `($cd, label) => $runtime.insertAfter(label, `);
|
|
5502
|
+
ctx.write(true, `($cd, $$label) => $runtime.insertAfter($$label, `);
|
|
5495
5503
|
ctx.build(n.slot.template);
|
|
5496
5504
|
ctx.write(`)\n`);
|
|
5497
5505
|
}
|
package/malina-esbuild.js
CHANGED
|
@@ -11,11 +11,9 @@ process.argv.includes('-w') ? process.env.WATCH = 1 : null;
|
|
|
11
11
|
|
|
12
12
|
const esbuildConfigPath = path.join(process.cwd(),'esbuild.config.js');
|
|
13
13
|
const derverConfigPath = path.join(process.cwd(),'derver.config.js');
|
|
14
|
-
const malinaConfigPath = path.join(process.cwd(),'malina.config.js');
|
|
15
14
|
|
|
16
15
|
const esbuildConfig = fs.existsSync(esbuildConfigPath) ? require(esbuildConfigPath) : {};
|
|
17
16
|
const derverConfig = fs.existsSync(derverConfigPath) ? require(derverConfigPath) : {};
|
|
18
|
-
const malinaConfig = fs.existsSync(malinaConfigPath) ? require(malinaConfigPath) : {};
|
|
19
17
|
|
|
20
18
|
// Executable
|
|
21
19
|
|
|
@@ -60,11 +58,6 @@ function malinaPlugin(options={}){
|
|
|
60
58
|
|
|
61
59
|
const cssModules = new Map();
|
|
62
60
|
|
|
63
|
-
options = {
|
|
64
|
-
...malinaConfig,
|
|
65
|
-
...options
|
|
66
|
-
}
|
|
67
|
-
|
|
68
61
|
if(options.displayVersion !== false) console.log('! Malina.js', malina.version);
|
|
69
62
|
|
|
70
63
|
return {
|
|
@@ -77,18 +70,19 @@ function malinaPlugin(options={}){
|
|
|
77
70
|
let source = await fsp.readFile(args.path, 'utf8');
|
|
78
71
|
|
|
79
72
|
let ctx = await malina.compile(source,{
|
|
73
|
+
path: args.path,
|
|
80
74
|
name: args.path.match(/([^/\\]+)\.\w+$/)[1],
|
|
81
75
|
...options
|
|
82
76
|
});
|
|
83
77
|
|
|
84
78
|
let code = ctx.result;
|
|
85
|
-
|
|
86
|
-
if(
|
|
79
|
+
|
|
80
|
+
if(ctx.css.result){
|
|
87
81
|
const cssPath = args.path.replace(/\.\w+$/, ".malina.css").replace(/\\/g, "/");
|
|
88
82
|
cssModules.set(cssPath,ctx.css.result);
|
|
89
83
|
code += `\nimport "${cssPath}";`
|
|
90
84
|
}
|
|
91
|
-
|
|
85
|
+
|
|
92
86
|
return { contents: code }
|
|
93
87
|
}
|
|
94
88
|
);
|
package/malina.js
CHANGED
|
@@ -25,10 +25,10 @@
|
|
|
25
25
|
});
|
|
26
26
|
}
|
|
27
27
|
function Q(s) {
|
|
28
|
-
return s.replace(
|
|
28
|
+
return s.replace(/\\/g, '\\\\').replace(/`/g, '\\`');
|
|
29
29
|
}
|
|
30
30
|
function Q2(s) {
|
|
31
|
-
return s.replace(
|
|
31
|
+
return s.replace(/\\/g, '\\\\').replace(/`/g, '\\`').replace(/\n/g, '\\n');
|
|
32
32
|
}
|
|
33
33
|
function unwrapExp(e) {
|
|
34
34
|
assert(e, 'Empty expression');
|
|
@@ -4024,8 +4024,10 @@
|
|
|
4024
4024
|
//if(e.name[0].match(/[A-Z]/)) return;
|
|
4025
4025
|
let n = new Node(e.name, {__node: e});
|
|
4026
4026
|
e.attributes.forEach(a => {
|
|
4027
|
-
if(a.name == 'class')
|
|
4028
|
-
|
|
4027
|
+
if(a.name == 'class') {
|
|
4028
|
+
if(a.value != null) n.className += ' ' + a.value;
|
|
4029
|
+
n.attributes[a.name] = a.value;
|
|
4030
|
+
} else if(a.name == 'id') n.attributes.id = n.id = a.value;
|
|
4029
4031
|
else if(a.name.startsWith('class:')) {
|
|
4030
4032
|
n.className += ' ' + a.name.substring(6);
|
|
4031
4033
|
} else n.attributes[a.name] = a.value;
|
|
@@ -4067,6 +4069,10 @@
|
|
|
4067
4069
|
return this.attributes[n];
|
|
4068
4070
|
};
|
|
4069
4071
|
|
|
4072
|
+
Node.prototype.hasAttribute = function(n) {
|
|
4073
|
+
return n in this.attributes;
|
|
4074
|
+
};
|
|
4075
|
+
|
|
4070
4076
|
Node.prototype.appendChild = function(n) {
|
|
4071
4077
|
n.parentElement = this;
|
|
4072
4078
|
this.childNodes.push(n);
|
|
@@ -4292,6 +4298,7 @@
|
|
|
4292
4298
|
let value = prop.value;
|
|
4293
4299
|
if(name == '@@') {
|
|
4294
4300
|
forwardAllEvents = true;
|
|
4301
|
+
this.require('$events');
|
|
4295
4302
|
return false;
|
|
4296
4303
|
} else if(name == 'this') {
|
|
4297
4304
|
dynamicComponent = unwrapExp(value);
|
|
@@ -4560,6 +4567,7 @@
|
|
|
4560
4567
|
// spread operator
|
|
4561
4568
|
name = name.substring(3);
|
|
4562
4569
|
assert(detectExpressionType(name) == 'identifier');
|
|
4570
|
+
this.detectDependency(name);
|
|
4563
4571
|
return node.spreading.push(`...${name}`);
|
|
4564
4572
|
} else {
|
|
4565
4573
|
prop.value = prop.name;
|
|
@@ -5346,7 +5354,7 @@
|
|
|
5346
5354
|
svg: block.svg
|
|
5347
5355
|
})
|
|
5348
5356
|
}, (ctx, n) => {
|
|
5349
|
-
ctx.write(true, `function $fragment_${n.name}($cd, label, $props, $events, $$fragmentSlot) {\n`);
|
|
5357
|
+
ctx.write(true, `function $fragment_${n.name}($cd, $$label, $props, $events, $$fragmentSlot) {\n`);
|
|
5350
5358
|
ctx.indent++;
|
|
5351
5359
|
|
|
5352
5360
|
if(n.props?.length) {
|
|
@@ -5361,7 +5369,7 @@
|
|
|
5361
5369
|
|
|
5362
5370
|
ctx.build(n.template);
|
|
5363
5371
|
ctx.build(n.source);
|
|
5364
|
-
ctx.writeLine(`$runtime.insertAfter(label, $parentElement);`);
|
|
5372
|
+
ctx.writeLine(`$runtime.insertAfter($$label, $parentElement);`);
|
|
5365
5373
|
|
|
5366
5374
|
ctx.indent--;
|
|
5367
5375
|
ctx.writeLine('}');
|
|
@@ -5484,15 +5492,15 @@
|
|
|
5484
5492
|
ctx.write(missed, ',\n');
|
|
5485
5493
|
missed = '';
|
|
5486
5494
|
if(n.slot.source) {
|
|
5487
|
-
ctx.writeLine(`($cd, label) => {`);
|
|
5495
|
+
ctx.writeLine(`($cd, $$label) => {`);
|
|
5488
5496
|
ctx.goIndent(() => {
|
|
5489
5497
|
ctx.build(n.slot.template);
|
|
5490
5498
|
ctx.build(n.slot.source);
|
|
5491
|
-
ctx.writeLine(`$runtime.insertAfter(label, $parentElement);`);
|
|
5499
|
+
ctx.writeLine(`$runtime.insertAfter($$label, $parentElement);`);
|
|
5492
5500
|
});
|
|
5493
5501
|
ctx.write(true, `}`);
|
|
5494
5502
|
} else {
|
|
5495
|
-
ctx.write(true, `($cd, label) => $runtime.insertAfter(label, `);
|
|
5503
|
+
ctx.write(true, `($cd, $$label) => $runtime.insertAfter($$label, `);
|
|
5496
5504
|
ctx.build(n.slot.template);
|
|
5497
5505
|
ctx.write(`)\n`);
|
|
5498
5506
|
}
|
|
@@ -5883,7 +5891,7 @@
|
|
|
5883
5891
|
return {event, fn};
|
|
5884
5892
|
}
|
|
5885
5893
|
|
|
5886
|
-
const version = '0.6.
|
|
5894
|
+
const version = '0.6.52';
|
|
5887
5895
|
|
|
5888
5896
|
|
|
5889
5897
|
async function compile(source, config = {}) {
|
package/package.json
CHANGED
package/runtime.js
CHANGED
|
@@ -295,12 +295,12 @@ function $tick(fn, uniq) {
|
|
|
295
295
|
_tick_list.push(fn);
|
|
296
296
|
if(_tick_planned.$tick) return;
|
|
297
297
|
_tick_planned.$tick = true;
|
|
298
|
-
|
|
298
|
+
Promise.resolve().then(() => {
|
|
299
299
|
_tick_planned = {};
|
|
300
300
|
let list = _tick_list;
|
|
301
301
|
_tick_list = [];
|
|
302
302
|
list.map(safeCall);
|
|
303
|
-
}
|
|
303
|
+
});
|
|
304
304
|
}
|
|
305
305
|
|
|
306
306
|
function $makeEmitter(option) {
|