ts-budgie
Version:
Converts TypeScript code to Budgie.
58 lines • 3.33 kB
JavaScript
;
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
var budgie_1 = require("budgie");
var budgieLine_1 = require("../../output/budgieLine");
var transformation_1 = require("../../output/transformation");
var unsupported_1 = require("../../output/unsupported");
var visitor_1 = require("../visitor");
var noArgumentExpressionComplaint = "No index passed to [] access.";
var knownSimpleFriendlyTypeCommands = new Map([["string", budgie_1.CommandNames.StringIndex]]);
var knownComplexFriendlyTypeCommands = new Map([
[budgie_1.CommandNames.ListType, "list index"],
[budgie_1.CommandNames.DictionaryType, "dictionary index"],
]);
var ElementAccessExpressionVisitor = /** @class */ (function (_super) {
__extends(ElementAccessExpressionVisitor, _super);
function ElementAccessExpressionVisitor() {
return _super !== null && _super.apply(this, arguments) || this;
}
ElementAccessExpressionVisitor.prototype.visit = function (node) {
if (node.argumentExpression === undefined) {
return [transformation_1.Transformation.fromNode(node, this.sourceFile, [unsupported_1.createUnsupportedBudgieLine(noArgumentExpressionComplaint)])];
}
var commandName = this.getCommandName(node.expression);
if (commandName instanceof budgieLine_1.BudgieLine) {
return [transformation_1.Transformation.fromNode(node, this.sourceFile, [unsupported_1.createUnsupportedBudgieLine(noArgumentExpressionComplaint)])];
}
var expression = this.router.recurseIntoValue(node.expression);
var argument = this.router.recurseIntoValue(node.argumentExpression);
return [transformation_1.Transformation.fromNode(node, this.sourceFile, [new budgieLine_1.BudgieLine(commandName, expression, argument)])];
};
ElementAccessExpressionVisitor.prototype.getCommandName = function (expression) {
var friendlyType = this.aliaser.getFriendlyTypeName(expression);
if (friendlyType === undefined) {
return unsupported_1.createUnsupportedTypeBudgieLine();
}
var _a = typeof friendlyType === "string"
? [friendlyType, knownSimpleFriendlyTypeCommands]
: [friendlyType.command, knownComplexFriendlyTypeCommands], typeKey = _a[0], commandsContainer = _a[1];
var typeCommand = commandsContainer.get(typeKey);
return typeCommand === undefined ? unsupported_1.createUnsupportedTypeBudgieLine() : typeCommand;
};
return ElementAccessExpressionVisitor;
}(visitor_1.NodeVisitor));
exports.ElementAccessExpressionVisitor = ElementAccessExpressionVisitor;
//# sourceMappingURL=elementAccessExpressionVisitor.js.map