Skip to content

Commit

Permalink
Add getPartOfSpeechFlags
Browse files Browse the repository at this point in the history
  • Loading branch information
toasted-nutbread committed Jan 28, 2024
1 parent 293f878 commit 2870c7b
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions ext/js/language/language-transformer.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ export class LanguageTransformer {
this._nextFlagIndex = 0;
/** @type {import('language-transformer-internal').Transform[]} */
this._transforms = [];
/** @type {Map<string, number>} */
this._partOfSpeechToFlagsMap = new Map();
}

/**
Expand Down Expand Up @@ -58,6 +60,23 @@ export class LanguageTransformer {
for (const transform of transforms2) {
this._transforms.push(transform);
}

for (const [type, condition] of conditionEntries) {
const flags = conditionFlagsMap.get(type);
if (typeof flags === 'undefined') { continue; } // This case should never happen
for (const partOfSpeech of condition.partsOfSpeech) {
this._partOfSpeechToFlagsMap.set(partOfSpeech, this.getPartOfSpeechFlags(partOfSpeech) | flags);
}
}
}

/**
* @param {string} partOfSpeech
* @returns {number}
*/
getPartOfSpeechFlags(partOfSpeech) {
const partOfSpeechFlags = this._partOfSpeechToFlagsMap.get(partOfSpeech);
return typeof partOfSpeechFlags !== 'undefined' ? partOfSpeechFlags : 0;
}

/**
Expand Down

0 comments on commit 2870c7b

Please sign in to comment.