From b4d5ee2a3d25613b35a2e8e10a0eb75582cc5654 Mon Sep 17 00:00:00 2001 From: Jan Krems Date: Tue, 14 Mar 2017 16:37:01 -0700 Subject: [PATCH] fix: Work around inconsistent handling of strict directive --- examples/alive.js | 1 - examples/backtrace.js | 1 - examples/cjs/index.js | 1 - examples/cjs/other.js | 1 - examples/exceptions.js | 1 - examples/three-lines.js | 1 - examples/use-strict.js | 2 ++ test/cli/backtrace.test.js | 4 ++-- test/cli/exceptions.test.js | 6 +++--- test/cli/use-strict.test.js | 27 +++++++++++++++++++++++++++ 10 files changed, 34 insertions(+), 11 deletions(-) create mode 100644 examples/use-strict.js create mode 100644 test/cli/use-strict.test.js diff --git a/examples/alive.js b/examples/alive.js index 3cf557b..c8ad157 100644 --- a/examples/alive.js +++ b/examples/alive.js @@ -1,4 +1,3 @@ -'use strict'; let x = 0; function heartbeat() { ++x; diff --git a/examples/backtrace.js b/examples/backtrace.js index f5d71a1..f18b33e 100644 --- a/examples/backtrace.js +++ b/examples/backtrace.js @@ -1,4 +1,3 @@ -'use strict'; const { exports: moduleScoped } = module; function topFn(a, b = false) { diff --git a/examples/cjs/index.js b/examples/cjs/index.js index d5815e8..ce6c782 100644 --- a/examples/cjs/index.js +++ b/examples/cjs/index.js @@ -1,4 +1,3 @@ -'use strict'; const { add } = require('./other'); const sum = add(40, 2); diff --git a/examples/cjs/other.js b/examples/cjs/other.js index efadaa1..44a9a43 100644 --- a/examples/cjs/other.js +++ b/examples/cjs/other.js @@ -1,4 +1,3 @@ -'use strict'; exports.add = function add(a, b) { return a + b; }; diff --git a/examples/exceptions.js b/examples/exceptions.js index 00c48ed..f57d48a 100644 --- a/examples/exceptions.js +++ b/examples/exceptions.js @@ -1,4 +1,3 @@ -'use strict'; let error = null; try { throw new Error('Caught'); diff --git a/examples/three-lines.js b/examples/three-lines.js index 4e1cb95..c17c7c1 100644 --- a/examples/three-lines.js +++ b/examples/three-lines.js @@ -1,4 +1,3 @@ -'use strict'; let x = 1; x = x + 1; module.exports = x; diff --git a/examples/use-strict.js b/examples/use-strict.js new file mode 100644 index 0000000..9fe4b8f --- /dev/null +++ b/examples/use-strict.js @@ -0,0 +1,2 @@ +'use strict'; +console.log('first real line'); diff --git a/test/cli/backtrace.test.js b/test/cli/backtrace.test.js index 2e2ba4a..9cd8a82 100644 --- a/test/cli/backtrace.test.js +++ b/test/cli/backtrace.test.js @@ -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); diff --git a/test/cli/exceptions.test.js b/test/cli/exceptions.test.js index 6d3ff68..b66c09f 100644 --- a/test/cli/exceptions.test.js +++ b/test/cli/exceptions.test.js @@ -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 @@ -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. diff --git a/test/cli/use-strict.test.js b/test/cli/use-strict.test.js new file mode 100644 index 0000000..81f4d91 --- /dev/null +++ b/test/cli/use-strict.test.js @@ -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) => { + 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); +});