Skip to content

Don't transform method definition in transform-es2015-function-name (T6779)#3176

Merged
amasad merged 2 commits intobabel:masterfrom
jmm:T6779-func-name-method
Dec 18, 2015
Merged

Don't transform method definition in transform-es2015-function-name (T6779)#3176
amasad merged 2 commits intobabel:masterfrom
jmm:T6779-func-name-method

Conversation

@jmm
Copy link
Member

@jmm jmm commented Dec 17, 2015

See https://phabricator.babeljs.io/T6779. Supercedes #3149.

function-name = babel-plugin-transform-es2015-function-name
shorthand-properties = babel-plugin-transform-es2015-shorthand-properties

Currently function-name transforms method definition (e.g. {x () {}}) to function expression. That seems wrong. shorthand-properties also performs that transformation and seems like the one that should be responsible for doing that and the one you should enable to opt-in to it. It seems like it should be possible to at the same time apply function-name to anonymous function expressions and not transform method definitions.

Example:

Input:

var z = {
  x () {},
  y: function () {},
};

shorthand-properties

babel.transform(input, {
  plugins: [
    "transform-es2015-shorthand-properties"
  ]
})

Output before and after PR:

var z = {
  x: function () {},

  y: function () {}
};

function-name

babel.transform(input, {
  plugins: [
    "transform-es2015-function-name"
  ]
})

Output before PR:

var z = {
  x: function x() {},

  y: function y() {}
};

Output after PR:

var z = {
  x() {},
  y: function y() {}
};

The current output of function-name can currently be achieved by using both transforms:

babel.transform(input, {
  plugins: [
    "transform-es2015-shorthand-properties",
    "transform-es2015-function-name"
  ]
})

Output before and after PR:

var z = {
  x: function x() {},

  y: function y() {}
};

The old implementation visited ObjectExpression and looped properties. I guess that was more efficient when transforming both ObjectMethod|ObjectProperty. I changed it to visit ObjectProperty directly.

jmm added 2 commits December 8, 2015 16:46
Fix T6779. It should be possible to apply this to ES5 functions without
mutating ES2015 MethodDefinition's.
@codecov-io
Copy link

Current coverage is 84.77%

Merging #3176 into master will decrease coverage by -0.25% as of 2e86b67

@@            master   #3176   diff @@
======================================
  Files          215     215       
  Stmts        15628   15610    -18
  Branches      3338    3333     -5
  Methods          0       0       
======================================
- Hit          13287   13233    -54
- Partial        686     724    +38
+ Missed        1655    1653     -2

Review entire Coverage Diff as of 2e86b67

Powered by Codecov. Updated on successful CI builds.

@amasad
Copy link
Member

amasad commented Dec 18, 2015

Great, I understand this now ✋. Good job on the description.

amasad added a commit that referenced this pull request Dec 18, 2015
Don't transform method definition in transform-es2015-function-name (T6779)
@amasad amasad merged commit 9de3a3c into babel:master Dec 18, 2015
@jmm jmm deleted the T6779-func-name-method branch January 19, 2016 22:16
@lock lock bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue label Oct 7, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Oct 7, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

outdated A closed issue/PR that is archived due to age. Recommended to make a new issue

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants