@@ -25,22 +25,23 @@ function spell(options) {
25
25
var digits = settings . ignoreDigits
26
26
var apos = settings . normalizeApostrophes
27
27
var personal = settings . personal
28
- var config = { }
28
+ var config
29
29
var loadError
30
30
31
31
if ( typeof load !== 'function' ) {
32
32
throw new Error ( 'Expected `Object`, got `' + load + '`' )
33
33
}
34
34
35
- config . ignoreLiteral =
36
- literal === null || literal === undefined ? true : literal
37
- config . ignoreDigits = digits === null || digits === undefined ? true : digits
38
- config . normalizeApostrophes =
39
- apos === null || apos === undefined ? true : apos
40
- config . ignore = settings . ignore
41
- config . max = settings . max || max
42
- config . count = 0
43
- config . cache = { }
35
+ config = {
36
+ ignoreLiteral : literal === null || literal === undefined ? true : literal ,
37
+ ignoreDigits : digits === null || digits === undefined ? true : digits ,
38
+ normalizeApostrophes : apos === null || apos === undefined ? true : apos ,
39
+ ignore : settings . ignore ,
40
+ max : settings . max || max ,
41
+ count : 0 ,
42
+ cache : { } ,
43
+ checker : null
44
+ }
44
45
45
46
load ( construct )
46
47
@@ -60,8 +61,8 @@ function spell(options) {
60
61
}
61
62
62
63
// Callback invoked when a `dictionary` is loaded (possibly erroneous) or
63
- // when `load`ing failed. Flushes the queue when available, and sets the
64
- // results on the parent scope.
64
+ // when `load`ing failed.
65
+ // Flushes the queue when available, and sets the results on the parent scope.
65
66
function construct ( err , dictionary ) {
66
67
var length = queue . length
67
68
var index = - 1
@@ -123,8 +124,12 @@ function all(tree, file, config) {
123
124
return
124
125
}
125
126
127
+ // Check the whole word.
126
128
correct = checker . correct ( word )
127
129
130
+ // If the whole word is not correct, check all its parts.
131
+ // This makes sure that, if `alpha` and `bravo` are correct, `alpha-bravo`
132
+ // is also seenn as correct.
128
133
if ( ! correct && children . length > 1 ) {
129
134
correct = true
130
135
length = children . length
@@ -144,6 +149,8 @@ function all(tree, file, config) {
144
149
}
145
150
146
151
if ( ! correct ) {
152
+ // Suggestions are very slow, so cache them (spelling mistakes other than
153
+ // typos often occur multiple times).
147
154
if ( own . call ( cache , word ) ) {
148
155
reason = cache [ word ]
149
156
} else {
0 commit comments