mirror of
https://github.com/fluencelabs/assemblyscript
synced 2025-06-21 18:51:43 +00:00
Fix some array function parsing and serialization issues
Quite similar to #256 and also uses its test, but also fixes the serializer and doesn't try to parse an untyped 'x => x'.
This commit is contained in:
@ -117,7 +117,8 @@ export function nodeIsCallable(kind: NodeKind): bool {
|
||||
case NodeKind.IDENTIFIER:
|
||||
case NodeKind.CALL:
|
||||
case NodeKind.ELEMENTACCESS:
|
||||
case NodeKind.PROPERTYACCESS: return true;
|
||||
case NodeKind.PROPERTYACCESS:
|
||||
case NodeKind.PARENTHESIZED: return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
@ -353,7 +353,8 @@ export class ASTBuilder {
|
||||
return;
|
||||
}
|
||||
var typeNode = <TypeNode>node;
|
||||
this.visitIdentifierExpression(<IdentifierExpression>typeNode.name);
|
||||
assert(typeNode.name.text.length);
|
||||
this.visitIdentifierExpression(typeNode.name);
|
||||
var typeArguments = typeNode.typeArguments;
|
||||
if (typeArguments) {
|
||||
let numTypeArguments = typeArguments.length;
|
||||
@ -1081,22 +1082,24 @@ export class ASTBuilder {
|
||||
var returnType = signature.returnType;
|
||||
if (node.is(CommonFlags.ARROW)) {
|
||||
if (body) {
|
||||
if (returnType) {
|
||||
if (isTypeOmitted(returnType)) {
|
||||
sb.push(")");
|
||||
} else {
|
||||
sb.push("): ");
|
||||
this.visitTypeNode(returnType);
|
||||
}
|
||||
sb.push(" => ");
|
||||
this.visitNode(body);
|
||||
} else {
|
||||
if (returnType) {
|
||||
sb.push(" => ");
|
||||
this.visitTypeNode(returnType);
|
||||
} else {
|
||||
sb.push(" => void");
|
||||
}
|
||||
assert(!isTypeOmitted(returnType));
|
||||
sb.push(" => ");
|
||||
this.visitTypeNode(returnType);
|
||||
}
|
||||
} else {
|
||||
if (returnType && !node.isAny(CommonFlags.CONSTRUCTOR | CommonFlags.SET)) {
|
||||
if (
|
||||
!isTypeOmitted(returnType) &&
|
||||
!node.isAny(CommonFlags.CONSTRUCTOR | CommonFlags.SET)
|
||||
) {
|
||||
sb.push("): ");
|
||||
this.visitTypeNode(returnType);
|
||||
} else {
|
||||
@ -1454,12 +1457,11 @@ export class ASTBuilder {
|
||||
var type = node.type;
|
||||
var initializer = node.initializer;
|
||||
if (type) {
|
||||
if (kind == ParameterKind.OPTIONAL && !initializer) {
|
||||
sb.push("?: ");
|
||||
} else {
|
||||
if (kind == ParameterKind.OPTIONAL) sb.push("?");
|
||||
if (!isTypeOmitted(type)) {
|
||||
sb.push(": ");
|
||||
this.visitTypeNode(type);
|
||||
}
|
||||
this.visitTypeNode(type);
|
||||
}
|
||||
if (initializer) {
|
||||
sb.push(" = ");
|
||||
@ -1503,3 +1505,7 @@ export class ASTBuilder {
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
function isTypeOmitted(type: CommonTypeNode): bool {
|
||||
return type.kind == NodeKind.TYPE && !changetype<TypeNode>(type).name.text.length;
|
||||
}
|
||||
|
@ -2993,7 +2993,10 @@ export class Parser extends DiagnosticEmitter {
|
||||
|
||||
// if we got here, check for arrow
|
||||
case Token.CLOSEPAREN: {
|
||||
if (!tn.skip(Token.EQUALS_GREATERTHAN)) {
|
||||
if (
|
||||
!tn.skip(Token.COLON) &&
|
||||
!tn.skip(Token.EQUALS_GREATERTHAN)
|
||||
) {
|
||||
again = false;
|
||||
break;
|
||||
}
|
||||
@ -3004,8 +3007,19 @@ export class Parser extends DiagnosticEmitter {
|
||||
tn.reset(state);
|
||||
return this.parseFunctionExpression(tn);
|
||||
}
|
||||
// can be both
|
||||
case Token.QUESTION: // optional parameter or ternary
|
||||
// optional parameter or parenthesized
|
||||
case Token.QUESTION: {
|
||||
if (
|
||||
tn.skip(Token.COLON) || // optional parameter with type
|
||||
tn.skip(Token.COMMA) || // optional parameter without type
|
||||
tn.skip(Token.CLOSEPAREN) // last optional parameter without type
|
||||
) {
|
||||
tn.reset(state);
|
||||
return this.parseFunctionExpression(tn);
|
||||
}
|
||||
again = false; // parenthesized
|
||||
break;
|
||||
}
|
||||
case Token.COMMA: {
|
||||
break; // continue
|
||||
}
|
||||
|
Reference in New Issue
Block a user