-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfile.js
54 lines (48 loc) · 1.39 KB
/
file.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
"use strict";
const makeFileCtx = function(imports) {
const {codesCtx, parserNameSet, dictionaryNameSet} = imports;
class File {
constructor(structure) {
this.structure = structure;
this.doctype = {
parserName: null,
dictionaryName: null
};
}
handleDoctypeChange(node) {
const {parserName, dictionaryName} = this.structure.links.getDoctype();
const hasValueChanged = (parserName != this.doctype.parserName) || (dictionaryName != this.doctype.dictionaryName);
const areBothRecognized = parserNameSet.has(parserName) && dictionaryNameSet.has(dictionaryName);
this.structure.links.setDoctypeValidity(areBothRecognized);
if (hasValueChanged && areBothRecognized) {
this.doctype.dictionaryName = dictionaryName;
this.doctype.parserName = parserName;
return true;
}
return false;
}
updateDoctype(needsDecrufted) {
const needsParsed = new Set();
for (let node of needsDecrufted) {
if (codesCtx.isRoot(node)) {
if (this.handleDoctypeChange(node)) {
for (let [editorHead, _] of this.structure.links.iterate(node, null)) {
if (codesCtx.isGrammarCheckable(editorHead)) {
needsParsed.add(editorHead);
}
}
break;
}
} else {
if (this.doctype.parserName != null && this.doctype.dictionaryName != null) {
needsParsed.add(node);
}
}
}
return needsParsed;
}
}
return {
File
};
};