Skip to content

Commit

Permalink
Guard the 'clean' block behind an experimental feature
Browse files Browse the repository at this point in the history
  • Loading branch information
daxian-dbw committed Oct 11, 2021
1 parent 535584c commit 93305d4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
Expand Up @@ -23,6 +23,7 @@ public class ExperimentalFeature
internal const string EngineSource = "PSEngine";
internal const string PSNativeCommandArgumentPassingFeatureName = "PSNativeCommandArgumentPassing";
internal const string PSNativeCommandErrorActionPreferenceFeatureName = "PSNativeCommandErrorActionPreference";
internal const string PSCleanBlockFeatureName = "PSCleanBlock";

#endregion

Expand Down Expand Up @@ -126,6 +127,9 @@ static ExperimentalFeature()
new ExperimentalFeature(
name: PSNativeCommandErrorActionPreferenceFeatureName,
description: "Native commands with non-zero exit codes issue errors according to $ErrorActionPreference when $PSNativeCommandUseErrorActionPreference is $true"),
new ExperimentalFeature(
name: PSCleanBlockFeatureName,
description: "Add support of a 'Clean' block to functions and script cmdlets for easy resource cleanup"),
};

EngineExperimentalFeatures = new ReadOnlyCollection<ExperimentalFeature>(engineFeatures);
Expand Down
8 changes: 8 additions & 0 deletions src/System.Management.Automation/engine/parser/tokenizer.cs
Expand Up @@ -699,8 +699,16 @@ static Tokenizer()
Diagnostics.Assert(s_keywordText.Length == s_keywordTokenKind.Length, "Keyword table sizes must match");
Diagnostics.Assert(_operatorText.Length == s_operatorTokenKind.Length, "Operator table sizes must match");

bool isCleanBlockFeatureEnabled = ExperimentalFeature.IsEnabled(ExperimentalFeature.PSCleanBlockFeatureName);

for (int i = 0; i < s_keywordText.Length; ++i)
{
if (!isCleanBlockFeatureEnabled && s_keywordText[i] == "clean")
{
// Skip adding the 'clean' keyword when the feature is disabled.
continue;
}

s_keywordTable.Add(s_keywordText[i], s_keywordTokenKind[i]);
}

Expand Down

0 comments on commit 93305d4

Please sign in to comment.