|
1 | 1 | package com.semmle.js.extractor;
|
2 | 2 |
|
| 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 | + |
3 | 11 | import com.semmle.js.extractor.ExtractorConfig.HTMLHandling;
|
4 | 12 | import com.semmle.js.extractor.ExtractorConfig.Platform;
|
5 | 13 | import com.semmle.js.extractor.ExtractorConfig.SourceType;
|
|
23 | 31 | import com.semmle.util.process.ArgsParser;
|
24 | 32 | import com.semmle.util.process.ArgsParser.FileMode;
|
25 | 33 | 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; |
33 | 34 |
|
34 | 35 | /** The main entry point of the JavaScript extractor. */
|
35 | 36 | public class Main {
|
@@ -134,7 +135,8 @@ public void run(String[] args) {
|
134 | 135 |
|
135 | 136 | TypeScriptParser tsParser = extractorState.getTypeScriptParser();
|
136 | 137 | tsParser.setTypescriptRam(extractorConfig.getTypeScriptRam());
|
137 |
| - if (containsTypeScriptFiles()) { |
| 138 | + boolean containsTypeScriptFiles = containsTypeScriptFiles(); |
| 139 | + if (containsTypeScriptFiles) { |
138 | 140 | tsParser.verifyInstallation(!ap.has(P_QUIET));
|
139 | 141 | }
|
140 | 142 | for (File projectFile : projectFiles) {
|
@@ -190,10 +192,29 @@ public void run(String[] args) {
|
190 | 192 |
|
191 | 193 | // Extract files that were not part of a project.
|
192 | 194 | for (File f : files) {
|
| 195 | + if (isFileDerivedFromTypeScriptFile(f)) |
| 196 | + continue; |
193 | 197 | ensureFileIsExtracted(f, ap);
|
194 | 198 | }
|
195 | 199 | }
|
196 | 200 |
|
| 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 | + |
197 | 218 | private void extractTypeTable(File fileHandle, TypeTable table) {
|
198 | 219 | TrapWriter trapWriter =
|
199 | 220 | extractorOutputConfig
|
|
0 commit comments