Avoid using |console| in default tracer and its tests when not defined

This makes default tracer and its tests work in IE 8-10.
redux
David Majda 9 years ago
parent e8b379f945
commit 671c22e80f

@ -817,12 +817,14 @@ function generateJavascript(ast, options) {
' return string + repeat(" ", length - string.length);', ' return string + repeat(" ", length - string.length);',
' }', ' }',
'', '',
' console.log(', ' if (typeof console === "object") {', // IE 8-10
' event.location.start.line + ":" + event.location.start.column + "-"', ' console.log(',
' + event.location.end.line + ":" + event.location.end.column + " "', ' event.location.start.line + ":" + event.location.start.column + "-"',
' + pad(event.type, 10) + " "', ' + event.location.end.line + ":" + event.location.end.column + " "',
' + repeat(" ", that.indentLevel) + event.rule', ' + pad(event.type, 10) + " "',
' );', ' + repeat(" ", that.indentLevel) + event.rule',
' );',
' }',
' }', ' }',
'', '',
' switch (event.type) {', ' switch (event.type) {',

@ -53,17 +53,21 @@ describe("generated parser API", function() {
].join("\n"), { trace: true }); ].join("\n"), { trace: true });
describe("default tracer", function() { describe("default tracer", function() {
it("traces using console.log", function() { it("traces using console.log (if console is defined)", function() {
spyOn(console, "log"); if (typeof console === "object") {
spyOn(console, "log");
}
parser.parse("b"); parser.parse("b");
expect(console.log).toHaveBeenCalledWith("1:1-1:1 rule.enter start"); if (typeof console === "object") {
expect(console.log).toHaveBeenCalledWith("1:1-1:1 rule.enter a"); expect(console.log).toHaveBeenCalledWith("1:1-1:1 rule.enter start");
expect(console.log).toHaveBeenCalledWith("1:1-1:1 rule.fail a"); expect(console.log).toHaveBeenCalledWith("1:1-1:1 rule.enter a");
expect(console.log).toHaveBeenCalledWith("1:1-1:1 rule.enter b"); expect(console.log).toHaveBeenCalledWith("1:1-1:1 rule.fail a");
expect(console.log).toHaveBeenCalledWith("1:1-1:2 rule.match b"); expect(console.log).toHaveBeenCalledWith("1:1-1:1 rule.enter b");
expect(console.log).toHaveBeenCalledWith("1:1-1:2 rule.match start"); expect(console.log).toHaveBeenCalledWith("1:1-1:2 rule.match b");
expect(console.log).toHaveBeenCalledWith("1:1-1:2 rule.match start");
}
}); });
}); });

Loading…
Cancel
Save