Skip to content

Commit

Permalink
fix(language-plugin-pug): should cache proxyed object (#4626)
Browse files Browse the repository at this point in the history
  • Loading branch information
KermanX authored Aug 2, 2024
1 parent 892e4de commit 5af4320
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions packages/language-plugin-pug/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[] = [];
Expand All @@ -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;
}
Expand Down

0 comments on commit 5af4320

Please sign in to comment.