ether-code 0.7.2 → 0.7.4

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.2'
9
+ const VERSION = '0.7.4'
10
10
 
11
11
  const COLORS = {
12
12
  reset: '\x1b[0m',
package/ether-parser.js CHANGED
@@ -3001,6 +3001,7 @@ class EtherParser {
3001
3001
  this.advance()
3002
3002
  const expr = this.parseExpression(lang)
3003
3003
  this.expect(TokenType.RPAREN)
3004
+ expr.parenthesized = true
3004
3005
  return expr
3005
3006
  }
3006
3007
 
@@ -1704,11 +1704,30 @@ class JSGenerator {
1704
1704
  return `${object}[${property}]`
1705
1705
  }
1706
1706
 
1707
- const translatedProperty = this.translateMethod(property)
1707
+ const knownObjects = [
1708
+ 'console', 'document', 'window', 'math', 'json', 'object', 'array',
1709
+ 'string', 'number', 'date', 'regexp', 'promise', 'set', 'map',
1710
+ 'weakset', 'weakmap', 'symbol', 'reflect', 'proxy', 'intl',
1711
+ 'atomics', 'sharedarraybuffer', 'arraybuffer', 'dataview',
1712
+ 'uint8array', 'int8array', 'uint16array', 'int16array',
1713
+ 'uint32array', 'int32array', 'float32array', 'float64array',
1714
+ 'bigint64array', 'biguint64array', 'error', 'typeerror',
1715
+ 'syntaxerror', 'referenceerror', 'rangeerror', 'urierror',
1716
+ 'localstorage', 'sessionstorage', 'navigator', 'location',
1717
+ 'history', 'screen', 'performance', 'fetch', 'request', 'response',
1718
+ 'headers', 'url', 'urlsearchparams', 'formdata', 'blob', 'file',
1719
+ 'filereader', 'xmlhttprequest', 'websocket', 'worker',
1720
+ 'serviceworker', 'notification', 'geolocation'
1721
+ ]
1722
+
1723
+ const objectLower = object.toLowerCase()
1724
+ const shouldTranslate = knownObjects.includes(objectLower)
1725
+
1726
+ const translatedProperty = shouldTranslate ? this.translateMethod(property) : property
1708
1727
 
1709
1728
  if (translatedProperty.includes('.')) {
1710
1729
  const parts = translatedProperty.split('.')
1711
- if (parts[0].toLowerCase() === object.toLowerCase()) {
1730
+ if (parts[0].toLowerCase() === objectLower) {
1712
1731
  return translatedProperty
1713
1732
  }
1714
1733
  return `${object}.${parts.slice(-1)[0]}`
@@ -1745,7 +1764,8 @@ class JSGenerator {
1745
1764
  const left = this.generateNode(node.left)
1746
1765
  const right = this.generateNode(node.right)
1747
1766
  const op = this.translateOperator(node.operator)
1748
- return `${left} ${op} ${right}`
1767
+ const expr = `${left} ${op} ${right}`
1768
+ return node.parenthesized ? `(${expr})` : expr
1749
1769
  }
1750
1770
 
1751
1771
  generateUnaryExpression(node) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ether-code",
3
- "version": "0.7.2",
3
+ "version": "0.7.4",
4
4
  "description": "Ether - Le langage intentionnel",
5
5
  "main": "cli/compiler.js",
6
6
  "bin": {