-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: option to hoist nested methods referencing
this
(`methods: tr…
…ue`) See README.md for documentation. This feature is blocked on the following Babel PRs/issues: * babel/babel#4500 * babel/babylon#121 * babel/babel#4337 * babel/babel#4230 (partially)
- Loading branch information
Showing
19 changed files
with
279 additions
and
23 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
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
20 changes: 20 additions & 0 deletions
20
test/fixtures/hoist-nested-methods-if-options.methods-true/actual.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,20 @@ | ||
class A { | ||
outer () { | ||
// NOTE: hoisted | ||
(function () {})(); | ||
} | ||
} | ||
|
||
class B { | ||
outer () { | ||
// NOTE: hoisted to bound method | ||
(() => this)(); | ||
} | ||
} | ||
|
||
class C { | ||
static outer () { | ||
// NOTE: hoisted to static method | ||
console.log((() => this)()); | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
test/fixtures/hoist-nested-methods-if-options.methods-true/expected.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 @@ | ||
const _hoistedMethod = new Symbol("_hoistedMethod"), | ||
_hoistedMethod2 = new Symbol("_hoistedMethod2"); | ||
|
||
var _hoistedAnonymousFunc2 = function () {}; | ||
|
||
class A { | ||
outer() { | ||
// NOTE: hoisted | ||
_hoistedAnonymousFunc2(); | ||
} | ||
} | ||
|
||
class B { | ||
[_hoistedMethod] = () => this; | ||
|
||
outer() { | ||
// NOTE: hoisted to bound method | ||
this[_hoistedMethod](); | ||
} | ||
} | ||
|
||
class C { | ||
[_hoistedMethod2] = () => this; | ||
|
||
static outer() { | ||
// NOTE: hoisted to static method | ||
console.log(this[_hoistedMethod2]()); | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
test/fixtures/hoist-nested-methods-if-options.methods-true/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,3 @@ | ||
{ | ||
"plugins": [["transform-hoist-nested-functions", {"methods": true}]] | ||
} |
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
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,3 @@ | ||
{ | ||
"plugins": [["transform-hoist-nested-functions", {"methods": true}]] | ||
} |
20 changes: 20 additions & 0 deletions
20
test/fixtures/not-hoist-nested-methods-by-default/actual.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,20 @@ | ||
class A { | ||
outer () { | ||
// NOTE: hoisted | ||
(function () {})(); | ||
} | ||
} | ||
|
||
class B { | ||
outer () { | ||
// NOTE: not hoisted (!options.methods) | ||
(() => this)(); | ||
} | ||
} | ||
|
||
class C { | ||
static outer () { | ||
// NOTE: not hoisted (!options.methods) | ||
console.log((() => this)()); | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
test/fixtures/not-hoist-nested-methods-by-default/expected.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,22 @@ | ||
var _hoistedAnonymousFunc2 = function () {}; | ||
|
||
class A { | ||
outer() { | ||
// NOTE: hoisted | ||
_hoistedAnonymousFunc2(); | ||
} | ||
} | ||
|
||
class B { | ||
outer() { | ||
// NOTE: not hoisted (!options.methods) | ||
(() => this)(); | ||
} | ||
} | ||
|
||
class C { | ||
static outer() { | ||
// NOTE: not hoisted (!options.methods) | ||
console.log((() => this)()); | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
test/fixtures/not-hoist-nested-methods-by-default/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,3 @@ | ||
{ | ||
"plugins": ["transform-hoist-nested-functions"] | ||
} |
20 changes: 20 additions & 0 deletions
20
test/fixtures/not-hoist-nested-methods-if-options.methods-false/actual.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,20 @@ | ||
class A { | ||
outer () { | ||
// NOTE: hoisted | ||
(function () {})(); | ||
} | ||
} | ||
|
||
class B { | ||
outer () { | ||
// NOTE: not hoisted (!options.methods) | ||
(() => this)(); | ||
} | ||
} | ||
|
||
class C { | ||
static outer () { | ||
// NOTE: not hoisted | ||
console.log((() => this)()); | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
test/fixtures/not-hoist-nested-methods-if-options.methods-false/expected.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,22 @@ | ||
var _hoistedAnonymousFunc2 = function () {}; | ||
|
||
class A { | ||
outer() { | ||
// NOTE: hoisted | ||
_hoistedAnonymousFunc2(); | ||
} | ||
} | ||
|
||
class B { | ||
outer() { | ||
// NOTE: not hoisted (!options.methods) | ||
(() => this)(); | ||
} | ||
} | ||
|
||
class C { | ||
static outer() { | ||
// NOTE: not hoisted | ||
console.log((() => this)()); | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
test/fixtures/not-hoist-nested-methods-if-options.methods-false/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,3 @@ | ||
{ | ||
"plugins": [["transform-hoist-nested-functions", {"methods": false}]] | ||
} |
Oops, something went wrong.