diff --git a/internal/printer/printer.go b/internal/printer/printer.go index 4f9c719793..00a9dfecba 100644 --- a/internal/printer/printer.go +++ b/internal/printer/printer.go @@ -5467,7 +5467,15 @@ func (p *Printer) emitSourceMapsBeforeNode(node *ast.Node) *sourceMapState { if !ast.IsNotEmittedStatement(node) && emitFlags&EFNoLeadingSourceMap == 0 && !ast.PositionIsSynthesized(loc.Pos()) { - p.emitSourcePos(p.sourceMapSource, scanner.SkipTrivia(p.currentSourceFile.Text(), loc.Pos())) // !!! support SourceMapRange from Strada? + // Check if the source map range is from the same file as the current file being emitted. + // For cross-file scenarios (e.g., type predicates referencing identifiers from other files), + // we should skip source map emission to avoid slice bounds violations. + nodeSourceFile := ast.GetSourceFileOfNode(node) + if p.currentSourceFile != nil && nodeSourceFile != nil && nodeSourceFile != p.currentSourceFile { + // Skip source map emission for cross-file references + } else { + p.emitSourcePos(p.sourceMapSource, scanner.SkipTrivia(p.currentSourceFile.Text(), loc.Pos())) // !!! support SourceMapRange from Strada? + } } if emitFlags&EFNoNestedSourceMaps != 0 { diff --git a/testdata/tests/cases/compiler/typePredicateDeclarationMap.ts b/testdata/tests/cases/compiler/typePredicateDeclarationMap.ts new file mode 100644 index 0000000000..d49c2ef49c --- /dev/null +++ b/testdata/tests/cases/compiler/typePredicateDeclarationMap.ts @@ -0,0 +1,13 @@ +// @declaration: true +// @declarationMap: true + +// @filename: predicateExport.ts +export function createPredicate() { + return (_item: unknown): _item is boolean => { + return true; + }; +} + +// @filename: predicateImport.ts +import { createPredicate } from './predicateExport'; +export const predicate = createPredicate(); \ No newline at end of file