mirror of
https://github.com/github/codeql.git
synced 2026-01-08 04:00:26 +01:00
basic support for .cjs files
This commit is contained in:
@@ -144,7 +144,7 @@ import com.semmle.util.trap.TrapWriter;
|
||||
*
|
||||
* <ul>
|
||||
* <li>All JavaScript files, that is, files with one of the extensions supported by {@link
|
||||
* FileType#JS} (currently ".js", ".jsx", ".mjs", ".es6", ".es").
|
||||
* FileType#JS} (currently ".js", ".jsx", ".mjs", ".cjs", ".es6", ".es").
|
||||
* <li>All HTML files, that is, files with with one of the extensions supported by {@link
|
||||
* FileType#HTML} (currently ".htm", ".html", ".xhtm", ".xhtml", ".vue").
|
||||
* <li>All YAML files, that is, files with one of the extensions supported by {@link
|
||||
|
||||
@@ -58,7 +58,7 @@ public class FileExtractor {
|
||||
}
|
||||
},
|
||||
|
||||
JS(".js", ".jsx", ".mjs", ".es6", ".es") {
|
||||
JS(".js", ".jsx", ".mjs", ".cjs", ".es6", ".es") {
|
||||
@Override
|
||||
public IExtractor mkExtractor(ExtractorConfig config, ExtractorState state) {
|
||||
return new ScriptExtractor(config);
|
||||
|
||||
@@ -43,7 +43,7 @@ public class Main {
|
||||
* A version identifier that should be updated every time the extractor changes in such a way that
|
||||
* it may produce different tuples for the same file under the same {@link ExtractorConfig}.
|
||||
*/
|
||||
public static final String EXTRACTOR_VERSION = "2020-08-18";
|
||||
public static final String EXTRACTOR_VERSION = "2020-08-19";
|
||||
|
||||
public static final Pattern NEWLINE = Pattern.compile("\n");
|
||||
|
||||
|
||||
@@ -19,6 +19,11 @@ public class ScriptExtractor implements IExtractor {
|
||||
return extension.equals(".mjs") || extension.equals(".es6") || extension.equals(".es");
|
||||
}
|
||||
|
||||
/** True if files with the given extension should always be treated as CommonJS modules. */
|
||||
private boolean isAlwaysCommonJSModule(String extension) {
|
||||
return extension.equals(".cjs");
|
||||
}
|
||||
|
||||
@Override
|
||||
public LoCInfo extract(TextualExtractor textualExtractor) {
|
||||
LocationManager locationManager = textualExtractor.getLocationManager();
|
||||
@@ -45,9 +50,13 @@ public class ScriptExtractor implements IExtractor {
|
||||
}
|
||||
|
||||
// Some file extensions are interpreted as modules by default.
|
||||
if (isAlwaysModule(locationManager.getSourceFileExtension())) {
|
||||
if (config.getSourceType() == SourceType.AUTO)
|
||||
if (config.getSourceType() == SourceType.AUTO) {
|
||||
if (isAlwaysModule(locationManager.getSourceFileExtension())) {
|
||||
config = config.withSourceType(SourceType.MODULE);
|
||||
}
|
||||
if (isAlwaysCommonJSModule(locationManager.getSourceFileExtension())) {
|
||||
config = config.withSourceType(SourceType.COMMONJS_MODULE);
|
||||
}
|
||||
}
|
||||
|
||||
ScopeManager scopeManager =
|
||||
|
||||
Reference in New Issue
Block a user