Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix exception on older browsers #246

Merged
merged 9 commits into from
Jun 19, 2024
5 changes: 1 addition & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,7 @@
"atLeast": 100,
"detail": true,
"ignoreCatch": true,
"strict": true,
"ignoreFiles": [
"test/*.js"
]
"strict": true
},
"xo": {
"overrides": [
Expand Down
18 changes: 13 additions & 5 deletions test/callable-instance.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// @ts-nocheck
import assert from 'node:assert/strict'
import test from 'node:test'
import {CallableInstance} from '../lib/callable-instance.js'
Expand All @@ -9,10 +8,13 @@ test('callable-instance', async function (t) {
constructor() {
super('copy')

/** @type {number} */
this.foo = 42
/** @type {number} */
this.bar = 0
}

/** @returns {Es6Class} */
copy() {
const destination = new Es6Class()
destination.foo = this.foo
Expand All @@ -27,20 +29,23 @@ test('callable-instance', async function (t) {
instance.bar = 100

// Instance is callable
/** @type {Es6Class} */
const copied = instance()
assert.strictEqual(copied.foo, 42)
assert.strictEqual(copied.bar, 100)
})

await t.test('can invoke new (ES5 class)', async function () {
function Es5Class() {
const _this = CallableInstance.call(this, ['copy'])
return _this
/** @type {Function} */
const callableInstance = CallableInstance
return callableInstance.call(this, ['copy'])
}

Es5Class.prototype.foo = 42
Es5Class.prototype.bar = 0
Es5Class.prototype.foo = 42 // type-coverage:ignore-line
Es5Class.prototype.bar = 0 // type-coverage:ignore-line

// type-coverage:ignore-next-line
Es5Class.prototype.copy = function () {
const destination = new Es5Class()
destination.foo = this.foo
Expand All @@ -51,9 +56,12 @@ test('callable-instance', async function (t) {
const instance = new Es5Class()
assert.strictEqual(instance.foo, 42)

/** @type {number} */
instance.bar = 100

// Instance is callable
/** @type {Es5Class} */
// @ts-ignore
ChristianMurphy marked this conversation as resolved.
Show resolved Hide resolved
const copied = instance()
assert.strictEqual(copied.foo, 42)
assert.strictEqual(copied.bar, 100)
Expand Down