diff --git a/lib/prototypes/README.md b/lib/PROTOTYPES.md similarity index 84% rename from lib/prototypes/README.md rename to lib/PROTOTYPES.md index c3d92fe..acd4893 100644 --- a/lib/prototypes/README.md +++ b/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 diff --git a/lib/called-in-order.mjs b/lib/called-in-order.mjs index febd910..4c756f7 100644 --- a/lib/called-in-order.mjs +++ b/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 diff --git a/lib/index.mjs b/lib/index.mjs index cc1193d..9c2a0ba 100644 --- a/lib/index.mjs +++ b/lib/index.mjs @@ -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"; diff --git a/lib/order-by-first-call.mjs b/lib/order-by-first-call.mjs index 502b2cb..4646be2 100644 --- a/lib/order-by-first-call.mjs +++ b/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 diff --git a/lib/prototypes.mjs b/lib/prototypes.mjs new file mode 100644 index 0000000..57ef8e3 --- /dev/null +++ b/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), +} diff --git a/lib/prototypes/index.test.mjs b/lib/prototypes.test.mjs similarity index 72% rename from lib/prototypes/index.test.mjs rename to lib/prototypes.test.mjs index e772e81..c6bf285 100644 --- a/lib/prototypes/index.test.mjs +++ b/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 () { @@ -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) { diff --git a/lib/prototypes/array.mjs b/lib/prototypes/array.mjs deleted file mode 100644 index ccbe500..0000000 --- a/lib/prototypes/array.mjs +++ /dev/null @@ -1,3 +0,0 @@ -import copyPrototype from "../copy-prototype-methods.mjs"; - -export default copyPrototype(Array.prototype); diff --git a/lib/prototypes/function.mjs b/lib/prototypes/function.mjs deleted file mode 100644 index 897a6ff..0000000 --- a/lib/prototypes/function.mjs +++ /dev/null @@ -1,3 +0,0 @@ -import copyPrototype from "../copy-prototype-methods.mjs"; - -export default copyPrototype(Function.prototype); diff --git a/lib/prototypes/index.mjs b/lib/prototypes/index.mjs deleted file mode 100644 index e063985..0000000 --- a/lib/prototypes/index.mjs +++ /dev/null @@ -1,15 +0,0 @@ -import array from "./array.mjs"; -import func from "./function.mjs"; -import map from "./map.mjs"; -import object from "./object.mjs"; -import set from "./set.mjs"; -import string from "./string.mjs"; - -export default { - array, - function: func, - map, - object, - set, - string, -}; diff --git a/lib/prototypes/map.mjs b/lib/prototypes/map.mjs deleted file mode 100644 index e3d0781..0000000 --- a/lib/prototypes/map.mjs +++ /dev/null @@ -1,3 +0,0 @@ -import copyPrototype from "../copy-prototype-methods.mjs"; - -export default copyPrototype(Map.prototype); diff --git a/lib/prototypes/object.mjs b/lib/prototypes/object.mjs deleted file mode 100644 index 5dc4d7b..0000000 --- a/lib/prototypes/object.mjs +++ /dev/null @@ -1,3 +0,0 @@ -import copyPrototype from "../copy-prototype-methods.mjs"; - -export default copyPrototype(Object.prototype); diff --git a/lib/prototypes/set.mjs b/lib/prototypes/set.mjs deleted file mode 100644 index ec6f658..0000000 --- a/lib/prototypes/set.mjs +++ /dev/null @@ -1,3 +0,0 @@ -import copyPrototype from "../copy-prototype-methods.mjs"; - -export default copyPrototype(Set.prototype); diff --git a/lib/prototypes/string.mjs b/lib/prototypes/string.mjs deleted file mode 100644 index 8598723..0000000 --- a/lib/prototypes/string.mjs +++ /dev/null @@ -1,3 +0,0 @@ -import copyPrototype from "../copy-prototype-methods.mjs"; - -export default copyPrototype(String.prototype);