Skip to content

Commit 471b4fe

Browse files
committed
Add support for Float16Array
This is only supported in environments where Float16Array is available.
1 parent f56b0fa commit 471b4fe

File tree

7 files changed

+26
-2
lines changed

7 files changed

+26
-2
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ Currently the following types are supported:
4949
- [`Boolean`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)
5050
- [`Buffer`](https://nodejs.org/api/buffer.html)
5151
- [`Date`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Date)
52+
- [`Float16Array`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Float16Array)
5253
- [`Float32Array`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Float32Array)
5354
- [`Float64Array`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Float64Array)
5455
- [`Int16Array`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Int16Array)

fixtures/float16array/input.js

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// Used as input
2+
// { preserveReferences: true }
3+
export default new Float16Array([1, 2, 3])
4+
5+
// -------------------------------------------------------------------------------------------------
6+
7+
// Default output
8+
// { preserveReferences: false }
9+
const withoutPreserveReferences = new Float16Array([1, 2, 3])

package-lock.json

+8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,9 @@
3232
"@types/estree": "^1.0.0"
3333
},
3434
"devDependencies": {
35-
"@remcohaszing/eslint": "^11.0.0",
3635
"@js-temporal/polyfill": "^0.4.0",
36+
"@petamoriken/float16": "^3.0.0",
37+
"@remcohaszing/eslint": "^11.0.0",
3738
"@types/node": "^22.0.0",
3839
"astring": "^1.0.0",
3940
"c8": "^9.0.0",

src/estree-util-value-to-estree.ts

+2
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ function isTypedArray(
159159
): value is
160160
| BigInt64Array
161161
| BigUint64Array
162+
| Float16Array
162163
| Float32Array
163164
| Float64Array
164165
| Int8Array
@@ -171,6 +172,7 @@ function isTypedArray(
171172
return (
172173
value instanceof BigInt64Array ||
173174
value instanceof BigUint64Array ||
175+
(typeof Float16Array !== 'undefined' && value instanceof Float16Array) ||
174176
value instanceof Float32Array ||
175177
value instanceof Float64Array ||
176178
value instanceof Int8Array ||

src/test.ts

+3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import assert from 'node:assert/strict'
22
import { test } from 'node:test'
33

44
import { Temporal as LocalTemporal } from '@js-temporal/polyfill'
5+
import { Float16Array } from '@petamoriken/float16'
56
import { generate } from 'astring'
67
import { valueToEstree } from 'estree-util-value-to-estree'
78
import { testFixturesDirectory } from 'snapshot-fixtures'
@@ -10,6 +11,8 @@ declare global {
1011
// eslint-disable-next-line no-var, @typescript-eslint/naming-convention
1112
var Temporal: typeof LocalTemporal
1213
}
14+
15+
globalThis.Float16Array ??= Float16Array
1316
globalThis.Temporal = LocalTemporal
1417

1518
testFixturesDirectory({

tsconfig.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"composite": true,
44
"declaration": true,
55
"declarationMap": true,
6-
"lib": ["es2022"],
6+
"lib": ["es2022", "esnext.float16"],
77
"module": "node16",
88
"noImplicitAny": true,
99
"rootDir": "src",

0 commit comments

Comments
 (0)