Skip to content

Commit

Permalink
chore: consolidate lib/prototypes/ into lib/prototypes.mjs
Browse files Browse the repository at this point in the history
This avoids creating another index file
  • Loading branch information
mroderick committed Dec 30, 2023
1 parent 3d3a038 commit bdd9614
Show file tree
Hide file tree
Showing 13 changed files with 34 additions and 48 deletions.
2 changes: 1 addition & 1 deletion lib/prototypes/README.md → lib/PROTOTYPES.md
@@ -1,6 +1,6 @@
# Prototypes

The functions in this folder are to be use for keeping cached references to the built-in prototypes, so that people can't inadvertently break the library by making mistakes in userland.
The functions in this module are to be used for keeping cached references to the built-in prototypes, so that people can't inadvertently break the library by making mistakes in userland.

See https://github.com/sinonjs/sinon/pull/1523

Expand Down
4 changes: 2 additions & 2 deletions lib/called-in-order.mjs
@@ -1,5 +1,5 @@
import array from "./prototypes/array.mjs";
const every = array.every;
import prototypes from "./prototypes.mjs";
const every = prototypes.array.every;

/**
* @private
Expand Down
2 changes: 1 addition & 1 deletion lib/index.mjs
Expand Up @@ -5,7 +5,7 @@ import * as deprecated from "./deprecated.js";
import every from "./every.mjs";
import functionName from "./function-name.mjs";
import orderByFirstCall from "./order-by-first-call.mjs";
import prototypes from "./prototypes/index.mjs";
import prototypes from "./prototypes.mjs";
import typeOf from "./type-of.mjs";
import valueToString from "./value-to-string.mjs";

Expand Down
4 changes: 2 additions & 2 deletions lib/order-by-first-call.mjs
@@ -1,5 +1,5 @@
import pkg from "./prototypes/array.mjs";
const { slice, sort } = pkg;
import prototypes from "./prototypes.mjs";
const { slice, sort } = prototypes.array;

/**
* @private
Expand Down
10 changes: 10 additions & 0 deletions lib/prototypes.mjs
@@ -0,0 +1,10 @@
import copyPrototypeMethods from "./copy-prototype-methods.mjs";

export default {
array: copyPrototypeMethods(Array.prototype),
function: copyPrototypeMethods(Function.prototype),
map: copyPrototypeMethods(Map.prototype),
object: copyPrototypeMethods(Object.prototype),
set: copyPrototypeMethods(Set.prototype),
string: copyPrototypeMethods(String.prototype),
}
27 changes: 18 additions & 9 deletions lib/prototypes/index.test.mjs → lib/prototypes.test.mjs
@@ -1,15 +1,16 @@
import pkg from "@sinonjs/referee-sinon";
const { assert } = pkg;
const { assert, refute } = pkg;

import throwsOnProto from "../throws-on-proto.mjs";
import copyPrototypeMethods from "./copy-prototype-methods.mjs";
import throwsOnProto from "./throws-on-proto.mjs";
import prototypes from "./prototypes.mjs";

import prototypes from "./index.mjs";
var arrayProto = prototypes.array;
var functionProto = prototypes.function;
var mapProto = prototypes.map;
var objectProto = prototypes.object;
var setProto = prototypes.set;
var stringProto = prototypes.string;
const arrayProto = prototypes.array;
const functionProto = prototypes.function;
const mapProto = prototypes.map;
const objectProto = prototypes.object;
const setProto = prototypes.set;
const stringProto = prototypes.string;

describe("prototypes", function () {
describe(".array", function () {
Expand All @@ -36,6 +37,14 @@ describe("prototypes", function () {
// eslint-disable-next-line mocha/no-setup-in-describe
verifyProperties(stringProto, String);
});

describe("copyPrototypeMethods", function () {
it("does not throw for Map", function () {
refute.exception(function () {
copyPrototypeMethods(Map.prototype);
});
});
});
});

function verifyProperties(p, origin) {
Expand Down
3 changes: 0 additions & 3 deletions lib/prototypes/array.mjs

This file was deleted.

3 changes: 0 additions & 3 deletions lib/prototypes/function.mjs

This file was deleted.

15 changes: 0 additions & 15 deletions lib/prototypes/index.mjs

This file was deleted.

3 changes: 0 additions & 3 deletions lib/prototypes/map.mjs

This file was deleted.

3 changes: 0 additions & 3 deletions lib/prototypes/object.mjs

This file was deleted.

3 changes: 0 additions & 3 deletions lib/prototypes/set.mjs

This file was deleted.

3 changes: 0 additions & 3 deletions lib/prototypes/string.mjs

This file was deleted.

0 comments on commit bdd9614

Please sign in to comment.