public static RazorParserFeatureFlags Create(RazorLanguageVersion version, string fileKind)
        {
            if (fileKind == null)
            {
                throw new ArgumentNullException(nameof(fileKind));
            }

            var allowMinimizedBooleanTagHelperAttributes = false;
            var allowHtmlCommentsInTagHelpers            = false;
            var allowComponentFileKind             = false;
            var allowRazorInAllCodeBlocks          = false;
            var allowUsingVariableDeclarations     = false;
            var allowConditionalDataDashAttributes = false;
            var allowCSharpInMarkupAttributeArea   = true;
            var allowNullableForgivenessOperator   = false;

            if (version.CompareTo(RazorLanguageVersion.Version_2_1) >= 0)
            {
                // Added in 2.1
                allowMinimizedBooleanTagHelperAttributes = true;
                allowHtmlCommentsInTagHelpers            = true;
            }

            if (version.CompareTo(RazorLanguageVersion.Version_3_0) >= 0)
            {
                // Added in 3.0
                allowComponentFileKind           = true;
                allowRazorInAllCodeBlocks        = true;
                allowUsingVariableDeclarations   = true;
                allowNullableForgivenessOperator = true;
            }

            if (FileKinds.IsComponent(fileKind))
            {
                allowConditionalDataDashAttributes = true;
                allowCSharpInMarkupAttributeArea   = false;
            }

            if (version.CompareTo(RazorLanguageVersion.Experimental) >= 0)
            {
                allowConditionalDataDashAttributes = true;
            }

            return(new DefaultRazorParserFeatureFlags(
                       allowMinimizedBooleanTagHelperAttributes,
                       allowHtmlCommentsInTagHelpers,
                       allowComponentFileKind,
                       allowRazorInAllCodeBlocks,
                       allowUsingVariableDeclarations,
                       allowConditionalDataDashAttributes,
                       allowCSharpInMarkupAttributeArea,
                       allowNullableForgivenessOperator));
        }
Beispiel #2
0
        private static void AddComponentFeatures(RazorProjectEngineBuilder builder, RazorLanguageVersion razorLanguageVersion)
        {
            // Project Engine Features
            builder.Features.Add(new ComponentImportProjectFeature());

            // Directives (conditional on file kind)
            ComponentCodeDirective.Register(builder);
            ComponentInjectDirective.Register(builder);
            ComponentLayoutDirective.Register(builder);
            ComponentPageDirective.Register(builder);



            if (razorLanguageVersion.CompareTo(RazorLanguageVersion.Version_6_0) >= 0)
            {
                ComponentConstrainedTypeParamDirective.Register(builder);
            }
            else
            {
                ComponentTypeParamDirective.Register(builder);
            }

            if (razorLanguageVersion.CompareTo(RazorLanguageVersion.Version_5_0) >= 0)
            {
                ComponentPreserveWhitespaceDirective.Register(builder);
            }

            // Document Classifier
            builder.Features.Add(new ComponentDocumentClassifierPass());

            // Directive Classifier
            builder.Features.Add(new ComponentWhitespacePass());

            // Optimization
            builder.Features.Add(new ComponentComplexAttributeContentPass());
            builder.Features.Add(new ComponentLoweringPass());
            builder.Features.Add(new ComponentScriptTagPass());
            builder.Features.Add(new ComponentEventHandlerLoweringPass());
            builder.Features.Add(new ComponentKeyLoweringPass());
            builder.Features.Add(new ComponentReferenceCaptureLoweringPass());
            builder.Features.Add(new ComponentSplatLoweringPass());
            builder.Features.Add(new ComponentBindLoweringPass());
            builder.Features.Add(new ComponentCssScopePass());
            builder.Features.Add(new ComponentTemplateDiagnosticPass());
            builder.Features.Add(new ComponentGenericTypePass());
            builder.Features.Add(new ComponentChildContentDiagnosticPass());
            builder.Features.Add(new ComponentMarkupDiagnosticPass());
            builder.Features.Add(new ComponentMarkupBlockPass());
            builder.Features.Add(new ComponentMarkupEncodingPass());
        }