Merge branch 'main' into seclab/dotjs

This commit is contained in:
Jorge
2023-12-19 10:44:52 +01:00
committed by GitHub
1504 changed files with 89568 additions and 60465 deletions

View File

@@ -192,7 +192,7 @@ export function augmentAst(ast: AugmentedSourceFile, code: string, project: Proj
}
if (typeChecker != null) {
if (isTypedNode(node)) {
if (isTypedNode(node) && !typeTable.skipExtractingTypes) {
let contextualType = isContextuallyTypedNode(node)
? typeChecker.getContextualType(node)
: null;

View File

@@ -554,7 +554,7 @@ function handleOpenProjectCommand(command: OpenProjectCommand) {
let program = project.program;
let typeChecker = program.getTypeChecker();
let shouldReportDiagnostics = getEnvironmentVariable("SEMMLE_TYPESCRIPT_REPORT_DIAGNOSTICS", Boolean, false);
let shouldReportDiagnostics = getEnvironmentVariable("SEMMLE_TYPESCRIPT_REPORT_DIAGNOSTICS", v => v.trim().toLowerCase() === "true", false);
let diagnostics = shouldReportDiagnostics
? program.getSemanticDiagnostics().filter(d => d.category === ts.DiagnosticCategory.Error)
: [];
@@ -807,7 +807,8 @@ function handleGetMetadataCommand(command: GetMetadataCommand) {
function reset() {
state = new State();
state.typeTable.restrictedExpansion = getEnvironmentVariable("SEMMLE_TYPESCRIPT_NO_EXPANSION", Boolean, true);
state.typeTable.restrictedExpansion = getEnvironmentVariable("SEMMLE_TYPESCRIPT_NO_EXPANSION", v => v.trim().toLowerCase() === "true", true);
state.typeTable.skipExtractingTypes = getEnvironmentVariable("CODEQL_EXTRACTOR_JAVASCRIPT_OPTION_SKIP_TYPES", v => v.trim().toLowerCase() === "true", false);
}
function getEnvironmentVariable<T>(name: string, parse: (x: string) => T, defaultValue: T) {
@@ -886,6 +887,7 @@ if (process.argv.length > 2) {
if (argument === "--version") {
console.log("parser-wrapper with TypeScript " + ts.version);
} else if (pathlib.basename(argument) === "tsconfig.json") {
reset();
handleOpenProjectCommand({
command: "open-project",
tsConfig: argument,
@@ -895,7 +897,7 @@ if (process.argv.length > 2) {
virtualSourceRoot: null,
});
for (let sf of state.project.program.getSourceFiles()) {
if (pathlib.basename(sf.fileName) === "lib.d.ts") continue;
if (/lib\..*\.d\.ts/.test(pathlib.basename(sf.fileName)) || pathlib.basename(sf.fileName) === "lib.d.ts") continue;
handleParseCommand({
command: "parse",
filename: sf.fileName,

View File

@@ -383,6 +383,11 @@ export class TypeTable {
*/
public restrictedExpansion = false;
/**
* If set to true, skip extracting types.
*/
public skipExtractingTypes = false;
private virtualSourceRoot: VirtualSourceRoot;
/**
@@ -1240,8 +1245,15 @@ export class TypeTable {
let indexOnStack = stack.length;
stack.push(id);
/** Indicates if a type contains no type variables, is a type variable, or strictly contains type variables. */
const enum TypeVarDepth {
noTypeVar = 0,
isTypeVar = 1,
containsTypeVar = 2,
}
for (let symbol of type.getProperties()) {
let propertyType = this.tryGetTypeOfSymbol(symbol);
let propertyType = typeTable.tryGetTypeOfSymbol(symbol);
if (propertyType == null) continue;
traverseType(propertyType);
}
@@ -1267,13 +1279,6 @@ export class TypeTable {
return lowlinkTable.get(id);
/** Indicates if a type contains no type variables, is a type variable, or strictly contains type variables. */
const enum TypeVarDepth {
noTypeVar = 0,
isTypeVar = 1,
containsTypeVar = 2,
}
function traverseType(type: ts.Type): TypeVarDepth {
if (isTypeVariable(type)) return TypeVarDepth.isTypeVar;
let depth = TypeVarDepth.noTypeVar;