From da0e566278349372983e5dad3bbaaca6c0e4c0a7 Mon Sep 17 00:00:00 2001 From: Chengzhong Wu Date: Wed, 3 Jun 2026 16:39:45 -0400 Subject: [PATCH] lib: remove source map deadcode in type stripping `processTypeScriptCode` does not produce source maps at all for type stripping. Given that the transform mode was removed, there is no need to keep the source map support around it. Signed-off-by: Chengzhong Wu --- lib/internal/modules/typescript.js | 31 ++---------------------------- 1 file changed, 2 insertions(+), 29 deletions(-) diff --git a/lib/internal/modules/typescript.js b/lib/internal/modules/typescript.js index 86ef400ca7559e..6e22560b5fc965 100644 --- a/lib/internal/modules/typescript.js +++ b/lib/internal/modules/typescript.js @@ -18,9 +18,7 @@ const { ERR_UNSUPPORTED_NODE_MODULES_TYPE_STRIPPING, ERR_UNSUPPORTED_TYPESCRIPT_SYNTAX, } = require('internal/errors').codes; -const { getOptionValue } = require('internal/options'); const assert = require('internal/assert'); -const { Buffer } = require('buffer'); const { getCompileCacheEntry, saveCompileCacheEntry, @@ -117,26 +115,18 @@ function stripTypeScriptTypes(code, options = kEmptyObject) { } /** - * @typedef {'strip-only' | 'transform'} TypeScriptMode * @typedef {object} TypeScriptOptions - * @property {TypeScriptMode} mode Mode. - * @property {boolean} sourceMap Whether to generate source maps. * @property {string|undefined} filename Filename. */ /** - * Processes TypeScript code by stripping types or transforming. - * Handles source maps if needed. + * Processes TypeScript code by stripping types. * @param {string} code TypeScript code to process. * @param {TypeScriptOptions} options The configuration object. * @returns {string} The processed code. */ function processTypeScriptCode(code, options) { - const { code: transformedCode, map } = parseTypeScript(code, options); - - if (map) { - return addSourceMap(transformedCode, map); - } + const { code: transformedCode } = parseTypeScript(code, options); if (options.filename) { return `${transformedCode}\n\n//# sourceURL=${options.filename}`; @@ -163,8 +153,6 @@ function stripTypeScriptModuleTypes(source, filename) { if (isUnderNodeModules(filename)) { throw new ERR_UNSUPPORTED_NODE_MODULES_TYPE_STRIPPING(filename); } - const sourceMap = getOptionValue('--enable-source-maps'); - // Get a compile cache entry into the native compile cache store, // keyed by the filename. If the cache can already be loaded on disk, // cached.transpiled contains the cached string. Otherwise we should do @@ -177,7 +165,6 @@ function stripTypeScriptModuleTypes(source, filename) { const options = { mode: 'strip-only', - sourceMap, filename, }; @@ -193,20 +180,6 @@ function stripTypeScriptModuleTypes(source, filename) { return transpiled; } -/** - * - * @param {string} code The compiled code. - * @param {string} sourceMap The source map. - * @returns {string} The code with the source map attached. - */ -function addSourceMap(code, sourceMap) { - // The base64 encoding should be https://datatracker.ietf.org/doc/html/rfc4648#section-4, - // not base64url https://datatracker.ietf.org/doc/html/rfc4648#section-5. See data url - // spec https://tools.ietf.org/html/rfc2397#section-2. - const base64SourceMap = Buffer.from(sourceMap).toString('base64'); - return `${code}\n\n//# sourceMappingURL=data:application/json;base64,${base64SourceMap}`; -} - module.exports = { stripTypeScriptModuleTypes, stripTypeScriptTypes,