Skip to content

Commit c7300fa

Browse files
committed
TS: Add workaround for 'globalThis' getProperties() crash
1 parent 9934996 commit c7300fa

File tree

5 files changed

+37
-1
lines changed

5 files changed

+37
-1
lines changed

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

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -819,8 +819,24 @@ export class TypeTable {
819819
this.isInShallowTypeContext = false;
820820
}
821821

822+
/**
823+
* Returns the properties of the given type, or `null` if the properties of this
824+
* type could not be computed.
825+
*/
826+
private tryGetProperties(type: ts.Type) {
827+
// Workaround for https://github.com/Microsoft/TypeScript/issues/30845
828+
// Should be safe to remove once that has been fixed.
829+
try {
830+
return type.getProperties();
831+
} catch (e) {
832+
return null;
833+
}
834+
}
835+
822836
private extractProperties(type: ts.Type, id: number) {
823-
for (let symbol of type.getProperties()) {
837+
let props = this.tryGetProperties(type);
838+
if (props == null) return;
839+
for (let symbol of props) {
824840
let propertyType = this.typeChecker.getTypeOfSymbolAtLocation(symbol, this.arbitraryAstNode);
825841
if (propertyType == null) continue;
826842
let propertyTypeId = this.getId(propertyType);
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
| Success |
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import javascript
2+
3+
select "Success"
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"include": ["."]
3+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
'use strict';
2+
3+
var _myGlobal = this;
4+
5+
module Test {
6+
var global = _myGlobal || {};
7+
8+
export class C {}
9+
10+
export function f(x: C) {
11+
global.field = x || {};
12+
}
13+
}

0 commit comments

Comments
 (0)