@@ -18,16 +18,6 @@ const {
18
18
globalThis : { WebAssembly } ,
19
19
} = primordials ;
20
20
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
-
31
21
const {
32
22
compileFunctionForCJSLoader,
33
23
} = internalBinding ( 'contextify' ) ;
@@ -37,7 +27,9 @@ const assert = require('internal/assert');
37
27
const { readFileSync } = require ( 'fs' ) ;
38
28
const { dirname, extname, isAbsolute } = require ( 'path' ) ;
39
29
const {
30
+ assertBufferSource,
40
31
loadBuiltinModule,
32
+ stringify,
41
33
stripTypeScriptTypes,
42
34
stripBOM,
43
35
urlToFilename,
@@ -57,7 +49,6 @@ let debug = require('internal/util/debuglog').debuglog('esm', (fn) => {
57
49
const { emitExperimentalWarning, kEmptyObject, setOwnProperty, isWindows } = require ( 'internal/util' ) ;
58
50
const {
59
51
ERR_UNKNOWN_BUILTIN_MODULE ,
60
- ERR_INVALID_RETURN_PROPERTY_VALUE ,
61
52
} = require ( 'internal/errors' ) . codes ;
62
53
const { maybeCacheSourceMap } = require ( 'internal/source_map/source_map_cache' ) ;
63
54
const moduleWrap = internalBinding ( 'module_wrap' ) ;
@@ -107,44 +98,6 @@ function initCJSParseSync() {
107
98
const translators = new SafeMap ( ) ;
108
99
exports . translators = translators ;
109
100
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
-
148
101
/**
149
102
* Converts a URL to a file path if the URL protocol is 'file:'.
150
103
* @param {string } url - The URL to convert.
0 commit comments