Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions internal/transformers/declarations/transform.go
Original file line number Diff line number Diff line change
Expand Up @@ -468,8 +468,12 @@ func (tx *DeclarationTransformer) visitDeclarationSubtree(input *ast.Node) *ast.
case ast.KindTupleType:
result = tx.Visitor().VisitEachChild(input)
if result != nil {
startLine, _ := scanner.GetLineAndCharacterOfPosition(tx.state.currentSourceFile, input.Loc.Pos())
endLine, _ := scanner.GetLineAndCharacterOfPosition(tx.state.currentSourceFile, input.Loc.End())
sourceFileForLocation := tx.state.currentSourceFile
if nodeFile := ast.GetSourceFileOfNode(input); nodeFile != nil && nodeFile != sourceFileForLocation {
sourceFileForLocation = nodeFile
}
startLine, _ := scanner.GetLineAndCharacterOfPosition(sourceFileForLocation, input.Loc.Pos())
endLine, _ := scanner.GetLineAndCharacterOfPosition(sourceFileForLocation, input.Loc.End())
if startLine == endLine {
tx.EmitContext().AddEmitFlags(result, printer.EFSingleLine)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
//// [tests/cases/compiler/declarationEmitAugmentationUsesCorrectSourceFile.ts] ////

//// [index.d.ts]
// A bunch of random text to move the positions forward
// A bunch of random text to move the positions forward
// A bunch of random text to move the positions forward
// A bunch of random text to move the positions forward
// A bunch of random text to move the positions forward
// A bunch of random text to move the positions forward
// A bunch of random text to move the positions forward
// A bunch of random text to move the positions forward
// A bunch of random text to move the positions forward

type ShouldJustBeAny = [any][0];

declare namespace knex {
export { Knex };
}

declare namespace Knex {
interface Interface {
method(): ShouldJustBeAny;
}
}

export = knex;

//// [index.ts]
import "knex";
declare module "knex" {
namespace Knex {
function newFunc(): Knex.Interface;
}
}




//// [index.js]
import "knex";


//// [index.d.ts]
import "knex";
declare module "knex" {
namespace Knex {
function newFunc(): Knex.Interface;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
//// [tests/cases/compiler/declarationEmitAugmentationUsesCorrectSourceFile.ts] ////

=== node_modules/knex/index.d.ts ===
// A bunch of random text to move the positions forward
// A bunch of random text to move the positions forward
// A bunch of random text to move the positions forward
// A bunch of random text to move the positions forward
// A bunch of random text to move the positions forward
// A bunch of random text to move the positions forward
// A bunch of random text to move the positions forward
// A bunch of random text to move the positions forward
// A bunch of random text to move the positions forward

type ShouldJustBeAny = [any][0];
>ShouldJustBeAny : Symbol(ShouldJustBeAny, Decl(index.d.ts, 0, 0))

declare namespace knex {
>knex : Symbol(knex, Decl(index.d.ts, 10, 32), Decl(index.ts, 0, 14))

export { Knex };
>Knex : Symbol(Knex, Decl(index.d.ts, 13, 10))
}

declare namespace Knex {
>Knex : Symbol(Knex, Decl(index.d.ts, 14, 1), Decl(index.ts, 1, 23))

interface Interface {
>Interface : Symbol(Interface, Decl(index.d.ts, 16, 24))

method(): ShouldJustBeAny;
>method : Symbol(method, Decl(index.d.ts, 17, 23))
>ShouldJustBeAny : Symbol(ShouldJustBeAny, Decl(index.d.ts, 0, 0))
}
}

export = knex;
>knex : Symbol(knex, Decl(index.d.ts, 10, 32), Decl(index.ts, 0, 14))

=== index.ts ===
import "knex";
declare module "knex" {
>"knex" : Symbol(knex, Decl(index.d.ts, 10, 32), Decl(index.ts, 0, 14))

namespace Knex {
>Knex : Symbol(Knex, Decl(index.d.ts, 14, 1), Decl(index.ts, 1, 23))

function newFunc(): Knex.Interface;
>newFunc : Symbol(newFunc, Decl(index.ts, 2, 18))
>Knex : Symbol(Knex, Decl(index.d.ts, 14, 1), Decl(index.ts, 1, 23))
>Interface : Symbol(Interface, Decl(index.d.ts, 16, 24))
}
}



Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
//// [tests/cases/compiler/declarationEmitAugmentationUsesCorrectSourceFile.ts] ////

=== node_modules/knex/index.d.ts ===
// A bunch of random text to move the positions forward
// A bunch of random text to move the positions forward
// A bunch of random text to move the positions forward
// A bunch of random text to move the positions forward
// A bunch of random text to move the positions forward
// A bunch of random text to move the positions forward
// A bunch of random text to move the positions forward
// A bunch of random text to move the positions forward
// A bunch of random text to move the positions forward

type ShouldJustBeAny = [any][0];
>ShouldJustBeAny : any

declare namespace knex {
export { Knex };
>Knex : any
}

declare namespace Knex {
interface Interface {
method(): ShouldJustBeAny;
>method : () => any
}
}

export = knex;
>knex : typeof import("knex")

=== index.ts ===
import "knex";
declare module "knex" {
>"knex" : typeof import("knex")

namespace Knex {
>Knex : typeof Knex

function newFunc(): Knex.Interface;
>newFunc : () => Interface
>Knex : any
}
}



Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// @strict: true
// @module: preserve
// @declaration: true

// @filename: node_modules/knex/index.d.ts

// A bunch of random text to move the positions forward
// A bunch of random text to move the positions forward
// A bunch of random text to move the positions forward
// A bunch of random text to move the positions forward
// A bunch of random text to move the positions forward
// A bunch of random text to move the positions forward
// A bunch of random text to move the positions forward
// A bunch of random text to move the positions forward
// A bunch of random text to move the positions forward

type ShouldJustBeAny = [any][0];

declare namespace knex {
export { Knex };
}

declare namespace Knex {
interface Interface {
method(): ShouldJustBeAny;
}
}

export = knex;

// @filename: index.ts

import "knex";
declare module "knex" {
namespace Knex {
function newFunc(): Knex.Interface;
}
}