diff --git a/src/babel/types/converters.js b/src/babel/types/converters.js index 1f74f43054..e43607bb4a 100644 --- a/src/babel/types/converters.js +++ b/src/babel/types/converters.js @@ -102,17 +102,26 @@ export function toSequenceExpression(nodes: Array, scope: Scope): Object export function toKeyAlias(node: Object, key: Object = node.key) { var alias; - if (t.isIdentifier(key)) { + + if (node.kind === "method") { + return toKeyAlias.uid++; + } else if (t.isIdentifier(key)) { alias = key.name; } else if (t.isLiteral(key)) { alias = JSON.stringify(key.value); } else { alias = JSON.stringify(traverse.removeProperties(t.cloneDeep(key))); } - if (node.computed) alias = `[${alias}]`; + + if (node.computed) { + alias = `[${alias}]`; + } + return alias; } +toKeyAlias.uid = 0; + /* * Description */ diff --git a/test/core/fixtures/transformation/es6.classes/relaxed-method-coercion/actual.js b/test/core/fixtures/transformation/es6.classes/relaxed-method-coercion/actual.js new file mode 100644 index 0000000000..98a4701574 --- /dev/null +++ b/test/core/fixtures/transformation/es6.classes/relaxed-method-coercion/actual.js @@ -0,0 +1,6 @@ +// #1649 + +class Foo { + [Symbol()]() {} + [Symbol()]() {} +} diff --git a/test/core/fixtures/transformation/es6.classes/relaxed-method-coercion/expected.js b/test/core/fixtures/transformation/es6.classes/relaxed-method-coercion/expected.js new file mode 100644 index 0000000000..8aed80c3c0 --- /dev/null +++ b/test/core/fixtures/transformation/es6.classes/relaxed-method-coercion/expected.js @@ -0,0 +1,18 @@ +// #1649 + +"use strict"; + +var Foo = (function () { + function Foo() { + babelHelpers.classCallCheck(this, Foo); + } + + babelHelpers.createClass(Foo, [{ + key: Symbol(), + value: function () {} + }, { + key: Symbol(), + value: function () {} + }]); + return Foo; +})();