Sublime Forum

Javascript code generator quiz

#1

Hi everyone.

I would like to write a plugin for JS code generation in addition to standard snippets.
It is always useful to be able to form your thoughts of future software architecture into some real code. Usually I grab a pen and a paper and start drawing entities, objects, relations, etc. But since I am developer, the code preview of future architecture is also very helpful.
To explain the idea more clearly, consider the following example (simple class creation):

class Player with name:string, score:int, keys:array, enabled:bool, active = true methods someMethod, anotherMethod(a, b = 123)

and the plugin will expand it to:

function Player() {
    this.name = ''
    this.score = 0
    this.keys  =]
    this.enabled = false
    this.active = true
}
 
Player.prototype.someMethod = function() {
 
}
 
Player.prototype.anotherMethod = function(a, b) {
    if (!b) {
        b = 123
    }
}

After reviewing generated code I might bury it, modify or edit the original line (“class Player …”) for further generations. After forming the desired application skeleton the developer should proceed with editing using standard sublime features like snippets and other plugins.
The example is very straight-forward, syntax, generation format will differ in real plugin (or not :smile: ).

Please tell me if you would like to see such kind of a plugin and if so - I’ll start working on it, taking further feature requests.

Thanks in advance.

0 Likes

#2

I think it’s a nice idea for the plugin, very helpful one.

I’d gladly use it.

0 Likes

#3

I know you have just shown sample code but… JS statements are semi-colon terminated, as should be the prototype assignments.

Be aware: supposing I want to assign b the value of 0?

0 Likes

#4

[quote=“agibsonsw”]I know you have just shown sample code but… JS statements are semi-colon terminated, as should be the prototype assignments.
Be aware: supposing I want to assign b the value of 0?[/quote]

It is really, really raw example, without any significant impact on the final result. I guess anyway I would use some kind of a required/optional flags to determine what argument should be skipped from testing. Or I would not include such kind of a functionality at all :smile:
The main question for now is - do anyone need this plugin or it is useless since developers usually just print the code right out of their heads :smile:

0 Likes

#5

I think you will find feedback a little hard to come by on this forum. If it is something that interests you then I would go ahead! In the process, it might encourage you to explore other ideas :wink:.

0 Likes

#6

Yeah, seems to me it is the only correct answer :smile: Thanks!

0 Likes

#7

You might consider doing this for TypeScript. It has a more formal structure and, is therefore, more suitable for templating. Besides which it is very new and there is currently limited support for it in ST. Just an idea :wink:

0 Likes