mirror of
https://github.com/fluencelabs/assemblyscript
synced 2025-06-25 12:41:50 +00:00
Implement optional type parameters (#360)
* Add a NATIVE<T> macro type to simplify use of a native WebAssembly type * Add default type parameters for internal helpers for explicit loads and stores * Unify loadUnsafe/loadUnsafeWithOffset etc. into one * Renamed loadUnsafe etc. into just LOAD, like a macro * Implement parsing of index signatures, but ignore them, for properly linting code * Refactor TypedArray<T> to use macros
This commit is contained in:
@ -68,6 +68,7 @@ import {
|
||||
FieldDeclaration,
|
||||
FunctionDeclaration,
|
||||
ImportDeclaration,
|
||||
IndexSignatureDeclaration,
|
||||
InterfaceDeclaration,
|
||||
MethodDeclaration,
|
||||
NamespaceDeclaration,
|
||||
@ -295,6 +296,10 @@ export class ASTBuilder {
|
||||
this.visitImportDeclaration(<ImportDeclaration>node);
|
||||
break;
|
||||
}
|
||||
case NodeKind.INDEXSIGNATUREDECLARATION: {
|
||||
this.visitIndexSignatureDeclaration(<IndexSignatureDeclaration>node);
|
||||
break;
|
||||
}
|
||||
case NodeKind.INTERFACEDECLARATION: {
|
||||
this.visitInterfaceDeclaration(<InterfaceDeclaration>node);
|
||||
break;
|
||||
@ -379,6 +384,11 @@ export class ASTBuilder {
|
||||
this.sb.push(" extends ");
|
||||
this.visitTypeNode(extendsType);
|
||||
}
|
||||
var defaultType = node.defaultType;
|
||||
if (defaultType) {
|
||||
this.sb.push("=");
|
||||
this.visitTypeNode(defaultType);
|
||||
}
|
||||
}
|
||||
|
||||
visitSignatureNode(node: SignatureNode): void {
|
||||
@ -1176,6 +1186,14 @@ export class ASTBuilder {
|
||||
this.visitStringLiteralExpression(node.path);
|
||||
}
|
||||
|
||||
visitIndexSignatureDeclaration(node: IndexSignatureDeclaration): void {
|
||||
var sb = this.sb;
|
||||
sb.push("[key: ");
|
||||
this.visitTypeNode(node.keyType);
|
||||
sb.push("]: ");
|
||||
this.visitTypeNode(node.valueType);
|
||||
}
|
||||
|
||||
visitInterfaceDeclaration(node: InterfaceDeclaration): void {
|
||||
var decorators = node.decorators;
|
||||
if (decorators) {
|
||||
|
Reference in New Issue
Block a user