@@ -1069,6 +1069,7 @@ export class ComponentDecoratorHandler implements
1069
1069
let templateContent : string ;
1070
1070
let sourceMapping : TemplateSourceMapping ;
1071
1071
let escapedString = false ;
1072
+ let sourceMapUrl : string | null ;
1072
1073
// We only support SourceMaps for inline templates that are simple string literals.
1073
1074
if ( ts . isStringLiteral ( template . expression ) ||
1074
1075
ts . isNoSubstitutionTemplateLiteral ( template . expression ) ) {
@@ -1082,6 +1083,7 @@ export class ComponentDecoratorHandler implements
1082
1083
type : 'direct' ,
1083
1084
node : template . expression ,
1084
1085
} ;
1086
+ sourceMapUrl = template . potentialSourceMapUrl ;
1085
1087
} else {
1086
1088
const resolvedTemplate = this . evaluator . evaluate ( template . expression ) ;
1087
1089
if ( typeof resolvedTemplate !== 'string' ) {
@@ -1098,10 +1100,15 @@ export class ComponentDecoratorHandler implements
1098
1100
componentClass : node ,
1099
1101
template : templateContent ,
1100
1102
} ;
1103
+
1104
+ // Indirect templates cannot be mapped to a particular byte range of any input file, since
1105
+ // they're computed by expressions that may span many files. Don't attempt to map them back
1106
+ // to a given file.
1107
+ sourceMapUrl = null ;
1101
1108
}
1102
1109
1103
1110
return {
1104
- ...this . _parseTemplate ( template , sourceStr , sourceParseRange , escapedString ) ,
1111
+ ...this . _parseTemplate ( template , sourceStr , sourceParseRange , escapedString , sourceMapUrl ) ,
1105
1112
content : templateContent ,
1106
1113
sourceMapping,
1107
1114
declaration : template ,
@@ -1116,7 +1123,8 @@ export class ComponentDecoratorHandler implements
1116
1123
return {
1117
1124
...this . _parseTemplate (
1118
1125
template , /* sourceStr */ templateContent , /* sourceParseRange */ null ,
1119
- /* escapedString */ false ) ,
1126
+ /* escapedString */ false ,
1127
+ /* sourceMapUrl */ template . potentialSourceMapUrl ) ,
1120
1128
content : templateContent ,
1121
1129
sourceMapping : {
1122
1130
type : 'external' ,
@@ -1134,11 +1142,11 @@ export class ComponentDecoratorHandler implements
1134
1142
1135
1143
private _parseTemplate (
1136
1144
template : TemplateDeclaration , sourceStr : string , sourceParseRange : LexerRange | null ,
1137
- escapedString : boolean ) : ParsedComponentTemplate {
1145
+ escapedString : boolean , sourceMapUrl : string | null ) : ParsedComponentTemplate {
1138
1146
// We always normalize line endings if the template has been escaped (i.e. is inline).
1139
1147
const i18nNormalizeLineEndingsInICUs = escapedString || this . i18nNormalizeLineEndingsInICUs ;
1140
1148
1141
- const parsedTemplate = parseTemplate ( sourceStr , template . sourceMapUrl , {
1149
+ const parsedTemplate = parseTemplate ( sourceStr , sourceMapUrl ?? '' , {
1142
1150
preserveWhitespaces : template . preserveWhitespaces ,
1143
1151
interpolationConfig : template . interpolationConfig ,
1144
1152
range : sourceParseRange ?? undefined ,
@@ -1163,7 +1171,7 @@ export class ComponentDecoratorHandler implements
1163
1171
// In order to guarantee the correctness of diagnostics, templates are parsed a second time
1164
1172
// with the above options set to preserve source mappings.
1165
1173
1166
- const { nodes : diagNodes } = parseTemplate ( sourceStr , template . sourceMapUrl , {
1174
+ const { nodes : diagNodes } = parseTemplate ( sourceStr , sourceMapUrl ?? '' , {
1167
1175
preserveWhitespaces : true ,
1168
1176
preserveLineEndings : true ,
1169
1177
interpolationConfig : template . interpolationConfig ,
@@ -1178,7 +1186,7 @@ export class ComponentDecoratorHandler implements
1178
1186
return {
1179
1187
...parsedTemplate ,
1180
1188
diagNodes,
1181
- file : new ParseSourceFile ( sourceStr , template . resolvedTemplateUrl ) ,
1189
+ file : new ParseSourceFile ( sourceStr , sourceMapUrl ?? '' ) ,
1182
1190
} ;
1183
1191
}
1184
1192
@@ -1223,7 +1231,7 @@ export class ComponentDecoratorHandler implements
1223
1231
templateUrl,
1224
1232
templateUrlExpression : templateUrlExpr ,
1225
1233
resolvedTemplateUrl : resourceUrl ,
1226
- sourceMapUrl : sourceMapUrl ( resourceUrl ) ,
1234
+ potentialSourceMapUrl : sourceMapUrl ( resourceUrl ) ,
1227
1235
} ;
1228
1236
} catch ( e ) {
1229
1237
throw this . makeResourceNotFoundError (
@@ -1237,7 +1245,7 @@ export class ComponentDecoratorHandler implements
1237
1245
expression : component . get ( 'template' ) ! ,
1238
1246
templateUrl : containingFile ,
1239
1247
resolvedTemplateUrl : containingFile ,
1240
- sourceMapUrl : containingFile ,
1248
+ potentialSourceMapUrl : containingFile ,
1241
1249
} ;
1242
1250
} else {
1243
1251
throw new FatalDiagnosticError (
@@ -1398,7 +1406,7 @@ interface CommonTemplateDeclaration {
1398
1406
interpolationConfig : InterpolationConfig ;
1399
1407
templateUrl : string ;
1400
1408
resolvedTemplateUrl : string ;
1401
- sourceMapUrl : string ;
1409
+ potentialSourceMapUrl : string ;
1402
1410
}
1403
1411
1404
1412
/**
0 commit comments