Skip to content
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

Empty moustache gives incomprehensible error #161

Open
cshaa opened this issue Jan 23, 2025 · 2 comments
Open

Empty moustache gives incomprehensible error #161

cshaa opened this issue Jan 23, 2025 · 2 comments

Comments

@cshaa
Copy link

cshaa commented Jan 23, 2025

Package version

6.2.1

Describe the bug

  1. Create a simple project as per the docs
  2. Into the Edge file, add double curly braces that either contain nothing, or only contain a comment:
Hello {{ /* world */ }}
Hello {{ }}
  1. Run the project, and see an nondescriptive and hard to understand error:
node_modules/.pnpm/[email protected]/node_modules/edge-parser/build/index.js:419
  const Expression = expressions_exports[astExpression.type];
                                                       ^

TypeError: Cannot read properties of undefined (reading 'type')
    at transformAst (node_modules/.pnpm/[email protected]/node_modules/edge-parser/build/index.js:419:56)
    at #processMustache (node_modules/.pnpm/[email protected]/node_modules/edge-parser/build/index.js:545:18)
    at Parser.processToken (node_modules/.pnpm/[email protected]/node_modules/edge-parser/build/index.js:592:30)
    at node_modules/.pnpm/[email protected]/node_modules/edge.js/build/index.js:1349:48
    at Array.forEach (<anonymous>)
    at Compiler.compile (node_modules/.pnpm/[email protected]/node_modules/edge.js/build/index.js:1349:22)
    at Template.render (node_modules/.pnpm/[email protected]/node_modules/edge.js/build/chunk-DA7IVQFT.js:578:43)
    at _EdgeRenderer.render (node_modules/.pnpm/[email protected]/node_modules/edge.js/build/index.js:1573:92)
    at _Edge.render (node_modules/.pnpm/[email protected]/node_modules/edge.js/build/index.js:1897:34)
    at Server.<anonymous> (index.js:9:27)

Node.js v23.6.0

I've spent quite some time looking for the type property in our codebase, until I've realized it's in your codebase.

Throwing a more user-friendly error is advisable.

Reproduction repo

https://github.com/cshaa/edge-bug-empty-moustache

@cshaa
Copy link
Author

cshaa commented Jan 23, 2025

The problem is on this line:

// edge-parser/src/parser/transform_ast.ts

/**
 * Transform acorn AST to Edge AST. This must always be performed before
 * writing it to the compiled template buffer.
 */
export function transformAst(astExpression: any, filename: string, parser: Parser): any {
  const Expression = Expressions[astExpression.type as keyof typeof Expressions]
  if (Expression) {
    return Expression.toStatement(astExpression, filename, parser)
  }

@thetutlage
Copy link
Member

I think we can fix this. Feel free to open a PR in the parser codebase for the same 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants