summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--changelogs/changelog_2_0_0.md1
-rw-r--r--compiler/jsgen.nim5
2 files changed, 6 insertions, 0 deletions
diff --git a/changelogs/changelog_2_0_0.md b/changelogs/changelog_2_0_0.md
index dcdaa797d..b15818ae6 100644
--- a/changelogs/changelog_2_0_0.md
+++ b/changelogs/changelog_2_0_0.md
@@ -473,6 +473,7 @@
 
 - When compiling for Release the flag `-fno-math-errno` is used for GCC.
 - Removed deprecated `LineTooLong` hint.
+- Line numbers and filenames of source files work correctly inside templates for JavaScript targets.
 
 
 ## Docgen
diff --git a/compiler/jsgen.nim b/compiler/jsgen.nim
index 45b0baec0..ecfc22108 100644
--- a/compiler/jsgen.nim
+++ b/compiler/jsgen.nim
@@ -110,6 +110,7 @@ type
     extraIndent: int
     up: PProc     # up the call chain; required for closure support
     declaredGlobals: IntSet
+    previousFileName: string  # For frameInfo inside templates.
 
 template config*(p: PProc): ConfigRef = p.module.config
 
@@ -803,6 +804,10 @@ proc genLineDir(p: PProc, n: PNode) =
     lineF(p, "$1", [lineDir(p.config, n.info, line)])
   if hasFrameInfo(p):
     lineF(p, "F.line = $1;$n", [rope(line)])
+    let currentFileName = toFilename(p.config, n.info)
+    if p.previousFileName != currentFileName:
+      lineF(p, "F.filename = $1;$n", [makeJSString(currentFileName)])
+      p.previousFileName = currentFileName
 
 proc genWhileStmt(p: PProc, n: PNode) =
   var cond: TCompRes