MCPcopy Index your code
hub / github.com/Moddable-OpenSource/moddable / cmdPrint

Method cmdPrint

tools/xsbug-log/xsbug-debugmachine.js:2057–2107  ·  view source on GitHub ↗
(args)

Source from the content-addressed store, hash-verified

2055 }
2056
2057 cmdPrint(args) {
2058 if (!this.requireBroken()) {
2059 this.showPrompt();
2060 return;
2061 }
2062 if (args.length === 0) {
2063 if (!this.view.local || this.view.local.length === 0) {
2064 this.commandError('No local variables.');
2065 return;
2066 }
2067
2068 this.gatherAllLocals(0, [], (collected) => {
2069 collected.sort((a, b) => a.name.toLowerCase().localeCompare(b.name.toLowerCase()));
2070 this.report('info_locals', { locals: collected }, undefined, (data) => {
2071 for (const c of data.locals) {
2072 this.printVariable(c, 0);
2073 }
2074 this.showPrompt();
2075 });
2076 });
2077 }
2078 else {
2079 const expr = args.join(' ');
2080
2081 // "import.meta" is a language expression, not a debug view variable
2082 if (expr === 'import.meta' || expr.startsWith('import.meta.')) {
2083 this.commandError('"import.meta" is not available as a debug variable. Assign it to a local first: let meta = import.meta');
2084 return;
2085 }
2086
2087 const parts = [];
2088 const regex = /\["([^"]+)"\]|\['([^']+)'\]|\[`([^`]+)`\]|(\[[0-9]+\])|\.([^.\[]+)|^([^.\[]+)/g;
2089 let match;
2090 while ((match = regex.exec(expr)) !== null) {
2091 parts.push(match[1] || match[2] || match[3] || match[4] || match[5] || match[6]);
2092 }
2093
2094 // "p globalThis.name" or "p global.name" — search global hierarchy
2095 if ((parts[0] === 'globalThis' || parts[0] === 'global') && parts.length > 1) {
2096 if (!this.view.global || this.view.global.length === 0) {
2097 this.commandError('No global variables available.');
2098 return;
2099 }
2100 this.resolveGlobalPath(parts.slice(1));
2101 }
2102 else {
2103 // Search locals first, fall back to globals
2104 this.resolveDotPath(this.view.local || [], parts, 0, true);
2105 }
2106 }
2107 }
2108
2109 // Skip internal/frame items when listing all locals
2110 isInternalLocal(item) {

Callers 5

handleCommandMethod · 0.95
resolveDotPathMethod · 0.95
expandAndSearchMethod · 0.95
cmdInfoMethod · 0.95

Calls 10

requireBrokenMethod · 0.95
showPromptMethod · 0.95
commandErrorMethod · 0.95
gatherAllLocalsMethod · 0.95
reportMethod · 0.95
printVariableMethod · 0.95
resolveGlobalPathMethod · 0.95
resolveDotPathMethod · 0.95
sliceMethod · 0.65
pushMethod · 0.45

Tested by

no test coverage detected