{"action":"closed","issue":{"url":"https://api.github.com/repos/babel/babel/issues/9117","repository_url":"https://api.github.com/repos/babel/babel","labels_url":"https://api.github.com/repos/babel/babel/issues/9117/labels{/name}","comments_url":"https://api.github.com/repos/babel/babel/issues/9117/comments","events_url":"https://api.github.com/repos/babel/babel/issues/9117/events","html_url":"https://github.com/babel/babel/issues/9117","id":386607351,"node_id":"MDU6SXNzdWUzODY2MDczNTE=","number":9117,"title":"plugin-proposal-class-properties generates ES6 code when child classes are present","user":{"login":"csvan","id":1127729,"node_id":"MDQ6VXNlcjExMjc3Mjk=","avatar_url":"https://avatars2.githubusercontent.com/u/1127729?v=4","gravatar_id":"","url":"https://api.github.com/users/csvan","html_url":"https://github.com/csvan","followers_url":"https://api.github.com/users/csvan/followers","following_url":"https://api.github.com/users/csvan/following{/other_user}","gists_url":"https://api.github.com/users/csvan/gists{/gist_id}","starred_url":"https://api.github.com/users/csvan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/csvan/subscriptions","organizations_url":"https://api.github.com/users/csvan/orgs","repos_url":"https://api.github.com/users/csvan/repos","events_url":"https://api.github.com/users/csvan/events{/privacy}","received_events_url":"https://api.github.com/users/csvan/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2018-12-02T22:25:12Z","updated_at":"2018-12-02T22:43:31Z","closed_at":"2018-12-02T22:43:31Z","author_association":"NONE","body":"## Bug Report\r\n\r\n**Current Behavior**\r\nA class without constructor transpiled using the `plugin-proposal-class-properties` will be given a default constructor which (unnecessarily) uses the spread operator. \r\n\r\n**Input Code**\r\n- REPL or Repo link if applicable:\r\n\r\n```js\r\nclass A {}\r\n\r\nclass B extends A {\r\n  state = {};\r\n}\r\n```\r\n\r\n**Expected behavior/code**\r\n\r\nRunning Babel with the below config generates the following:\r\n```js\r\nfunction _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }\r\n\r\nclass A {}\r\n\r\nclass B extends A {\r\n  constructor() {\r\n    super(...arguments);\r\n    _defineProperty(this, \"state\", {});\r\n  }\r\n}\r\n```\r\nAs can be seen, the above use the spread operator to forward arguments to the super constructor. This causes transpiled code to break in e.g. Edge even if `preset-env` is set to support the last two major versions of it.\r\n\r\n**Babel Configuration (.babelrc, package.json, cli command)**\r\n\r\n```js\r\nmodule.exports = (api) => {\r\n  api.cache.never(); // TODO Figure out what to use\r\n\r\n  const browsers = [\r\n    'last 2 Chrome versions',\r\n    'last 2 ChromeAndroid versions',\r\n    'last 2 Firefox versions',\r\n    'last 2 FirefoxAndroid versions',\r\n    'last 2 Safari versions',\r\n    'last 2 Edge versions',\r\n    'Samsung >= 4',\r\n    'iOS >= 10',\r\n  ];\r\n\r\n  return {\r\n    presets: [\r\n      [\r\n        '@babel/preset-env',\r\n        {\r\n          useBuiltIns: 'usage',\r\n          targets: { browsers },\r\n        },\r\n      ],\r\n      '@babel/preset-react',\r\n      '@babel/preset-flow',\r\n    ],\r\n    plugins: [\r\n      '@babel/plugin-proposal-export-default-from',\r\n      '@babel/plugin-proposal-logical-assignment-operators',\r\n      ['@babel/plugin-proposal-optional-chaining', { loose: false }],\r\n      ['@babel/plugin-proposal-pipeline-operator', { proposal: 'minimal' }],\r\n      ['@babel/plugin-proposal-nullish-coalescing-operator', { loose: false }],\r\n      '@babel/plugin-proposal-do-expressions',\r\n      ['@babel/plugin-proposal-decorators', { legacy: true }],\r\n      '@babel/plugin-proposal-function-sent',\r\n      '@babel/plugin-proposal-export-namespace-from',\r\n      '@babel/plugin-proposal-numeric-separator',\r\n      '@babel/plugin-proposal-throw-expressions',\r\n      '@babel/plugin-syntax-dynamic-import',\r\n      '@babel/plugin-syntax-import-meta',\r\n      ['@babel/plugin-proposal-class-properties', { loose: false }],\r\n      '@babel/plugin-proposal-json-strings',\r\n      ['styled-components', { uglifyPure: false }],\r\n      [\r\n        'transform-imports',\r\n        {\r\n          lodash: {\r\n            transform: 'lodash/${member}',\r\n            preventFullImport: true,\r\n          },\r\n          'react-bootstrap': {\r\n            transform: 'react-bootstrap/lib/${member}',\r\n            preventFullImport: true,\r\n          },\r\n        },\r\n      ],\r\n    ],\r\n    env: {\r\n      development: {\r\n        plugins: ['@babel/plugin-transform-react-jsx-source'],\r\n      },\r\n      test: {\r\n        presets: [\r\n          [\r\n            '@babel/preset-env',\r\n            {\r\n              targets: {\r\n                node: 'current',\r\n              },\r\n            },\r\n          ],\r\n        ],\r\n        plugins: ['@babel/plugin-transform-react-jsx-source', 'dynamic-import-node'],\r\n      },\r\n      production: {\r\n        presets: [\r\n          [\r\n            '@babel/preset-env',\r\n            {\r\n              useBuiltIns: 'entry', \r\n              targets: { browsers },\r\n              modules: false,\r\n            },\r\n          ],\r\n        ],\r\n        plugins: ['transform-react-remove-prop-types'],\r\n      },\r\n    },\r\n  };\r\n};\r\n```\r\n\r\n**Environment**\r\n- Babel version(s): 7.1\r\n- Node/yarn version: Node 11.1, yarn 1.12\r\n- OS: Ubuntu 18.10\r\n- Monorepo: no\r\n- How you are using Babel: cli, loader\r\n\r\n**Possible Solution**\r\nDo not use class properties\r\n\r\n**Additional context/Screenshots**\r\nAdd any other context about the problem here. If applicable, add screenshots to help explain.\r\n"}}
{"actor":{"display_login":"nicolo-ribaudo"}}