@@ -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 } ` ;
@@ -163,8 +153,6 @@ function stripTypeScriptModuleTypes(source, filename) {
163153 if ( isUnderNodeModules ( filename ) ) {
164154 throw new ERR_UNSUPPORTED_NODE_MODULES_TYPE_STRIPPING ( filename ) ;
165155 }
166- const sourceMap = getOptionValue ( '--enable-source-maps' ) ;
167-
168156 // Get a compile cache entry into the native compile cache store,
169157 // keyed by the filename. If the cache can already be loaded on disk,
170158 // cached.transpiled contains the cached string. Otherwise we should do
@@ -177,7 +165,6 @@ function stripTypeScriptModuleTypes(source, filename) {
177165
178166 const options = {
179167 mode : 'strip-only' ,
180- sourceMap,
181168 filename,
182169 } ;
183170
@@ -193,20 +180,6 @@ function stripTypeScriptModuleTypes(source, filename) {
193180 return transpiled ;
194181}
195182
196- /**
197- *
198- * @param {string } code The compiled code.
199- * @param {string } sourceMap The source map.
200- * @returns {string } The code with the source map attached.
201- */
202- function addSourceMap ( code , sourceMap ) {
203- // The base64 encoding should be https://datatracker.ietf.org/doc/html/rfc4648#section-4,
204- // not base64url https://datatracker.ietf.org/doc/html/rfc4648#section-5. See data url
205- // spec https://tools.ietf.org/html/rfc2397#section-2.
206- const base64SourceMap = Buffer . from ( sourceMap ) . toString ( 'base64' ) ;
207- return `${ code } \n\n//# sourceMappingURL=data:application/json;base64,${ base64SourceMap } ` ;
208- }
209-
210183module . exports = {
211184 stripTypeScriptModuleTypes,
212185 stripTypeScriptTypes,
0 commit comments