Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Typings of sourcesContent does not match implementation #234

Closed
AriPerkkio opened this issue Jan 10, 2023 · 0 comments · Fixed by #235
Closed

Typings of sourcesContent does not match implementation #234

AriPerkkio opened this issue Jan 10, 2023 · 0 comments · Fixed by #235

Comments

@AriPerkkio
Copy link
Contributor

AriPerkkio commented Jan 10, 2023

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:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant