Skip to content

Commit 0d17e46

Browse files
authored
opt: Optimize the logic for evaluating expressions in the Console. (#25)
Instead of maintaining a list of property names in multiApps, change every identifier expression to: "(this.identifier ?? this.multiApps[this.currentDebugAppId ?? this.currentAppId]?.identifier)". This way, we can eliminate the need for string comparisons.
1 parent 465e604 commit 0d17e46

File tree

1 file changed

+13
-38
lines changed

1 file changed

+13
-38
lines changed

packages/devtools-frontend-lynx/front_end/core/sdk/ConsoleModel.ts

Lines changed: 13 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -173,57 +173,32 @@ export class ConsoleModel extends Common.ObjectWrapper.ObjectWrapper implements
173173
Common.EventTarget.removeEventListeners(this._targetListeners.get(target) || []);
174174
}
175175

176-
_isLocalObject(node: Acorn.Node): boolean {
177-
const localIdentifiers = [
178-
'LynxTestModule',
179-
'NativeModules',
180-
'NetworkingModule',
181-
'allRemoved',
182-
'clearInterval',
183-
'clearTimeout',
184-
'componentEventBatch',
185-
'lynx',
186-
'modules',
187-
'nativeAppId',
188-
'resolvedPromise',
189-
'setInterval',
190-
'setTimeout',
191-
'__sourcemap__release__',
192-
'_apiList',
193-
'_appInstance',
194-
'_cardPath',
195-
'_componentInstance',
196-
'_componentOpts',
197-
'_intersectionObserverManager',
198-
'_nativeApp',
199-
'_params',
200-
'appInstance',
201-
'nativeApp',
202-
'params'
203-
];
204-
// @ts-ignore
205-
return localIdentifiers.includes(node.name);
206-
}
207-
208176
_addGlobalPrefix(input: string): string {
209177
const ast = Acorn.parse(input, { ecmaVersion: 2022 });
210178
// @ts-ignore
211179
const ranges = [];
212180
// @ts-ignore
213181
window.acorn.walk.simple(ast, {
214182
// @ts-ignore
215-
Identifier: node => {
216-
if (node.type === 'Identifier' && this._isLocalObject(node)) {
183+
Identifier: (node) => {
184+
if (node.type === 'Identifier') {
217185
ranges.push([node.start, node.end]);
218186
}
219-
},
187+
}
220188
});
221189
// @ts-ignore
222-
ranges.sort((f, s) => (s[0] - f[0]));
190+
ranges.sort((f, s) => s[0] - f[0]);
223191
let result = input;
224192
// @ts-ignore
225-
ranges.forEach(range => {
226-
result = result.substring(0, range[0]) + 'globalThis.multiApps[globalThis.currentAppId].' + result.substring(range[0]);
193+
ranges.forEach((range) => {
194+
result =
195+
result.substring(0, range[0]) +
196+
'(this.' +
197+
result.substring(range[0], range[1]) +
198+
' ?? this.multiApps[this.currentDebugAppId ?? this.currentAppId]?.' +
199+
result.substring(range[0], range[1]) +
200+
')' +
201+
result.substring(range[1]);
227202
});
228203
return result;
229204
}

0 commit comments

Comments
 (0)