forked from babel/babel
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add function name to spec-transformed arrow functions (babel#5620)
While it may appear that this should be done by es2015-function-name, another way to think about it is that es2015-function-name implements the naming that javascript engines are supposed to do; and javascript engines cannot name function expressions that are the object of a member expression.
- Loading branch information
Diogo Franco
committed
May 3, 2017
1 parent
79c1eed
commit 86a5377
Showing
9 changed files
with
58 additions
and
13 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
5 changes: 5 additions & 0 deletions
5
...ugin-transform-es2015-arrow-functions/test/fixtures/arrow-functions/spec-naming/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,5 @@ | ||
[].map(x => x); | ||
|
||
const f = x => x | ||
|
||
const o = { k: x => x } |
16 changes: 16 additions & 0 deletions
16
...in-transform-es2015-arrow-functions/test/fixtures/arrow-functions/spec-naming/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,16 @@ | ||
var _this = this; | ||
|
||
[].map(function (x) { | ||
babelHelpers.newArrowCheck(this, _this); | ||
return x; | ||
}.bind(this)); | ||
|
||
const f = function f(x) { | ||
babelHelpers.newArrowCheck(this, _this); | ||
return x; | ||
}.bind(this); | ||
|
||
const o = { k: function k(x) { | ||
babelHelpers.newArrowCheck(this, _this); | ||
return x; | ||
}.bind(this) }; |
3 changes: 3 additions & 0 deletions
3
...n-transform-es2015-arrow-functions/test/fixtures/arrow-functions/spec-naming/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": ["external-helpers", ["transform-es2015-arrow-functions", { "spec": 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,4 +4,7 @@ function foo() { | |
(function () { | ||
return () => this; | ||
})(); | ||
return { | ||
g: () => this | ||
} | ||
} |
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
3 changes: 1 addition & 2 deletions
3
...5-function-name/test/fixtures/function-name/with-arrow-functions-transform-spec/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 |
---|---|---|
@@ -1,5 +1,4 @@ | ||
// I don't know if this is a bug with arrow-functions spec: true | ||
// or with function-name, but the functions are missing their names. | ||
// These are actually handled by transform-es2015-arrow-function | ||
const x = () => x; | ||
const y = x => x(); | ||
const z = { z: () => y(x) }.z; |
9 changes: 4 additions & 5 deletions
9
...function-name/test/fixtures/function-name/with-arrow-functions-transform-spec/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 |
---|---|---|
@@ -1,16 +1,15 @@ | ||
var _this = this; | ||
|
||
// I don't know if this is a bug with arrow-functions spec: true | ||
// or with function-name, but the functions are missing their names. | ||
const x = function () { | ||
// These are actually handled by transform-es2015-arrow-function | ||
const x = function x() { | ||
babelHelpers.newArrowCheck(this, _this); | ||
return x; | ||
}.bind(this); | ||
const y = function (x) { | ||
const y = function y(x) { | ||
babelHelpers.newArrowCheck(this, _this); | ||
return x(); | ||
}.bind(this); | ||
const z = { z: function z() { | ||
babelHelpers.newArrowCheck(this, _this); | ||
return y(x); | ||
}.bind(this) }.z; | ||
}.bind(this) }.z; |