C: Skip unnecessary token_copy() in AST node constructors#1388
Draft
citizen428 wants to merge 2 commits intomarcoroth:mainfrom
Draft
C: Skip unnecessary token_copy() in AST node constructors#1388citizen428 wants to merge 2 commits intomarcoroth:mainfrom
token_copy() in AST node constructors#1388citizen428 wants to merge 2 commits intomarcoroth:mainfrom
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #1339
@marcoroth I followed the
node/borrowed_nodecode for this. But I'm not entirely sure if this is what you wanted because we only seem to useborrowed_nodeforHTMLConditionalElementNode(there are 2 occurrences ofborrowed_nodeand 50 ofnode).