Comparing version 0.0.2 to 0.0.3
@@ -136,6 +136,15 @@ /* | ||
if (typeof Object.freeze === 'function') { | ||
Object.freeze(Syntax); | ||
Object.freeze(Precedence); | ||
Object.freeze(BinaryPrecedence); | ||
function getDefaultOptions() { | ||
// default options | ||
return { | ||
indent: null, | ||
base: null, | ||
parse: null, | ||
format: { | ||
indent: { | ||
style: ' ', | ||
base: 0 | ||
} | ||
} | ||
}; | ||
} | ||
@@ -162,2 +171,38 @@ | ||
function stringRepeat(str, num) { | ||
var result = ''; | ||
for (num |= 0; num > 0; num >>>= 1, str += str) { | ||
if (num & 1) { | ||
result += str; | ||
} | ||
} | ||
return result; | ||
} | ||
function updateDeeply(target, override) { | ||
var key, val; | ||
function isHashObject(target) { | ||
return typeof target === 'object' && target instanceof Object && !(target instanceof RegExp); | ||
} | ||
for (key in override) { | ||
if (override.hasOwnProperty(key)) { | ||
val = override[key]; | ||
if (isHashObject(val)) { | ||
if (isHashObject(target[key])) { | ||
updateDeeply(target[key], val); | ||
} else { | ||
target[key] = updateDeeply({}, val); | ||
} | ||
} else { | ||
target[key] = val; | ||
} | ||
} | ||
} | ||
return target; | ||
} | ||
function escapeString(str) { | ||
@@ -728,3 +773,3 @@ var result = '', i, len, ch; | ||
for (i = 0, len = stmt.body.length; i < len; i += 1) { | ||
result += generateStatement(stmt.body[i]); | ||
result += addIndent(generateStatement(stmt.body[i])); | ||
if ((i + 1) < len) { | ||
@@ -779,10 +824,28 @@ result += '\n'; | ||
function generate(node, options) { | ||
var defaultOptions = getDefaultOptions(); | ||
if (typeof options !== 'undefined') { | ||
base = options.base || ''; | ||
indent = options.indent || ' '; | ||
// Obsolete options | ||
// | ||
// `options.indent` | ||
// `options.base` | ||
// | ||
// Instead of them, we can use `option.format.indent`. | ||
if (typeof options.indent === 'string') { | ||
defaultOptions.format.indent.style = options.indent; | ||
} | ||
options = updateDeeply(defaultOptions, options); | ||
indent = options.format.indent.style; | ||
if (typeof options.base === 'string') { | ||
base = options.base; | ||
} else { | ||
base = stringRepeat(indent, options.format.indent.base); | ||
} | ||
parse = options.parse; | ||
} else { | ||
base = ''; | ||
indent = ' '; | ||
parse = null; | ||
options = defaultOptions; | ||
indent = options.format.indent.style; | ||
base = stringRepeat(indent, options.format.indent.base); | ||
parse = options.parse; | ||
} | ||
@@ -842,3 +905,3 @@ | ||
// Sync with package.json. | ||
exports.version = '0.0.2'; | ||
exports.version = '0.0.3'; | ||
@@ -845,0 +908,0 @@ exports.generate = generate; |
@@ -9,3 +9,3 @@ { | ||
}, | ||
"version": "0.0.2", | ||
"version": "0.0.3", | ||
"engines": { | ||
@@ -12,0 +12,0 @@ "node": ">=0.4.0" |
@@ -30,2 +30,3 @@ Escodegen ([escodegen](http://github.com/Constellation/escodegen)) is | ||
See [API page](https://github.com/Constellation/escodegen/wiki/API) for options. | ||
And see [online generator demo](http://constellation.github.com/escodegen/demo/index.html). | ||
@@ -32,0 +33,0 @@ ### License |
@@ -39,2 +39,4 @@ /* | ||
'test', | ||
'api', | ||
'options', | ||
'identity' | ||
@@ -41,0 +43,0 @@ ]; |
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
59
3213100
32
90625
4