Skip to content
This repository was archived by the owner on Feb 1, 2022. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix: Work around inconsistent handling of strict directive
  • Loading branch information
Jan Krems committed Mar 14, 2017
commit b4d5ee2a3d25613b35a2e8e10a0eb75582cc5654
1 change: 0 additions & 1 deletion examples/alive.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
'use strict';
let x = 0;
function heartbeat() {
++x;
Expand Down
1 change: 0 additions & 1 deletion examples/backtrace.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
'use strict';
const { exports: moduleScoped } = module;

function topFn(a, b = false) {
Expand Down
1 change: 0 additions & 1 deletion examples/cjs/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
'use strict';
const { add } = require('./other');

const sum = add(40, 2);
Expand Down
1 change: 0 additions & 1 deletion examples/cjs/other.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
'use strict';
exports.add = function add(a, b) {
return a + b;
};
1 change: 0 additions & 1 deletion examples/exceptions.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
'use strict';
let error = null;
try {
throw new Error('Caught');
Expand Down
1 change: 0 additions & 1 deletion examples/three-lines.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
'use strict';
let x = 1;
x = x + 1;
module.exports = x;
2 changes: 2 additions & 0 deletions examples/use-strict.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
'use strict';
console.log('first real line');
4 changes: 2 additions & 2 deletions test/cli/backtrace.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ test('display and navigate backtrace', (t) => {
.then(() => cli.stepCommand('c'))
.then(() => cli.command('bt'))
.then(() => {
t.match(cli.output, `#0 topFn ${script}:8:2`);
t.match(cli.output, `#0 topFn ${script}:7:2`);
})
.then(() => cli.command('backtrace'))
.then(() => {
t.match(cli.output, `#0 topFn ${script}:8:2`);
t.match(cli.output, `#0 topFn ${script}:7:2`);
})
.then(() => cli.quit())
.then(null, onFatal);
Expand Down
6 changes: 3 additions & 3 deletions test/cli/exceptions.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ test('break on (uncaught) exceptions', (t) => {
.then(() => cli.command('breakOnException'))
.then(() => cli.stepCommand('c'))
.then(() => {
t.match(cli.output, `exception in ${script}:4`);
t.match(cli.output, `exception in ${script}:3`);
})
.then(() => cli.stepCommand('c'))
.then(() => {
t.match(cli.output, `exception in ${script}:10`);
t.match(cli.output, `exception in ${script}:9`);
})

// Next run: With `breakOnUncaught` it only pauses on the 2nd exception
Expand All @@ -46,7 +46,7 @@ test('break on (uncaught) exceptions', (t) => {
})
.then(() => cli.stepCommand('c'))
.then(() => {
t.match(cli.output, `exception in ${script}:10`);
t.match(cli.output, `exception in ${script}:9`);
})

// Next run: Back to the initial state! It should die again.
Expand Down
27 changes: 27 additions & 0 deletions test/cli/use-strict.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
'use strict';
const Path = require('path');

const { test } = require('tap');

const startCLI = require('./start-cli');

test('for whiles that starts with strict directive', (t) => {
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added this test for documentation purposes and to make sure that adding a strict directive doesn't actually break everything.

const script = Path.join('examples', 'use-strict.js');
const cli = startCLI([script]);

function onFatal(error) {
cli.quit();
throw error;
}

return cli.waitFor(/break/)
.then(() => cli.waitForPrompt())
.then(() => {
t.match(
cli.output,
/break in [^:]+:(?:1|2)[^\d]/,
'pauses either on strict directive or first "real" line');
})
.then(() => cli.quit())
.then(null, onFatal);
});