1+ /**
2+ * @typedef Options
3+ * Configuration.
4+ * @property {boolean } [allowLiterals=false]
5+ * Suggest straight (`'`) instead of smart (`’`) apostrophes.
6+ * Use `retext-quotes` if you want to properly check that though.
7+ * @property {boolean } [straight=false]
8+ * Include literal phrases.
9+ * The default is to ignore them.
10+ */
11+
112import { visit } from 'unist-util-visit'
213import { toString } from 'nlcst-to-string'
314import { isLiteral } from 'nlcst-is-literal'
@@ -10,7 +21,11 @@ const own = {}.hasOwnProperty
1021
1122const data = initialize ( )
1223
13- // Check contractions use.
24+ /**
25+ * Plugin to check contractions use.
26+ *
27+ * @type {import('unified').Plugin<[Options?]> }
28+ */
1429export default function retextContractions ( options = { } ) {
1530 const ignore = options . allowLiterals
1631 const straight = options . straight
@@ -32,7 +47,7 @@ export default function retextContractions(options = {}) {
3247 // Perfect.
3348 actual === expected ||
3449 // Ignore literal misspelt words: `like this: “hasnt”`.
35- ( ! ignore && isLiteral ( parent , index ) )
50+ ( parent && index !== null && ! ignore && isLiteral ( parent , index ) )
3651 ) {
3752 return
3853 }
@@ -66,8 +81,11 @@ export default function retextContractions(options = {}) {
6681 }
6782}
6883
84+ /** @returns {Record<string, string> } */
6985function initialize ( ) {
86+ /** @type {Record<string, string> } */
7087 const result = { }
88+ /** @type {string } */
7189 let key
7290
7391 for ( key in list ) {
0 commit comments