Skip to content

Commit 2dd235f

Browse files
committed
Make handleThis: true the default when using Parser API
1 parent 72b7c0e commit 2dd235f

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
### 1.4.1
2+
3+
Make `handleThis` the default if you use the `Lexer` and `Parser` directly, and you don't use `.compile`.
4+
5+
This is a way less common use case but it makes sense to have handleThis be the same default for both cases.
6+
7+
(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`.
8+
19
### 1.4.0
210

311
Add support for `handleThis: false` to disable handling of this.

lib/parse.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -763,7 +763,7 @@ var ESCAPE = {
763763
* @constructor
764764
*/
765765
function Lexer(options) {
766-
this.options = options;
766+
this.options = options || {};
767767
}
768768

769769
Lexer.prototype = {
@@ -2785,6 +2785,8 @@ ASTInterpreter.prototype = {
27852785
var Parser = function Parser(lexer, $filter, options) {
27862786
this.lexer = lexer;
27872787
this.$filter = $filter;
2788+
options = options || {};
2789+
options.handleThis = options.handleThis != null ? options.handleThis : true;
27882790
this.options = options;
27892791
this.ast = new AST(lexer, options);
27902792
this.ast.selfReferential = {

test/main.test.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,14 @@ describe("expressions", function () {
4040

4141
expect(parser.parse).to.be.a("function");
4242
});
43+
44+
it("should work with Parser and use handleThis by default", function () {
45+
expect(
46+
new expressions.Parser(new expressions.Lexer(), null, {
47+
csp: true,
48+
}).parse("this+this")(2)
49+
).to.equal(4);
50+
});
4351
});
4452

4553
describe(".compile(src)", function () {

0 commit comments

Comments
 (0)