Skip to content

Commit

Permalink
esm: use correct error arguments
Browse files Browse the repository at this point in the history
ERR_UNKNOWN_FILE_EXTENSION expects a single argument. This
commit fixes the argument count.

PR-URL: nodejs#27763
Fixes: nodejs#27761
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
  • Loading branch information
cjihrig committed May 20, 2019
1 parent 1b381d6 commit 873c372
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
3 changes: 1 addition & 2 deletions lib/internal/modules/esm/default_resolve.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,7 @@ function resolve(specifier, parentURL) {
if (isMain)
format = type === TYPE_MODULE ? 'module' : 'commonjs';
else
throw new ERR_UNKNOWN_FILE_EXTENSION(fileURLToPath(url),
fileURLToPath(parentURL));
throw new ERR_UNKNOWN_FILE_EXTENSION(fileURLToPath(url));
}
return { url: `${url}`, format };
}
Expand Down
13 changes: 13 additions & 0 deletions test/es-module/test-esm-invalid-extension.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
'use strict';
require('../common');
const fixtures = require('../common/fixtures');
const assert = require('assert');
const { spawnSync } = require('child_process');
const fixture = fixtures.path('/es-modules/import-invalid-ext.mjs');
const child = spawnSync(process.execPath, ['--experimental-modules', fixture]);
const errMsg = 'TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension';

assert.strictEqual(child.status, 1);
assert.strictEqual(child.signal, null);
assert.strictEqual(child.stdout.toString().trim(), '');
assert(child.stderr.toString().includes(errMsg));
1 change: 1 addition & 0 deletions test/fixtures/es-modules/import-invalid-ext.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import './simple.wat';

0 comments on commit 873c372

Please sign in to comment.