Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add support for multi-config JSEP
Before this change, JSEP `parse` was constructing a new instance of the JSEP class to encapsulate the expression and index as it was parsed, and the JSEP configuration was static on the class. Since JSEP parsing is synchronous, separate calls to parse can safely reset the expression and index instead of creating a new instance. Doing so allows the configuration to be moved into the JSEP instance, so that separate configurations can be used for different jsep parsing usages. The `parse` method then resets the instance's expression and index rather than constructing a new instance. This allows JSEP to functionally maintain backward compatibility despite the structural change. This commit essentially adds `instance()` (with default `clearConfig()` setup), and `defaultConfig()` methods. All static accesses were replaced with `this`. Specific things to note: - JSEP still exports the parse function with the instance's properties and methods for configuration - all static methods and properties have been moved to the instance (even constants and methods that don't access instance properties, so they can still be used by plugins). To keep the static constants available on each instance without forcing users to now access the prototype, they get assigned in the constructor - the export is still the instance's parse function, with all methods and properties accessed through a Proxy (rather than copying all properties and binding all methods) - the Jsep class export is replaced with the jsep instance export so that `{ Jsep } = require('jsep')` still works as before (unless user was calling (new Jsep('expr')).parse()) - because the ternary plugin is included by default, it gets specially registered once, so that `defaultConfig` can include the default plugin as well - fix `removeAllBinaryOps` not clearing `right_associative` fixes #211 BREAKING: changes JSEP internals to be a class instance per config, rather than per parse. `Jsep` export is now the combined parse function & class instance instead of the Jsep class. so usages that were directly using the Jsep class (`new Jsep(expression)`) will have update to either `Jsep(expression)` or `Jsep.parse(expression)`. Most applications should be backward compatible without any changes to code
- Loading branch information