ether-code 0.7.0 → 0.7.2

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/cli/ether.js CHANGED
@@ -6,7 +6,7 @@ const http = require('http')
6
6
  const { EtherCompiler } = require('./compiler')
7
7
  const { Watcher } = require('./watcher')
8
8
 
9
- const VERSION = '0.7.0'
9
+ const VERSION = '0.7.2'
10
10
 
11
11
  const COLORS = {
12
12
  reset: '\x1b[0m',
@@ -32,11 +32,15 @@ class JSGenerator {
32
32
  return
33
33
  }
34
34
 
35
+ const normalize = (str) => {
36
+ return str.toLowerCase().normalize('NFD').replace(/[\u0300-\u036f]/g, '')
37
+ }
38
+
35
39
  const addToMap = (map, section, prefix = '') => {
36
40
  if (!section) return
37
41
  for (const [key, translations] of Object.entries(section)) {
38
42
  if (translations && translations.fr && translations.en) {
39
- const frKey = translations.fr.toLowerCase()
43
+ const frKey = normalize(translations.fr)
40
44
  const enValue = translations.en
41
45
  if (prefix) {
42
46
  if (!this.contextualMap[frKey]) {
@@ -266,7 +270,9 @@ class JSGenerator {
266
270
  }
267
271
 
268
272
  buildDefaultMaps() {
269
- this.keywordMap = {
273
+ const norm = (str) => str.toLowerCase().normalize('NFD').replace(/[\u0300-\u036f]/g, '')
274
+
275
+ const rawKeywords = {
270
276
  'variable': 'let',
271
277
  'constante': 'const',
272
278
  'variable globale': 'var',
@@ -377,7 +383,7 @@ class JSGenerator {
377
383
  'gabarit étiqueté': 'tagged template'
378
384
  }
379
385
 
380
- this.operatorMap = {
386
+ const rawOperators = {
381
387
  'plus': '+',
382
388
  'moins': '-',
383
389
  'fois': '*',
@@ -414,7 +420,7 @@ class JSGenerator {
414
420
  'décomposition': '...'
415
421
  }
416
422
 
417
- this.methodMap = {
423
+ const rawMethods = {
418
424
  'afficher': 'console.log',
419
425
  'journal': 'console.log',
420
426
  'erreur': 'console.error',
@@ -776,7 +782,23 @@ class JSGenerator {
776
782
  'décoder URI': 'decodeURI',
777
783
  'décoder composant URI': 'decodeURIComponent',
778
784
  'encoder URI': 'encodeURI',
779
- 'encoder composant URI': 'encodeURIComponent'
785
+ 'encoder composant URI': 'encodeURIComponent',
786
+ 'selecteur': 'querySelector',
787
+ 'selecteurs': 'querySelectorAll'
788
+ }
789
+
790
+ this.keywordMap = {}
791
+ this.operatorMap = {}
792
+ this.methodMap = {}
793
+
794
+ for (const [key, value] of Object.entries(rawKeywords)) {
795
+ this.keywordMap[norm(key)] = value
796
+ }
797
+ for (const [key, value] of Object.entries(rawOperators)) {
798
+ this.operatorMap[norm(key)] = value
799
+ }
800
+ for (const [key, value] of Object.entries(rawMethods)) {
801
+ this.methodMap[norm(key)] = value
780
802
  }
781
803
 
782
804
  this.buildConflictResolution()
@@ -795,7 +817,7 @@ class JSGenerator {
795
817
  }
796
818
 
797
819
  translateWithContext(word, explicitContext = null) {
798
- const lower = word.toLowerCase()
820
+ const lower = this.normalize(word)
799
821
  const ctx = explicitContext || this.getCurrentContext()
800
822
 
801
823
  if (this.conflicts[lower] && ctx) {
@@ -814,8 +836,12 @@ class JSGenerator {
814
836
  word
815
837
  }
816
838
 
839
+ normalize(str) {
840
+ return str.toLowerCase().normalize('NFD').replace(/[\u0300-\u036f]/g, '')
841
+ }
842
+
817
843
  translate(word, isMethod = false) {
818
- const lower = word.toLowerCase()
844
+ const lower = this.normalize(word)
819
845
 
820
846
  if (this.keywordMap[lower]) {
821
847
  return this.keywordMap[lower]
@@ -1060,16 +1086,17 @@ class JSGenerator {
1060
1086
  const name = node.name || (node.id ? (node.id.name || node.id) : '')
1061
1087
  const params = (node.params || []).map(p => this.generateParam(p)).join(', ')
1062
1088
 
1063
- let body = ''
1064
1089
  const savedOutput = this.output
1090
+ const baseIndent = this.indent
1065
1091
  this.output = ''
1066
- this.indent++
1092
+ this.indent = baseIndent + 1
1067
1093
  this.generateNode(node.body)
1068
- this.indent--
1069
- body = this.output.trim()
1094
+ const body = this.output.trimEnd()
1070
1095
  this.output = savedOutput
1096
+ this.indent = baseIndent
1071
1097
 
1072
- return `${async}function${generator} ${name}(${params}) {\n${body}\n${this.getIndent()}}`
1098
+ const closingIndent = ' '.repeat(baseIndent)
1099
+ return `${async}function${generator} ${name}(${params}) {\n${body}\n${closingIndent}}`
1073
1100
  }
1074
1101
 
1075
1102
  generateParam(param) {
@@ -1644,15 +1671,17 @@ class JSGenerator {
1644
1671
  : `(${params})`
1645
1672
 
1646
1673
  if (node.body?.type === 'BlockStatement') {
1647
- let body = ''
1648
1674
  const savedOutput = this.output
1675
+ const baseIndent = this.indent
1649
1676
  this.output = ''
1650
- this.indent++
1677
+ this.indent = baseIndent + 1
1651
1678
  this.generateNode(node.body)
1652
- this.indent--
1653
- body = this.output.trim()
1679
+ const body = this.output.trimEnd()
1654
1680
  this.output = savedOutput
1655
- return `${async}${paramsStr} => {\n${body}\n${this.getIndent()}}`
1681
+ this.indent = baseIndent
1682
+
1683
+ const closingIndent = ' '.repeat(baseIndent)
1684
+ return `${async}${paramsStr} => {\n${body}\n${closingIndent}}`
1656
1685
  } else {
1657
1686
  const body = this.generateNode(node.body)
1658
1687
  return `${async}${paramsStr} => ${body}`
@@ -1716,7 +1745,7 @@ class JSGenerator {
1716
1745
  const left = this.generateNode(node.left)
1717
1746
  const right = this.generateNode(node.right)
1718
1747
  const op = this.translateOperator(node.operator)
1719
- return `(${left} ${op} ${right})`
1748
+ return `${left} ${op} ${right}`
1720
1749
  }
1721
1750
 
1722
1751
  generateUnaryExpression(node) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ether-code",
3
- "version": "0.7.0",
3
+ "version": "0.7.2",
4
4
  "description": "Ether - Le langage intentionnel",
5
5
  "main": "cli/compiler.js",
6
6
  "bin": {