UNPKG

pogo

Version:

A readable, DSL friendly programming language that compiles to JavaScript

56 lines 1.91 kB
(function() { var self = this; var codegenUtils, isLegalJavaScriptIdentifier; codegenUtils = require("./codegenUtils"); module.exports = function(terms) { var self = this; return terms.term({ constructor: function(field, value) { var self = this; self.isHashEntry = true; self.field = field; return self.value = value; }, legalFieldName: function() { var self = this; var f; if (self.field.isString) { return codegenUtils.formatJavaScriptString(self.field.string); } f = codegenUtils.concatName(self.field); if (isLegalJavaScriptIdentifier(f)) { return f; } else { return codegenUtils.formatJavaScriptString(f); } }, valueOrTrue: function() { var self = this; if (self.value === undefined) { return self.cg.boolean(true); } else { return self.value; } }, hashEntry: function() { var self = this; return self; }, parameter: function() { var self = this; return self; }, generateHashEntry: function(scope) { var self = this; return self.code(self.legalFieldName(), ":", self.valueOrTrue().generate(scope)); }, asyncify: function() { var self = this; return self.value.asyncify(); } }); }; isLegalJavaScriptIdentifier = function(id) { return /^[$_a-zA-Z][$_a-zA-Z0-9]*$/.test(id); }; }).call(this);