@yr-lang/yr 0.3.0 → 0.3.4

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/BUGS.md CHANGED
@@ -15,3 +15,62 @@ _ .teste
15
15
  _ .teste2
16
16
  _wrapper/test2
17
17
  ```
18
+
19
+ ### Wrappers calls are not being called in the correct order ✓ Fixed in 0.3.4
20
+
21
+ e.g, if I have
22
+
23
+ #### Test/N2
24
+
25
+ ```
26
+ !! @wrapper
27
+
28
+ ++
29
+
30
+ _ .something
31
+
32
+
33
+ @>
34
+
35
+ _@wrapper(Test, N2) {
36
+ console.log('n2');
37
+ @}
38
+ ```
39
+
40
+ #### Test/N1
41
+
42
+ ```
43
+ !! @wrapper
44
+
45
+ ++
46
+
47
+ _test/n2
48
+
49
+ @>
50
+
51
+ _@wrapper(Test, N1) {
52
+ console.log('n1');
53
+ @}
54
+ ```
55
+
56
+ My output becomes
57
+
58
+ ```
59
+ __Teste_N1({});
60
+ __Teste_N2({});
61
+ ```
62
+
63
+ Instead of
64
+
65
+ ```
66
+ __Teste_N2({});
67
+ __Teste_N1({});
68
+ ```
69
+
70
+ That means that the wrapper calls might be swapping the orders, or some other
71
+ behaviour, which is incorrect. The correct would be:
72
+
73
+ * The calls of the imported wrappers must come first
74
+
75
+ The workaround for this issues is to add the code that relies on the child
76
+ wrappers calls, inside a `setTimeout`, so it goes to the next event loop.
@@ -0,0 +1,32 @@
1
+ %%
2
+
3
+ _@wrapper(#category, #option, #debug=false) {
4
+ async function __#category_#option(_config) {
5
+ let element = (_config.id === 'body') ? document.body
6
+ : document.querySelector(`.${_config.id}`);
7
+
8
+ if (!element) return;
9
+
10
+ try {
11
+ element._config = _config;
12
+
13
+ if (window.__preview) {
14
+ element._html = element.outerHTML;
15
+
16
+ element._refresh = () => {
17
+ element.outerHTML = element._html;
18
+ __#category_#option(_config)
19
+ };
20
+ }
21
+
22
+ ___
23
+ } catch(error) {
24
+ if (window.__preview || #debug) {
25
+ //element.innerHTML = '<div style="background: red; color: white">'
26
+ //+ `#category #option error: ${error.message}</div>`;
27
+
28
+ console.error(error);
29
+ }
30
+ }
31
+ }
32
+ @}
package/node.js CHANGED
@@ -382,11 +382,17 @@ module.exports = {
382
382
  app[value] = [...new Set([...app[value], ...item.output[value]])];
383
383
  }
384
384
 
385
- devops = [...item.output.devops, ...devops];
385
+ let ext = item?.outputs?.devops;
386
+ if (!ext) ext = [];
387
+ if (!devops) devops = [];
388
+ devops = [...ext, ...devops];
386
389
  result.macros = { ...item.output.macros, ...result.macros };
387
390
 
391
+ let mods = item?.outputs?.modules;
392
+ if (!mods) mods = [];
393
+
388
394
  result.modules = [...new Set([
389
- ...item.output.modules, ...result.modules
395
+ ...mods, ...result.modules
390
396
  ])];
391
397
 
392
398
  views.push(item);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yr-lang/yr",
3
- "version": "0.3.0",
3
+ "version": "0.3.4",
4
4
  "description": "Yr is a modern structural language and parser",
5
5
  "main": "./node.js",
