@@ -18,9 +18,7 @@ const {
1818 ERR_UNSUPPORTED_NODE_MODULES_TYPE_STRIPPING ,
1919 ERR_UNSUPPORTED_TYPESCRIPT_SYNTAX ,
2020} = require ( 'internal/errors' ) . codes ;
21- const { getOptionValue } = require ( 'internal/options' ) ;
2221const assert = require ( 'internal/assert' ) ;
23- const { Buffer } = require ( 'buffer' ) ;
2422const {
2523 getCompileCacheEntry,
2624 saveCompileCacheEntry,
@@ -117,26 +115,18 @@ function stripTypeScriptTypes(code, options = kEmptyObject) {
117115}
118116
119117/**
120- * @typedef {'strip-only' | 'transform' } TypeScriptMode
121118 * @typedef {object } TypeScriptOptions
122- * @property {TypeScriptMode } mode Mode.
123- * @property {boolean } sourceMap Whether to generate source maps.
124119 * @property {string|undefined } filename Filename.
125120 */
126121
127122/**
128- * Processes TypeScript code by stripping types or transforming.
129- * Handles source maps if needed.
123+ * Processes TypeScript code by stripping types.
130124 * @param {string } code TypeScript code to process.
131125 * @param {TypeScriptOptions } options The configuration object.
132126 * @returns {string } The processed code.
133127 */
134128function processTypeScriptCode ( code , options ) {
135- const { code : transformedCode , map } = parseTypeScript ( code , options ) ;
136-
137- if ( map ) {
138- return addSourceMap ( transformedCode , map ) ;
139- }
129+ const { code : transformedCode } = parseTypeScript ( code , options ) ;
140130
141131 if ( options . filename ) {
142132 return `${ transformedCode } \n\n//# sourceURL=${ options . filename } ` ;
@@ -164,8 +154,6 @@ function stripTypeScriptModuleTypes(source, filename, sourceURL) {
164154 if ( isUnderNodeModules ( filename ) ) {
165155 throw new ERR_UNSUPPORTED_NODE_MODULES_TYPE_STRIPPING ( filename ) ;
166156 }
167- const sourceMap = getOptionValue ( '--enable-source-maps' ) ;
168-
169157 // Get a compile cache entry into the native compile cache store,
170158 // keyed by the filename. If the cache can already be loaded on disk,
171159 // cached.transpiled contains the cached string. Otherwise we should do
@@ -178,7 +166,6 @@ function stripTypeScriptModuleTypes(source, filename, sourceURL) {
178166
179167 const options = {
180168 mode : 'strip-only' ,
181- sourceMap,
182169 filename : sourceURL ?? filename ,
183170 } ;
184171
@@ -194,20 +181,6 @@ function stripTypeScriptModuleTypes(source, filename, sourceURL) {
194181 return transpiled ;
195182}
196183
197- /**
198- *
199- * @param {string } code The compiled code.
200- * @param {string } sourceMap The source map.
201- * @returns {string } The code with the source map attached.
202- */
203- function addSourceMap ( code , sourceMap ) {
204- // The base64 encoding should be https://datatracker.ietf.org/doc/html/rfc4648#section-4,
205- // not base64url https://datatracker.ietf.org/doc/html/rfc4648#section-5. See data url
206- // spec https://tools.ietf.org/html/rfc2397#section-2.
207- const base64SourceMap = Buffer . from ( sourceMap ) . toString ( 'base64' ) ;
208- return `${ code } \n\n//# sourceMappingURL=data:application/json;base64,${ base64SourceMap } ` ;
209- }
210-
211184module . exports = {
212185 stripTypeScriptModuleTypes,
213186 stripTypeScriptTypes,
0 commit comments