ether-code 0.7.1 → 0.7.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 +1 -1
- package/generators/js-generator.js +35 -13
- package/package.json +1 -1
package/cli/ether.js
CHANGED
|
@@ -1086,16 +1086,17 @@ class JSGenerator {
|
|
|
1086
1086
|
const name = node.name || (node.id ? (node.id.name || node.id) : '')
|
|
1087
1087
|
const params = (node.params || []).map(p => this.generateParam(p)).join(', ')
|
|
1088
1088
|
|
|
1089
|
-
let body = ''
|
|
1090
1089
|
const savedOutput = this.output
|
|
1090
|
+
const baseIndent = this.indent
|
|
1091
1091
|
this.output = ''
|
|
1092
|
-
this.indent
|
|
1092
|
+
this.indent = baseIndent + 1
|
|
1093
1093
|
this.generateNode(node.body)
|
|
1094
|
-
this.
|
|
1095
|
-
body = this.output.trim()
|
|
1094
|
+
const body = this.output.trimEnd()
|
|
1096
1095
|
this.output = savedOutput
|
|
1096
|
+
this.indent = baseIndent
|
|
1097
1097
|
|
|
1098
|
-
|
|
1098
|
+
const closingIndent = ' '.repeat(baseIndent)
|
|
1099
|
+
return `${async}function${generator} ${name}(${params}) {\n${body}\n${closingIndent}}`
|
|
1099
1100
|
}
|
|
1100
1101
|
|
|
1101
1102
|
generateParam(param) {
|
|
@@ -1670,15 +1671,17 @@ class JSGenerator {
|
|
|
1670
1671
|
: `(${params})`
|
|
1671
1672
|
|
|
1672
1673
|
if (node.body?.type === 'BlockStatement') {
|
|
1673
|
-
let body = ''
|
|
1674
1674
|
const savedOutput = this.output
|
|
1675
|
+
const baseIndent = this.indent
|
|
1675
1676
|
this.output = ''
|
|
1676
|
-
this.indent
|
|
1677
|
+
this.indent = baseIndent + 1
|
|
1677
1678
|
this.generateNode(node.body)
|
|
1678
|
-
this.
|
|
1679
|
-
body = this.output.trim()
|
|
1679
|
+
const body = this.output.trimEnd()
|
|
1680
1680
|
this.output = savedOutput
|
|
1681
|
-
|
|
1681
|
+
this.indent = baseIndent
|
|
1682
|
+
|
|
1683
|
+
const closingIndent = ' '.repeat(baseIndent)
|
|
1684
|
+
return `${async}${paramsStr} => {\n${body}\n${closingIndent}}`
|
|
1682
1685
|
} else {
|
|
1683
1686
|
const body = this.generateNode(node.body)
|
|
1684
1687
|
return `${async}${paramsStr} => ${body}`
|
|
@@ -1701,11 +1704,30 @@ class JSGenerator {
|
|
|
1701
1704
|
return `${object}[${property}]`
|
|
1702
1705
|
}
|
|
1703
1706
|
|
|
1704
|
-
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
|
|
1705
1727
|
|
|
1706
1728
|
if (translatedProperty.includes('.')) {
|
|
1707
1729
|
const parts = translatedProperty.split('.')
|
|
1708
|
-
if (parts[0].toLowerCase() ===
|
|
1730
|
+
if (parts[0].toLowerCase() === objectLower) {
|
|
1709
1731
|
return translatedProperty
|
|
1710
1732
|
}
|
|
1711
1733
|
return `${object}.${parts.slice(-1)[0]}`
|
|
@@ -1742,7 +1764,7 @@ class JSGenerator {
|
|
|
1742
1764
|
const left = this.generateNode(node.left)
|
|
1743
1765
|
const right = this.generateNode(node.right)
|
|
1744
1766
|
const op = this.translateOperator(node.operator)
|
|
1745
|
-
return
|
|
1767
|
+
return `${left} ${op} ${right}`
|
|
1746
1768
|
}
|
|
1747
1769
|
|
|
1748
1770
|
generateUnaryExpression(node) {
|