This commit is contained in:
Nick Guerrera 2021-02-10 11:24:53 -08:00 коммит произвёл GitHub
Родитель 38f915eb87
Коммит a8b5456762
4 изменённых файлов: 86 добавлений и 74 удалений

Просмотреть файл

@ -88,36 +88,36 @@ export function createChecker(program: Program) {
switch (node.kind) {
case SyntaxKind.ModelExpression:
return checkModel(<ModelExpressionNode>node);
return checkModel(node);
case SyntaxKind.ModelStatement:
return checkModel(<ModelStatementNode>node);
return checkModel(node);
case SyntaxKind.ModelProperty:
return checkModelProperty(<ModelPropertyNode>node);
return checkModelProperty(node);
case SyntaxKind.NamespaceStatement:
return checkNamespace(<NamespaceStatementNode>node);
return checkNamespace(node);
case SyntaxKind.NamespaceProperty:
return checkNamespaceProperty(<NamespacePropertyNode>node);
return checkNamespaceProperty(node);
case SyntaxKind.Identifier:
// decorator bindings presently return an empty binding
return <any>checkIdentifier(<IdentifierNode>node);
return <any>checkIdentifier(node);
case SyntaxKind.NumericLiteral:
return checkNumericLiteral(<NumericLiteralNode>node);
return checkNumericLiteral(node);
case SyntaxKind.BooleanLiteral:
return checkBooleanLiteral(<BooleanLiteralNode>node);
return checkBooleanLiteral(node);
case SyntaxKind.TupleExpression:
return checkTupleExpression(<TupleExpressionNode>node);
return checkTupleExpression(node);
case SyntaxKind.StringLiteral:
return checkStringLiteral(<StringLiteralNode>node);
return checkStringLiteral(node);
case SyntaxKind.ArrayExpression:
return checkArrayExpression(<ArrayExpressionNode>node);
return checkArrayExpression(node);
case SyntaxKind.UnionExpression:
return checkUnionExpression(<UnionExpressionNode>node);
return checkUnionExpression(node);
case SyntaxKind.IntersectionExpression:
return checkIntersectionExpression(<IntersectionExpressionNode>node);
return checkIntersectionExpression(node);
case SyntaxKind.TemplateApplication:
return checkTemplateApplication(<TemplateApplicationNode>node);
return checkTemplateApplication(node);
case SyntaxKind.TemplateParameterDeclaration:
return checkTemplateParameterDeclaration(<TemplateParameterDeclarationNode>node);
return checkTemplateParameterDeclaration(node);
}
throw new Error('cant eval ' + SyntaxKind[node.kind]);
@ -126,11 +126,11 @@ export function createChecker(program: Program) {
function getTypeName(type: Type): string {
switch (type.kind) {
case 'Model':
return getModelName(<ModelType>type);
return getModelName(type);
case 'Union':
return (<UnionType>type).options.map(getTypeName).join(' | ');
return type.options.map(getTypeName).join(' | ');
case 'Array':
return getTypeName((<ArrayType>type).elementType) + '[]';
return getTypeName(type.elementType) + '[]';
case 'String':
case 'Number':
case 'Boolean':

Просмотреть файл

@ -630,54 +630,54 @@ type NodeCb<T> = (c: Types.Node) => T;
export function visitChildren<T>(node: Types.Node, cb: NodeCb<T>): T | undefined {
switch (node.kind) {
case Types.SyntaxKind.ADLScript:
return visitEach(cb, (<Types.ADLScriptNode>node).statements);
return visitEach(cb, node.statements);
case Types.SyntaxKind.ArrayExpression:
return visitNode(cb, (<Types.ArrayExpressionNode>node).elementType);
return visitNode(cb, node.elementType);
case Types.SyntaxKind.DecoratorExpression:
return visitNode(cb, (<Types.DecoratorExpressionNode>node).target) ||
visitEach(cb, (<Types.DecoratorExpressionNode>node).arguments);
return visitNode(cb, node.target) ||
visitEach(cb, node.arguments);
case Types.SyntaxKind.ImportStatement:
return visitNode(cb, (<Types.ImportStatementNode>node).id) ||
visitEach(cb, (<Types.ImportStatementNode>node).as);
return visitNode(cb, node.id) ||
visitEach(cb, node.as);
case Types.SyntaxKind.NamespaceProperty:
return visitEach(cb, (<Types.NamespacePropertyNode>node).decorators) ||
visitNode(cb, (<Types.NamespacePropertyNode>node).id) ||
visitNode(cb, (<Types.NamespacePropertyNode>node).parameters) ||
visitNode(cb, (<Types.NamespacePropertyNode>node).returnType);
return visitEach(cb, node.decorators) ||
visitNode(cb, node.id) ||
visitNode(cb, node.parameters) ||
visitNode(cb, node.returnType);
case Types.SyntaxKind.NamespaceStatement:
return visitEach(cb, (<Types.NamespaceStatementNode> node).decorators) ||
visitNode(cb, (<Types.NamespaceStatementNode>node).id) ||
visitNode(cb, (<Types.NamespaceStatementNode>node).parameters) ||
visitEach(cb, (<Types.NamespaceStatementNode>node).properties);
return visitEach(cb, node.decorators) ||
visitNode(cb, node.id) ||
visitNode(cb, node.parameters) ||
visitEach(cb, node.properties);
case Types.SyntaxKind.IntersectionExpression:
return visitEach(cb, (<Types.IntersectionExpressionNode>node).options);
return visitEach(cb, node.options);
case Types.SyntaxKind.MemberExpression:
return visitNode(cb, (<Types.MemberExpressionNode>node).base) ||
visitNode(cb, (<Types.MemberExpressionNode>node).id);
return visitNode(cb, node.base) ||
visitNode(cb, node.id);
case Types.SyntaxKind.ModelExpression:
return visitEach(cb, (<Types.ModelExpressionNode>node).decorators) ||
visitEach(cb, (<Types.ModelExpressionNode>node).properties);
return visitEach(cb, node.decorators) ||
visitEach(cb, node.properties);
case Types.SyntaxKind.ModelProperty:
return visitEach(cb, (<Types.ModelPropertyNode>node).decorators) ||
visitNode(cb, (<Types.ModelPropertyNode>node).id) ||
visitNode(cb, (<Types.ModelPropertyNode>node).value);
return visitEach(cb, node.decorators) ||
visitNode(cb, node.id) ||
visitNode(cb, node.value);
case Types.SyntaxKind.ModelSpreadProperty:
return visitNode(cb, (<Types.ModelSpreadPropertyNode>node).target);
return visitNode(cb, node.target);
case Types.SyntaxKind.ModelStatement:
return visitEach(cb, (<Types.ModelStatementNode>node).decorators) ||
visitNode(cb, (<Types.ModelStatementNode>node).id) ||
visitEach(cb, (<Types.ModelStatementNode>node).templateParameters) ||
visitNode(cb, (<Types.ModelStatementNode>node).assignment) ||
visitEach(cb, (<Types.ModelStatementNode>node).properties);
return visitEach(cb, node.decorators) ||
visitNode(cb, node.id) ||
visitEach(cb, node.templateParameters) ||
visitNode(cb, node.assignment) ||
visitEach(cb, node.properties);
case Types.SyntaxKind.NamedImport:
return visitNode(cb, (<Types.NamedImportNode>node).id);
return visitNode(cb, node.id);
case Types.SyntaxKind.TemplateApplication:
return visitNode(cb, (<Types.TemplateApplicationNode>node).target) ||
visitEach(cb, (<Types.TemplateApplicationNode>node).arguments);
return visitNode(cb, node.target) ||
visitEach(cb, node.arguments);
case Types.SyntaxKind.TupleExpression:
return visitEach(cb, (<Types.TupleExpressionNode>node).values);
return visitEach(cb, node.values);
case Types.SyntaxKind.UnionExpression:
return visitEach(cb, (<Types.UnionExpressionNode>node).options);
return visitEach(cb, node.options);
// no children for the rest of these.
case Types.SyntaxKind.StringLiteral:
case Types.SyntaxKind.NumericLiteral:

Просмотреть файл

@ -119,7 +119,7 @@ export async function compile(rootDir: string, options?: CompilerOptions) {
throw new Error('Decorator must be identifier');
}
const decName = (<IdentifierNode>dec.target).sv;
const decName = dec.target.sv;
const args = dec.arguments.map((a) =>
toJSON(checker.getTypeForNode(a))
);

Просмотреть файл

@ -126,14 +126,26 @@ export enum SyntaxKind {
TemplateParameterDeclaration
}
export interface Node {
export interface BaseNode {
kind: SyntaxKind;
pos: number;
end: number;
parent?: Node;
}
export interface ADLScriptNode extends Node {
export type Node =
| ADLScriptNode
| TemplateParameterDeclarationNode
| ModelPropertyNode
| NamespacePropertyNode
| NamedImportNode
| ModelPropertyNode
| ModelSpreadPropertyNode
| DecoratorExpressionNode
| Statement
| Expression;
export interface ADLScriptNode extends BaseNode {
kind: SyntaxKind.ADLScript;
statements: Array<Statement>;
}
@ -143,23 +155,23 @@ export type Statement =
| ModelStatementNode
| NamespaceStatementNode;
export interface ImportStatementNode extends Node {
export interface ImportStatementNode extends BaseNode {
kind: SyntaxKind.ImportStatement;
id: IdentifierNode;
as: Array<NamedImportNode>;
}
export interface IdentifierNode extends Node {
export interface IdentifierNode extends BaseNode {
kind: SyntaxKind.Identifier;
sv: string;
}
export interface NamedImportNode extends Node {
export interface NamedImportNode extends BaseNode {
kind: SyntaxKind.NamedImport;
id: IdentifierNode;
}
export interface DecoratorExpressionNode extends Node {
export interface DecoratorExpressionNode extends BaseNode {
kind: SyntaxKind.DecoratorExpression;
target: IdentifierNode | MemberExpressionNode;
arguments: Array<Expression>;
@ -178,13 +190,13 @@ export type Expression =
| NumericLiteralNode
| BooleanLiteralNode;
export interface MemberExpressionNode extends Node {
export interface MemberExpressionNode extends BaseNode {
kind: SyntaxKind.MemberExpression;
id: IdentifierNode;
base: MemberExpressionNode | IdentifierNode;
}
export interface NamespaceStatementNode extends Node {
export interface NamespaceStatementNode extends BaseNode {
kind: SyntaxKind.NamespaceStatement;
id: IdentifierNode;
parameters?: ModelExpressionNode;
@ -192,7 +204,7 @@ export interface NamespaceStatementNode extends Node {
decorators: Array<DecoratorExpressionNode>;
}
export interface NamespacePropertyNode extends Node {
export interface NamespacePropertyNode extends BaseNode {
kind: SyntaxKind.NamespaceProperty;
id: IdentifierNode;
parameters: ModelExpressionNode;
@ -201,7 +213,7 @@ export interface NamespacePropertyNode extends Node {
}
export interface ModelStatementNode extends Node {
export interface ModelStatementNode extends BaseNode {
kind: SyntaxKind.ModelStatement;
id: IdentifierNode;
properties?: Array<ModelPropertyNode | ModelSpreadPropertyNode>;
@ -211,22 +223,22 @@ export interface ModelStatementNode extends Node {
decorators: Array<DecoratorExpressionNode>;
}
export interface ModelExpressionNode extends Node {
export interface ModelExpressionNode extends BaseNode {
kind: SyntaxKind.ModelExpression;
properties: Array<ModelPropertyNode | ModelSpreadPropertyNode>;
decorators: Array<DecoratorExpressionNode>;
}
export interface ArrayExpressionNode extends Node {
export interface ArrayExpressionNode extends BaseNode {
kind: SyntaxKind.ArrayExpression;
elementType: Expression;
}
export interface TupleExpressionNode extends Node {
export interface TupleExpressionNode extends BaseNode {
kind: SyntaxKind.TupleExpression;
values: Array<Expression>;
}
export interface ModelPropertyNode extends Node {
export interface ModelPropertyNode extends BaseNode {
kind: SyntaxKind.ModelProperty;
id: IdentifierNode | StringLiteralNode;
value: Expression;
@ -234,45 +246,45 @@ export interface ModelPropertyNode extends Node {
optional: boolean;
}
export interface ModelSpreadPropertyNode extends Node {
export interface ModelSpreadPropertyNode extends BaseNode {
kind: SyntaxKind.ModelSpreadProperty;
target: IdentifierNode;
}
export type LiteralNode = StringLiteralNode | NumericLiteralNode | BooleanLiteralNode;
export interface StringLiteralNode extends Node {
export interface StringLiteralNode extends BaseNode {
kind: SyntaxKind.StringLiteral;
value: string;
}
export interface NumericLiteralNode extends Node {
export interface NumericLiteralNode extends BaseNode {
kind: SyntaxKind.NumericLiteral;
value: number;
}
export interface BooleanLiteralNode extends Node {
export interface BooleanLiteralNode extends BaseNode {
kind: SyntaxKind.BooleanLiteral;
value: boolean;
}
export interface UnionExpressionNode extends Node {
export interface UnionExpressionNode extends BaseNode {
kind: SyntaxKind.UnionExpression;
options: Array<Expression>;
}
export interface IntersectionExpressionNode extends Node {
export interface IntersectionExpressionNode extends BaseNode {
kind: SyntaxKind.IntersectionExpression;
options: Array<Expression>;
}
export interface TemplateApplicationNode extends Node {
export interface TemplateApplicationNode extends BaseNode {
kind: SyntaxKind.TemplateApplication;
target: Expression;
arguments: Array<Expression>;
}
export interface TemplateParameterDeclarationNode extends Node {
export interface TemplateParameterDeclarationNode extends BaseNode {
kind: SyntaxKind.TemplateParameterDeclaration;
sv: string;
}