From a73b5420c7734540fdead135ccd71121b03d07f2 Mon Sep 17 00:00:00 2001 From: Gil Eckstein Date: Mon, 30 Sep 2024 13:31:59 +0300 Subject: [PATCH] add WixMap (#330) Co-authored-by: dorcoh-wix <126170119+dorcoh-wix@users.noreply.github.com> --- .eslintignore | 3 ++- .github/workflows/nodejs.yml | 2 +- .../__snapshots__/macro-debug.spec.js.snap | 24 ++++++++++++++++--- .../macro-no-current-line.spec.js.snap | 24 ++++++++++++++++--- .../__snapshots__/macro.spec.js.snap | 24 ++++++++++++++++--- src/templates/optimizing.js | 13 +++++++++- 6 files changed, 78 insertions(+), 12 deletions(-) diff --git a/.eslintignore b/.eslintignore index 691103a2..70faf940 100644 --- a/.eslintignore +++ b/.eslintignore @@ -3,4 +3,5 @@ /src/babelPlugin/test.compiled.carmi.js /website/ /docs -/bytecode/bytecode-functions.js \ No newline at end of file +/bytecode/bytecode-functions.js +/node_modules \ No newline at end of file diff --git a/.github/workflows/nodejs.yml b/.github/workflows/nodejs.yml index 7e2e4d75..bfea51f4 100644 --- a/.github/workflows/nodejs.yml +++ b/.github/workflows/nodejs.yml @@ -9,7 +9,7 @@ jobs: strategy: matrix: - node-version: [12.x, 14.x, 16.x] + node-version: [16.x] steps: - uses: actions/checkout@v1 diff --git a/src/babelPlugin/__snapshots__/macro-debug.spec.js.snap b/src/babelPlugin/__snapshots__/macro-debug.spec.js.snap index 902d80b1..68750f14 100644 --- a/src/babelPlugin/__snapshots__/macro-debug.spec.js.snap +++ b/src/babelPlugin/__snapshots__/macro-debug.spec.js.snap @@ -31,7 +31,13 @@ module.exports = function () { }if (types.some(checkType)) { return; }const asString = typeof input === 'object' ? JSON.stringify(input) : input;throw new TypeError(\`\${functionName} expects \${types.join('/')}. \${name} at \${source}: \${asString}.\${functionName}\`); - }const $res = { $model };const $listeners = new Set();const $trackingMap = new WeakMap();const $trackingWildcards = new WeakMap();const $invalidatedMap = new WeakMap();const $invalidatedRoots = new Set();$invalidatedRoots.$subKeys = new Map();$invalidatedRoots.$parentKey = null;$invalidatedRoots.$parent = null;$invalidatedRoots.$tracked = new Map();let $first = true;let $tainted = new WeakSet();$invalidatedMap.set($res, $invalidatedRoots);function untrack($targetKeySet, $targetKey) { + }const $res = { $model };const $listeners = new Set();function getWeakMap() { + if (typeof window !== 'undefined') { + return new WeakMap(); + }if (window.WixMap) { + return new window.WixMap(); + }return new WeakMap(); + }const $trackingMap = new WeakMap();const $trackingWildcards = new WeakMap();const $invalidatedMap = getWeakMap();const $invalidatedRoots = new Set();$invalidatedRoots.$subKeys = new Map();$invalidatedRoots.$parentKey = null;$invalidatedRoots.$parent = null;$invalidatedRoots.$tracked = new Map();let $first = true;let $tainted = new WeakSet();$invalidatedMap.set($res, $invalidatedRoots);function untrack($targetKeySet, $targetKey) { const $tracked = $targetKeySet.$tracked;if (!$tracked || !$tracked.has($targetKey)) { return; }const $trackedByKey = $tracked.get($targetKey);for (let i = 0; i < $trackedByKey.length; i += 3) { @@ -635,7 +641,13 @@ module.exports = function () { }if (types.some(checkType)) { return; }const asString = typeof input === 'object' ? JSON.stringify(input) : input;throw new TypeError(\`\${functionName} expects \${types.join('/')}. \${name} at \${source}: \${asString}.\${functionName}\`); - }const $res = { $model };const $listeners = new Set();const $trackingMap = new WeakMap();const $trackingWildcards = new WeakMap();const $invalidatedMap = new WeakMap();const $invalidatedRoots = new Set();$invalidatedRoots.$subKeys = new Map();$invalidatedRoots.$parentKey = null;$invalidatedRoots.$parent = null;$invalidatedRoots.$tracked = new Map();let $first = true;let $tainted = new WeakSet();$invalidatedMap.set($res, $invalidatedRoots);function untrack($targetKeySet, $targetKey) { + }const $res = { $model };const $listeners = new Set();function getWeakMap() { + if (typeof window !== 'undefined') { + return new WeakMap(); + }if (window.WixMap) { + return new window.WixMap(); + }return new WeakMap(); + }const $trackingMap = new WeakMap();const $trackingWildcards = new WeakMap();const $invalidatedMap = getWeakMap();const $invalidatedRoots = new Set();$invalidatedRoots.$subKeys = new Map();$invalidatedRoots.$parentKey = null;$invalidatedRoots.$parent = null;$invalidatedRoots.$tracked = new Map();let $first = true;let $tainted = new WeakSet();$invalidatedMap.set($res, $invalidatedRoots);function untrack($targetKeySet, $targetKey) { const $tracked = $targetKeySet.$tracked;if (!$tracked || !$tracked.has($targetKey)) { return; }const $trackedByKey = $tracked.get($targetKey);for (let i = 0; i < $trackedByKey.length; i += 3) { @@ -1241,7 +1253,13 @@ const modelBuilder = (function () { }if (types.some(checkType)) { return; }const asString = typeof input === 'object' ? JSON.stringify(input) : input;throw new TypeError(\`\${functionName} expects \${types.join('/')}. \${name} at \${source}: \${asString}.\${functionName}\`); - }const $res = { $model };const $listeners = new Set();const $trackingMap = new WeakMap();const $trackingWildcards = new WeakMap();const $invalidatedMap = new WeakMap();const $invalidatedRoots = new Set();$invalidatedRoots.$subKeys = new Map();$invalidatedRoots.$parentKey = null;$invalidatedRoots.$parent = null;$invalidatedRoots.$tracked = new Map();let $first = true;let $tainted = new WeakSet();$invalidatedMap.set($res, $invalidatedRoots);function untrack($targetKeySet, $targetKey) { + }const $res = { $model };const $listeners = new Set();function getWeakMap() { + if (typeof window !== 'undefined') { + return new WeakMap(); + }if (window.WixMap) { + return new window.WixMap(); + }return new WeakMap(); + }const $trackingMap = new WeakMap();const $trackingWildcards = new WeakMap();const $invalidatedMap = getWeakMap();const $invalidatedRoots = new Set();$invalidatedRoots.$subKeys = new Map();$invalidatedRoots.$parentKey = null;$invalidatedRoots.$parent = null;$invalidatedRoots.$tracked = new Map();let $first = true;let $tainted = new WeakSet();$invalidatedMap.set($res, $invalidatedRoots);function untrack($targetKeySet, $targetKey) { const $tracked = $targetKeySet.$tracked;if (!$tracked || !$tracked.has($targetKey)) { return; }const $trackedByKey = $tracked.get($targetKey);for (let i = 0; i < $trackedByKey.length; i += 3) { diff --git a/src/babelPlugin/__snapshots__/macro-no-current-line.spec.js.snap b/src/babelPlugin/__snapshots__/macro-no-current-line.spec.js.snap index d577fee7..96c89582 100644 --- a/src/babelPlugin/__snapshots__/macro-no-current-line.spec.js.snap +++ b/src/babelPlugin/__snapshots__/macro-no-current-line.spec.js.snap @@ -31,7 +31,13 @@ module.exports = function () { }if (types.some(checkType)) { return; }const asString = typeof input === 'object' ? JSON.stringify(input) : input;throw new TypeError(\`\${functionName} expects \${types.join('/')}. \${name} at \${source}: \${asString}.\${functionName}\`); - }const $res = { $model };const $listeners = new Set();const $trackingMap = new WeakMap();const $trackingWildcards = new WeakMap();const $invalidatedMap = new WeakMap();const $invalidatedRoots = new Set();$invalidatedRoots.$subKeys = new Map();$invalidatedRoots.$parentKey = null;$invalidatedRoots.$parent = null;$invalidatedRoots.$tracked = new Map();let $first = true;let $tainted = new WeakSet();$invalidatedMap.set($res, $invalidatedRoots);function untrack($targetKeySet, $targetKey) { + }const $res = { $model };const $listeners = new Set();function getWeakMap() { + if (typeof window !== 'undefined') { + return new WeakMap(); + }if (window.WixMap) { + return new window.WixMap(); + }return new WeakMap(); + }const $trackingMap = new WeakMap();const $trackingWildcards = new WeakMap();const $invalidatedMap = getWeakMap();const $invalidatedRoots = new Set();$invalidatedRoots.$subKeys = new Map();$invalidatedRoots.$parentKey = null;$invalidatedRoots.$parent = null;$invalidatedRoots.$tracked = new Map();let $first = true;let $tainted = new WeakSet();$invalidatedMap.set($res, $invalidatedRoots);function untrack($targetKeySet, $targetKey) { const $tracked = $targetKeySet.$tracked;if (!$tracked || !$tracked.has($targetKey)) { return; }const $trackedByKey = $tracked.get($targetKey);for (let i = 0; i < $trackedByKey.length; i += 3) { @@ -635,7 +641,13 @@ module.exports = function () { }if (types.some(checkType)) { return; }const asString = typeof input === 'object' ? JSON.stringify(input) : input;throw new TypeError(\`\${functionName} expects \${types.join('/')}. \${name} at \${source}: \${asString}.\${functionName}\`); - }const $res = { $model };const $listeners = new Set();const $trackingMap = new WeakMap();const $trackingWildcards = new WeakMap();const $invalidatedMap = new WeakMap();const $invalidatedRoots = new Set();$invalidatedRoots.$subKeys = new Map();$invalidatedRoots.$parentKey = null;$invalidatedRoots.$parent = null;$invalidatedRoots.$tracked = new Map();let $first = true;let $tainted = new WeakSet();$invalidatedMap.set($res, $invalidatedRoots);function untrack($targetKeySet, $targetKey) { + }const $res = { $model };const $listeners = new Set();function getWeakMap() { + if (typeof window !== 'undefined') { + return new WeakMap(); + }if (window.WixMap) { + return new window.WixMap(); + }return new WeakMap(); + }const $trackingMap = new WeakMap();const $trackingWildcards = new WeakMap();const $invalidatedMap = getWeakMap();const $invalidatedRoots = new Set();$invalidatedRoots.$subKeys = new Map();$invalidatedRoots.$parentKey = null;$invalidatedRoots.$parent = null;$invalidatedRoots.$tracked = new Map();let $first = true;let $tainted = new WeakSet();$invalidatedMap.set($res, $invalidatedRoots);function untrack($targetKeySet, $targetKey) { const $tracked = $targetKeySet.$tracked;if (!$tracked || !$tracked.has($targetKey)) { return; }const $trackedByKey = $tracked.get($targetKey);for (let i = 0; i < $trackedByKey.length; i += 3) { @@ -1241,7 +1253,13 @@ const modelBuilder = (function () { }if (types.some(checkType)) { return; }const asString = typeof input === 'object' ? JSON.stringify(input) : input;throw new TypeError(\`\${functionName} expects \${types.join('/')}. \${name} at \${source}: \${asString}.\${functionName}\`); - }const $res = { $model };const $listeners = new Set();const $trackingMap = new WeakMap();const $trackingWildcards = new WeakMap();const $invalidatedMap = new WeakMap();const $invalidatedRoots = new Set();$invalidatedRoots.$subKeys = new Map();$invalidatedRoots.$parentKey = null;$invalidatedRoots.$parent = null;$invalidatedRoots.$tracked = new Map();let $first = true;let $tainted = new WeakSet();$invalidatedMap.set($res, $invalidatedRoots);function untrack($targetKeySet, $targetKey) { + }const $res = { $model };const $listeners = new Set();function getWeakMap() { + if (typeof window !== 'undefined') { + return new WeakMap(); + }if (window.WixMap) { + return new window.WixMap(); + }return new WeakMap(); + }const $trackingMap = new WeakMap();const $trackingWildcards = new WeakMap();const $invalidatedMap = getWeakMap();const $invalidatedRoots = new Set();$invalidatedRoots.$subKeys = new Map();$invalidatedRoots.$parentKey = null;$invalidatedRoots.$parent = null;$invalidatedRoots.$tracked = new Map();let $first = true;let $tainted = new WeakSet();$invalidatedMap.set($res, $invalidatedRoots);function untrack($targetKeySet, $targetKey) { const $tracked = $targetKeySet.$tracked;if (!$tracked || !$tracked.has($targetKey)) { return; }const $trackedByKey = $tracked.get($targetKey);for (let i = 0; i < $trackedByKey.length; i += 3) { diff --git a/src/babelPlugin/__snapshots__/macro.spec.js.snap b/src/babelPlugin/__snapshots__/macro.spec.js.snap index f8f1c75e..c027c9d1 100644 --- a/src/babelPlugin/__snapshots__/macro.spec.js.snap +++ b/src/babelPlugin/__snapshots__/macro.spec.js.snap @@ -31,7 +31,13 @@ module.exports = function () { }if (types.some(checkType)) { return; }const asString = typeof input === 'object' ? JSON.stringify(input) : input;throw new TypeError(\`\${functionName} expects \${types.join('/')}. \${name} at \${source}: \${asString}.\${functionName}\`); - }const $res = { $model };const $listeners = new Set();const $trackingMap = new WeakMap();const $trackingWildcards = new WeakMap();const $invalidatedMap = new WeakMap();const $invalidatedRoots = new Set();$invalidatedRoots.$subKeys = new Map();$invalidatedRoots.$parentKey = null;$invalidatedRoots.$parent = null;$invalidatedRoots.$tracked = new Map();let $first = true;let $tainted = new WeakSet();$invalidatedMap.set($res, $invalidatedRoots);function untrack($targetKeySet, $targetKey) { + }const $res = { $model };const $listeners = new Set();function getWeakMap() { + if (typeof window !== 'undefined') { + return new WeakMap(); + }if (window.WixMap) { + return new window.WixMap(); + }return new WeakMap(); + }const $trackingMap = new WeakMap();const $trackingWildcards = new WeakMap();const $invalidatedMap = getWeakMap();const $invalidatedRoots = new Set();$invalidatedRoots.$subKeys = new Map();$invalidatedRoots.$parentKey = null;$invalidatedRoots.$parent = null;$invalidatedRoots.$tracked = new Map();let $first = true;let $tainted = new WeakSet();$invalidatedMap.set($res, $invalidatedRoots);function untrack($targetKeySet, $targetKey) { const $tracked = $targetKeySet.$tracked;if (!$tracked || !$tracked.has($targetKey)) { return; }const $trackedByKey = $tracked.get($targetKey);for (let i = 0; i < $trackedByKey.length; i += 3) { @@ -635,7 +641,13 @@ module.exports = function () { }if (types.some(checkType)) { return; }const asString = typeof input === 'object' ? JSON.stringify(input) : input;throw new TypeError(\`\${functionName} expects \${types.join('/')}. \${name} at \${source}: \${asString}.\${functionName}\`); - }const $res = { $model };const $listeners = new Set();const $trackingMap = new WeakMap();const $trackingWildcards = new WeakMap();const $invalidatedMap = new WeakMap();const $invalidatedRoots = new Set();$invalidatedRoots.$subKeys = new Map();$invalidatedRoots.$parentKey = null;$invalidatedRoots.$parent = null;$invalidatedRoots.$tracked = new Map();let $first = true;let $tainted = new WeakSet();$invalidatedMap.set($res, $invalidatedRoots);function untrack($targetKeySet, $targetKey) { + }const $res = { $model };const $listeners = new Set();function getWeakMap() { + if (typeof window !== 'undefined') { + return new WeakMap(); + }if (window.WixMap) { + return new window.WixMap(); + }return new WeakMap(); + }const $trackingMap = new WeakMap();const $trackingWildcards = new WeakMap();const $invalidatedMap = getWeakMap();const $invalidatedRoots = new Set();$invalidatedRoots.$subKeys = new Map();$invalidatedRoots.$parentKey = null;$invalidatedRoots.$parent = null;$invalidatedRoots.$tracked = new Map();let $first = true;let $tainted = new WeakSet();$invalidatedMap.set($res, $invalidatedRoots);function untrack($targetKeySet, $targetKey) { const $tracked = $targetKeySet.$tracked;if (!$tracked || !$tracked.has($targetKey)) { return; }const $trackedByKey = $tracked.get($targetKey);for (let i = 0; i < $trackedByKey.length; i += 3) { @@ -1241,7 +1253,13 @@ const modelBuilder = (function () { }if (types.some(checkType)) { return; }const asString = typeof input === 'object' ? JSON.stringify(input) : input;throw new TypeError(\`\${functionName} expects \${types.join('/')}. \${name} at \${source}: \${asString}.\${functionName}\`); - }const $res = { $model };const $listeners = new Set();const $trackingMap = new WeakMap();const $trackingWildcards = new WeakMap();const $invalidatedMap = new WeakMap();const $invalidatedRoots = new Set();$invalidatedRoots.$subKeys = new Map();$invalidatedRoots.$parentKey = null;$invalidatedRoots.$parent = null;$invalidatedRoots.$tracked = new Map();let $first = true;let $tainted = new WeakSet();$invalidatedMap.set($res, $invalidatedRoots);function untrack($targetKeySet, $targetKey) { + }const $res = { $model };const $listeners = new Set();function getWeakMap() { + if (typeof window !== 'undefined') { + return new WeakMap(); + }if (window.WixMap) { + return new window.WixMap(); + }return new WeakMap(); + }const $trackingMap = new WeakMap();const $trackingWildcards = new WeakMap();const $invalidatedMap = getWeakMap();const $invalidatedRoots = new Set();$invalidatedRoots.$subKeys = new Map();$invalidatedRoots.$parentKey = null;$invalidatedRoots.$parent = null;$invalidatedRoots.$tracked = new Map();let $first = true;let $tainted = new WeakSet();$invalidatedMap.set($res, $invalidatedRoots);function untrack($targetKeySet, $targetKey) { const $tracked = $targetKeySet.$tracked;if (!$tracked || !$tracked.has($targetKey)) { return; }const $trackedByKey = $tracked.get($targetKey);for (let i = 0; i < $trackedByKey.length; i += 3) { diff --git a/src/templates/optimizing.js b/src/templates/optimizing.js index 8472da92..89e2bc96 100644 --- a/src/templates/optimizing.js +++ b/src/templates/optimizing.js @@ -165,9 +165,20 @@ function base() { } function library() { + function getWeakMap() { + if (typeof window !== 'undefined') { + return new WeakMap() + } + + if (window.WixMap) { + return new window.WixMap() + } + + return new WeakMap() + } const $trackingMap = new WeakMap(); const $trackingWildcards = new WeakMap(); - const $invalidatedMap = new WeakMap(); + const $invalidatedMap = getWeakMap() const $invalidatedRoots = new Set(); $invalidatedRoots.$subKeys = new Map(); $invalidatedRoots.$parentKey = null;