mirror of
https://github.com/github/codeql.git
synced 2026-04-30 11:15:13 +02:00
TS: Add workaround for 'globalThis' getProperties() crash
This commit is contained in:
@@ -819,8 +819,24 @@ export class TypeTable {
|
||||
this.isInShallowTypeContext = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the properties of the given type, or `null` if the properties of this
|
||||
* type could not be computed.
|
||||
*/
|
||||
private tryGetProperties(type: ts.Type) {
|
||||
// Workaround for https://github.com/Microsoft/TypeScript/issues/30845
|
||||
// Should be safe to remove once that has been fixed.
|
||||
try {
|
||||
return type.getProperties();
|
||||
} catch (e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private extractProperties(type: ts.Type, id: number) {
|
||||
for (let symbol of type.getProperties()) {
|
||||
let props = this.tryGetProperties(type);
|
||||
if (props == null) return;
|
||||
for (let symbol of props) {
|
||||
let propertyType = this.typeChecker.getTypeOfSymbolAtLocation(symbol, this.arbitraryAstNode);
|
||||
if (propertyType == null) continue;
|
||||
let propertyTypeId = this.getId(propertyType);
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
| Success |
|
||||
@@ -0,0 +1,3 @@
|
||||
import javascript
|
||||
|
||||
select "Success"
|
||||
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"include": ["."]
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
'use strict';
|
||||
|
||||
var _myGlobal = this;
|
||||
|
||||
module Test {
|
||||
var global = _myGlobal || {};
|
||||
|
||||
export class C {}
|
||||
|
||||
export function f(x: C) {
|
||||
global.field = x || {};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user