GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||
GeezerVison is showing github.com — Alternative way of obtaining function AST. by hubuk · Pull Request #1659 · PowerShell/PSScriptAnalyzer Conversation
|
|
Playing with this a bit, I wonder if we actually just want $ast = { function Test { "Hello" } }.Ast.EndBlock.Statements[0] # No output, because $ast.Body is a nested scriptblock $ast.Find({ $args[0] -is [System.Management.Automation.Language.ScriptBlockAst] }, $false) # Finds the body $ast.Find({ $args[0] -is [System.Management.Automation.Language.ScriptBlockAst] }, $true) |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Rob Holt (@rjmholt) If this is guaranteed that |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
$ast = { function Test { { "decoy" }; "Hello" } }.Ast.EndBlock.Statements[0] # Gets the body rather than the decoy scriptblock $ast.Find({ $args[0] -is [System.Management.Automation.Language.ScriptBlockAst] }, $true) Looks like the answer is yes 🙂. The AST visitor visits the parents before the children, so the body is the first thing it sees. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
A good way to ensure that guarantee though would be to add a regression test |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Rob Holt (@rjmholt) Regression test may be hard to implement as the changed code is executed only when there is an exception thrown due to problem described here: #966 (comment) The comment in code mentions: I will dig into that a little bit deeper tho. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
I updated the changes. Unfortunately was unable to provide test for this :( |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
Exception occurred while constructing custom validator attribute.
There was an error while loading. Please reload this page.