Skip to content

Commit 4ece153

Browse files
committed
refactor(export-map): use versioning approach instead of hashes for options
1 parent f62f89e commit 4ece153

File tree

1 file changed

+20
-29
lines changed

1 file changed

+20
-29
lines changed

src/utils/export-map.ts

Lines changed: 20 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import type {
2121
} from '../types'
2222

2323
import { getValue } from './get-value'
24-
import { hashObject, hashify } from './hash'
24+
import { hashObject } from './hash'
2525
import { hasValidExtension, ignore } from './ignore'
2626
import { parse } from './parse'
2727
import { relative, resolve } from './resolve'
@@ -1103,55 +1103,46 @@ function childContext(
11031103
}
11041104
}
11051105

1106-
type OptionsHashesCache = Record<
1107-
'settings' | 'parserOptions' | 'parserMeta',
1108-
{ value: unknown; hash: string }
1106+
type OptionsVersionsCache = Record<
1107+
'settings' | 'parserOptions' | 'parser',
1108+
{ value: unknown; version: number }
11091109
>
11101110

1111-
const optionsHashesCache: OptionsHashesCache = {
1112-
settings: { value: null, hash: '' },
1113-
parserOptions: { value: null, hash: '' },
1114-
parserMeta: { value: null, hash: '' },
1111+
const optionsVersionsCache: OptionsVersionsCache = {
1112+
settings: { value: null, version: 0 },
1113+
parserOptions: { value: null, version: 0 },
1114+
parser: { value: null, version: 0 },
11151115
}
11161116

1117-
function getOptionsHash(key: keyof OptionsHashesCache, value: unknown) {
1118-
const entry = optionsHashesCache[key]
1117+
function getOptionsVersion(key: keyof OptionsVersionsCache, value: unknown) {
1118+
const entry = optionsVersionsCache[key]
11191119

1120-
if (dequal(value, entry.value)) {
1121-
return entry.hash
1120+
if (!dequal(value, entry.value)) {
1121+
entry.value = value
1122+
entry.version += 1
11221123
}
11231124

1124-
const hash = hashify(value).digest('hex')
1125-
1126-
optionsHashesCache[key].value = value
1127-
optionsHashesCache[key].hash = hash
1128-
1129-
return hash
1125+
return String(entry.version)
11301126
}
11311127

11321128
function makeContextCacheKey(context: RuleContext | ChildContext) {
11331129
const { settings, parserPath, parserOptions, languageOptions } = context
11341130

1135-
let hash = getOptionsHash('settings', settings)
1131+
let hash = getOptionsVersion('settings', settings)
11361132

11371133
const usedParserOptions = languageOptions?.parserOptions ?? parserOptions
11381134

1139-
hash += getOptionsHash('parserOptions', usedParserOptions)
1135+
hash += getOptionsVersion('parserOptions', usedParserOptions)
11401136

11411137
if (languageOptions) {
11421138
const { ecmaVersion, sourceType } = languageOptions
11431139
hash += String(ecmaVersion) + String(sourceType)
11441140
}
11451141

1146-
if (parserPath) {
1147-
hash += parserPath
1148-
} else {
1149-
const { meta } = languageOptions?.parser ?? {}
1150-
1151-
if (meta) {
1152-
hash += getOptionsHash('parserMeta', meta)
1153-
}
1154-
}
1142+
hash += getOptionsVersion(
1143+
'parser',
1144+
parserPath ?? languageOptions?.parser?.meta ?? languageOptions?.parser,
1145+
)
11551146

11561147
return hash
11571148
}

0 commit comments

Comments
 (0)