summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorJuan Carlos <juancarlospaco@gmail.com>2023-05-23 04:59:21 -0300
committerGitHub <noreply@github.com>2023-05-23 09:59:21 +0200
commitd372ad3ee6563cff2c086e774f1e00b091b79373 (patch)
treee094319d7f289ed0115d369f0927d0a086e32360
parent76a98fee650228306a6b1af72e64bb83a9473ef0 (diff)
downloadNim-d372ad3ee6563cff2c086e774f1e00b091b79373.tar.gz
Fix jsgen (#21880)
* .

* Fix jsgen FrameInfo

* Fix jsgen FrameInfo

* .

* Move to PProc
-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