From 91d99ce41c221c7da1ea29e6c839eb90bedd138d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Zasso?= Date: Mon, 17 Jun 2019 10:00:31 +0200 Subject: [PATCH] lib,test: fix error message check after V8 update Backport-PR-URL: https://github.com/nodejs/node/pull/29241 PR-URL: https://github.com/nodejs/node/pull/28918 Reviewed-By: Colin Ihrig Reviewed-By: Ben Noordhuis Reviewed-By: Jiawen Geng Reviewed-By: Rich Trott --- lib/internal/modules/cjs/loader.js | 2 +- test/parallel/test-v8-flags.js | 4 ++-- test/parallel/test-vm-basic.js | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/internal/modules/cjs/loader.js b/lib/internal/modules/cjs/loader.js index b09e3cceb55120..a002efa175a708 100644 --- a/lib/internal/modules/cjs/loader.js +++ b/lib/internal/modules/cjs/loader.js @@ -97,7 +97,7 @@ function enrichCJSError(err) { usage. However, some cases are not matching, cases like import statement after a comment block and/or after a variable definition. */ - if (err.message.startsWith('Unexpected token export') || + if (err.message.startsWith('Unexpected token \'export\'') || (/^\s*import(?=[ {'"*])\s*(?![ (])/).test(lineWithErr)) { process.emitWarning( 'To load an ES module, set "type": "module" in the package.json or use ' + diff --git a/test/parallel/test-v8-flags.js b/test/parallel/test-v8-flags.js index 50d7047a5ddfa9..e476c5e3886661 100644 --- a/test/parallel/test-v8-flags.js +++ b/test/parallel/test-v8-flags.js @@ -13,6 +13,6 @@ assert(vm.runInThisContext('%_IsSmi(43)')); v8.setFlagsFromString('--noallow_natives_syntax'); assert.throws(function() { eval('%_IsSmi(44)'); }, - /^SyntaxError: Unexpected token %$/); + /^SyntaxError: Unexpected token '%'$/); assert.throws(function() { vm.runInThisContext('%_IsSmi(45)'); }, - /^SyntaxError: Unexpected token %$/); + /^SyntaxError: Unexpected token '%'$/); diff --git a/test/parallel/test-vm-basic.js b/test/parallel/test-vm-basic.js index 29e2a8b5251934..69fd859b028815 100644 --- a/test/parallel/test-vm-basic.js +++ b/test/parallel/test-vm-basic.js @@ -152,7 +152,7 @@ const vm = require('vm'); ); }, { type: SyntaxError, - message: 'Unexpected token }' + message: "Unexpected token '}'" }); // Tests for failed argument validation