Skip to content

Commit 9543c23

Browse files
authored
Merge pull request github#15111 from erik-krogh/mergeback-ts-extractor
JS: TypeScript extractor fixes into rc/3.12
2 parents 96b793a + c752f26 commit 9543c23

File tree

3 files changed

+19
-12
lines changed

3 files changed

+19
-12
lines changed

javascript/extractor/lib/typescript/src/ast_extractor.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ export function augmentAst(ast: AugmentedSourceFile, code: string, project: Proj
192192
}
193193

194194
if (typeChecker != null) {
195-
if (isTypedNode(node)) {
195+
if (isTypedNode(node) && !typeTable.skipExtractingTypes) {
196196
let contextualType = isContextuallyTypedNode(node)
197197
? typeChecker.getContextualType(node)
198198
: null;

javascript/extractor/lib/typescript/src/main.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -554,7 +554,7 @@ function handleOpenProjectCommand(command: OpenProjectCommand) {
554554
let program = project.program;
555555
let typeChecker = program.getTypeChecker();
556556

557-
let shouldReportDiagnostics = getEnvironmentVariable("SEMMLE_TYPESCRIPT_REPORT_DIAGNOSTICS", Boolean, false);
557+
let shouldReportDiagnostics = getEnvironmentVariable("SEMMLE_TYPESCRIPT_REPORT_DIAGNOSTICS", v => v.trim().toLowerCase() === "true", false);
558558
let diagnostics = shouldReportDiagnostics
559559
? program.getSemanticDiagnostics().filter(d => d.category === ts.DiagnosticCategory.Error)
560560
: [];
@@ -807,7 +807,8 @@ function handleGetMetadataCommand(command: GetMetadataCommand) {
807807

808808
function reset() {
809809
state = new State();
810-
state.typeTable.restrictedExpansion = getEnvironmentVariable("SEMMLE_TYPESCRIPT_NO_EXPANSION", Boolean, true);
810+
state.typeTable.restrictedExpansion = getEnvironmentVariable("SEMMLE_TYPESCRIPT_NO_EXPANSION", v => v.trim().toLowerCase() === "true", true);
811+
state.typeTable.skipExtractingTypes = getEnvironmentVariable("CODEQL_EXTRACTOR_JAVASCRIPT_OPTION_SKIP_TYPES", v => v.trim().toLowerCase() === "true", false);
811812
}
812813

813814
function getEnvironmentVariable<T>(name: string, parse: (x: string) => T, defaultValue: T) {
@@ -886,6 +887,7 @@ if (process.argv.length > 2) {
886887
if (argument === "--version") {
887888
console.log("parser-wrapper with TypeScript " + ts.version);
888889
} else if (pathlib.basename(argument) === "tsconfig.json") {
890+
reset();
889891
handleOpenProjectCommand({
890892
command: "open-project",
891893
tsConfig: argument,
@@ -895,7 +897,7 @@ if (process.argv.length > 2) {
895897
virtualSourceRoot: null,
896898
});
897899
for (let sf of state.project.program.getSourceFiles()) {
898-
if (pathlib.basename(sf.fileName) === "lib.d.ts") continue;
900+
if (/lib\..*\.d\.ts/.test(pathlib.basename(sf.fileName)) || pathlib.basename(sf.fileName) === "lib.d.ts") continue;
899901
handleParseCommand({
900902
command: "parse",
901903
filename: sf.fileName,

javascript/extractor/lib/typescript/src/type_table.ts

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,11 @@ export class TypeTable {
383383
*/
384384
public restrictedExpansion = false;
385385

386+
/**
387+
* If set to true, skip extracting types.
388+
*/
389+
public skipExtractingTypes = false;
390+
386391
private virtualSourceRoot: VirtualSourceRoot;
387392

388393
/**
@@ -1240,8 +1245,15 @@ export class TypeTable {
12401245
let indexOnStack = stack.length;
12411246
stack.push(id);
12421247

1248+
/** Indicates if a type contains no type variables, is a type variable, or strictly contains type variables. */
1249+
const enum TypeVarDepth {
1250+
noTypeVar = 0,
1251+
isTypeVar = 1,
1252+
containsTypeVar = 2,
1253+
}
1254+
12431255
for (let symbol of type.getProperties()) {
1244-
let propertyType = this.tryGetTypeOfSymbol(symbol);
1256+
let propertyType = typeTable.tryGetTypeOfSymbol(symbol);
12451257
if (propertyType == null) continue;
12461258
traverseType(propertyType);
12471259
}
@@ -1267,13 +1279,6 @@ export class TypeTable {
12671279

12681280
return lowlinkTable.get(id);
12691281

1270-
/** Indicates if a type contains no type variables, is a type variable, or strictly contains type variables. */
1271-
const enum TypeVarDepth {
1272-
noTypeVar = 0,
1273-
isTypeVar = 1,
1274-
containsTypeVar = 2,
1275-
}
1276-
12771282
function traverseType(type: ts.Type): TypeVarDepth {
12781283
if (isTypeVariable(type)) return TypeVarDepth.isTypeVar;
12791284
let depth = TypeVarDepth.noTypeVar;

0 commit comments

Comments
 (0)