Skip to content

Commit 063f69c

Browse files
authored
Merge pull request #15072 from erik-krogh/ts-various
JS: Various TypeScript extraction fixes.
2 parents 7c141b9 + 72e99b5 commit 063f69c

File tree

3 files changed

+17
-10
lines changed

3 files changed

+17
-10
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: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -808,6 +808,7 @@ function handleGetMetadataCommand(command: GetMetadataCommand) {
808808
function reset() {
809809
state = new State();
810810
state.typeTable.restrictedExpansion = getEnvironmentVariable("SEMMLE_TYPESCRIPT_NO_EXPANSION", Boolean, true);
811+
state.typeTable.skipExtractingTypes = getEnvironmentVariable("CODEQL_EXTRACTOR_JAVASCRIPT_OPTION_SKIP_TYPES", Boolean, 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)