-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement
pureGetters
assumption (#12504)
* feat: allow pureGetters in assumptions * feat: respect pureGetters assumption
- Loading branch information
Showing
9 changed files
with
120 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
...in-proposal-optional-chaining/test/fixtures/assumption-pureGetters/function-call/input.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
foo?.(foo); | ||
|
||
foo?.bar() | ||
|
||
foo.bar?.(foo.bar, false) | ||
|
||
foo?.bar?.(foo.bar, true) | ||
|
||
foo?.().bar | ||
|
||
foo?.()?.bar | ||
|
||
foo.bar?.().baz | ||
|
||
foo.bar?.()?.baz | ||
|
||
foo?.bar?.().baz | ||
|
||
foo?.bar?.()?.baz |
12 changes: 12 additions & 0 deletions
12
...n-proposal-optional-chaining/test/fixtures/assumption-pureGetters/function-call/output.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
var _foo, _foo2, _foo3, _foo$bar, _foo4, _foo5, _foo5$bar; | ||
|
||
foo === null || foo === void 0 ? void 0 : foo(foo); | ||
(_foo = foo) === null || _foo === void 0 ? void 0 : _foo.bar(); | ||
foo.bar === null || foo.bar === void 0 ? void 0 : foo.bar(foo.bar, false); | ||
(_foo2 = foo) === null || _foo2 === void 0 ? void 0 : _foo2.bar === null || _foo2.bar === void 0 ? void 0 : _foo2.bar(foo.bar, true); | ||
foo === null || foo === void 0 ? void 0 : foo().bar; | ||
foo === null || foo === void 0 ? void 0 : (_foo3 = foo()) === null || _foo3 === void 0 ? void 0 : _foo3.bar; | ||
foo.bar === null || foo.bar === void 0 ? void 0 : foo.bar().baz; | ||
foo.bar === null || foo.bar === void 0 ? void 0 : (_foo$bar = foo.bar()) === null || _foo$bar === void 0 ? void 0 : _foo$bar.baz; | ||
(_foo4 = foo) === null || _foo4 === void 0 ? void 0 : _foo4.bar === null || _foo4.bar === void 0 ? void 0 : _foo4.bar().baz; | ||
(_foo5 = foo) === null || _foo5 === void 0 ? void 0 : _foo5.bar === null || _foo5.bar === void 0 ? void 0 : (_foo5$bar = _foo5.bar()) === null || _foo5$bar === void 0 ? void 0 : _foo5$bar.baz; |
29 changes: 29 additions & 0 deletions
29
...l-plugin-proposal-optional-chaining/test/fixtures/assumption-pureGetters/memoize/input.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
function test(foo) { | ||
foo?.bar; | ||
|
||
foo?.bar?.baz; | ||
|
||
foo?.(foo); | ||
|
||
foo?.bar() | ||
|
||
foo.get(bar)?.() | ||
|
||
foo.bar()?.() | ||
foo[bar]()?.() | ||
|
||
foo.bar().baz?.() | ||
foo[bar]().baz?.() | ||
|
||
foo.bar?.(foo.bar, false) | ||
|
||
foo?.bar?.(foo.bar, true) | ||
|
||
foo.bar?.baz(foo.bar, false) | ||
|
||
foo?.bar?.baz(foo.bar, true) | ||
|
||
foo.bar?.baz?.(foo.bar, false) | ||
|
||
foo?.bar?.baz?.(foo.bar, true) | ||
} |
19 changes: 19 additions & 0 deletions
19
...-plugin-proposal-optional-chaining/test/fixtures/assumption-pureGetters/memoize/output.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
function test(foo) { | ||
var _foo$bar, _foo$get, _foo$bar2, _foo$bar3, _foo$bar$baz, _foo$bar4, _foo$bar$baz2, _foo$bar5, _foo$bar6, _foo$bar7, _foo$bar8, _foo$bar9; | ||
|
||
foo === null || foo === void 0 ? void 0 : foo.bar; | ||
foo === null || foo === void 0 ? void 0 : (_foo$bar = foo.bar) === null || _foo$bar === void 0 ? void 0 : _foo$bar.baz; | ||
foo === null || foo === void 0 ? void 0 : foo(foo); | ||
foo === null || foo === void 0 ? void 0 : foo.bar(); | ||
(_foo$get = foo.get(bar)) === null || _foo$get === void 0 ? void 0 : _foo$get(); | ||
(_foo$bar2 = foo.bar()) === null || _foo$bar2 === void 0 ? void 0 : _foo$bar2(); | ||
(_foo$bar3 = foo[bar]()) === null || _foo$bar3 === void 0 ? void 0 : _foo$bar3(); | ||
(_foo$bar$baz = (_foo$bar4 = foo.bar()).baz) === null || _foo$bar$baz === void 0 ? void 0 : _foo$bar$baz.call(_foo$bar4); | ||
(_foo$bar$baz2 = (_foo$bar5 = foo[bar]()).baz) === null || _foo$bar$baz2 === void 0 ? void 0 : _foo$bar$baz2.call(_foo$bar5); | ||
foo.bar === null || foo.bar === void 0 ? void 0 : foo.bar(foo.bar, false); | ||
foo === null || foo === void 0 ? void 0 : foo.bar === null || foo.bar === void 0 ? void 0 : foo.bar(foo.bar, true); | ||
(_foo$bar6 = foo.bar) === null || _foo$bar6 === void 0 ? void 0 : _foo$bar6.baz(foo.bar, false); | ||
foo === null || foo === void 0 ? void 0 : (_foo$bar7 = foo.bar) === null || _foo$bar7 === void 0 ? void 0 : _foo$bar7.baz(foo.bar, true); | ||
(_foo$bar8 = foo.bar) === null || _foo$bar8 === void 0 ? void 0 : _foo$bar8.baz === null || _foo$bar8.baz === void 0 ? void 0 : _foo$bar8.baz(foo.bar, false); | ||
foo === null || foo === void 0 ? void 0 : (_foo$bar9 = foo.bar) === null || _foo$bar9 === void 0 ? void 0 : _foo$bar9.baz === null || _foo$bar9.baz === void 0 ? void 0 : _foo$bar9.baz(foo.bar, true); | ||
} |
6 changes: 6 additions & 0 deletions
6
...babel-plugin-proposal-optional-chaining/test/fixtures/assumption-pureGetters/options.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"plugins": ["proposal-optional-chaining"], | ||
"assumptions": { | ||
"pureGetters": true | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
...roposal-optional-chaining/test/fixtures/assumption-pureGetters/super-method-call/input.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
"use strict"; | ||
class Base { | ||
method() { | ||
return 'Hello!'; | ||
} | ||
} | ||
|
||
class Derived extends Base { | ||
method() { | ||
return super.method?.() | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
...oposal-optional-chaining/test/fixtures/assumption-pureGetters/super-method-call/output.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
"use strict"; | ||
|
||
class Base { | ||
method() { | ||
return 'Hello!'; | ||
} | ||
|
||
} | ||
|
||
class Derived extends Base { | ||
method() { | ||
return super.method === null || super.method === void 0 ? void 0 : super.method(); | ||
} | ||
|
||
} |