Skip to content

Commit

Permalink
Merge pull request #51 from Rich-Harris/gh-26
Browse files Browse the repository at this point in the history
ignore missing sourcemap segments
  • Loading branch information
Rich-Harris authored Aug 28, 2023
2 parents a0ecd0a + fc2ecae commit 09d697c
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/create-module-declaration.js
Original file line number Diff line number Diff line change
Expand Up @@ -279,12 +279,13 @@ export function create_module_declaration(id, entry, created, resolve) {
if (identifier && name) {
const pos = identifier.getStart(module.ast);
const loc = module.locator(pos);

if (loc) {
if (module.source) {
// the sourcemaps generated by TypeScript are very inaccurate, borderline useless.
// we need to fix them up here. TODO is it only inaccurate in the JSDoc case?
const segments = module.source.mappings?.[loc.line - 1];
// the sourcemaps generated by TypeScript are very inaccurate, borderline useless.
// we need to fix them up here. TODO is it only inaccurate in the JSDoc case?
const segments = module.source?.mappings?.[loc.line - 1];

if (module.source && segments) {
// find the segments immediately before and after the generated column
const index = segments.findIndex((segment) => segment[0] >= loc.column);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export const object = {
answer: 42
};

export function hello() {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
declare module 'ignores-missing-sourcemap-segments' {
export function hello(): void;
export namespace object {
const answer: number;
}
}

//# sourceMappingURL=index.d.ts.map
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"version": 3,
"file": "index.d.ts",
"names": [
"hello",
"object"
],
"sources": [
"../input/index.js",
"../input/index.d.ts"
],
"sourcesContent": [
null,
null
],
"mappings": ";iBAIgBA,KAAKA;kBCHJC,MAAMA"
}

0 comments on commit 09d697c

Please sign in to comment.