@yr-lang/yr 0.4.1 → 0.5.0

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 (58) hide show
  1. package/CHANGELOG.md +9 -3
  2. package/node.js +12 -1
  3. package/package.json +1 -1
  4. package/tests/.yrrc +2 -0
  5. package/yr.js +87 -27
  6. /package/{lib → tests}/Ciyr/A1.yr +0 -0
  7. /package/{lib → tests}/Ciyr/B1.yr +0 -0
  8. /package/{lib → tests}/Ciyr/B2.yr +0 -0
  9. /package/{lib → tests}/Ciyr/C1.yr +0 -0
  10. /package/{lib → tests}/Ciyr/C2.yr +0 -0
  11. /package/{lib → tests}/Ciyr/C2_2.yr +0 -0
  12. /package/{lib → tests}/Ciyr/a1.yr +0 -0
  13. /package/{lib → tests}/Ciyr/b1.yr +0 -0
  14. /package/{lib → tests}/Ciyr/c1.yr +0 -0
  15. /package/{lib → tests}/Yrci/&app.yr +0 -0
  16. /package/{lib → tests}/Yrci/&app2.yr +0 -0
  17. /package/{lib → tests}/Yrci/@m1.yr +0 -0
  18. /package/{lib → tests}/Yrci/@m2.yr +0 -0
  19. /package/{lib → tests}/Yrci/A1.yr +0 -0
  20. /package/{lib → tests}/Yrci/A2.yr +0 -0
  21. /package/{lib → tests}/Yrci/A3.yr +0 -0
  22. /package/{lib → tests}/Yrci/B1.yr +0 -0
  23. /package/{lib → tests}/Yrci/C1.yr +0 -0
  24. /package/{lib → tests}/Yrci/C1.yrr +0 -0
  25. /package/{lib → tests}/Yrci/C2.yr +0 -0
  26. /package/{lib → tests}/Yrci/C3.yr +0 -0
  27. /package/{lib → tests}/Yrci/C4.yr +0 -0
  28. /package/{lib → tests}/Yrci/C5.yr +0 -0
  29. /package/{lib → tests}/Yrci/C6.yr +0 -0
  30. /package/{lib → tests}/Yrci/C7.yr +0 -0
  31. /package/{lib → tests}/Yrci/C8.yr +0 -0
  32. /package/{lib → tests}/Yrci/C9.yr +0 -0
  33. /package/{lib → tests}/Yrci/Index_.yr +0 -0
  34. /package/{lib → tests}/Yrci/Login.yr +0 -0
  35. /package/{lib → tests}/Yrci/M1.yr +0 -0
  36. /package/{lib → tests}/Yrci/React.yr +0 -0
  37. /package/{lib → tests}/Yrci/Sp.yr +0 -0
  38. /package/{lib → tests}/Yrci/T1.yr +0 -0
  39. /package/{lib → tests}/Yrci/T2.yr +0 -0
  40. /package/{lib → tests}/Yrci/Ta1.yr +0 -0
  41. /package/{lib → tests}/Yrci/Ta2.yr +0 -0
  42. /package/{lib → tests}/Yrci/Tg.yr +0 -0
  43. /package/{lib → tests}/Yrci/Wr.yr +0 -0
  44. /package/{lib → tests}/Yrci/Wrapper.yr +0 -0
  45. /package/{lib → tests}/Yrci/Wrapper1.yr +0 -0
  46. /package/{lib → tests}/Yrci/Wrapper2.yr +0 -0
  47. /package/{lib → tests}/Yrci/Wrapper3.yr +0 -0
  48. /package/{lib → tests}/Yrci/Wrapperext.yr +0 -0
  49. /package/{lib → tests}/Yrci/Wrt.yr +0 -0
  50. /package/{lib → tests}/Yrci/Yrwm.yr +0 -0
  51. /package/{lib → tests}/Yrci/a1.yr +0 -0
  52. /package/{lib → tests}/Yrci/a2.yr +0 -0
  53. /package/{lib → tests}/Yrci/app.yr +0 -0
  54. /package/{lib → tests}/Yrci/b2.yr +0 -0
  55. /package/{lib → tests}/Yrci/j1.yr +0 -0
  56. /package/{lib → tests}/Yrci/j2.yr +0 -0
  57. /package/{lib → tests}/Yrci/j3.yr +0 -0
  58. /package/{lib → tests}/Yrci/modal.yr +0 -0
