Skip to content

Commit 100225f

Browse files
aduh95targos
authored andcommittedAug 14, 2024
module: do not attempt to strip type when there's no source
PR-URL: #54287 Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com> Reviewed-By: Mohammed Keyvanzadeh <mohammadkeyvanzade94@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Moshe Atlow <moshe@atlow.co.il> Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent 417120a commit 100225f

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed
 

‎lib/internal/modules/esm/get_format.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,12 @@ function getFileProtocolModuleFormat(url, context = { __proto__: null }, ignoreE
160160
default: { // The user did not pass `--experimental-default-type`.
161161
// `source` is undefined when this is called from `defaultResolve`;
162162
// but this gets called again from `defaultLoad`/`defaultLoadSync`.
163-
const { tsParse } = require('internal/modules/helpers');
164-
const parsedSource = tsParse(source);
163+
let parsedSource;
164+
if (source) {
165+
// We do the type stripping only if `source` is not falsy.
166+
const { tsParse } = require('internal/modules/helpers');
167+
parsedSource = tsParse(source);
168+
}
165169
const detectedFormat = detectModuleFormat(parsedSource, url);
166170
// When source is undefined, default to module-typescript.
167171
const format = detectedFormat ? `${detectedFormat}-typescript` : 'module-typescript';

‎lib/internal/modules/helpers.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -331,8 +331,7 @@ function loadTypeScriptParser(parser) {
331331
* @returns {string} JavaScript code.
332332
*/
333333
function tsParse(source) {
334-
// TODO(@marco-ippolito) Checking empty string or non string input should be handled in Amaro.
335-
if (!source || typeof source !== 'string') { return ''; }
334+
assert(typeof source === 'string');
336335
const parse = loadTypeScriptParser();
337336
const { code } = parse(source);
338337
return code;

0 commit comments

Comments
 (0)
Please sign in to comment.