ether-code 0.8.5 → 0.8.7

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.5'
9
+ const VERSION = '0.8.7'
10
10
 
11
11
  const COLORS = {
12
12
  reset: '\x1b[0m',
@@ -228,22 +228,27 @@ class PHPGenerator {
228
228
  result += this.translate(p.visibility) + ' '
229
229
  }
230
230
 
231
- if (p.type) {
232
- result += this.translateType(p.type) + ' '
231
+ if (p.readonly) {
232
+ result += 'readonly '
233
+ }
234
+
235
+ const typeHint = p.typeHint || p.type
236
+ if (typeHint) {
237
+ result += this.translateType(typeHint) + ' '
233
238
  }
234
239
 
235
240
  if (p.variadic) {
236
241
  result += '...'
237
242
  }
238
243
 
239
- if (p.reference) {
244
+ if (p.byReference || p.reference) {
240
245
  result += '&'
241
246
  }
242
247
 
243
248
  const name = this.safeString(p.name || p.id?.name || p)
244
- result += '$' + this.translate(name)
249
+ result += '$' + name
245
250
 
246
- if (p.default !== undefined) {
251
+ if (p.default !== undefined && p.default !== null) {
247
252
  result += ' = ' + this.generateNode(p.default)
248
253
  }
249
254
 
@@ -263,7 +268,6 @@ class PHPGenerator {
263
268
  if (!type) return ''
264
269
 
265
270
  if (typeof type === 'string') {
266
- const translated = this.translate(type)
267
271
  const typeMap = {
268
272
  'chaîne': 'string', 'chaine': 'string', 'string': 'string',
269
273
  'entier': 'int', 'integer': 'int', 'int': 'int',
@@ -278,19 +282,24 @@ class PHPGenerator {
278
282
  'itérable': 'iterable', 'iterable': 'iterable',
279
283
  'jamais': 'never', 'never': 'never'
280
284
  }
281
- const lower = translated.toLowerCase()
282
- return typeMap[lower] || typeMap[type.toLowerCase()] || type
285
+ const lower = type.toLowerCase()
286
+ return typeMap[lower] || type
283
287
  }
284
288
 
285
- if (type.union) {
289
+ if (type.type === 'TypeHint' && type.types) {
290
+ const typeStr = type.types.join('|')
291
+ return (type.nullable ? '?' : '') + typeStr
292
+ }
293
+
294
+ if (type.union && type.types) {
286
295
  return type.types.map(t => this.translateType(t)).join('|')
287
296
  }
288
297
 
289
- if (type.intersection) {
298
+ if (type.intersection && type.types) {
290
299
  return type.types.map(t => this.translateType(t)).join('&')
291
300
  }
292
301
 
293
- if (type.nullable) {
302
+ if (type.nullable && type.type) {
294
303
  return '?' + this.translateType(type.type)
295
304
  }
296
305
 
@@ -727,6 +736,9 @@ class PHPGenerator {
727
736
  callee = this.generateMemberExpression(node.callee)
728
737
  } else if (node.callee && node.callee.type === 'StaticMemberExpression') {
729
738
  callee = this.generateStaticMemberExpression(node.callee)
739
+ } else if (node.callee && node.callee.type === 'Identifier') {
740
+ const name = this.safeString(node.callee.name)
741
+ callee = this.translate(name)
730
742
  } else {
731
743
  callee = this.generateNode(node.callee)
732
744
  }
@@ -749,9 +761,11 @@ class PHPGenerator {
749
761
  let property
750
762
 
751
763
  if (typeof node.property === 'string') {
752
- property = node.property
764
+ property = this.translateMethodName(node.property)
753
765
  } else if (node.property && node.property.name) {
754
- property = node.property.name
766
+ property = this.translateMethodName(node.property.name)
767
+ } else if (node.property && node.property.type === 'Identifier') {
768
+ property = this.translateMethodName(node.property.name || node.property.value)
755
769
  } else {
756
770
  property = this.generateNode(node.property)
757
771
  }
@@ -768,6 +782,20 @@ class PHPGenerator {
768
782
  return `${object}->${property}`
769
783
  }
770
784
 
785
+ translateMethodName(name) {
786
+ if (!name) return name
787
+ const translated = this.translate(name)
788
+ if (translated.includes('->')) {
789
+ const parts = translated.split('->')
790
+ return parts[parts.length - 1].replace(/\(\)$/, '')
791
+ }
792
+ if (translated.includes('::')) {
793
+ const parts = translated.split('::')
794
+ return parts[parts.length - 1].replace(/\(\)$/, '')
795
+ }
796
+ return translated.replace(/\(\)$/, '')
797
+ }
798
+
771
799
  generateStaticMemberExpression(node) {
772
800
  const cls = this.generateNode(node.class)
773
801
  let member
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ether-code",
3
- "version": "0.8.5",
3
+ "version": "0.8.7",
4
4
  "description": "Ether - Le langage intentionnel",
5
5
  "main": "cli/compiler.js",
6
6
  "bin": {
@@ -1089,6 +1089,8 @@ class EtherParserPHP extends EtherParserBase {
1089
1089
  }
1090
1090
  }
1091
1091
 
1092
+ this.match(TokenType.COLON)
1093
+ this.skipNewlines()
1092
1094
  body = this.parseBlock(lang)
1093
1095
 
1094
1096
  return {
@@ -2139,12 +2141,12 @@ class EtherParserPHP extends EtherParserBase {
2139
2141
  return { type: 'UnaryExpression', operator: '!', operand }
2140
2142
  }
2141
2143
 
2142
- if (this.match(TokenType.MINUS)) {
2144
+ if (this.match(TokenType.MINUS) && !this.check(TokenType.MINUS)) {
2143
2145
  const operand = this.parseUnary(lang)
2144
2146
  return { type: 'UnaryExpression', operator: '-', operand }
2145
2147
  }
2146
2148
 
2147
- if (this.match(TokenType.PLUS)) {
2149
+ if (this.match(TokenType.PLUS) && !this.check(TokenType.PLUS)) {
2148
2150
  const operand = this.parseUnary(lang)
2149
2151
  return { type: 'UnaryExpression', operator: '+', operand }
2150
2152
  }
@@ -2159,12 +2161,15 @@ class EtherParserPHP extends EtherParserBase {
2159
2161
  return { type: 'UnaryExpression', operator: '~', operand }
2160
2162
  }
2161
2163
 
2162
- if (this.match(TokenType.DOUBLE_PLUS)) {
2164
+ const current = this.current()
2165
+ if (current && current.type === TokenType.PLUS && current.value === '++') {
2166
+ this.advance()
2163
2167
  const operand = this.parseUnary(lang)
2164
2168
  return { type: 'UpdateExpression', operator: '++', prefix: true, operand }
2165
2169
  }
2166
2170
 
2167
- if (this.match(TokenType.DOUBLE_MINUS)) {
2171
+ if (current && current.type === TokenType.MINUS && current.value === '--') {
2172
+ this.advance()
2168
2173
  const operand = this.parseUnary(lang)
2169
2174
  return { type: 'UpdateExpression', operator: '--', prefix: true, operand }
2170
2175
  }
@@ -2276,11 +2281,14 @@ class EtherParserPHP extends EtherParserBase {
2276
2281
  parsePostfix(lang) {
2277
2282
  let expr = this.parseCall(lang)
2278
2283
 
2279
- if (this.match(TokenType.DOUBLE_PLUS)) {
2284
+ const current = this.current()
2285
+ if (current && current.type === TokenType.PLUS && current.value === '++') {
2286
+ this.advance()
2280
2287
  return { type: 'UpdateExpression', operator: '++', prefix: false, operand: expr }
2281
2288
  }
2282
2289
 
2283
- if (this.match(TokenType.DOUBLE_MINUS)) {
2290
+ if (current && current.type === TokenType.MINUS && current.value === '--') {
2291
+ this.advance()
2284
2292
  return { type: 'UpdateExpression', operator: '--', prefix: false, operand: expr }
2285
2293
  }
2286
2294
 
@@ -2441,9 +2449,8 @@ class EtherParserPHP extends EtherParserBase {
2441
2449
  return { type: 'Variable', name: value.substring(1) }
2442
2450
  }
2443
2451
 
2444
- const translated = this.translatePHP(value)
2445
2452
  this.advance()
2446
- return { type: 'Identifier', name: translated || value }
2453
+ return { type: 'Identifier', name: value }
2447
2454
  }
2448
2455
 
2449
2456
  if (token.type === TokenType.VARIABLE) {