@@ -27,18 +27,19 @@ These features are documented in [about_Requires](https://docs.microsoft.com/en-
27
27
28
28
Currently however, this is untrue, as ` #requires `
29
29
statements 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.
32
33
33
34
This RFC proposes the following changes:
34
35
35
36
* Only allow ` #requires ` at the top level of a script,
36
37
before any lines that are not comments (i.e. with the
37
38
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.
42
43
* Using ` #requires ` in the interactive console will cause
43
44
a parse-time error. This could be a ** minor breaking
44
45
change** , since currently PowerShell throws a [ pipeline
@@ -88,7 +89,12 @@ This RFC proposes the following changes:
88
89
1 . ` #requires ` statements must appear in scripts
89
90
above all executable PowerShell. Any ` #requires `
90
91
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 ` ).
92
98
2 . Any use of ` #requires ` in an interactive session causes
93
99
a specific parse-time error to be thrown, informing the
94
100
user that ` #requires ` may not be used in the interactive
@@ -138,4 +144,9 @@ PowerShell issue](https://github.com/PowerShell/PowerShell/issues/4549).
138
144
* ` -Architecture ` , where a script must be run on a
139
145
machine with a given processor architecture.
140
146
* ` -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