@fontoxml/fontoxml-development-tools
Version:
Development tools for Fonto.
56 lines (48 loc) • 1.52 kB
JavaScript
import Option from './Option.js';
import symbols from './symbols.js';
export default class IsolatedOption extends Option {
constructor(name) {
super(name);
}
// By resetting all tiers there are no "unresolved" syntax parts
[symbols.updateTiersAfterMatch](tiers) {
tiers = {
ordered: [],
unordered: tiers.unordered.filter(
(tier) => tier.isExemptFromIsolatedOption
),
};
return tiers;
}
// By emptying out parts there should be no further attempts to match
[symbols.spliceInputFromParts](parts, tiers) {
const input = Option.prototype[symbols.spliceInputFromParts].apply(
this,
arguments
);
// Clear existing parts, keeping only the parts which are exempt from isolated option emptying.
const exemptTiers = tiers.unordered.filter((tier) => tier.isExemptFromIsolatedOption);
const exemptParts = parts.filter(
(part) => exemptTiers.some((tier) => tier[symbols.isMatchForPart](part))
);
parts.length = 0;
for (const part of exemptParts) {
parts.push(part);
}
return input;
}
// By resetting the results to just the command and this instance the Request object stays clean
[symbols.updateInputSpecsAfterMatch](resolvedInputSpecs, inputValue) {
resolvedInputSpecs = [
resolvedInputSpecs
.reverse()
.find((inputSpec) => inputSpec.syntax.getType() === 'command'),
...resolvedInputSpecs.filter(inputSpec => inputSpec.syntax?.isExemptFromIsolatedOption),
{
syntax: this,
input: inputValue,
},
];
return resolvedInputSpecs;
}
}