Skip to content

Commit 8ae1f8f

Browse files
committed
refactor(export-map): declare all known properties for optionsHashesCache and use dequal instead of JSON.stringify
1 parent cb53163 commit 8ae1f8f

File tree

2 files changed

+18
-8
lines changed

2 files changed

+18
-8
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
"dependencies": {
5151
"@typescript-eslint/utils": "^7.4.0",
5252
"debug": "^4.3.4",
53+
"dequal": "^2.0.3",
5354
"doctrine": "^3.0.0",
5455
"eslint-import-resolver-node": "^0.3.9",
5556
"get-tsconfig": "^4.7.3",

src/utils/export-map.ts

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import path from 'node:path'
33

44
import type { TSESLint, TSESTree } from '@typescript-eslint/utils'
55
import debug from 'debug'
6+
import { dequal } from 'dequal'
67
import type { Annotation } from 'doctrine'
78
import doctrine from 'doctrine'
89
import type { AST } from 'eslint'
@@ -1102,21 +1103,29 @@ function childContext(
11021103
}
11031104
}
11041105

1105-
const optionsHashesCache: Record<
1106-
string,
1107-
{ value: string; hash: string } | undefined
1108-
> = {}
1106+
type OptionsHashesCache = Record<
1107+
'settings' | 'parserOptions' | 'parserMeta' | 'languageOptions',
1108+
{ value: unknown; hash: string }
1109+
>
1110+
1111+
const optionsHashesCache: OptionsHashesCache = {
1112+
settings: { value: null, hash: '' },
1113+
parserOptions: { value: null, hash: '' },
1114+
parserMeta: { value: null, hash: '' },
1115+
languageOptions: { value: null, hash: '' },
1116+
}
11091117

1110-
function getOptionsHash(key: string, value: unknown) {
1118+
function getOptionsHash(key: keyof OptionsHashesCache, value: unknown) {
11111119
const entry = optionsHashesCache[key]
1112-
const stringifiedValue = JSON.stringify(value)
11131120

1114-
if (stringifiedValue === entry?.value) {
1121+
if (dequal(value, entry.value)) {
11151122
return entry.hash
11161123
}
11171124

11181125
const hash = hashify(value).digest('hex')
1119-
optionsHashesCache[key] = { value: stringifiedValue, hash }
1126+
1127+
optionsHashesCache[key].value = value
1128+
optionsHashesCache[key].hash = hash
11201129

11211130
return hash
11221131
}

0 commit comments

Comments
 (0)