@@ -36,6 +36,7 @@ export const defineVocabulary = (id, keywords) => {
36
36
37
37
const _dialects = { } ;
38
38
const _allowUnknownKeywords = { } ;
39
+ const _persistentDialects = { } ;
39
40
40
41
export const getKeywordId = ( keyword , dialectId ) => getDialect ( dialectId ) ?. [ keyword ]
41
42
|| ( _allowUnknownKeywords [ dialectId ] || keyword . startsWith ( "x-" ) )
@@ -60,8 +61,9 @@ const getDialect = (dialectId) => {
60
61
61
62
export const hasDialect = ( dialectId ) => dialectId in _dialects ;
62
63
63
- export const loadDialect = ( dialectId , dialect , allowUnknownKeywords = false ) => {
64
+ export const loadDialect = ( dialectId , dialect , allowUnknownKeywords = false , isPersistent = true ) => {
64
65
_allowUnknownKeywords [ dialectId ] = allowUnknownKeywords ;
66
+ _persistentDialects [ dialectId ] = _persistentDialects [ dialectId ] || isPersistent ;
65
67
66
68
_dialects [ dialectId ] = { } ;
67
69
Object . entries ( dialect )
@@ -77,12 +79,16 @@ export const loadDialect = (dialectId, dialect, allowUnknownKeywords = false) =>
77
79
} ) ;
78
80
} else if ( ! allowUnknownKeywords || isRequired ) {
79
81
delete _dialects [ dialectId ] ;
82
+ delete _allowUnknownKeywords [ dialectId ] ;
83
+ delete _persistentDialects [ dialectId ] ;
80
84
throw Error ( `Unrecognized vocabulary: ${ vocabularyId } . You can define this vocabulary with the 'defineVocabulary' function.` ) ;
81
85
}
82
86
} ) ;
83
87
} ;
84
88
85
89
export const unloadDialect = ( dialectId ) => {
86
- delete _allowUnknownKeywords [ dialectId ] ;
87
- delete _dialects [ dialectId ] ;
90
+ if ( ! _persistentDialects [ dialectId ] ) {
91
+ delete _allowUnknownKeywords [ dialectId ] ;
92
+ delete _dialects [ dialectId ] ;
93
+ }
88
94
} ;
0 commit comments