ether-code 0.9.6 → 0.9.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.9.6'
9
+ const VERSION = '0.9.7'
10
10
 
11
11
  const COLORS = {
12
12
  reset: '\x1b[0m',
@@ -356,8 +356,10 @@ class PHPGenerator {
356
356
  this.output = ''
357
357
  this.indent = 0
358
358
  this.closureVariables = new Set()
359
+ this.importedClasses = new Set()
359
360
 
360
361
  this.collectClosureVariables(ast)
362
+ this.collectImportedClasses(ast)
361
363
 
362
364
  if (ast.phpTag !== false) {
363
365
  this.output = '<?php\n'
@@ -382,6 +384,27 @@ class PHPGenerator {
382
384
  return this.output.trim()
383
385
  }
384
386
 
387
+ collectImportedClasses(ast) {
388
+ const nodes = Array.isArray(ast) ? ast : (ast?.body || [ast])
389
+
390
+ for (const node of nodes) {
391
+ if (!node) continue
392
+
393
+ if (node.type === 'UseStatement') {
394
+ if (node.imports && node.imports.length > 0) {
395
+ for (const imp of node.imports) {
396
+ const path = imp.path || imp.name || ''
397
+ const className = path.split('\\').pop()
398
+ if (className) this.importedClasses.add(className)
399
+ }
400
+ } else if (node.name) {
401
+ const className = node.name.split('\\').pop()
402
+ if (className) this.importedClasses.add(className)
403
+ }
404
+ }
405
+ }
406
+ }
407
+
385
408
  collectClosureVariables(ast) {
386
409
  const nodes = Array.isArray(ast) ? ast : (ast?.body || [ast])
387
410
 
@@ -963,6 +986,12 @@ class PHPGenerator {
963
986
  }
964
987
 
965
988
  prefixGlobalClass(name) {
989
+ if (!name) return name
990
+
991
+ if (this.importedClasses && this.importedClasses.has(name)) {
992
+ return name
993
+ }
994
+
966
995
  const phpGlobalClasses = [
967
996
  'Exception', 'Error', 'TypeError', 'ValueError', 'ArgumentCountError',
968
997
  'ArithmeticError', 'DivisionByZeroError', 'ParseError', 'AssertionError',
@@ -419,7 +419,7 @@ class EtherLexer {
419
419
  break
420
420
  }
421
421
  if (this.peek() === '\n') {
422
- this.tokens.push(new Token(TokenType.ERROR, 'Chaîne non terminée', startLine, startCol, this.currentIndent))
422
+ this.tokens.push(new Token(TokenType.ERROR, 'Chaîne non terminée', startLine, startCol, this.currentIndent))
423
423
  return
424
424
  }
425
425
  }
@@ -458,7 +458,7 @@ class EtherLexer {
458
458
  value += String.fromCodePoint(parseInt(unicode, 16))
459
459
  break
460
460
  default:
461
- value += escaped
461
+ value += '\\' + escaped
462
462
  }
463
463
  } else {
464
464
  value += this.advance()
@@ -1001,7 +1001,7 @@ class EtherLexer {
1001
1001
  break
1002
1002
 
1003
1003
  default:
1004
- this.tokens.push(new Token(TokenType.ERROR, `Caractère inattendu: ${char}`, startLine, startCol, this.currentIndent))
1004
+ this.tokens.push(new Token(TokenType.ERROR, `Caractère inattendu: ${char}`, startLine, startCol, this.currentIndent))
1005
1005
  }
1006
1006
  }
1007
1007
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ether-code",
3
- "version": "0.9.6",
3
+ "version": "0.9.7",
4
4
  "description": "Ether - Le langage intentionnel",
5
5
  "main": "cli/compiler.js",
6
6
  "bin": {