Typings of the sourcesContent is string[]:
|
sourcesContent: string[]; |
|
sourcesContent: string[]; |
The implementation may return { sourcesContent: [null] } when includeContent = false (default value) is used:
|
sourcesContent: options.includeContent ? [this.original] : [null], |
Minimal reproduction
import MagicString from "magic-string";
const s = new MagicString('Hello world');
const map = s.generateMap({});
const [firstSourcesContent] = map.sourcesContent;
console.log(firstSourcesContent.charAt(0));
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
// TypeError: Cannot read properties of null (reading 'charAt')
// at <anonymous> (/x/y/repro/index.ts:14:33)
// This should not raise tsc errors
map.sourcesContent[0] = null
// ^^^^^^^^^^^^^^^^^^
// Type 'null' is not assignable to type 'string'.ts(2322)
Based on the standard the implementation works correctly:
Proposed Format
[...]
6. "sourcesContent": [null, null],
[...]
Line 6: An optional list of source content, useful when the “source” can’t be hosted. The contents are listed in the same order as the sources in line 5. “null” may be used if some original sources should be retrieved by name.
Related downstream bug:
Typings of the
sourcesContentisstring[]:magic-string/index.d.ts
Line 38 in 69b13c7
magic-string/index.d.ts
Line 49 in 69b13c7
The implementation may return
{ sourcesContent: [null] }whenincludeContent = false(default value) is used:magic-string/src/MagicString.js
Line 168 in 69b13c7
Minimal reproduction
Based on the standard the implementation works correctly:
Related downstream bug: