Skip to content

Commit

Permalink
fix: perf_hooks reference
Browse files Browse the repository at this point in the history
In browser environment (e.g. jsdom),
the named export could fail when there is no polyfill. e.g.:

```sh
"performance" is not exported by "__vite-browser-external"
```

Use namespace export should avoid that problem
  • Loading branch information
unional committed Mar 13, 2023
1 parent 7a7067d commit a161808
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions ts/assert-order/StateMachine.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { performance } from 'perf_hooks'
import * as perf from 'perf_hooks'
import { State } from './types.js'

let timeTracker: { start(): void, taken(): number }
Expand All @@ -13,11 +13,12 @@ if (process && typeof process.hrtime === 'function') {
}
}
}
else if (performance && typeof performance.now === 'function') {
else if (perf.performance && typeof perf.performance.now === 'function') {
const now = perf.performance.now
let tick: number
timeTracker = {
start() { tick = performance.now() },
taken() { return performance.now() - tick }
start() { tick = now() },
taken() { return now() - tick }
}
}
else {
Expand Down

0 comments on commit a161808

Please sign in to comment.