package/CHANGELOG.md CHANGED
@@ -1,10 +1,16 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.4.0] - 2026-08-18
4
+
5
+ Added React sections: `@@r`, `@@r`, `@<r`
6
+
7
+ See `/tests/Yrci/React.yr` to see an example
8
+
3
9
  ## [0.3.0] - 2026-04-27
4
10
 
5
- Remove `wrapperheader`, `header`, `scripts` and `footer` from parsedYr
6
- Created `wrapperheader` sections
7
- Added `VOID_TAGS` in order to not add elementId to all elements `if (preview === true)`
11
+ * Remove `wrapperheader`, `header`, `scripts` and `footer` from parsedYr
12
+ * Created `wrapperheader` sections
13
+ * Added `VOID_TAGS` in order to not add elementId to all elements `if (preview === true)`
8
14
 
9
15
  ## [0.2.0] - 2026-03-01
10
16
 
package/node.js CHANGED
@@ -501,7 +501,7 @@ for (let item of ['HOME', 'LIBS', 'BUILDS', 'TREE', 'CONFIG']) {
501
501
  env.BUILDS, projectPath,
502
502
  `${projectPath}/www`, `${projectPath}/www/assets`,
503
503
  `${projectPath}/app`, `${projectPath}/app/assets`,
504
- `${projectPath}/actions`
504
+ `${projectPath}/actions`, `${projectPath}/bin`
505
505
  ]) { if (!fs.existsSync(item)) fs.mkdirSync(item, { recursive: true }); }
506
506
 
