-
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Description
Bug Report
Current Behavior
In loose mode, @babel/plugin-proposal-class-properties emits a property assignment for TypeScript definite assignments.
Input Code
REPL (I'm not sure if it's possible to turn turn on loose mode for the plugin)
TS Playground
// Like Object.assign but will not assign properties which are already defined
declare const assignDefaults: typeof Object.assign
class Foo {
bar!: number;
constructor(overrides: { bar: number }) {
assignDefaults(this, overrides);
}
}Expected behavior/code
A definite assignment should not emit any JS.
// Like Object.assign but will not assign properties which are already defined
class Foo {
constructor(overrides) {
assignDefaults(this, overrides);
}
}Babel Configuration (.babelrc, package.json, cli command)
{
"presets": ["@babel/preset-typescript"],
"plugins": [["@babel/plugin-proposal-class-properties", { "loose": true }]]
}Environment
- Babel version(s): 7.5.5
- Node/npm version: Node 12.6 / yarn 1.15.2
- OS: macOS 10.14.5
- Monorepo: no
- How you are using Babel: cli
Additional context/Screenshots
This was previously raised in #7997, but considered expected behavior. It was mentioned that it could be reconsidered for loose mode, however.
I do feel like it should be reconsidered one way or another; emitting for these declarations is problematic in the same way emitting for a declare would be. Additionally, this syntax is not valid JS so there the only applicable spec compliance is that of TS.