6
6
  "exports": {
package/yr.js CHANGED
@@ -154,7 +154,9 @@ function addIdToElement(line, config, elementId=false) {
154
154
 
155
155
  if (tag.startsWith('_')) {
156
156
  tag = tag.replace(/^_/, '');
157
- if (VOID_TAGS.has(tag) || ['title', 'script', 'style'].includes(tag)) return line;
157
+
158
+ if ((VOID_TAGS.has(tag) && !['input', 'img'].includes(tag))
159
+ || ['title', 'script', 'style'].includes(tag)) return line;
158
160
  }
159
161
 
160
162
  if (config.preview && !line.includes('.__') && !line.includes('.{{__')) {
@@ -364,7 +366,8 @@ const parserFns = {
364
366
  wrapper[1] = utils.capitalize(wrapper[1]);
365
367
  const wrapperName = wrapper.join('/');
366
368
  core.extend(wrapper, wrapperName, sections, state, {
367
- redoWrapper: true, simple: config.simple
369
+ redoWrapper: true, simple: config.simple,
370
+ ignoreHtml: config.ignoreHtml
368
371
  });
369
372
  let newWrapper, wrapperIndentation;
370
373
  if (!tag.includes('!')) {
@@ -659,6 +662,8 @@ const core = {
659
662
  wrapper[1] = wrapper[1].replace(/!/, '');
660
663
  wrapperName = wrapperName.replace(/!/, '');
661
664
  config.ignoreHtml = true;
665
+ sections.wrappers[wrapperName] = sections.wrappers[wrapperName] || {};
666
+ sections.wrappers[wrapperName].owned = true;
662
667
  }
663
668
 
664
669
  if (!sections.wrapperjs) sections.wrapperjs = '';
@@ -671,7 +676,7 @@ const core = {
671
676
 
672
677
  sections.wrappers[wrapperName] = newWrapper.wrappers[wrapperName];
673
678
  sections.wrappers[wrapperName].redone = true;
674
- sections.wrapperjs += newWrapper.wrapperjs;
679
+ sections.wrapperjs = newWrapper.wrapperjs + sections.wrapperjs;
675
680
  }
676
681
 
677
682
  return;
@@ -1136,7 +1141,7 @@ const core = {
1136
1141
  if (wrapper.length === 1) wrapper.unshift('__');
1137
1142
 
1138
1143
  this.extend(wrapper, wrapperName, sections, state, {
1139
- simple: config.simple
1144
+ simple: config.simple, ignoreHtml: config.ignoreHtml
1140
1145
  });
1141
1146
  //} else if (line.startsWith('\\\\')) {
1142
1147
  // const wrapperName = line.replace(/\\\\/g, '').trim() + '\n';
@@ -1336,9 +1341,8 @@ const core = {
1336
1341
  sections.parsedyr[value] = sections.yr[value];
1337
1342
 
1338
1343
  for (let item in sections.wrappers) {
1339
- // fix!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
1340
- if (sections.wrappers[item].redone) continue; // this will cause files to be parsed wrongly
1341
- // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
1344
+ if (sections.wrappers[item].redone && value === 'body') continue;
1345
+ if (value === 'body' && sections.wrappers[item].owned) continue;
1342
1346
 
1343
1347
  if (!sections.wrappers[item].yr)
1344
1348
  sections.wrappers[item].yr = {};
@@ -1382,10 +1386,9 @@ const core = {
1382
1386
  if (sections.parsedjs !== '')
1383
1387
  sections.parsedjs = this.macros(sections, 'parsedjs');
1384
1388
 
1385
- let newWrapperJs = '';//const __runenv = async () => {\n';
1386
- //sections.parsedjs += 'const __runenv = async () => {\n';
1389
+ let newWrapperJs = '';
1387
1390
  const arr = sections.parsedyr.wrapperjs.split('\n');
1388
- if (code.includes('!! !')) arr.reverse();
1391
+
1389
1392
  for (let item of arr) {
1390
1393
  if (!item) continue;
1391
1394
 
@@ -1698,12 +1701,12 @@ if (typeof window !== 'undefined' && !window.yr) {
1698
1701
  const parse = core.parse.bind(core);
1699
1702
  window.yr = parse;
1700
1703
 
1701
- const createLog = (text) => {
1702
- const parsed = parse(text);
1703
- console.log(parsed);
1704
- document.body.innerHTML += `<div>${text}</div>`;
1705
- document.body.innerHTML += `<div>${parsed.parsedyr.body}</div>`;
1706
- };
1704
+ //const createLog = (text) => {
1705
+ // const parsed = parse(text);
1706
+ // console.log(parsed);
1707
+ // document.body.innerHTML += `<div>${text}</div>`;
1708
+ // document.body.innerHTML += `<div>${parsed.parsedyr.body}</div>`;
1709
+ //};
1707
1710
 
1708
- createLog('><\n_ .teste');
1711
+ //createLog('><\n_ .teste');
1709
1712
  }