Skip to content

Commit 04b3562

Browse files
Fix based on comments
1 parent 96e5669 commit 04b3562

File tree

5 files changed

+197
-2
lines changed

5 files changed

+197
-2
lines changed

internal/transformers/declarations/transform.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -468,8 +468,12 @@ func (tx *DeclarationTransformer) visitDeclarationSubtree(input *ast.Node) *ast.
468468
case ast.KindTupleType:
469469
result = tx.Visitor().VisitEachChild(input)
470470
if result != nil {
471-
startLine, _ := scanner.GetLineAndCharacterOfPosition(tx.state.currentSourceFile, input.Loc.Pos())
472-
endLine, _ := scanner.GetLineAndCharacterOfPosition(tx.state.currentSourceFile, input.Loc.End())
471+
sourceFileForLocation := tx.state.currentSourceFile
472+
if nodeFile := ast.GetSourceFileOfNode(input); nodeFile != nil && nodeFile != sourceFileForLocation {
473+
sourceFileForLocation = nodeFile
474+
}
475+
startLine, _ := scanner.GetLineAndCharacterOfPosition(sourceFileForLocation, input.Loc.Pos())
476+
endLine, _ := scanner.GetLineAndCharacterOfPosition(sourceFileForLocation, input.Loc.End())
473477
if startLine == endLine {
474478
tx.EmitContext().AddEmitFlags(result, printer.EFSingleLine)
475479
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
//// [tests/cases/compiler/declarationEmitAugmentationUsesCorrectSourceFile.ts] ////
2+
3+
//// [index.d.ts]
4+
// A bunch of random text to move the positions forward
5+
// A bunch of random text to move the positions forward
6+
// A bunch of random text to move the positions forward
7+
// A bunch of random text to move the positions forward
8+
// A bunch of random text to move the positions forward
9+
// A bunch of random text to move the positions forward
10+
// A bunch of random text to move the positions forward
11+
// A bunch of random text to move the positions forward
12+
// A bunch of random text to move the positions forward
13+
14+
type ShouldJustBeAny = [any][0];
15+
16+
declare namespace knex {
17+
export { Knex };
18+
}
19+
20+
declare namespace Knex {
21+
interface Interface {
22+
method(): ShouldJustBeAny;
23+
}
24+
}
25+
26+
export = knex;
27+
28+
//// [index.ts]
29+
import "knex";
30+
declare module "knex" {
31+
namespace Knex {
32+
function newFunc(): Knex.Interface;
33+
}
34+
}
35+
36+
37+
38+
39+
//// [index.js]
40+
import "knex";
41+
42+
43+
//// [index.d.ts]
44+
import "knex";
45+
declare module "knex" {
46+
namespace Knex {
47+
function newFunc(): Knex.Interface;
48+
}
49+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
//// [tests/cases/compiler/declarationEmitAugmentationUsesCorrectSourceFile.ts] ////
2+
3+
=== node_modules/knex/index.d.ts ===
4+
// A bunch of random text to move the positions forward
5+
// A bunch of random text to move the positions forward
6+
// A bunch of random text to move the positions forward
7+
// A bunch of random text to move the positions forward
8+
// A bunch of random text to move the positions forward
9+
// A bunch of random text to move the positions forward
10+
// A bunch of random text to move the positions forward
11+
// A bunch of random text to move the positions forward
12+
// A bunch of random text to move the positions forward
13+
14+
type ShouldJustBeAny = [any][0];
15+
>ShouldJustBeAny : Symbol(ShouldJustBeAny, Decl(index.d.ts, 0, 0))
16+
17+
declare namespace knex {
18+
>knex : Symbol(knex, Decl(index.d.ts, 10, 32), Decl(index.ts, 0, 14))
19+
20+
export { Knex };
21+
>Knex : Symbol(Knex, Decl(index.d.ts, 13, 10))
22+
}
23+
24+
declare namespace Knex {
25+
>Knex : Symbol(Knex, Decl(index.d.ts, 14, 1), Decl(index.ts, 1, 23))
26+
27+
interface Interface {
28+
>Interface : Symbol(Interface, Decl(index.d.ts, 16, 24))
29+
30+
method(): ShouldJustBeAny;
31+
>method : Symbol(method, Decl(index.d.ts, 17, 23))
32+
>ShouldJustBeAny : Symbol(ShouldJustBeAny, Decl(index.d.ts, 0, 0))
33+
}
34+
}
35+
36+
export = knex;
37+
>knex : Symbol(knex, Decl(index.d.ts, 10, 32), Decl(index.ts, 0, 14))
38+
39+
=== index.ts ===
40+
import "knex";
41+
declare module "knex" {
42+
>"knex" : Symbol(knex, Decl(index.d.ts, 10, 32), Decl(index.ts, 0, 14))
43+
44+
namespace Knex {
45+
>Knex : Symbol(Knex, Decl(index.d.ts, 14, 1), Decl(index.ts, 1, 23))
46+
47+
function newFunc(): Knex.Interface;
48+
>newFunc : Symbol(newFunc, Decl(index.ts, 2, 18))
49+
>Knex : Symbol(Knex, Decl(index.d.ts, 14, 1), Decl(index.ts, 1, 23))
50+
>Interface : Symbol(Interface, Decl(index.d.ts, 16, 24))
51+
}
52+
}
53+
54+
55+
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
//// [tests/cases/compiler/declarationEmitAugmentationUsesCorrectSourceFile.ts] ////
2+
3+
=== node_modules/knex/index.d.ts ===
4+
// A bunch of random text to move the positions forward
5+
// A bunch of random text to move the positions forward
6+
// A bunch of random text to move the positions forward
7+
// A bunch of random text to move the positions forward
8+
// A bunch of random text to move the positions forward
9+
// A bunch of random text to move the positions forward
10+
// A bunch of random text to move the positions forward
11+
// A bunch of random text to move the positions forward
12+
// A bunch of random text to move the positions forward
13+
14+
type ShouldJustBeAny = [any][0];
15+
>ShouldJustBeAny : any
16+
17+
declare namespace knex {
18+
export { Knex };
19+
>Knex : any
20+
}
21+
22+
declare namespace Knex {
23+
interface Interface {
24+
method(): ShouldJustBeAny;
25+
>method : () => any
26+
}
27+
}
28+
29+
export = knex;
30+
>knex : typeof import("knex")
31+
32+
=== index.ts ===
33+
import "knex";
34+
declare module "knex" {
35+
>"knex" : typeof import("knex")
36+
37+
namespace Knex {
38+
>Knex : typeof Knex
39+
40+
function newFunc(): Knex.Interface;
41+
>newFunc : () => Interface
42+
>Knex : any
43+
}
44+
}
45+
46+
47+
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// @strict: true
2+
// @module: preserve
3+
// @declaration: true
4+
5+
// @filename: node_modules/knex/index.d.ts
6+
7+
// A bunch of random text to move the positions forward
8+
// A bunch of random text to move the positions forward
9+
// A bunch of random text to move the positions forward
10+
// A bunch of random text to move the positions forward
11+
// A bunch of random text to move the positions forward
12+
// A bunch of random text to move the positions forward
13+
// A bunch of random text to move the positions forward
14+
// A bunch of random text to move the positions forward
15+
// A bunch of random text to move the positions forward
16+
17+
type ShouldJustBeAny = [any][0];
18+
19+
declare namespace knex {
20+
export { Knex };
21+
}
22+
23+
declare namespace Knex {
24+
interface Interface {
25+
method(): ShouldJustBeAny;
26+
}
27+
}
28+
29+
export = knex;
30+
31+
// @filename: index.ts
32+
33+
import "knex";
34+
declare module "knex" {
35+
namespace Knex {
36+
function newFunc(): Knex.Interface;
37+
}
38+
}
39+
40+

0 commit comments

Comments
 (0)