UNPKG

@microsoft.azure/autorest.incubator

Version:
100 lines 3.1 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const variable_1 = require("../../csharp/code-dom/variable"); const statement_1 = require("../../csharp/code-dom/statements/statement"); const text_manipulation_1 = require("../../common/text-manipulation"); const access_modifier_1 = require("../../csharp/code-dom/access-modifier"); function toExpression(expression) { return typeof expression === 'string' ? new LiteralExpression(expression) : expression; } exports.toExpression = toExpression; function valueOf(expression) { return typeof expression === 'string' ? expression : expression.value; } exports.valueOf = valueOf; /** an expression of a constant string value */ class StringExpression { constructor(value) { this.value = `@"${value.replace(/"/g, '""')}"`; } toString() { return this.value; } } exports.StringExpression = StringExpression; /** an arbitrary user-defined expression */ class LiteralExpression { constructor(value) { this.value = value; } toString() { return this.value; } } exports.LiteralExpression = LiteralExpression; /** a c# 'is' expression */ function Is(expression, isType) { return new IsExpression(expression, isType); } exports.Is = Is; /** a c# 'is' expression */ class IsExpression { constructor(expression, isType) { this.expression = expression; this.isType = isType; } get value() { return `${valueOf(this.expression)} is ${this.isType.declaration}`; } toString() { return this.value; } } exports.IsExpression = IsExpression; /** a c# 'is' expression that declares a local variable */ function IsDeclaration(expression, isType, name) { return new IsExpressionDeclaration(expression, isType, name); } exports.IsDeclaration = IsDeclaration; /** a c# 'is' expression that declares a local variable */ class IsExpressionDeclaration extends variable_1.LocalVariable { constructor(expression, isType, name) { super(name, isType); this.expression = expression; this.isType = isType; } get check() { return new LiteralExpression(`${valueOf(this.expression)} is ${this.isType.declaration} ${this.name}`); } get value() { return this.name; } toString() { return this.value; } } exports.IsExpressionDeclaration = IsExpressionDeclaration; function Lambda(parameters, body, objectIntializer) { } exports.Lambda = Lambda; class LambdaExpression extends statement_1.Statements { constructor(parameters, body, objectIntializer) { super(body); this.parameters = parameters; this.body = body; this.async = access_modifier_1.Modifier.None; this.apply(objectIntializer); } get value() { return ` ${this.async}(${this.parameters.joinWith(each => each.name)}) => { ${text_manipulation_1.indent(super.implementation)} } `.trim(); } toString() { return this.value; } } exports.LambdaExpression = LambdaExpression; //# sourceMappingURL=expression.js.map