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 +1 -1
- package/ether-parser.js +1 -0
- package/generators/js-generator.js +23 -3
- package/package.json +1 -1
package/cli/ether.js
CHANGED
package/ether-parser.js
CHANGED
|
@@ -1704,11 +1704,30 @@ class JSGenerator {
|
|
|
1704
1704
|
return `${object}[${property}]`
|
|
1705
1705
|
}
|
|
1706
1706
|
|
|
1707
|
-
const
|
|
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() ===
|
|
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
|
-
|
|
1767
|
+
const expr = `${left} ${op} ${right}`
|
|
1768
|
+
return node.parenthesized ? `(${expr})` : expr
|
|
1749
1769
|
}
|
|
1750
1770
|
|
|
1751
1771
|
generateUnaryExpression(node) {
|