Skip to content

Commit da3d1a3

Browse files
committed
JS: Recognize 'lang' attribute of script tags
1 parent e00a8f7 commit da3d1a3

File tree

4 files changed

+19
-1
lines changed

4 files changed

+19
-1
lines changed

javascript/extractor/src/com/semmle/js/extractor/HTMLExtractor.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
package com.semmle.js.extractor;
22

3+
import java.util.regex.Pattern;
4+
35
import com.semmle.js.extractor.ExtractorConfig.Platform;
46
import com.semmle.js.extractor.ExtractorConfig.SourceType;
57
import com.semmle.js.parser.ParseError;
68
import com.semmle.util.data.StringUtil;
79
import com.semmle.util.trap.TrapWriter;
810
import com.semmle.util.trap.TrapWriter.Label;
9-
import java.util.regex.Pattern;
11+
1012
import net.htmlparser.jericho.Attribute;
1113
import net.htmlparser.jericho.Attributes;
1214
import net.htmlparser.jericho.CharacterReference;
@@ -143,6 +145,10 @@ private SourceType getScriptSourceType(Element script) {
143145
String scriptType = getAttributeValueLC(script, "type");
144146
String scriptLanguage = getAttributeValueLC(script, "language");
145147

148+
if (scriptLanguage == null) { // Vue templates use 'lang' instead of 'language'.
149+
scriptLanguage = getAttributeValueLC(script, "lang");
150+
}
151+
146152
// if `type` and `language` are both either missing, contain the
147153
// string "javascript", or if `type` is the string "text/jsx", this is a plain script
148154
if ((scriptType == null || scriptType.contains("javascript") || "text/jsx".equals(scriptType))
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
classDeclaration
2+
exprType
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import javascript
2+
3+
query ClassDefinition classDeclaration() { any() }
4+
5+
query Type exprType(Expr e) { result = e.getType() }
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<script lang='ts'>
2+
export default class MyComponent {
3+
x!: number;
4+
}
5+
</script>

0 commit comments

Comments
 (0)