cfprotected 1.1.0 → 1.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -4,16 +4,20 @@
4
4
  // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5
5
  "version": "0.2.0",
6
6
  "configurations": [
7
+
7
8
  {
8
9
  "type": "node",
9
10
  "request": "launch",
10
11
  "name": "Jest Tests",
11
- "program": "${workspaceRoot}/node_modules/jest/bin/jest.js",
12
- "internalConsoleOptions": "openOnSessionStart",
13
- "outFiles": [
14
- "${workspaceRoot}/dist/**/*"
12
+ "runtimeArgs": [
13
+ "--experimental-vm-modules",
14
+ "--inspect-brk",
15
+ "${workspaceRoot}/node_modules/jest/bin/jest.js",
16
+ "--runInBand"
15
17
  ],
16
- "envFile": "${workspaceRoot}/.env"
18
+ "internalConsoleOptions": "neverOpen",
19
+ "console": "integratedTerminal",
20
+ "port": 9229
17
21
  }
18
22
  ]
19
23
  }
package/index.mjs CHANGED
@@ -167,6 +167,11 @@ function abstract(klass) {
167
167
  super(...args);
168
168
  }
169
169
  };
170
+
171
+ if (memos.has(klass)) {
172
+ memos.set(retval, memos.get(klass));
173
+ }
174
+
170
175
  return retval;
171
176
  };
172
177
 
@@ -218,6 +223,10 @@ function final(klass) {
218
223
  }
219
224
  });
220
225
 
226
+ if (memos.has(klass)) {
227
+ memos.set(retval, memos.get(klass));
228
+ }
229
+
221
230
  return retval;
222
231
  };
223
232
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cfprotected",
3
- "version": "1.1.0",
3
+ "version": "1.1.1",
4
4
  "description": "An implementation of protected fields on top of class fields.",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/test/test.mjs CHANGED
@@ -138,31 +138,56 @@ describe(`Testing that $uper works in all cases`, () => {
138
138
  });
139
139
 
140
140
  describe(`Testing that abstract classes function as expected`, () => {
141
- const ATest = abstract(class {});
142
- class DTest extends ATest {};
141
+ const key = Symbol();
142
+ const ATest = abstract(class ATest {
143
+ #shared = share(this, ATest, {
144
+ [key]: true
145
+ });
146
+ });
147
+ class DTest extends ATest {
148
+ #shared = share(this, DTest, {});
149
+ run() { return this.#shared[key]; }
150
+ };
143
151
 
144
- test(`Should not be able to instantiate an abstract class directly`, () => {
152
+ test(`Should not be able to instantiate directly`, () => {
145
153
  expect(() => { new ATest; }).toThrow();
146
154
  });
147
- test(`Should be able to instantiate a class derived from an abstract class`, () => {
155
+ test(`Should be able to instantiate a derived class`, () => {
148
156
  expect(() => { new DTest; }).not.toThrow();
149
157
  });
158
+ test(`Should see shared members from constructed instance`, () => {
159
+ expect((new DTest).run()).toBe(true);
160
+ });
150
161
  });
151
162
 
152
163
  describe(`Testing that final classes function as expected`, () => {
153
- const FTest = final(class {});
164
+ const key = Symbol();
165
+ class TestBase {
166
+ #shared = share(this, TestBase, {
167
+ [key]: true
168
+ });
169
+ }
170
+ const FTest = final(class FTest extends TestBase {
171
+ #shared = share(this, FTest, {});
172
+ run() {
173
+ return this.#shared[key];
174
+ }
175
+ });
154
176
 
155
- test(`Should be able to instantiate an instance of a final class directly`, () => {
177
+ test(`Should be able to instantiate an instance directly`, () => {
156
178
  expect(() => { new FTest; }).not.toThrow();
157
179
  });
158
- test(`Should not be able to extend a final class directly`, () => {
180
+ test(`Should not be able to extend directly`, () => {
159
181
  expect(() => { class DTest extends FTest {}; }).toThrow();
160
182
  });
161
- test(`Should not be able to cheat and create an instance of a class derived from a final class`, () => {
183
+ test(`Should not be able to cheat and create an instance of a derived class`, () => {
162
184
  expect(() => {
163
185
  FTest.prototype = {};
164
186
  class DTest extends FTest {}
165
187
  new DTest;
166
188
  }).toThrow();
167
- })
189
+ });
190
+ test(`Should see shared members from constructed instance`, () => {
191
+ expect((new FTest).run()).toBe(true);
192
+ });
168
193
  });