Skip to content


Subversion checkout URL

You can clone with
Download ZIP


Template syntax error? #8

robogeek opened this Issue · 13 comments

2 participants


A template that contains this snippet fails to compile

{skimlinks({start: 0, rows: 300, fq: "+groupId:45335650 +merchantId:12678 +id:86680570", searchFor: "Pogoplug" })}

A SyntaxError is thrown here (I have overidden resourceLoader)

    at length (/Users/davidherron/node_modules/kernel/kernel.js:175:18)
    at Function.K.resourceLoader (/Users/davidherron/boilerplate/gulp/lib/renderer.js:54:5)
    at compile (/Users/davidherron/node_modules/kernel/kernel.js:159:10)

It seems to compile on it's own.

var source = 'before {skimlinks({start: 0, rows: 300, fq: "+groupId:45335650 +merchantId:12678 +id:86680570", searchFor: "Pogoplug" })} after';
var tokens = Kernel.tokenizer(source);

Which outputs:

[ 'before ',                                                                                                                     
  { start: 7,                                                                                                                    
    end: 121,                                                                                                                    
    name: 'skimlinks',                                                                                                           
    args: '{start: 0, rows: 300, fq: "+groupId:45335650 +merchantId:12678 +id:86680570", searchFor: "Pogoplug" }' },             
  ' after' ]                                                                                                                     

BTW I updated to kernel 0.1.2 and the behavior is the same.

Here's a modification to your test that includes the whole template that I'm trying to compile. This also runs fine. Even does the first step of generating the javascript okay.

var Kernel = require('kernel');
var util   = require('util');

var source = "<p>Youtube URL</p>\n\n"
   + "{oembed(\"\")}\n\n"
   + "{skimlinks({start: 0, rows: 300, fq: \"+groupId:45335650 +merchantId:12678 +id:86680570\", searchFor: \"Pogoplug\" })}\n";

var blocks = [];
var tokens = Kernel.tokenizer(source);
Kernel.generator(Kernel.parser(tokens, source, "yt.html.kernel"), blocks);

var code = (block, i) {
        return "function block_" + i + "(callback) {\n" +
          block + "\n}\n";


[ '<p>Youtube URL</p>\n\n',
  { start: 79,
    end: 149,
    name: 'oembed',
    args: '""' },
  { start: 151,
    end: 265,
    name: 'skimlinks',
    args: '{start: 0, rows: 300, fq: "+groupId:45335650 +merchantId:12678 +id:86680570", searchFor: "Pogoplug" }' },
  '\n' ]
[ '  var state = new State(4, 2, callback);\n[0] = "<p>Youtube URL</p>\\n\\n";\n[2] = "\\n";\n  run(state, 1, this.oembed, [""]);\n  run(state, 3, this.skimlinks, [{this.start: 0, this.rows: 300, this.fq: "+groupId:45335650 +merchantId:12678 +id:86680570", this.searchFor: "Pogoplug" }]);',
  needsLib: true ]
function block_0(callback) {
  var state = new State(4, 2, callback);[0] = "<p>Youtube URL</p>\n\n";[2] = "\n";
  run(state, 1, this.oembed, [""]);
  run(state, 3, this.skimlinks, [{this.start: 0, this.rows: 300, this.fq: "+groupId:45335650 +merchantId:12678 +id:86680570", this.searchFor: "Pogoplug" }]);


The stack traceback points to this line:

      template = Function("locals", "callback", '"use strict"\n\n' +
        ", callback);\n\n" + code);

Meaning it's constructing a Function.. meaning, is the generated code something that can be constructed into a Function. Looking at that generated code I wonder if this line is legit.

  run(state, 3, this.skimlinks, [{this.start: 0, this.rows: 300, this.fq: "+groupId:45335650 +merchantId:12678 +id:86680570", this.searchFor: "Pogoplug" }]);

Specifically is this legit:

this.whosis: "gronk",

waaaaaait... is that even a good idea to modify the labels of the fields in my anonymous object to read "this.start" etc?

That anonymous object is getting passed to another API that is going to look for a field named "start" not "this.start".


And, changing my template to this results in a successful run. This means there is a workaround, but the bug is that you generate "{ this.whosis: value ... }" in this case rather than "{ whosis: value ... }".

<p>{skimlinks({"start": 0, "rows": 300, "fq": "+groupId:45335650 +merchantId:12678 +id:86680570", "searchFor": "Pogoplug" })}</p>

Ahh, I see, it's a bug in withit. Yeah, it shouldn't be prepending "this" to object keys.


Fixed by f7b0de1

@creationix creationix closed this

Also published to npm and jamjs as version 0.1.3.




Thanks for the bug report! Also, I don't have many users. What do you think of kernel? What do you like about it? What drives you crazy?


Good point. I just exposed "compile(source, filename)" as a standalone function where you just want to pass in some text and get back a template function. 7adf070


I started development on Kernel several years ago long before dust existed. Though I did steal some of the syntax from them in this latest edition. Dust is way too complicated for me.

Regarding moving if, loop, and others into core, this is a non-feature. Kernel is meant to be embedded in a web-framework that provides those to the app user. I did provide examples of some of the common stuff so people who want to use it directly or put it in a framework have a starting point. Implementing if is very simple, but async loops are very complicated and everyone has a unique requirement on how it should work. I don't like baking in APIs that I'm unsure are a good idea. Better, I think, to leave it simple and extensible.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.