Try parsing signatures only if node is callable, see #149; Minor refactoring

This commit is contained in:
dcodeIO
2018-06-24 01:04:24 +02:00
parent 7a8995b18b
commit 188b4e48ce
14 changed files with 933 additions and 813 deletions

View File

@ -4,10 +4,13 @@
*//***/
import {
Program,
CommonFlags,
LIBRARY_PREFIX,
PATH_DELIMITER
} from "./common";
import {
Program
} from "./program";
import {
@ -77,7 +80,9 @@ import {
VoidStatement,
WhileStatement,
mangleInternalPath
mangleInternalPath,
nodeIsCallable,
nodeIsGenericCallable
} from "./ast";
const builtinsFile = LIBRARY_PREFIX + "builtins.ts";
@ -3113,16 +3118,18 @@ export class Parser extends DiagnosticEmitter {
if (!expr) return null;
var startPos = expr.range.start;
// CallExpression with type arguments
var typeArguments: CommonTypeNode[] | null;
while (
// there might be better ways to distinguish a LESSTHAN from a CALL with type arguments
(typeArguments = this.tryParseTypeArgumentsBeforeArguments(tn)) ||
tn.skip(Token.OPENPAREN)
) {
let args = this.parseArguments(tn);
if (!args) return null;
expr = Node.createCallExpression(expr, typeArguments, args, tn.range(startPos, tn.pos));
// CallExpression?
if (nodeIsCallable(expr.kind)) {
let typeArguments: CommonTypeNode[] | null = null;
while (
tn.skip(Token.OPENPAREN)
||
nodeIsGenericCallable(expr.kind) && (typeArguments = this.tryParseTypeArgumentsBeforeArguments(tn)) !== null
) {
let args = this.parseArguments(tn);
if (!args) return null;
expr = Node.createCallExpression(expr, typeArguments, args, tn.range(startPos, tn.pos)); // is again callable
}
}
var token: Token;