ether-code 0.8.2 → 0.8.3

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.8.2'
9
+ const VERSION = '0.8.3'
10
10
 
11
11
  const COLORS = {
12
12
  reset: '\x1b[0m',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ether-code",
3
- "version": "0.8.2",
3
+ "version": "0.8.3",
4
4
  "description": "Ether - Le langage intentionnel",
5
5
  "main": "cli/compiler.js",
6
6
  "bin": {
@@ -226,6 +226,12 @@ class EtherParserPHP extends EtherParserBase {
226
226
  this.phpModifiers = ['statique', 'static', 'final', 'finale', 'abstrait', 'abstraite', 'abstract', 'readonly', 'lecture seule']
227
227
  }
228
228
 
229
+ safeStr(val) {
230
+ if (typeof val === 'string') return val
231
+ if (val && typeof val === 'object') return String(val.name || val.value || '')
232
+ return String(val || '')
233
+ }
234
+
229
235
  translatePHP(word) {
230
236
  if (!word) return word
231
237
  const lower = this.normalizeAccents(String(word))
@@ -736,7 +742,7 @@ class EtherParserPHP extends EtherParserBase {
736
742
  }
737
743
 
738
744
  const nameToken = this.current()
739
- let name = nameToken ? nameToken.value : 'property'
745
+ let name = this.safeStr(nameToken ? nameToken.value : 'property')
740
746
 
741
747
  if (name.startsWith('$')) {
742
748
  name = name.substring(1)
@@ -1047,7 +1053,7 @@ class EtherParserPHP extends EtherParserBase {
1047
1053
  }
1048
1054
 
1049
1055
  const varToken = this.current()
1050
- let varName = varToken ? varToken.value : ''
1056
+ let varName = this.safeStr(varToken ? varToken.value : '')
1051
1057
  if (varName.startsWith('$')) {
1052
1058
  varName = varName.substring(1)
1053
1059
  }
@@ -1126,7 +1132,7 @@ class EtherParserPHP extends EtherParserBase {
1126
1132
  const nameToken = this.current()
1127
1133
  if (!nameToken) return null
1128
1134
 
1129
- let name = nameToken.value
1135
+ let name = this.safeStr(nameToken.value)
1130
1136
  if (name.startsWith('$')) {
1131
1137
  name = name.substring(1)
1132
1138
  }
@@ -1218,7 +1224,7 @@ class EtherParserPHP extends EtherParserBase {
1218
1224
  }
1219
1225
 
1220
1226
  const nameToken = this.current()
1221
- let name = nameToken ? nameToken.value : 'variable'
1227
+ let name = this.safeStr(nameToken ? nameToken.value : 'variable')
1222
1228
  if (name.startsWith('$')) {
1223
1229
  name = name.substring(1)
1224
1230
  }
@@ -1372,7 +1378,7 @@ class EtherParserPHP extends EtherParserBase {
1372
1378
  }
1373
1379
 
1374
1380
  const firstVar = this.current()
1375
- let firstName = firstVar ? firstVar.value : 'item'
1381
+ let firstName = this.safeStr(firstVar ? firstVar.value : 'item')
1376
1382
  if (firstName.startsWith('$')) firstName = firstName.substring(1)
1377
1383
  this.advance()
1378
1384
 
@@ -1384,7 +1390,7 @@ class EtherParserPHP extends EtherParserBase {
1384
1390
  }
1385
1391
 
1386
1392
  const valueVar = this.current()
1387
- value = valueVar ? valueVar.value : 'value'
1393
+ let value = this.safeStr(valueVar ? valueVar.value : 'value')
1388
1394
  if (value.startsWith('$')) value = value.substring(1)
1389
1395
  this.advance()
1390
1396
  } else {
@@ -1632,7 +1638,7 @@ class EtherParserPHP extends EtherParserBase {
1632
1638
  do {
1633
1639
  const typeToken = this.current()
1634
1640
  if (typeToken && typeToken.type === TokenType.IDENTIFIER) {
1635
- const typeName = typeToken.value
1641
+ const typeName = this.safeStr(typeToken.value)
1636
1642
  if (typeName.startsWith('$')) {
1637
1643
  param = typeName.substring(1)
1638
1644
  } else {
@@ -1645,7 +1651,7 @@ class EtherParserPHP extends EtherParserBase {
1645
1651
  if (!param) {
1646
1652
  const paramToken = this.current()
1647
1653
  if (paramToken && paramToken.type === TokenType.IDENTIFIER) {
1648
- param = paramToken.value
1654
+ param = this.safeStr(paramToken.value)
1649
1655
  if (param.startsWith('$')) param = param.substring(1)
1650
1656
  this.advance()
1651
1657
  }
@@ -1759,7 +1765,7 @@ class EtherParserPHP extends EtherParserBase {
1759
1765
  const variables = []
1760
1766
  do {
1761
1767
  const varToken = this.current()
1762
- let varName = varToken ? varToken.value : ''
1768
+ let varName = this.safeStr(varToken ? varToken.value : '')
1763
1769
  if (varName.startsWith('$')) varName = varName.substring(1)
1764
1770
  this.advance()
1765
1771
  variables.push(varName)
@@ -2209,11 +2215,11 @@ class EtherParserPHP extends EtherParserBase {
2209
2215
 
2210
2216
  if (token.type === TokenType.STRING) {
2211
2217
  this.advance()
2212
- let value = token.value
2218
+ let value = this.safeStr(token.value)
2213
2219
  if ((value.startsWith('"') && value.endsWith('"')) || (value.startsWith("'") && value.endsWith("'"))) {
2214
2220
  value = value.slice(1, -1)
2215
2221
  }
2216
- const isDouble = token.value.startsWith('"')
2222
+ const isDouble = value.startsWith('"') || this.safeStr(token.value).startsWith('"')
2217
2223
  return { type: 'StringLiteral', value, doubleQuoted: isDouble }
2218
2224
  }
2219
2225
 
@@ -2223,7 +2229,7 @@ class EtherParserPHP extends EtherParserBase {
2223
2229
  }
2224
2230
 
2225
2231
  if (token.type === TokenType.IDENTIFIER) {
2226
- const value = token.value
2232
+ const value = this.safeStr(token.value)
2227
2233
  const valueLower = this.normalizeAccents(value.toLowerCase())
2228
2234
 
2229
2235
  if (valueLower === 'vrai' || valueLower === 'true') {
@@ -2285,7 +2291,7 @@ class EtherParserPHP extends EtherParserBase {
2285
2291
 
2286
2292
  if (token.type === TokenType.VARIABLE) {
2287
2293
  this.advance()
2288
- let name = token.value
2294
+ let name = this.safeStr(token.value)
2289
2295
  if (name.startsWith('$')) name = name.substring(1)
2290
2296
  return { type: 'Variable', name }
2291
2297
  }
@@ -30,13 +30,23 @@ class EtherParser {
30
30
  if (!this.parsers[lang]) {
31
31
  switch (lang) {
32
32
  case 'js':
33
+ this.parsers[lang] = new EtherParserJS(this.options)
34
+ break
33
35
  case 'ts':
36
+ this.parsers[lang] = new EtherParserJS(this.options)
37
+ break
34
38
  case 'react':
39
+ this.parsers[lang] = new EtherParserJS(this.options)
40
+ break
35
41
  case 'node':
42
+ this.parsers[lang] = new EtherParserJS(this.options)
43
+ break
36
44
  case 'php':
37
45
  this.parsers[lang] = new EtherParserPHP(this.options)
38
46
  break
39
47
  case 'python':
48
+ this.parsers[lang] = new EtherParserJS(this.options)
49
+ break
40
50
  case 'ruby':
41
51
  this.parsers[lang] = new EtherParserJS(this.options)
42
52
  break
@@ -53,15 +63,13 @@ class EtherParser {
53
63
  this.parsers[lang] = new EtherParserGraphQL(this.options)
54
64
  break
55
65
  default:
56
- this.parsers[lang] = new EtherParserJS(this.options)
66
+ this.parsers[lang] = new EtherParserHTML(this.options)
57
67
  }
58
68
  }
59
69
  return this.parsers[lang]
60
70
  }
61
71
 
62
72
  detectTargetLanguage(source) {
63
- const lower = source.toLowerCase()
64
-
65
73
  const targetMatch = source.match(/\/\/\s*cible\s*:\s*(\w+)/i)
66
74
  if (targetMatch) {
67
75
  const target = targetMatch[1].toLowerCase()
@@ -83,6 +91,8 @@ class EtherParser {
83
91
  }
84
92
  }
85
93
 
94
+ const lower = source.toLowerCase()
95
+
86
96
  if (/^\s*(document|page|<!doctype|<html|tete|corps|entete|navigation|section|article)/m.test(lower)) {
87
97
  return 'html'
88
98
  }
@@ -133,7 +143,7 @@ class EtherParser {
133
143
  return 'js'
134
144
  }
135
145
 
136
- return 'js'
146
+ return 'html'
137
147
  }
138
148
 
139
149
  parse(source, targetLang = null) {
@@ -145,4 +155,4 @@ class EtherParser {
145
155
  }
146
156
  }
147
157
 
148
- module.exports = { EtherParser, TokenType }
158
+ module.exports = { EtherParser, TokenType }