diff --git a/app/assets/javascripts/discourse/tests/unit/lib/pretty-text-test.js b/app/assets/javascripts/discourse/tests/unit/lib/pretty-text-test.js index b03f30fa7bd..34384a54a29 100644 --- a/app/assets/javascripts/discourse/tests/unit/lib/pretty-text-test.js +++ b/app/assets/javascripts/discourse/tests/unit/lib/pretty-text-test.js @@ -1689,6 +1689,7 @@ var bar = 'bar'; }; assert.cookedOptions("test fun funny", opts, "

test times funny

"); + assert.cookedOptions("constructor", opts, "

constructor

"); }); test("watched words link", function (assert) { diff --git a/app/assets/javascripts/pretty-text/engines/discourse-markdown/watched-words.js b/app/assets/javascripts/pretty-text/engines/discourse-markdown/watched-words.js index d82e13f8d03..7c09bf1c35c 100644 --- a/app/assets/javascripts/pretty-text/engines/discourse-markdown/watched-words.js +++ b/app/assets/javascripts/pretty-text/engines/discourse-markdown/watched-words.js @@ -73,7 +73,7 @@ export function setup(helper) { return; } - const cache = {}; + const cache = new Map(); md.core.ruler.push("watched-words", (state) => { for (let j = 0, l = state.tokens.length; j < l; j++) { @@ -153,8 +153,14 @@ export function setup(helper) { if (currentToken.type === "text") { const text = currentToken.content; - const matches = (cache[text] = - cache[text] || findAllMatches(text, matchers)); + + let matches; + if (cache.has(text)) { + matches = cache.get(text); + } else { + matches = findAllMatches(text, matchers); + cache.set(text, matches); + } // Now split string to nodes const nodes = [];