Skip to content

Commit 54021a1

Browse files
committed
JS: Update old entry point and add a test
1 parent a78f1b8 commit 54021a1

File tree

5 files changed

+35
-8
lines changed

5 files changed

+35
-8
lines changed

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

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
package com.semmle.js.extractor;
22

3+
import java.io.File;
4+
import java.io.IOException;
5+
import java.util.ArrayList;
6+
import java.util.LinkedHashSet;
7+
import java.util.List;
8+
import java.util.Set;
9+
import java.util.regex.Pattern;
10+
311
import com.semmle.js.extractor.ExtractorConfig.HTMLHandling;
412
import com.semmle.js.extractor.ExtractorConfig.Platform;
513
import com.semmle.js.extractor.ExtractorConfig.SourceType;
@@ -23,13 +31,6 @@
2331
import com.semmle.util.process.ArgsParser;
2432
import com.semmle.util.process.ArgsParser.FileMode;
2533
import com.semmle.util.trap.TrapWriter;
26-
import java.io.File;
27-
import java.io.IOException;
28-
import java.util.ArrayList;
29-
import java.util.LinkedHashSet;
30-
import java.util.List;
31-
import java.util.Set;
32-
import java.util.regex.Pattern;
3334

3435
/** The main entry point of the JavaScript extractor. */
3536
public class Main {
@@ -134,7 +135,8 @@ public void run(String[] args) {
134135

135136
TypeScriptParser tsParser = extractorState.getTypeScriptParser();
136137
tsParser.setTypescriptRam(extractorConfig.getTypeScriptRam());
137-
if (containsTypeScriptFiles()) {
138+
boolean containsTypeScriptFiles = containsTypeScriptFiles();
139+
if (containsTypeScriptFiles) {
138140
tsParser.verifyInstallation(!ap.has(P_QUIET));
139141
}
140142
for (File projectFile : projectFiles) {
@@ -190,10 +192,29 @@ public void run(String[] args) {
190192

191193
// Extract files that were not part of a project.
192194
for (File f : files) {
195+
if (isFileDerivedFromTypeScriptFile(f))
196+
continue;
193197
ensureFileIsExtracted(f, ap);
194198
}
195199
}
196200

201+
/**
202+
* Returns true if the given path is likely the output of compiling a TypeScript file
203+
* which we have already extracted.
204+
*/
205+
private boolean isFileDerivedFromTypeScriptFile(File path) {
206+
String name = path.getName();
207+
if (!name.endsWith(".js"))
208+
return false;
209+
String stem = name.substring(0, name.length() - ".js".length());
210+
for (String ext : FileType.TYPESCRIPT.getExtensions()) {
211+
if (new File(path.getParent(), stem + ext).exists()) {
212+
return true;
213+
}
214+
}
215+
return false;
216+
}
217+
197218
private void extractTypeTable(File fileHandle, TypeTable table) {
198219
TrapWriter trapWriter =
199220
extractorOutputConfig
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export default 45;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export default 45 as number;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
| index.ts:0:0:0:0 | index.ts |
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import javascript
2+
3+
query File files() { any() }

0 commit comments

Comments
 (0)