Skip to content
This repository has been archived by the owner on Oct 2, 2021. It is now read-only.

Commit

Permalink
Change logpoint from an expression to plain text with expressions mar…
Browse files Browse the repository at this point in the history
  • Loading branch information
roblourens committed Mar 22, 2018
1 parent 6086af5 commit f4e5513
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion src/chrome/internalSourceBreakpoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export class InternalSourceBreakpoint {
this.hitCondition = breakpoint.hitCondition;

if (breakpoint.logMessage) {
this.condition = `console.log(${breakpoint.logMessage})`;
this.condition = logMessageToExpression(breakpoint.logMessage);
if (breakpoint.condition) {
this.condition = `(${breakpoint.condition}) && ${this.condition}`;
}
Expand All @@ -25,3 +25,24 @@ export class InternalSourceBreakpoint {
}
}
}

const LOGMESSAGE_VARIABLE_REGEXP = /{(.*?)}/g;

function logMessageToExpression(msg) {
msg = msg.replace('%', '%%');

let args: string[] = [];
let format = msg.replace(LOGMESSAGE_VARIABLE_REGEXP, (match, group) => {
const a = group.trim();
if (a) {
args.push(`(${a})`);
return '%s';
} else {
return '';
}
});

format = format.replace('\'', '\\\'');

return `console.log('${format}', ${args.join(', ')})`;
}

0 comments on commit f4e5513

Please sign in to comment.