-
Notifications
You must be signed in to change notification settings - Fork 26
fix: handle template imports without file extensions #977
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
The emitter incorrectly used filepath.Ext() to distinguish template
imports from native package imports. This caused imports without file
extensions to be silently skipped, resulting in:
panic: scriggo: internal error: none of the previous conditions
matched identifier <MacroName>
The correct check is node.Tree != nil, which indicates a template import
(parsed AST exists) vs node.Tree == nil for native package imports.
This matches the logic used in the type checker.
Changes:
- emitter_statements.go: Replace filepath.Ext check with node.Tree check
- fstest/files.go: Add FormatFiles type for testing extension-less imports
- multi_file_template_test.go: Add tests for extension-less macro/variable imports
gazerro
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for fixing this! I have a few comments below.
|
|
||
| // Tests for extension-less imports using FormatFiles (FormatFS interface) | ||
| "import with 'for' - macro without file extension": { | ||
| sources: fstest.FormatFiles{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not necessary to introduce fastest.FormatFiles, since files without an extension already default to the Text format. I'd recommend restoring internal/fstest/files.go to its previous state.
| expectedOut: "hello, world!", | ||
| }, | ||
|
|
||
| // Tests for extension-less imports using FormatFiles (FormatFS interface) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would remove this comment, as the test name already documents the behavior.
| pkg := node.Tree.Nodes[0].(*ast.Package) | ||
| funcs, vars, inits := em.emitPackage(pkg, false, node.Tree.Path) | ||
|
|
||
| // If importing specific identifiers with "for" clause, filter to only those. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the purpose of this change? It's not documented in the commit message, and the issue seems to be fixed even without it.
The emitter incorrectly used filepath.Ext() to distinguish template imports from native package imports. This caused imports without file extensions to be silently skipped, resulting in:
panic: scriggo: internal error: none of the previous conditions
matched identifier
The correct check is node.Tree != nil, which indicates a template import (parsed AST exists) vs node.Tree == nil for native package imports. This matches the logic used in the type checker.
Changes: