| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Sorry, something went wrong.
|
Playing with this a bit, I wonder if we actually just want searchNestedScriptBlocks to be true? $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.
|
Rob Holt (@rjmholt) If this is guaranteed that Find will always return function body even if the body itself contains other script blocks then searchNestedScriptBlocks: $true looks OK and I can change my commit. |
Sorry, something went wrong.
$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.
|
A good way to ensure that guarantee though would be to add a regression test |
Sorry, something went wrong.
|
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: // functionInfo.ScriptBlock.Attributes may throw if it cannot resolve an attribute type but I could not trigger this behavior by simply providing an unknown attribute. I will dig into that a little bit deeper tho. |
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
PR Summary
Fixes #966.
Method UseShouldProcessCorrectly.TryGetShouldProcessValueFromAst is trying to obtain function body AST using Find with ScriptBlockAst filter. Unfortunately FunctionInfo exposes only FunctionDefinitionAst so the Find method fails.
This PR improves this behavior by checking existence of FunctionDefinitionAst first and using old code as a fallback mechanism.
PR Checklist