module: do not attempt to strip type when there's no source
PR-URL: https://github.com/nodejs/node/pull/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>
This commit is contained in:
parent
d7f373075d
commit
9a4eb210ae
@ -161,8 +161,12 @@ function getFileProtocolModuleFormat(url, context = { __proto__: null }, ignoreE
|
||||
default: { // The user did not pass `--experimental-default-type`.
|
||||
// `source` is undefined when this is called from `defaultResolve`;
|
||||
// but this gets called again from `defaultLoad`/`defaultLoadSync`.
|
||||
const { tsParse } = require('internal/modules/helpers');
|
||||
const parsedSource = tsParse(source);
|
||||
let parsedSource;
|
||||
if (source) {
|
||||
// We do the type stripping only if `source` is not falsy.
|
||||
const { tsParse } = require('internal/modules/helpers');
|
||||
parsedSource = tsParse(source);
|
||||
}
|
||||
const detectedFormat = detectModuleFormat(parsedSource, url);
|
||||
// When source is undefined, default to module-typescript.
|
||||
const format = detectedFormat ? `${detectedFormat}-typescript` : 'module-typescript';
|
||||
|
@ -331,8 +331,7 @@ function loadTypeScriptParser(parser) {
|
||||
* @returns {string} JavaScript code.
|
||||
*/
|
||||
function tsParse(source) {
|
||||
// TODO(@marco-ippolito) Checking empty string or non string input should be handled in Amaro.
|
||||
if (!source || typeof source !== 'string') { return ''; }
|
||||
assert(typeof source === 'string');
|
||||
const parse = loadTypeScriptParser();
|
||||
const { code } = parse(source);
|
||||
return code;
|
||||
|
Loading…
x
Reference in New Issue
Block a user