Skip to content

Commit e9d69ef

Browse files
committed
fix: preserve loc for comment nodes
closes #168
1 parent 28d8e65 commit e9d69ef

File tree

3 files changed

+7
-5
lines changed

3 files changed

+7
-5
lines changed

src/debug.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
import { Buffer } from 'node:buffer'
55

6-
export function printCodeWithSourceMap(code: string, result: any) {
6+
export function printCodeWithSourceMap(code: string, result: any): void {
77
const codeWithMap = `\n\n${
88
result.code
99
}\n//# sourceMappingURL=data:application/json;base64,${Buffer.from(

src/fake-js.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -364,8 +364,11 @@ export function createFakeJsPlugin({
364364
const declarationId = declarationIdNode.value
365365
const declaration = getDeclaration(declarationId)
366366

367-
walkAST(declaration.decl, {
367+
walkAST<t.Node | t.Comment>(declaration.decl, {
368368
enter(node) {
369+
if (node.type === 'CommentBlock') {
370+
return
371+
}
369372
delete node.loc
370373
},
371374
})
@@ -435,7 +438,6 @@ export function createFakeJsPlugin({
435438
}
436439

437440
const result = generate(file, {
438-
comments: true,
439441
sourceMaps: sourcemap,
440442
sourceFileName: chunk.fileName,
441443
})

tests/__snapshots__/tsc.test.ts.snap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -364,8 +364,8 @@ declare function fn(): number;
364364
*/
365365
interface Options {
366366
/**
367-
* interface member
368-
*/
367+
* interface member
368+
*/
369369
foo: string;
370370
}
371371
/**

0 commit comments

Comments
 (0)