| 1 | /* eslint no-restricted-syntax: 0, no-with: 0, strict: 0 */
|
|---|
| 2 |
|
|---|
| 3 | var test = require('tape');
|
|---|
| 4 |
|
|---|
| 5 | var shimUnscopables = require('../');
|
|---|
| 6 |
|
|---|
| 7 | test('`with` statement', { skip: typeof Symbol !== 'function' || !Symbol.unscopables }, function (t) {
|
|---|
| 8 | // @ts-expect-error this variable is declared in case unscopables doesn't work
|
|---|
| 9 | var entries;
|
|---|
| 10 | // @ts-expect-error this variable is declared in case unscopables doesn't work
|
|---|
| 11 | var concat;
|
|---|
| 12 | // @ts-expect-error `with` unsupported
|
|---|
| 13 | with ([]) {
|
|---|
| 14 | t.equal(concat, Array.prototype.concat, 'concat is dynamically bound');
|
|---|
| 15 | t.notEqual(entries, Array.prototype.entries, 'entries is not dynamically bound');
|
|---|
| 16 | }
|
|---|
| 17 |
|
|---|
| 18 | /** @type {Record<PropertyKey, unknown>} */
|
|---|
| 19 | var obj = {
|
|---|
| 20 | foo: 1,
|
|---|
| 21 | bar: 2
|
|---|
| 22 | };
|
|---|
| 23 | // @ts-expect-error this variable is declared in case unscopables doesn't work
|
|---|
| 24 | var foo;
|
|---|
| 25 | // @ts-expect-error this variable is declared in case unscopables doesn't work
|
|---|
| 26 | var bar;
|
|---|
| 27 | obj[Symbol.unscopables] = { foo: true };
|
|---|
| 28 | // @ts-expect-error `with` unsupported
|
|---|
| 29 | with (obj) {
|
|---|
| 30 | t.equal(foo, undefined);
|
|---|
| 31 | t.equal(bar, obj.bar);
|
|---|
| 32 | }
|
|---|
| 33 |
|
|---|
| 34 | shimUnscopables('concat');
|
|---|
| 35 |
|
|---|
| 36 | // @ts-expect-error `with` unsupported
|
|---|
| 37 | with ([]) {
|
|---|
| 38 | t.notEqual(concat, Array.prototype.concat, 'concat is no longer dynamically bound');
|
|---|
| 39 | t.notEqual(entries, Array.prototype.entries, 'entries is still not dynamically bound');
|
|---|
| 40 | }
|
|---|
| 41 |
|
|---|
| 42 | t.end();
|
|---|
| 43 | });
|
|---|