escodegen
Advanced tools
Comparing version 0.0.5 to 0.0.6
@@ -9,3 +9,3 @@ { | ||
}, | ||
"version": "0.0.5", | ||
"version": "0.0.6", | ||
"engines": { | ||
@@ -12,0 +12,0 @@ "node": ">=0.4.0" |
@@ -5,3 +5,7 @@ Escodegen ([escodegen](http://github.com/Constellation/escodegen)) is | ||
code generator from [Parser API](https://developer.mozilla.org/en/SpiderMonkey/Parser_API) AST. | ||
See [online generator demo](http://constellation.github.com/escodegen/demo/index.html). | ||
### Install | ||
Escodegen can be used in a web browser: | ||
@@ -16,4 +20,6 @@ | ||
simple example: | ||
### Usage | ||
A simple example: the program | ||
escodegen.generate({ | ||
@@ -26,10 +32,8 @@ type: 'BinaryExpression', | ||
and gets following string | ||
produces the string `'40 + 2'` | ||
40 + 2 | ||
See the [API page](https://github.com/Constellation/escodegen/wiki/API) for | ||
options. To run the tests, execute `npm test` in the root directory. | ||
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). | ||
### License | ||
@@ -36,0 +40,0 @@ |
@@ -596,3 +596,5 @@ /* | ||
'({})': ' ({});', | ||
'(function(){})': ' (function () {\n });' | ||
'(function(){})': ' (function () {\n });', | ||
'/ / / / /': ' / / / / /;', | ||
'/ / /10': ' / / / 10;' | ||
} | ||
@@ -658,3 +660,5 @@ }, { | ||
'({})': '({});', | ||
'(function(){})': '(function(){});' | ||
'(function(){})': '(function(){});', | ||
'/ / / / /': '/ // / /;', | ||
'/ / /1': '/ //1;' | ||
} | ||
@@ -695,2 +699,132 @@ }, { | ||
} | ||
}, { | ||
options: { | ||
format: { | ||
indent: { | ||
base: 1, | ||
style: ' ' | ||
}, | ||
semicolons: true | ||
} | ||
}, | ||
items: { | ||
'{}': ' {\n }', | ||
'{;}': ' {\n ;\n }', | ||
'{42}': ' {\n 42;\n }', | ||
'if(42);': ' if (42);', | ||
'if(42)42': ' if (42)\n 42;', | ||
'if(42);else;': ' if (42);\n else ;', | ||
'if(42)42;else 42': ' if (42)\n 42;\n else\n 42;', | ||
'do;while(42)': ' do ;\n while (42);', | ||
'do 42;while(42)': ' do\n 42;\n while (42);', | ||
'while(42);': ' while (42);', | ||
'while(42)42': ' while (42)\n 42;', | ||
'for(;;);': ' for (;;);', | ||
'for(;;)42': ' for (;;)\n 42;', | ||
'for(foo in 42);': ' for (foo in 42);', | ||
'for(foo in 42)42': ' for (foo in 42)\n 42;', | ||
'with({});': ' with ({});', | ||
'with({})42': ' with ({})\n 42;', | ||
'switch(42){default:}': ' switch (42) {\n default:\n }', | ||
'switch(42){default:;}': ' switch (42) {\n default:\n ;\n }', | ||
'switch(42){default:42}': ' switch (42) {\n default:\n 42;\n }', | ||
'foo:;': ' foo:;', | ||
'foo:42': ' foo:\n 42;', | ||
'try{}catch(foo){}finally{}': ' try {\n } catch (foo) {\n } finally {\n }', | ||
'try{;}catch(foo){;}finally{;}': ' try {\n ;\n } catch (foo) {\n ;\n } finally {\n ;\n }', | ||
'try{42}catch(foo){42}finally{42}': ' try {\n 42;\n } catch (foo) {\n 42;\n } finally {\n 42;\n }', | ||
'!function(){}': ' !function () {\n };', | ||
'!function(){;}': ' !function () {\n ;\n };', | ||
'!function(){42}': ' !function () {\n 42;\n };', | ||
'': '', | ||
';': ' ;', | ||
'42': ' 42;', | ||
'42;foo': ' 42;\n foo;' | ||
} | ||
}, { | ||
options: { | ||
format: { | ||
indent: { | ||
base: 1, | ||
style: ' ' | ||
}, | ||
semicolons: false | ||
} | ||
}, | ||
items: { | ||
'{}': ' {\n }', | ||
'{;}': ' {\n ;\n }', | ||
'{42}': ' {\n 42\n }', | ||
'if(42);': ' if (42);', | ||
'if(42)42': ' if (42)\n 42', | ||
'if(42);else;': ' if (42);\n else ;', | ||
'if(42)42;else 42': ' if (42)\n 42;\n else\n 42', | ||
'do;while(42)': ' do ;\n while (42)', | ||
'do 42;while(42)': ' do\n 42;\n while (42)', | ||
'while(42);': ' while (42);', | ||
'while(42)42': ' while (42)\n 42', | ||
'for(;;);': ' for (;;);', | ||
'for(;;)42': ' for (;;)\n 42', | ||
'for(foo in 42);': ' for (foo in 42);', | ||
'for(foo in 42)42': ' for (foo in 42)\n 42', | ||
'with({});': ' with ({});', | ||
'with({})42': ' with ({})\n 42', | ||
'switch(42){default:}': ' switch (42) {\n default:\n }', | ||
'switch(42){default:;}': ' switch (42) {\n default:\n ;\n }', | ||
'switch(42){default:42}': ' switch (42) {\n default:\n 42\n }', | ||
'foo:;': ' foo:;', | ||
'foo:42': ' foo:\n 42', | ||
'try{}catch(foo){}finally{}': ' try {\n } catch (foo) {\n } finally {\n }', | ||
'try{;}catch(foo){;}finally{;}': ' try {\n ;\n } catch (foo) {\n ;\n } finally {\n ;\n }', | ||
'try{42}catch(foo){42}finally{42}': ' try {\n 42\n } catch (foo) {\n 42\n } finally {\n 42\n }', | ||
'!function(){}': ' !function () {\n }', | ||
'!function(){;}': ' !function () {\n ;\n }', | ||
'!function(){42}': ' !function () {\n 42\n }', | ||
'': '', | ||
';': ' ;', | ||
'42': ' 42', | ||
'42;foo': ' 42;\n foo' | ||
} | ||
}, { | ||
options: { | ||
format: { | ||
compact: true, | ||
semicolons: false | ||
} | ||
}, | ||
items: { | ||
'switch(42){case 42:42;default:}': 'switch(42){case 42:42;default:}' | ||
} | ||
}, { | ||
options: { | ||
comment: true, | ||
format: { | ||
compact: true, | ||
semicolons: false, | ||
safeConcatenation: false | ||
} | ||
}, | ||
items: { | ||
'': '', | ||
'//A': '//A', | ||
'{}': '{}', | ||
'!{}': '!{}', | ||
'{}//A': '{}//A' | ||
} | ||
}, { | ||
options: { | ||
comment: true, | ||
format: { | ||
compact: true, | ||
semicolons: false, | ||
safeConcatenation: true | ||
} | ||
}, | ||
items: { | ||
'': '', | ||
'//A': '\n//A\n', | ||
'{}': '\n{}', | ||
'!{}': '\n!{};', | ||
'{}//A': '\n{}//A\n' | ||
} | ||
}]; | ||
@@ -728,7 +862,19 @@ | ||
function runTest(options, source, expectedCode) { | ||
var tree, actualTree, expectedTree, actualCode; | ||
var tree, actualTree, expectedTree, actualCode, optionsParser = { | ||
raw: true | ||
}; | ||
if (options.comment) { | ||
optionsParser.comment = true; | ||
optionsParser.range = true; | ||
optionsParser.loc = true; | ||
optionsParser.tokens = true; | ||
} | ||
try { | ||
tree = esprima.parse(source); | ||
expectedTree = JSON.stringify(tree, adjustRegexLiteral, 4); | ||
actualCode = escodegen.generate(esprima.parse(source, {raw: true}), options); | ||
tree = esprima.parse(source, optionsParser); | ||
if (options.comment) { | ||
tree = escodegen.attachComments(tree, tree.comments, tree.tokens); | ||
} | ||
actualCode = escodegen.generate(tree, options); | ||
tree = esprima.parse(actualCode); | ||
@@ -735,0 +881,0 @@ actualTree = JSON.stringify(tree, adjustRegexLiteral, 4); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
4309434
107358
63
94