@@ -59,6 +59,7 @@ public LoCInfo extract(TextualExtractor textualExtractor) {
59
59
60
60
Segment content = elt .getContent ();
61
61
String source = content .toString ();
62
+ boolean isTypeScript = isTypeScriptTag (elt );
62
63
63
64
/*
64
65
* Script blocks in XHTML files may wrap (parts of) their code inside CDATA sections.
@@ -81,7 +82,8 @@ public LoCInfo extract(TextualExtractor textualExtractor) {
81
82
textualExtractor ,
82
83
source ,
83
84
contentStart .getRow (),
84
- contentStart .getColumn ());
85
+ contentStart .getColumn (),
86
+ isTypeScript );
85
87
}
86
88
}
87
89
} else {
@@ -103,7 +105,8 @@ public LoCInfo extract(TextualExtractor textualExtractor) {
103
105
textualExtractor ,
104
106
source ,
105
107
valueStart .getRow (),
106
- valueStart .getColumn ());
108
+ valueStart .getColumn (),
109
+ false /* isTypeScript */ );
107
110
} else if (source .startsWith ("javascript:" )) {
108
111
source = source .substring (11 );
109
112
snippetLoC =
@@ -114,7 +117,8 @@ public LoCInfo extract(TextualExtractor textualExtractor) {
114
117
textualExtractor ,
115
118
source ,
116
119
valueStart .getRow (),
117
- valueStart .getColumn () + 11 );
120
+ valueStart .getColumn () + 11 ,
121
+ false /* isTypeScript */ );
118
122
}
119
123
}
120
124
}
@@ -143,11 +147,9 @@ public LoCInfo extract(TextualExtractor textualExtractor) {
143
147
*/
144
148
private SourceType getScriptSourceType (Element script ) {
145
149
String scriptType = getAttributeValueLC (script , "type" );
146
- String scriptLanguage = getAttributeValueLC (script , "language" );
150
+ String scriptLanguage = getScriptLanguage (script );
147
151
148
- if (scriptLanguage == null ) { // Vue templates use 'lang' instead of 'language'.
149
- scriptLanguage = getAttributeValueLC (script , "lang" );
150
- }
152
+ if (isTypeScriptTag (script )) return config .getSourceType ();
151
153
152
154
// if `type` and `language` are both either missing, contain the
153
155
// string "javascript", or if `type` is the string "text/jsx", this is a plain script
@@ -171,6 +173,23 @@ private SourceType getScriptSourceType(Element script) {
171
173
return null ;
172
174
}
173
175
176
+ private String getScriptLanguage (Element script ) {
177
+ String scriptLanguage = getAttributeValueLC (script , "language" );
178
+
179
+ if (scriptLanguage == null ) { // Vue templates use 'lang' instead of 'language'.
180
+ scriptLanguage = getAttributeValueLC (script , "lang" );
181
+ }
182
+ return scriptLanguage ;
183
+ }
184
+
185
+ private boolean isTypeScriptTag (Element script ) {
186
+ String language = getScriptLanguage (script );
187
+ if ("ts" .equals (language ) || "typescript" .equals (language )) return true ;
188
+ String type = getAttributeValueLC (script , "type" );
189
+ if (type != null && type .contains ("typescript" )) return true ;
190
+ return false ;
191
+ }
192
+
174
193
/**
175
194
* Get the value of attribute <code>attr</code> of element <code>elt</code> in lower case; if the
176
195
* attribute has no value, <code>null</code> is returned.
@@ -187,7 +206,10 @@ private LoCInfo extractSnippet(
187
206
TextualExtractor textualExtractor ,
188
207
String source ,
189
208
int line ,
190
- int column ) {
209
+ int column ,
210
+ boolean isTypeScript ) {
211
+ if (isTypeScript )
212
+ return null ; // not supported right now
191
213
TrapWriter trapwriter = textualExtractor .getTrapwriter ();
192
214
LocationManager locationManager = textualExtractor .getLocationManager ();
193
215
LocationManager scriptLocationManager =
0 commit comments