Merge pull request #15072 from erik-krogh/ts-various

JS: Various TypeScript extraction fixes.
This commit is contained in:
Erik Krogh Kristensen
2023-12-14 14:17:42 +01:00
committed by GitHub
3 changed files with 17 additions and 10 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

@@ -808,6 +808,7 @@ function handleGetMetadataCommand(command: GetMetadataCommand) {
function reset() {
state = new State();
state.typeTable.restrictedExpansion = getEnvironmentVariable("SEMMLE_TYPESCRIPT_NO_EXPANSION", Boolean, true);
state.typeTable.skipExtractingTypes = getEnvironmentVariable("CODEQL_EXTRACTOR_JAVASCRIPT_OPTION_SKIP_TYPES", Boolean, 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;