Last modified: 2014-08-01 19:52:09 UTC
Oh man, this was annoying to discover… jqueryMsg uses the same astCache for all parser objects. This is apparently expected behavior, but I'm pretty sure it's incorrect, as each parser can have different messages under the same key. mw.jqueryMsg.parser.prototype = { ... * This cache is shared by all instances of mw.jqueryMsg.parser. astCache: {}, ... }
Seems like this would be easy to fix, just create astCache as a property upon initialization. Seems to have been a bug since the beginning (sorry), but the fact that there's a comment makes me think that maybe someone has deliberately preserved this behavior now. I can't think of any situation where you want multiple instances to share a cache, is there? If you need multiple newly-created objects to share a cache, write a singleton to wrap this class. Kind of an antipattern IMO but whatever.
I added the comment after I also discovered it the hard way. If it's desired behavior to allow different messages with the same key, I agree it needs to change. It would use more memory, but simplify things. I think this has come up for me when writing unit tests. If this change is made, onlyCurlyBraceTransform can also be removed from the AST key, since that is a per-parser setting.