[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] master 3df50ab 17/31: Add option js2-getprop-has-side-effects (#4
From: |
Dmitry Gutov |
Subject: |
[elpa] master 3df50ab 17/31: Add option js2-getprop-has-side-effects (#424) |
Date: |
Fri, 21 Jul 2017 09:04:57 -0400 (EDT) |
branch: master
commit 3df50ab9a4ad8c5e6c90318fdc6178a174ca5a4e
Author: Stephen Hicks <address@hidden>
Commit: Dmitry Gutov <address@hidden>
Add option js2-getprop-has-side-effects (#424)
Includes a slight restructuring of how side-effect calculations are done
(for better testability) and adds basic test coverage for no.side.effect
warnings.
---
js2-mode.el | 12 ++++++++++--
tests/parser.el | 37 +++++++++++++++++++++++++++++++++++++
2 files changed, 47 insertions(+), 2 deletions(-)
diff --git a/js2-mode.el b/js2-mode.el
index 15be4b3..0389833 100644
--- a/js2-mode.el
+++ b/js2-mode.el
@@ -359,6 +359,13 @@ This is useful for xulrunner apps."
:type 'boolean
:group 'js2-mode)
+(defcustom js2-getprop-has-side-effects nil
+ "If non-nil, treats the getprop operator as having side effects.
+This is useful for testing libraries with nontrivial getters and for
+compilers that use empty getprops to declare interface properties."
+ :type 'boolean
+ :group 'js2-mode)
+
(defcustom js2-move-point-on-right-click t
"Non-nil to move insertion point when you right-click.
This makes right-click context menu behavior a bit more intuitive,
@@ -5143,8 +5150,6 @@ You should use `js2-print-tree' instead of this function."
js2-WITHEXPR
js2-YIELD))
(aset tokens tt t))
- (if js2-instanceof-has-side-effects
- (aset tokens js2-INSTANCEOF t))
tokens))
(defun js2-node-has-side-effects (node)
@@ -5176,6 +5181,9 @@ You should use `js2-print-tree' instead of this function."
(js2-node-has-side-effects (js2-paren-node-expr node)))
((= tt js2-ERROR) ; avoid cascaded error messages
nil)
+ ((or (and js2-instanceof-has-side-effects (= tt js2-INSTANCEOF))
+ (and js2-getprop-has-side-effects (= tt js2-GETPROP)))
+ t)
(t
(aref js2-side-effecting-tokens tt))))))
diff --git a/tests/parser.el b/tests/parser.el
index e279900..7f9d392 100644
--- a/tests/parser.el
+++ b/tests/parser.el
@@ -1251,3 +1251,40 @@ the test."
(js2-deftest-classify-variables destructure-object-mixed
"function foo() { let {a, b, c = 3} = {a: 1, b: 2}; }"
'("address@hidden:U" "address@hidden:U" "address@hidden:U"
"address@hidden:U"))
+
+;; Side effects
+
+(js2-deftest no-side-effects-at-top-level
+ "var x; x.foo;"
+ (js2-mode--and-parse)
+ (should (null js2-parsed-warnings)))
+
+(js2-deftest getprop-has-no-side-effects
+ "function f() { this.x; }"
+ (js2-mode--and-parse)
+ (should (equal "msg.no.side.effects"
+ (car (caar js2-parsed-warnings)))))
+
+(js2-deftest getprop-has-side-effects-option
+ "function f() { this.x; }"
+ (let ((js2-getprop-has-side-effects t))
+ (js2-mode--and-parse)
+ (should (null js2-parsed-warnings))))
+
+(js2-deftest arithmetic-has-no-side-effects
+ "function f() { 1 + 2; }"
+ (js2-mode--and-parse)
+ (should (equal "msg.no.side.effects"
+ (car (caar js2-parsed-warnings)))))
+
+(js2-deftest instanceof-has-no-side-effects
+ "function f() { this instanceof f; }"
+ (js2-mode--and-parse)
+ (should (equal "msg.no.side.effects"
+ (car (caar js2-parsed-warnings)))))
+
+(js2-deftest instanceof-has-side-effects-option
+ "function f() { this instanceof f; }"
+ (let ((js2-instanceof-has-side-effects t))
+ (js2-mode--and-parse)
+ (should (null js2-parsed-warnings))))
- [elpa] master 9ce2542 07/31: Add support for ES7 class public fields, (continued)
- [elpa] master 9ce2542 07/31: Add support for ES7 class public fields, Dmitry Gutov, 2017/07/21
- [elpa] master 7349309 21/31: Add tests for `/*jslint*/` declarations, Dmitry Gutov, 2017/07/21
- [elpa] master b176925 24/31: Update NEWS.md, Dmitry Gutov, 2017/07/21
- [elpa] master 92a8857 23/31: Support async arrow function without parentheses, Dmitry Gutov, 2017/07/21
- [elpa] master 890cf81 27/31: Merge pull request #434 from lelit/issue420, Dmitry Gutov, 2017/07/21
- [elpa] master 558f53f 22/31: Merge pull request #358 from JulianKniephoff/master, Dmitry Gutov, 2017/07/21
- [elpa] master cb57d9b 30/31: Bump the version, Dmitry Gutov, 2017/07/21
- [elpa] master a604872 26/31: Recognize initialized variable in destructuring object assignment, Dmitry Gutov, 2017/07/21
- [elpa] master f1badee 18/31: Replace (equal nil ...) with (null ...), Dmitry Gutov, 2017/07/21
- [elpa] master 2c459c6 29/31: Merge pull request #436 from felipeochoa/issue429, Dmitry Gutov, 2017/07/21
- [elpa] master 3df50ab 17/31: Add option js2-getprop-has-side-effects (#424),
Dmitry Gutov <=
- [elpa] master 867919e 28/31: Always consider `await` to have side-effects, Dmitry Gutov, 2017/07/21
- [elpa] master 97d27d6 15/31: Put the visitor and printer properties on unprefixed symbols as well, Dmitry Gutov, 2017/07/21
- [elpa] master 231ac7f 31/31: Merge commit 'cb57d9b67390ae3ff70ab64169bbc4f1264244bc' from js2-mode, Dmitry Gutov, 2017/07/21