зеркало из https://github.com/github/codeql.git
Merge pull request #1298 from asger-semmle/full-mode-fixes-rc120
TS: Backport full-mode fixes to rc/1.20
This commit is contained in:
Коммит
e0e6224987
|
@ -156,7 +156,21 @@ export function augmentAst(ast: AugmentedSourceFile, code: string, project: Proj
|
|||
}
|
||||
}
|
||||
|
||||
forEachNode(ast, (node: AugmentedNode) => {
|
||||
// Number of conditional type expressions the visitor is currently inside.
|
||||
// We disable type extraction inside such type expressions, to avoid complications
|
||||
// with `infer` types.
|
||||
let insideConditionalTypes = 0;
|
||||
|
||||
visitAstNode(ast);
|
||||
function visitAstNode(node: AugmentedNode) {
|
||||
if (node.kind === ts.SyntaxKind.ConditionalType) {
|
||||
++insideConditionalTypes;
|
||||
}
|
||||
ts.forEachChild(node, visitAstNode);
|
||||
if (node.kind === ts.SyntaxKind.ConditionalType) {
|
||||
--insideConditionalTypes;
|
||||
}
|
||||
|
||||
// fill in line/column info
|
||||
if ("pos" in node) {
|
||||
node.$pos = augmentPos(node.pos, true);
|
||||
|
@ -176,7 +190,7 @@ export function augmentAst(ast: AugmentedSourceFile, code: string, project: Proj
|
|||
}
|
||||
}
|
||||
|
||||
if (typeChecker != null) {
|
||||
if (typeChecker != null && insideConditionalTypes === 0) {
|
||||
if (isTypedNode(node)) {
|
||||
let type = typeChecker.getTypeAtLocation(node);
|
||||
if (type != null) {
|
||||
|
@ -247,7 +261,7 @@ export function augmentAst(ast: AugmentedSourceFile, code: string, project: Proj
|
|||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
type NamedNodeWithSymbol = AugmentedNode & (ts.ClassDeclaration | ts.InterfaceDeclaration
|
||||
|
|
|
@ -372,7 +372,9 @@ function handleOpenProjectCommand(command: OpenProjectCommand) {
|
|||
function getEffectiveExportTarget(symbol: ts.Symbol) {
|
||||
if (symbol.exports != null && symbol.exports.has(ts.InternalSymbolName.ExportEquals)) {
|
||||
let exportAlias = symbol.exports.get(ts.InternalSymbolName.ExportEquals);
|
||||
return typeChecker.getAliasedSymbol(exportAlias);
|
||||
if (exportAlias.flags & ts.SymbolFlags.Alias) {
|
||||
return typeChecker.getAliasedSymbol(exportAlias);
|
||||
}
|
||||
}
|
||||
return symbol;
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
14
javascript/ql/test/library-tests/TypeScript/RegressionTests/ExportEqualsExpr/extern.d.ts
поставляемый
Normal file
14
javascript/ql/test/library-tests/TypeScript/RegressionTests/ExportEqualsExpr/extern.d.ts
поставляемый
Normal file
|
@ -0,0 +1,14 @@
|
|||
class Foo {}
|
||||
|
||||
declare module 'foo' {
|
||||
export = new Foo();
|
||||
}
|
||||
|
||||
declare module 'bar' {
|
||||
import * as baz from "baz";
|
||||
export = baz;
|
||||
}
|
||||
|
||||
declare module 'baz' {
|
||||
export class C {}
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
| "bar" in global scope |
|
||||
| C in module 'bar' |
|
||||
| Foo in global scope |
|
||||
| Foo in tst.ts |
|
||||
| module 'bar' |
|
||||
| module 'foo' |
|
||||
| tst.ts |
|
|
@ -0,0 +1,4 @@
|
|||
import javascript
|
||||
|
||||
from CanonicalName name
|
||||
select name
|
|
@ -0,0 +1,6 @@
|
|||
{
|
||||
"include": ["."],
|
||||
"compilerOptions": {
|
||||
"esModuleInterop": true
|
||||
}
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
import self from "./tst";
|
||||
|
||||
class Foo {}
|
||||
|
||||
export = new Foo();
|
|
@ -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 || {};
|
||||
}
|
||||
}
|
Загрузка…
Ссылка в новой задаче