@@ -12,14 +12,12 @@ export interface SFCParseResult {
12
12
}
13
13
14
14
export const cache = new Map < string , SFCDescriptor > ( )
15
- export const hmrCache = new Map < string , SFCDescriptor > ( )
16
15
const prevCache = new Map < string , SFCDescriptor | undefined > ( )
17
16
18
17
export function createDescriptor (
19
18
filename : string ,
20
19
source : string ,
21
20
{ root, isProduction, sourceMap, compiler } : ResolvedOptions ,
22
- hmr = false ,
23
21
) : SFCParseResult {
24
22
const { descriptor, errors } = compiler . parse ( source , {
25
23
filename,
@@ -30,39 +28,35 @@ export function createDescriptor(
30
28
// project (relative to root) and on different systems.
31
29
const normalizedPath = slash ( path . normalize ( path . relative ( root , filename ) ) )
32
30
descriptor . id = getHash ( normalizedPath + ( isProduction ? source : '' ) )
33
- ; ( hmr ? hmrCache : cache ) . set ( filename , descriptor )
31
+
32
+ cache . set ( filename , descriptor )
34
33
return { descriptor, errors }
35
34
}
36
35
37
36
export function getPrevDescriptor ( filename : string ) : SFCDescriptor | undefined {
38
37
return prevCache . get ( filename )
39
38
}
40
39
41
- export function invalidateDescriptor ( filename : string , hmr = false ) : void {
42
- const _cache = hmr ? hmrCache : cache
43
- const prev = _cache . get ( filename )
44
- _cache . delete ( filename )
45
- if ( prev ) {
46
- prevCache . set ( filename , prev )
47
- }
40
+ export function setPrevDescriptor (
41
+ filename : string ,
42
+ entry : SFCDescriptor ,
43
+ ) : void {
44
+ prevCache . set ( filename , entry )
48
45
}
49
46
50
47
export function getDescriptor (
51
48
filename : string ,
52
49
options : ResolvedOptions ,
53
50
createIfNotFound = true ,
54
- hmr = false ,
55
51
) : SFCDescriptor | undefined {
56
- const _cache = hmr ? hmrCache : cache
57
- if ( _cache . has ( filename ) ) {
58
- return _cache . get ( filename ) !
52
+ if ( cache . has ( filename ) ) {
53
+ return cache . get ( filename ) !
59
54
}
60
55
if ( createIfNotFound ) {
61
56
const { descriptor, errors } = createDescriptor (
62
57
filename ,
63
58
fs . readFileSync ( filename , 'utf-8' ) ,
64
59
options ,
65
- hmr ,
66
60
)
67
61
if ( errors . length ) {
68
62
throw errors [ 0 ]
0 commit comments