Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

using dust.isArray in place of Array.isArray #241

Merged
merged 1 commit into from Feb 28, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 11 additions & 3 deletions lib/compiler.js
@@ -1,4 +1,4 @@
(function(dust) {
var comp = (function(dust) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what does this variable "comp" mean? , why not use a more descriptive name, if it refers to the compiler version

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The compiler function was executed immediately when you require ./compiler. this function receive the dust object as param. In the browser case, the dust object is obtained with the getGlobal function but in nodejs we don't have access to the dust object. So I have assigned the compiler function to a variable, comp, and if dust is being executed from browser I call it but if dust is being executed in node, I return the function, so the server can call it with the dust object.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do you prefer calling it compiler? I can change it easily.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

one more q: is this only relevant to node? or anything that works with server side?
I assume that latter?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is just for node, because the server file is just included when exports and process are different from "undefined"

if (typeof exports !== "undefined") {
  if (typeof process !== "undefined") {
      require('./server')(dust);
  }
  module.exports = dust;
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why woud not it apply for rhino or nashhorn?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because Exports is undefined in Rhino.

I don't know in Nashorn.

I didn't know that we were maintaining dust compatible with it.


dust.compile = function(source, name, strip) {
try {
Expand Down Expand Up @@ -312,7 +312,7 @@ dust.nodes = {
list = [];

for (var i=0,len=keys.length; i<len; i++) {
if (Array.isArray(keys[i]))
if (dust.isArray(keys[i]))
list.push(dust.compileNode(context, keys[i]));
else
list.push("\"" + keys[i] + "\"");
Expand All @@ -338,4 +338,12 @@ var escape = (typeof JSON === "undefined")
? function(str) { return "\"" + dust.escapeJs(str) + "\"" }
: JSON.stringify;

})(typeof exports !== 'undefined' ? exports : getGlobal());
return dust;

});

if (typeof exports !== 'undefined') {
module.exports = comp;
} else {
comp(getGlobal());
}
2 changes: 1 addition & 1 deletion lib/server.js
@@ -1,9 +1,9 @@
var path = require('path'),
parser = require('./parser'),
compiler = require('./compiler'),
vm = require('vm');

module.exports = function(dust) {
var compiler = require('./compiler')(dust);
compiler.parse = parser.parse;
dust.compile = compiler.compile;

Expand Down