From 5af4320406a09e088cde1e13676df786bf14c2ef Mon Sep 17 00:00:00 2001 From: _Kerman Date: Fri, 2 Aug 2024 20:43:15 +0800 Subject: [PATCH] fix(language-plugin-pug): should cache proxyed object (#4626) --- packages/language-plugin-pug/index.ts | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/packages/language-plugin-pug/index.ts b/packages/language-plugin-pug/index.ts index a8036a4d59..140e7f45e4 100644 --- a/packages/language-plugin-pug/index.ts +++ b/packages/language-plugin-pug/index.ts @@ -34,8 +34,9 @@ const plugin: VueLanguagePlugin = ({ modules }) => { return createProxyObject(completed); function createProxyObject(target: any): any { + const proxys = new WeakMap(); return new Proxy(target, { - get(target, prop) { + get(target, prop, receiver) { if (prop === 'offset') { const htmlOffset = target.offset; const nums: number[] = []; @@ -44,9 +45,14 @@ const plugin: VueLanguagePlugin = ({ modules }) => { } return Math.max(-1, ...nums); } - const value = target[prop]; - if (typeof value === 'object') { - return createProxyObject(target[prop]); + const value = Reflect.get(target, prop, receiver); + if (typeof value === 'object' && value !== null) { + let proxyed = proxys.get(value) + if (proxyed) + return proxyed; + proxyed = createProxyObject(value); + proxys.set(value, proxyed); + return proxyed; } return value; }