GeezerVison is showing github.com — module: do not attempt to strip type when there's no source · nodejs/node@100225f
File tree
Expand file treeCollapse file tree
Open diff view settings
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: lib/internal/modules/esm/get_format.js +6-2Lines changed: 6 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -160,8 +160,12 @@ function getFileProtocolModuleFormat(url, context = { __proto__: null }, ignoreE |
160 | 160 | default: { // The user did not pass `--experimental-default-type`. |
161 | 161 | // `source` is undefined when this is called from `defaultResolve`; |
162 | 162 | // but this gets called again from `defaultLoad`/`defaultLoadSync`. |
163 | | - const { tsParse } = require('internal/modules/helpers'); |
164 | | - const parsedSource = tsParse(source); |
| 163 | + let parsedSource; |
| 164 | + if (source) { |
| 165 | + // We do the type stripping only if `source` is not falsy. |
| 166 | + const { tsParse } = require('internal/modules/helpers'); |
| 167 | + parsedSource = tsParse(source); |
| 168 | + } |
165 | 169 | const detectedFormat = detectModuleFormat(parsedSource, url); |
166 | 170 | // When source is undefined, default to module-typescript. |
167 | 171 | const format = detectedFormat ? `${detectedFormat}-typescript` : 'module-typescript'; |
|
Collapse file
Copy file name to clipboardExpand all lines: lib/internal/modules/helpers.js +1-2Lines changed: 1 addition & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -331,8 +331,7 @@ function loadTypeScriptParser(parser) { |
331 | 331 | * @returns {string} JavaScript code. |
332 | 332 | */ |
333 | 333 | function tsParse(source) { |
334 | | - // TODO(@marco-ippolito) Checking empty string or non string input should be handled in Amaro. |
335 | | - if (!source || typeof source !== 'string') { return ''; } |
| 334 | + assert(typeof source === 'string'); |
336 | 335 | const parse = loadTypeScriptParser(); |
337 | 336 | const { code } = parse(source); |
338 | 337 | return code; |
|