11/**
2- * @typedef {import('unist').Parent } Parent
3- * @typedef {import('unist').Node } Node
2+ * @typedef {import('nlcst').Root } Root
3+ * @typedef {import('nlcst').Sentence } Sentence
4+ * @typedef {import('nlcst').Word } Word
5+ * @typedef {import('nlcst').SentenceContent } SentenceContent
46 *
57 * @typedef Options
68 * Configuration.
2527 * @property {string } stem
2628 *
2729 * @typedef PhraseMatch
28- * @property {Node [] } nodes
29- * @property {Parent } parent
30+ * @property {SentenceContent [] } nodes
31+ * @property {Sentence } parent
3032 *
3133 * @typedef KeywordMatch
32- * @property {Node } node
34+ * @property {Word } node
3335 * @property {number } index
34- * @property {Parent } parent
36+ * @property {Sentence } parent
3537 */
3638
3739import { stemmer } from 'stemmer'
@@ -43,7 +45,7 @@ const own = {}.hasOwnProperty
4345/**
4446 * Plugin to extract keywords and key-phrases.
4547 *
46- * @type {import('unified').Plugin<[Options?]> }
48+ * @type {import('unified').Plugin<[Options?]|[], Root > }
4749 */
4850export default function retextKeywords ( options = { } ) {
4951 const maximum = options . maximum || 5
@@ -58,17 +60,17 @@ export default function retextKeywords(options = {}) {
5860/**
5961 * Get following or preceding important words or white space.
6062 *
61- * @param {Parent } parent
63+ * @param {Sentence } parent
6264 * @param {number } index
6365 * @param {number } offset
6466 */
6567function findPhraseInDirection ( parent , index , offset ) {
6668 const children = parent . children
67- /** @type {Node [] } */
69+ /** @type {SentenceContent [] } */
6870 const nodes = [ ]
6971 /** @type {string[] } */
7072 const stems = [ ]
71- /** @type {Node [] } */
73+ /** @type {SentenceContent [] } */
7274 const queue = [ ]
7375
7476 while ( children [ ( index += offset ) ] ) {
@@ -97,7 +99,7 @@ function findPhraseInDirection(parent, index, offset) {
9799function getKeyphrases ( results , maximum ) {
98100 /** @type {Record<string, Keyphrase> } */
99101 const stemmedPhrases = { }
100- /** @type {Node [] } */
102+ /** @type {Word [] } */
101103 const initialWords = [ ]
102104 /** @type {string } */
103105 let keyword
@@ -112,7 +114,7 @@ function getKeyphrases(results, maximum) {
112114 while ( ++ index < matches . length ) {
113115 const phrase = findPhrase ( matches [ index ] )
114116 const stemmedPhrase = stemmedPhrases [ phrase . value ]
115- const first = phrase . nodes [ 0 ]
117+ const first = /** @type { Word } */ ( phrase . nodes [ 0 ] )
116118 const match = { nodes : phrase . nodes , parent : matches [ index ] . parent }
117119
118120 // If we've detected the same stemmed phrase somewhere.
@@ -260,13 +262,14 @@ function merge(previous, current, next) {
260262/**
261263 * Get most important words in `node`.
262264 *
263- * @param {Node } node
265+ * @param {Root } node
264266 */
265267function getImportantWords ( node ) {
266268 /** @type {Record<string, Keyword> } */
267269 const words = { }
268270
269- visit ( node , 'WordNode' , ( word , index , parent ) => {
271+ visit ( node , 'WordNode' , ( word , index , parent_ ) => {
272+ const parent = /** @type {Sentence } */ ( parent_ )
270273 if ( parent && index !== null && important ( word ) ) {
271274 const stem = stemNode ( word )
272275 const match = { node : word , index, parent}
@@ -309,7 +312,7 @@ function cloneMatches(words) {
309312/**
310313 * Check if `node` is important.
311314 *
312- * @param {Node } node
315+ * @param {SentenceContent } node
313316 * @returns {boolean }
314317 */
315318function important ( node ) {
@@ -336,7 +339,7 @@ function uppercase(value) {
336339/**
337340 * Get the stem of a node.
338341 *
339- * @param {Node } node
342+ * @param {SentenceContent } node
340343 * @returns {string }
341344 */
342345function stemNode ( node ) {
0 commit comments