507
507
  fs.writeFileSync(projectPath + '/.gitignore', `*/node_modules/
@@ -527,6 +527,17 @@ package*.json
527
527
  fs.writeFileSync(`${projectPath}/requirements.txt`, requirements);
528
528
 
529
529
  for (let item in result.devops) {
530
+ if (result.devops[item].split('\n')[0].endsWith('cpp')) {
531
+ let _code = result.devops[item].split('\n');
532
+ _code.shift();
533
+ _code = _code.join('\n').trim();
534
+ let filename = item;
535
+ if (!filename.endsWith('.cpp')) filename += '.cpp';
536
+ const srcPath= `${projectPath}/bin/${item}.cpp`;
537
+ fs.writeFileSync(srcPath, _code);
538
+ spawn('g++', [srcPath, '-o', `${projectPath}/bin/${item}.exe`, '-O2']);
539
+ continue;
540
+ }
530
541
  fs.writeFileSync(`${projectPath}/actions/${item}`, result.devops[item])
531
542
  spawn('chmod', ['+x', `${projectPath}/actions/${item}`]);
532
543
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yr-lang/yr",
3
- "version": "0.4.1",
3
+ "version": "0.5.0",
4
4
  "description": "Yr is a modern structural language and parser",
5
5
  "main": "./node.js",
6
6
  "exports": {
package/tests/.yrrc ADDED
@@ -0,0 +1,2 @@
1
+ NAME=yrtests
2
+ DESCRIPTION=Built-in yr tests
package/yr.js CHANGED
@@ -40,6 +40,14 @@ const namespaces = {
40
40
  '@@r': { name: 'jsreact', parser: 'string', default: '', merge: true },
41
41
  '@<r': { name: 'jsfooterreact', parser: 'string', default: '', merge: true },
42
42
  '<@r': { name: 'wrapperjscustomreact', parser: 'string', default: '', merge: true },
43
+ '@@t': { name: 'jsts', parser: 'string', default: '', merge: true },
44
+ '@>t': { name: 'jsheaderts', parser: 'string', default: '', merge: true },
45
+ '@<t': { name: 'jsfooterts', parser: 'string', default: '', merge: true },
46
+ '<@t': { name: 'wrapperjscustomts', parser: 'string', default: '', merge: true },
47
+ '@@x': { name: 'jstsx', parser: 'string', default: '', merge: true },
48
+ '@>x': { name: 'jsheadertsx', parser: 'string', default: '', merge: true },
49
+ '@<x': { name: 'jsfootertsx', parser: 'string', default: '', merge: true },
50
+ '<@x': { name: 'wrapperjscustomtsx', parser: 'string', default: '', merge: true },
43
51
  '""': { name: 'documentation', parser: 'string', default: '' },
44
52
  '--': { name: 'modules', parser: 'object', default: [], merge: true },
45
53
  '==': { name: 'pixel', parser: 'string', default: '', merge: true },
@@ -74,23 +82,67 @@ for (let item of Object.keys(namespaces)) {
74
82
  }
75
83
 
76
84
  let viewType, scriptUrl, builtInLib = {};
77
- function transformReact(code, sections, section, config) {
85
+
86
+ const JS_KINDS = {
87
+ react: {
88
+ suffix: 'react',
89
+ loader: 'jsx',
90
+ babelPresets: [['react', { runtime: 'classic' }]],
91
+ modules: ['react', 'react-dom'],
92
+ npmImports: "import React from 'react';\nimport ReactDOM from 'react-dom/client';\n",
93
+ cdnShimModules: {
94
+ 'react': 'window.React',
95
+ 'react-dom': 'window.ReactDOM',
96
+ 'react-dom/client': 'window.ReactDOM'
97
+ }
98
+ },
99
+ ts: {
100
+ suffix: 'ts',
101
+ loader: 'ts',
102
+ babelPresets: ['typescript'],
103
+ modules: [],
104
+ npmImports: '',
105
+ cdnShimModules: {}
106
+ },
107
+ tsx: {
108
+ suffix: 'tsx',
109
+ loader: 'tsx',
110
+ babelPresets: [['react', { runtime: 'classic' }], 'typescript'],
111
+ modules: ['react', 'react-dom'],
112
+ npmImports: "import React from 'react';\nimport ReactDOM from 'react-dom/client';\n",
113
+ cdnShimModules: {
114
+ 'react': 'window.React',
115
+ 'react-dom': 'window.ReactDOM',
116
+ 'react-dom/client': 'window.ReactDOM'
117
+ }
118
+ }
119
+ };
120
+
121
+ function transformJS(code, kind, sections, section, config) {
122
+ const spec = JS_KINDS[kind];
123
+ if (!spec) throw `Yr: tipo desconhecido em transformJS: ${kind}`;
124
+
78
125
  code = core.macros(sections, section);
79
126
 
80
127
  if (viewType === 'cdn') {
81
- if (!window.Babel) return 'alert("Babel unavailable");';
128
+ if (!window.Babel) return `alert("Babel unavailable (${kind})");`;
129
+
130
+ const needsShim = Object.keys(spec.cdnShimModules).length > 0;
131
+ const plugins = needsShim ? ['transform-modules-commonjs'] : [];
132
+
82
133
  const transformed = window.Babel.transform(code, {
83
- presets: [['react', { runtime: 'classic' }]],
84
- plugins: ['transform-modules-commonjs']
134
+ presets: spec.babelPresets, plugins,
135
+ filename: `file.${kind === 'react' ? 'jsx' : kind}`
85
136
  }).code;
86
137
 
138
+ if (!needsShim) return transformed; // ts puro não importa nada shimável, não precisa embrulhar
139
+
140
+ const shimEntries = Object.entries(spec.cdnShimModules)
141
+ .map(([name, ref]) => `'${name}': ${ref}`).join(',\n ');
142
+
87
143
  const shim = `
88
144
  const require = (function () {
89
- const modules = {
90
- 'react': window.React,
91
- 'react-dom': window.ReactDOM,
92
- 'react-dom/client': window.ReactDOM
93
- };
145
+ const modules = { ${shimEntries} };
94
146
  return function (name) {
95
147
  if (modules[name]) return modules[name];
96
148
  throw new Error('Módulo não disponível no runtime cdn: ' + name);
@@ -104,17 +156,17 @@ function transformReact(code, sections, section, config) {
104
156
  }
105
157
 
106
158
  if (viewType === 'npm') {
107
- for (let item of ['react', 'react-dom']) {
159
+ for (let item of spec.modules) {
108
160
  if (sections.modules.includes(item)) continue;
109
- sections.modules.push(item)
161
+ sections.modules.push(item);
110
162
  }
163
+
111
164
  try {
112
165
  const esbuild = require('esbuild');
113
- code = "import React from 'react';\n"
114
- + "import ReactDOM from 'react-dom/client';\n" + code;
166
+ code = spec.npmImports + code;
115
167
  const result = esbuild.buildSync({
116
168
  stdin: {
117
- contents: code, loader: 'jsx',
169
+ contents: code, loader: spec.loader,
118
170
  resolveDir: config.projectPath || process.cwd()
119
171
  },
120
172
  bundle: true, write: false, format: 'iife',
@@ -129,7 +181,7 @@ function transformReact(code, sections, section, config) {
129
181
  if (!unresolved) throw error;
130
182
 
131
183
  if (sections) sections.reactBuildFailed = true;
132
- return 'alert("esbuild error");';
184
+ return `alert("esbuild error (${kind})");`;
133
185
  }
134
186
  }
135
187
  }
@@ -1302,12 +1354,16 @@ const core = {
1302
1354
  if (section === 'macros')
1303
1355
  this.aux(sections, { macrosAux: sections.macrosAux });
1304
1356
 
1305
- if (section.endsWith('react')) {
1306
- sections[section.replace(/react/, '')] +=
1307
- transformReact(sections[section], sections, section, config) + '\n';
1308
- sections[section] = '';
1309
- sections.reactUsed = true;
1310
- }
1357
+ for (let kind in JS_KINDS) {
1358
+ const suffix = JS_KINDS[kind].suffix;
1359
+ if (section.endsWith(suffix)) {
1360
+ sections[section.slice(0, -suffix.length)] +=
1361
+ transformJS(sections[section], kind, sections, config) + '\n';
1362
+ sections[section] = '';
1363
+ if (JS_KINDS[kind].modules.includes('react')) sections.reactUsed = true;
1364
+ break;
1365
+ }
1366
+ }
1311
1367
 
1312
1368
  section = parsers.namespaces[line].name;
1313
1369
  state.sectionChanged = true;
@@ -1406,12 +1462,16 @@ const core = {
1406
1462
  lineNumber++;
1407
1463
  }
1408
1464
 
1409
- if (section.endsWith('react')) {
1410
- sections[section.replace(/react/, '')] +=
1411
- transformReact(sections[section], sections, section, config) + '\n';
1412
- sections[section] = '';
1413
- sections.reactUsed = true;
1414
- }
1465
+ for (let kind in JS_KINDS) {
1466
+ const suffix = JS_KINDS[kind].suffix;
1467
+ if (section.endsWith(suffix)) {
1468
+ sections[section.slice(0, -suffix.length)] +=
1469
+ transformJS(sections[section], kind, sections, config) + '\n';
1470
+ sections[section] = '';
1471
+ if (JS_KINDS[kind].modules.includes('react')) sections.reactUsed = true;
1472
+ break;
1473
+ }
1474
+ }
1415
1475
 
1416
1476
  section = false;
1417
1477
 
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes