66 * found in the LICENSE file at https://angular.io/license
77 */
88import { BoundTarget , ChangeDetectionStrategy , compileComponentFromMetadata , ConstantPool , DeclarationListEmitMode , DEFAULT_INTERPOLATION_CONFIG , ForwardRefHandling , InterpolationConfig , makeBindingParser , outputAst as o , parseTemplate , R3ComponentMetadata , R3DeclareComponentMetadata , R3DeclareDirectiveDependencyMetadata , R3DeclarePipeDependencyMetadata , R3DeferBlockMetadata , R3DirectiveDependencyMetadata , R3PartialDeclaration , R3TargetBinder , R3TemplateDependencyKind , R3TemplateDependencyMetadata , SelectorMatcher , TmplAstDeferredBlock , TmplAstDeferredBlockTriggers , TmplAstDeferredTrigger , TmplAstElement , ViewEncapsulation } from '@angular/compiler' ;
9+ import semver from 'semver' ;
910
1011import { AbsoluteFsPath } from '../../../../src/ngtsc/file_system' ;
1112import { Range } from '../../ast/ast_host' ;
@@ -15,7 +16,7 @@ import {GetSourceFileFn} from '../get_source_file';
1516
1617import { toR3DirectiveMeta } from './partial_directive_linker_1' ;
1718import { LinkedDefinition , PartialLinker } from './partial_linker' ;
18- import { extractForwardRef } from './util' ;
19+ import { extractForwardRef , PLACEHOLDER_VERSION } from './util' ;
1920
2021function makeDirectiveMetadata < TExpression > (
2122 directiveExpr : AstObject < R3DeclareDirectiveDependencyMetadata , TExpression > ,
@@ -49,22 +50,27 @@ export class PartialComponentLinkerVersion1<TStatement, TExpression> implements
4950 private code : string ) { }
5051
5152 linkPartialDeclaration (
52- constantPool : ConstantPool ,
53- metaObj : AstObject < R3PartialDeclaration , TExpression > ) : LinkedDefinition {
54- const meta = this . toR3ComponentMeta ( metaObj ) ;
53+ constantPool : ConstantPool , metaObj : AstObject < R3PartialDeclaration , TExpression > ,
54+ version : string ) : LinkedDefinition {
55+ const meta = this . toR3ComponentMeta ( metaObj , version ) ;
5556 return compileComponentFromMetadata ( meta , constantPool , makeBindingParser ( ) ) ;
5657 }
5758
5859 /**
5960 * This function derives the `R3ComponentMetadata` from the provided AST object.
6061 */
61- private toR3ComponentMeta ( metaObj : AstObject < R3DeclareComponentMetadata , TExpression > ) :
62- R3ComponentMetadata < R3TemplateDependencyMetadata > {
62+ private toR3ComponentMeta (
63+ metaObj : AstObject < R3DeclareComponentMetadata , TExpression > ,
64+ version : string ) : R3ComponentMetadata < R3TemplateDependencyMetadata > {
6365 const interpolation = parseInterpolationConfig ( metaObj ) ;
6466 const templateSource = metaObj . getValue ( 'template' ) ;
6567 const isInline = metaObj . has ( 'isInline' ) ? metaObj . getBoolean ( 'isInline' ) : false ;
6668 const templateInfo = this . getTemplateInfo ( templateSource , isInline ) ;
6769
70+ // Enable the new block syntax if compiled with v17 and
71+ // above, or when using the local placeholder version.
72+ const supportsBlockSyntax = semver . major ( version ) >= 17 || version === PLACEHOLDER_VERSION ;
73+
6874 const template = parseTemplate ( templateInfo . code , templateInfo . sourceUrl , {
6975 escapedString : templateInfo . isEscaped ,
7076 interpolationConfig : interpolation ,
@@ -74,6 +80,12 @@ export class PartialComponentLinkerVersion1<TStatement, TExpression> implements
7480 metaObj . has ( 'preserveWhitespaces' ) ? metaObj . getBoolean ( 'preserveWhitespaces' ) : false ,
7581 // We normalize line endings if the template is was inline.
7682 i18nNormalizeLineEndingsInICUs : isInline ,
83+
84+ // TODO(crisbeto): hardcode the supported blocks for now. Before the final release
85+ // `enabledBlockTypes` will be replaced with a boolean, at which point `supportsBlockSyntax`
86+ // can be passed in directly here.
87+ enabledBlockTypes : supportsBlockSyntax ? new Set ( [ 'if' , 'switch' , 'for' , 'defer' ] ) :
88+ undefined ,
7789 } ) ;
7890 if ( template . errors !== null ) {
7991 const errors = template . errors . map ( err => err . toString ( ) ) . join ( '\n' ) ;
0 commit comments