@@ -18,16 +18,6 @@ const {
1818 globalThis : { WebAssembly } ,
1919} = primordials ;
2020
21- /** @type {import('internal/util/types') } */
22- let _TYPES = null ;
23- /**
24- * Lazily loads and returns the internal/util/types module.
25- */
26- function lazyTypes ( ) {
27- if ( _TYPES !== null ) { return _TYPES ; }
28- return _TYPES = require ( 'internal/util/types' ) ;
29- }
30-
3121const {
3222 compileFunctionForCJSLoader,
3323} = internalBinding ( 'contextify' ) ;
@@ -37,7 +27,9 @@ const assert = require('internal/assert');
3727const { readFileSync } = require ( 'fs' ) ;
3828const { dirname, extname, isAbsolute } = require ( 'path' ) ;
3929const {
30+ assertBufferSource,
4031 loadBuiltinModule,
32+ stringify,
4133 stripTypeScriptTypes,
4234 stripBOM,
4335 urlToFilename,
@@ -57,7 +49,6 @@ let debug = require('internal/util/debuglog').debuglog('esm', (fn) => {
5749const { emitExperimentalWarning, kEmptyObject, setOwnProperty, isWindows } = require ( 'internal/util' ) ;
5850const {
5951 ERR_UNKNOWN_BUILTIN_MODULE ,
60- ERR_INVALID_RETURN_PROPERTY_VALUE ,
6152} = require ( 'internal/errors' ) . codes ;
6253const { maybeCacheSourceMap } = require ( 'internal/source_map/source_map_cache' ) ;
6354const moduleWrap = internalBinding ( 'module_wrap' ) ;
@@ -107,44 +98,6 @@ function initCJSParseSync() {
10798const translators = new SafeMap ( ) ;
10899exports . translators = translators ;
109100
110- let DECODER = null ;
111- /**
112- * Asserts that the given body is a buffer source (either a string, array buffer, or typed array).
113- * Throws an error if the body is not a buffer source.
114- * @param {string | ArrayBufferView | ArrayBuffer } body - The body to check.
115- * @param {boolean } allowString - Whether or not to allow a string as a valid buffer source.
116- * @param {string } hookName - The name of the hook being called.
117- * @throws {ERR_INVALID_RETURN_PROPERTY_VALUE } If the body is not a buffer source.
118- */
119- function assertBufferSource ( body , allowString , hookName ) {
120- if ( allowString && typeof body === 'string' ) {
121- return ;
122- }
123- const { isArrayBufferView, isAnyArrayBuffer } = lazyTypes ( ) ;
124- if ( isArrayBufferView ( body ) || isAnyArrayBuffer ( body ) ) {
125- return ;
126- }
127- throw new ERR_INVALID_RETURN_PROPERTY_VALUE (
128- `${ allowString ? 'string, ' : '' } array buffer, or typed array` ,
129- hookName ,
130- 'source' ,
131- body ,
132- ) ;
133- }
134-
135- /**
136- * Converts a buffer or buffer-like object to a string.
137- * @param {string | ArrayBuffer | ArrayBufferView } body - The buffer or buffer-like object to convert to a string.
138- * @returns {string } The resulting string.
139- */
140- function stringify ( body ) {
141- if ( typeof body === 'string' ) { return body ; }
142- assertBufferSource ( body , false , 'load' ) ;
143- const { TextDecoder } = require ( 'internal/encoding' ) ;
144- DECODER = DECODER === null ? new TextDecoder ( ) : DECODER ;
145- return DECODER . decode ( body ) ;
146- }
147-
148101/**
149102 * Converts a URL to a file path if the URL protocol is 'file:'.
150103 * @param {string } url - The URL to convert.
0 commit comments