Skip to content

Commit

Permalink
Make handleThis: true the default when using Parser API
Browse files Browse the repository at this point in the history
  • Loading branch information
edi9999 committed Nov 25, 2024
1 parent 72b7c0e commit 2dd235f
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
4 changes: 3 additions & 1 deletion lib/parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -763,7 +763,7 @@ var ESCAPE = {
* @constructor
*/
function Lexer(options) {
this.options = options;
this.options = options || {};
}

Lexer.prototype = {
Expand Down Expand Up @@ -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 = {
Expand Down
8 changes: 8 additions & 0 deletions test/main.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down

0 comments on commit 2dd235f

Please sign in to comment.