diff --git a/CHANGELOG.md b/CHANGELOG.md index 5dc5cb4..aa248d3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,11 @@ +### 1.4.1 + +Make `handleThis` the default if you use the `Lexer` and `Parser` directly, and you don't use `.compile`. + +This is a way less common use case but it makes sense to have handleThis be the same default for both cases. + +(This also makes the library behave in the same way between 1.3.0 and 1.4.1 when using Parser or Lexer). There was a backwards incompatible change brought by 1.4.0 for users of `Parser`. + ### 1.4.0 Add support for `handleThis: false` to disable handling of this. diff --git a/lib/parse.js b/lib/parse.js index 8366311..ca18dd8 100644 --- a/lib/parse.js +++ b/lib/parse.js @@ -763,7 +763,7 @@ var ESCAPE = { * @constructor */ function Lexer(options) { - this.options = options; + this.options = options || {}; } Lexer.prototype = { @@ -2785,6 +2785,8 @@ ASTInterpreter.prototype = { var Parser = function Parser(lexer, $filter, options) { this.lexer = lexer; this.$filter = $filter; + options = options || {}; + options.handleThis = options.handleThis != null ? options.handleThis : true; this.options = options; this.ast = new AST(lexer, options); this.ast.selfReferential = { diff --git a/test/main.test.js b/test/main.test.js index 565bc38..d46f685 100644 --- a/test/main.test.js +++ b/test/main.test.js @@ -40,6 +40,14 @@ describe("expressions", function () { expect(parser.parse).to.be.a("function"); }); + + it("should work with Parser and use handleThis by default", function () { + expect( + new expressions.Parser(new expressions.Lexer(), null, { + csp: true, + }).parse("this+this")(2) + ).to.equal(4); + }); }); describe(".compile(src)", function () {