Skip to content

Commit

Permalink
Mark class prototype as read-only
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolo-ribaudo committed Dec 10, 2021
1 parent a5e8b8b commit 5e412a6
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/babel-helpers/src/helpers.ts
Expand Up @@ -223,6 +223,7 @@ helpers.createClass = helper("7.0.0-beta.0")`
export default function _createClass(Constructor, protoProps, staticProps) {
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
if (staticProps) _defineProperties(Constructor, staticProps);
Object.defineProperty(Constructor, "prototype", {});
return Constructor;
}
`;
Expand Down
@@ -0,0 +1,16 @@
class A {}
class B extends A {}

expect(Object.getOwnPropertyDescriptor(A, "prototype")).toEqual({
value: A.prototype,
configurable: false,
enumerable: false,
writable: false,
});

expect(Object.getOwnPropertyDescriptor(B, "prototype")).toEqual({
value: A.prototype,
configurable: false,
enumerable: false,
writable: false,
});

0 comments on commit 5e412a6

Please sign in to comment.