Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Derived constructors should not be allowed to return primitives (#13571)
Closes gh-13571
- Loading branch information
1 parent
ab79f08
commit 23d4f8c
Showing
5 changed files
with
47 additions
and
3 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
18 changes: 18 additions & 0 deletions
18
...ugin-transform-classes/test/fixtures/spec/derived-constructor-no-primitive-return/exec.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,18 @@ | ||
class Bar {} | ||
|
||
class Foo extends Bar { | ||
constructor() { | ||
super(); | ||
return 3; | ||
} | ||
} | ||
|
||
class Foo2 extends Bar { | ||
constructor() { | ||
super(); | ||
return null; | ||
} | ||
} | ||
|
||
expect(() => new Foo()).toThrow("Derived constructors may only return object or undefined"); | ||
expect(() => new Foo2()).toThrow("Derived constructors may only return object or undefined"); |
6 changes: 6 additions & 0 deletions
6
...gin-transform-classes/test/fixtures/spec/derived-constructor-no-primitive-return/input.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,6 @@ | ||
class Foo extends Bar { | ||
constructor() { | ||
super(); | ||
return 3; | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
...in-transform-classes/test/fixtures/spec/derived-constructor-no-primitive-return/output.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,17 @@ | ||
var Foo = /*#__PURE__*/function (_Bar) { | ||
"use strict"; | ||
|
||
babelHelpers.inherits(Foo, _Bar); | ||
|
||
var _super = babelHelpers.createSuper(Foo); | ||
|
||
function Foo() { | ||
var _this; | ||
|
||
babelHelpers.classCallCheck(this, Foo); | ||
_this = _super.call(this); | ||
return babelHelpers.possibleConstructorReturn(_this, 3); | ||
} | ||
|
||
return Foo; | ||
}(Bar); |
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