Skip to content

Commit

Permalink
Merge pull request #6 from Jimdooz/5-prevent-pass-array-by-reference-…
Browse files Browse the repository at this point in the history
…recursively-inside-unpack-function

prevent pass by reference recursively
  • Loading branch information
Jimdooz authored Mar 11, 2023
2 parents 5579c04 + 35608cc commit 1240868
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ type ContextUnpack = {
function recursiveUnpack<A extends API_DECLARATION>(api: A, callback: (fun: API_FUNCTION, context: ContextUnpack) => void, context: ContextUnpack = { key: "", allAfter: [], allBefore: [], parent: api }) {
if (!api) return;

if (api.$beforeAll) context.allBefore.push(api.$beforeAll);
// Create a new array if needed, that prevent to pass by reference recursively
if (api.$beforeAll) context.allBefore = [...context.allBefore, api.$beforeAll];
if (api.$afterAll) context.allAfter = [api.$afterAll, ...context.allAfter];

context.parent = api;
Expand Down

0 comments on commit 1240868

Please sign in to comment.