diff options
-rw-r--r-- | ext/js/language/language-transformer.js | 11 | ||||
-rw-r--r-- | types/ext/language-transformer-internal.d.ts | 1 |
2 files changed, 10 insertions, 2 deletions
diff --git a/ext/js/language/language-transformer.js b/ext/js/language/language-transformer.js index c9e261ea..7ad1895f 100644 --- a/ext/js/language/language-transformer.js +++ b/ext/js/language/language-transformer.js @@ -15,6 +15,8 @@ * along with this program. If not, see <https://www.gnu.org/licenses/>. */ +import {escapeRegExp} from '../core/utilities.js'; + export class LanguageTransformer { constructor() { /** @type {number} */ @@ -65,7 +67,9 @@ export class LanguageTransformer { conditionsOut: conditionFlagsOut }); } - transforms2.push({name, rules: rules2}); + const suffixes = rules.map((rule) => rule.suffixIn); + const suffixHeuristic = new RegExp(`(${suffixes.map((suffix) => escapeRegExp(suffix)).join('|')})$`); + transforms2.push({name, rules: rules2, suffixHeuristic}); } this._nextFlagIndex = nextFlagIndex; @@ -133,7 +137,10 @@ export class LanguageTransformer { const results = [this._createTransformedText(sourceText, 0, [])]; for (let i = 0; i < results.length; ++i) { const {text, conditions, trace} = results[i]; - for (const {name, rules} of this._transforms) { + for (const transform of this._transforms) { + if (!transform.suffixHeuristic.test(text)) { continue; } + + const {name, rules} = transform; for (let j = 0, jj = rules.length; j < jj; ++j) { const rule = rules[j]; if (!LanguageTransformer.conditionsMatch(conditions, rule.conditionsIn)) { continue; } diff --git a/types/ext/language-transformer-internal.d.ts b/types/ext/language-transformer-internal.d.ts index cb0899e9..c186eeca 100644 --- a/types/ext/language-transformer-internal.d.ts +++ b/types/ext/language-transformer-internal.d.ts @@ -18,6 +18,7 @@ export type Transform = { name: string; rules: Rule[]; + suffixHeuristic: RegExp; }; export type Rule = { |