Skip to content

C: Skip unnecessary token_copy() in AST node constructors#1388

Draft
citizen428 wants to merge 2 commits intomarcoroth:mainfrom
citizen428:issue-1339
Draft

C: Skip unnecessary token_copy() in AST node constructors#1388
citizen428 wants to merge 2 commits intomarcoroth:mainfrom
citizen428:issue-1339

Conversation

@citizen428
Copy link
Contributor

Closes #1339

@marcoroth I followed the node/borrowed_node code for this. But I'm not entirely sure if this is what you wanted because we only seem to use borrowed_node for HTMLConditionalElementNode (there are 2 occurrences of borrowed_node and 50 of node).

marcoroth and others added 2 commits March 16, 2026 01:23
This pull request adds support for detecting ActionView `render` calls
in ERB templates and representing them as structured `ERBRenderNode`
nodes.

A new `render_nodes` parser option is available to enable this analysis
(defaults to `false`, since `render` may mean something different
outside of Rails).

When enabled, `ERBContentNodes` containing a render call are transformed
into `ERBRenderNodes` with extracted fields that mirror ActionView's
render keyword arguments.

For example, the following template:
```erb
<%= render partial: "card", locals: { title: @title, body: "Hello" } %>
```

Produces the following with `render_nodes: true`:
```js
@ DocumentNode (location: (1:0)-(1:71))
└── children: (1 item)
    └── @ ERBRenderNode (location: (1:0)-(1:71))
        ├── tag_opening: "<%=" (location: (1:0)-(1:3))
        ├── content: " render partial: "card", locals: { title: @title, body: "Hello" } " (location: (1:3)-(1:69))
        ├── tag_closing: "%>" (location: (1:69)-(1:71))
        ├── partial: "card" (location: (1:20)-(1:26))
        ├── template_path: ∅
        ├── layout: ∅
        ├── file: ∅
        ├── inline_template: ∅
        ├── body: ∅
        ├── plain: ∅
        ├── html: ∅
        ├── renderable: ∅
        ├── collection: ∅
        ├── object: ∅
        ├── as: ∅
        ├── spacer_template: ∅
        ├── formats: ∅
        ├── variants: ∅
        ├── handlers: ∅
        ├── content_type: ∅
        └── locals: (2 items)
            ├── @ RubyRenderLocalNode (location: (1:38)-(1:51))
            │   ├── name: "title" (location: (1:38)-(1:44))
            │   └── value: 
            │       └── @ RubyLiteralNode (location: (1:45)-(1:51))
            │           └── content: "@title"
            │           
            └── @ RubyRenderLocalNode (location: (1:53)-(1:66))
                ├── name: "body" (location: (1:53)-(1:58))
                └── value: 
                    └── @ RubyLiteralNode (location: (1:59)-(1:66))
                        └── content: "\"Hello\""
 ```               
       
Resolves marcoroth#1373

Enables marcoroth#160
Enables marcoroth#181
Enables marcoroth#182
Enables marcoroth#639
Enables marcoroth#654  
Enables marcoroth#1386
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

C: Skip unnecessary token_copy() in AST node constructors

2 participants