From f96ed184284c7c3f36fdb5608a90449b745742d7 Mon Sep 17 00:00:00 2001 From: Bradley Farias Date: Sun, 21 Mar 2021 14:35:49 -0500 Subject: [PATCH 1/6] esm: use correct URL for error decoration --- lib/internal/modules/esm/module_job.js | 4 ++-- test/parallel/test-policy-dependencies.js | 17 +++++++++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/lib/internal/modules/esm/module_job.js b/lib/internal/modules/esm/module_job.js index 6cf968553bae6d..0604f5d692e17b 100644 --- a/lib/internal/modules/esm/module_job.js +++ b/lib/internal/modules/esm/module_job.js @@ -109,7 +109,7 @@ class ModuleJob { if (StringPrototypeIncludes(e.message, ' does not provide an export named')) { const splitStack = StringPrototypeSplit(e.stack, '\n'); - const parentFileUrl = splitStack[0]; + const parentFileUrl = splitStack[0].replace(/:\d+$/, ''); const { 1: childSpecifier, 2: name } = StringPrototypeMatch( e.message, /module '(.*)' does not provide an export named '(.+)'/); @@ -120,7 +120,7 @@ class ModuleJob { const importStatement = splitStack[1]; // TODO(@ctavan): The original error stack only provides the single // line which causes the error. For multi-line import statements we - // cannot generate an equivalent object descructuring assignment by + // cannot generate an equivalent object destructuring assignment by // just parsing the error stack. const oneLineNamedImports = StringPrototypeMatch(importStatement, /{.*}/); const destructuringAssignment = oneLineNamedImports && diff --git a/test/parallel/test-policy-dependencies.js b/test/parallel/test-policy-dependencies.js index 4486e0f8aa08c0..5d0cba60d7e7c0 100644 --- a/test/parallel/test-policy-dependencies.js +++ b/test/parallel/test-policy-dependencies.js @@ -89,3 +89,20 @@ const dep = fixtures.path('policy', 'parent.js'); ); assert.strictEqual(status, 1); } +{ + // Regression test for https://github.com/nodejs/node/issues/37812 + const depPolicy = fixtures.path( + 'policy', + 'dependencies', + 'dependencies-missing-export-policy.json'); + const { status, stderr } = spawnSync( + process.execPath, + [ + '--experimental-policy', depPolicy, fixtures.path('policy', 'bad-main.mjs') + ] + ); + assert.strictEqual(status, 1); + assert.match(`${stderr}`, + /SyntaxError: Named export 'doesNotExist' not found./, + 'Should give the real SyntaxError and position'); +} From 400797c31930c9aef2b8b7d4500a60c30aab8d1e Mon Sep 17 00:00:00 2001 From: Bradley Farias Date: Sun, 21 Mar 2021 14:41:19 -0500 Subject: [PATCH 2/6] linter --- test/parallel/test-policy-dependencies.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/test/parallel/test-policy-dependencies.js b/test/parallel/test-policy-dependencies.js index 5d0cba60d7e7c0..4459c3cc453b05 100644 --- a/test/parallel/test-policy-dependencies.js +++ b/test/parallel/test-policy-dependencies.js @@ -98,11 +98,14 @@ const dep = fixtures.path('policy', 'parent.js'); const { status, stderr } = spawnSync( process.execPath, [ - '--experimental-policy', depPolicy, fixtures.path('policy', 'bad-main.mjs') + '--experimental-policy', + depPolicy, + fixtures.path('policy', 'bad-main.mjs') ] ); assert.strictEqual(status, 1); - assert.match(`${stderr}`, - /SyntaxError: Named export 'doesNotExist' not found./, + assert.match( + `${stderr}`, + /SyntaxError: Named export 'doesNotExist' not found\./, 'Should give the real SyntaxError and position'); } From 92766cd60de2da9d1f12813f66c221ec17c71226 Mon Sep 17 00:00:00 2001 From: Bradley Farias Date: Sun, 21 Mar 2021 14:42:42 -0500 Subject: [PATCH 3/6] primordial --- lib/internal/modules/esm/module_job.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/internal/modules/esm/module_job.js b/lib/internal/modules/esm/module_job.js index 0604f5d692e17b..ba97a0e31784c2 100644 --- a/lib/internal/modules/esm/module_job.js +++ b/lib/internal/modules/esm/module_job.js @@ -109,7 +109,11 @@ class ModuleJob { if (StringPrototypeIncludes(e.message, ' does not provide an export named')) { const splitStack = StringPrototypeSplit(e.stack, '\n'); - const parentFileUrl = splitStack[0].replace(/:\d+$/, ''); + const parentFileUrl = StringPrototypeReplace( + splitStack[0], + /:\d+$/, + '' + ); const { 1: childSpecifier, 2: name } = StringPrototypeMatch( e.message, /module '(.*)' does not provide an export named '(.+)'/); From 413ed35188ea555df6976f869c3df08447a411a4 Mon Sep 17 00:00:00 2001 From: Bradley Farias Date: Sun, 21 Mar 2021 14:52:09 -0500 Subject: [PATCH 4/6] missing files --- test/fixtures/policy/bad-main.mjs | 1 + .../dependencies-missing-export-policy.json | 11 +++++++++++ 2 files changed, 12 insertions(+) create mode 100644 test/fixtures/policy/bad-main.mjs create mode 100644 test/fixtures/policy/dependencies/dependencies-missing-export-policy.json diff --git a/test/fixtures/policy/bad-main.mjs b/test/fixtures/policy/bad-main.mjs new file mode 100644 index 00000000000000..db1938ad7c2e87 --- /dev/null +++ b/test/fixtures/policy/bad-main.mjs @@ -0,0 +1 @@ +import {doesNotExist} from './dep.js'; diff --git a/test/fixtures/policy/dependencies/dependencies-missing-export-policy.json b/test/fixtures/policy/dependencies/dependencies-missing-export-policy.json new file mode 100644 index 00000000000000..a4689f6ce33190 --- /dev/null +++ b/test/fixtures/policy/dependencies/dependencies-missing-export-policy.json @@ -0,0 +1,11 @@ +{ + "resources": { + "../bad-main.mjs": { + "integrity": true, + "dependencies": true + }, + "../dep.js": { + "integrity": true + } + } +} \ No newline at end of file From 12ebfce155e8bc0558ca807933c731c81f4637bc Mon Sep 17 00:00:00 2001 From: Bradley Farias Date: Fri, 9 Apr 2021 17:13:17 -0500 Subject: [PATCH 5/6] linter --- test/parallel/test-policy-dependencies.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/parallel/test-policy-dependencies.js b/test/parallel/test-policy-dependencies.js index 4459c3cc453b05..157da8295266db 100644 --- a/test/parallel/test-policy-dependencies.js +++ b/test/parallel/test-policy-dependencies.js @@ -100,7 +100,7 @@ const dep = fixtures.path('policy', 'parent.js'); [ '--experimental-policy', depPolicy, - fixtures.path('policy', 'bad-main.mjs') + fixtures.path('policy', 'bad-main.mjs'), ] ); assert.strictEqual(status, 1); From 5096064de8a52e057da871911f2d48253a86d4ce Mon Sep 17 00:00:00 2001 From: Bradley Farias Date: Mon, 12 Apr 2021 11:30:03 -0500 Subject: [PATCH 6/6] nit --- .../policy/dependencies/dependencies-missing-export-policy.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/fixtures/policy/dependencies/dependencies-missing-export-policy.json b/test/fixtures/policy/dependencies/dependencies-missing-export-policy.json index a4689f6ce33190..5da0de13920936 100644 --- a/test/fixtures/policy/dependencies/dependencies-missing-export-policy.json +++ b/test/fixtures/policy/dependencies/dependencies-missing-export-policy.json @@ -8,4 +8,4 @@ "integrity": true } } -} \ No newline at end of file +}