aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormax99x <max99x@gmail.com>2011-08-23 16:52:30 +0300
committermax99x <max99x@gmail.com>2011-08-24 02:46:04 +0300
commit2ea581f293392aebdfb1edbbba895c28462b8443 (patch)
tree65a6123c1709cdbad3c25d2152867113e4b7ff52
parent238ca947686672f4eec0339617e0e7aaf7fcc407 (diff)
Prevented quoting of library object properties (Closure Compiler compatibility).
-rw-r--r--src/jsifier.js23
1 files changed, 11 insertions, 12 deletions
diff --git a/src/jsifier.js b/src/jsifier.js
index 3da296f1..1e02555f 100644
--- a/src/jsifier.js
+++ b/src/jsifier.js
@@ -277,19 +277,18 @@ function JSify(data, functionsOnly, givenFunctions, givenGlobalVariables) {
snippet = '_' + snippet;
}
} else if (typeof snippet === 'object') {
- // JSON.stringify removes functions, so we need to make sure they are added
- var funcs = [];
- var hasNonFunc = false;
- for (var x in snippet) {
- if (typeof snippet[x] === 'function') {
- funcs.push(x + ': ' + snippet[x].toString());
- } else {
- hasNonFunc = true;
+ if (snippet === null) {
+ snippet = 'null';
+ } else {
+ var members = [];
+ for (var property in snippet) {
+ if (typeof snippet[property] === 'function') {
+ members.push(property + ': ' + snippet[property].toString());
+ } else {
+ members.push(property + ': ' + JSON.stringify(snippet[property]));
+ }
}
- }
- snippet = JSON.stringify(snippet);
- if (funcs.length > 0) {
- snippet = snippet.replace(/}$/, (hasNonFunc ? ', ' : '') + funcs.join(', ') + ' }');
+ snippet = '{' + members.join(', ') + ' }';
}
} else if (typeof snippet === 'function') {
snippet = snippet.toString();