@@ -27,18 +27,19 @@ These features are documented in [about_Requires](https://docs.microsoft.com/en-
2727
2828Currently however, this is untrue, as ` #requires `
2929statements are allowed by the parser/tokenizer anywhere in
30- a script and then effectively hoisted to the top of that
31- script, no matter where they are placed.
30+ a script and then effectively hoisted to the top of that
31+ script to be checked before any part of the script is
32+ executed, no matter where they are placed.
3233
3334This RFC proposes the following changes:
3435
3536* Only allow ` #requires ` at the top level of a script,
3637 before any lines that are not comments (i.e. with the
3738 intention that a hashbang can still work, just before
38- any executable PowerShell code). Placing ` #requires `
39- anywhere will cause a parse-time error. This would be
40- a ** breaking change** , albeit one that the documentation
41- already claims to be in force.
39+ any executable PowerShell code). Placing ` #requires ` anywhere
40+ after will cause a parse-time error. This would be a ** breaking
41+ change** , albeit one that the documentation already claims to be
42+ in force.
4243* Using ` #requires ` in the interactive console will cause
4344 a parse-time error. This could be a ** minor breaking
4445 change** , since currently PowerShell throws a [ pipeline
@@ -88,7 +89,12 @@ This RFC proposes the following changes:
88891 . ` #requires ` statements must appear in scripts
8990 above all executable PowerShell. Any ` #requires `
9091 statement placed after any PowerShell code causes
91- an unrecoverable parse-time error.
92+ an unrecoverable parse-time error. This new restriction
93+ should not affect the usage of other comment-embedded
94+ directives or pragmas, such as ` #sig ` , linter directives or
95+ inline editor configurations. Specifically, the new ` #requires `
96+ placement restriction must not interfere with Unix-style
97+ hashbangs (e.g. ` #!/usr/bin/pwsh ` ).
92982 . Any use of ` #requires ` in an interactive session causes
9399 a specific parse-time error to be thrown, informing the
94100 user that ` #requires ` may not be used in the interactive
@@ -138,4 +144,9 @@ PowerShell issue](https://github.com/PowerShell/PowerShell/issues/4549).
138144 * ` -Architecture ` , where a script must be run on a
139145 machine with a given processor architecture.
140146 * ` -Platform ` , rather than trying to use combining
141- logic with ` -OS ` .
147+ logic with ` -OS ` .
148+ * Another requires parameter, ` -PSEdition ` , also seems to have
149+ been added to the ` #requires ` functionality. However, it is
150+ currently [ undocumented] ( https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_requires?view=powershell-6 ) and
151+ there is an [ open issue for it] ( https://github.com/PowerShell/PowerShell/issues/5908 ) . It may
152+ be worth discussing in this RFC.
0 commit comments