Created
July 19, 2012 09:42
-
-
Save RGustBardon/3142709 to your computer and use it in GitHub Desktop.
Illustration for issue #20 at Constellation/escodegen
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Written in 2012 by Robert Gust-Bardon <http://robert.gust-bardon.org/>. | |
# To the extent possible under law, the author(s) have dedicated all copyright | |
# and related and neighboring rights to this software to the public domain | |
# worldwide. This software is distributed without any warranty. | |
# | |
# You should have received a copy of the CC0 Public Domain Dedication along | |
# with this software. If not, see | |
# <http://creativecommons.org/publicdomain/zero/1.0/>. | |
# Requires updating $ESPRIMA and $ESCODEGEN to appropriate paths. | |
# Tested under Ubuntu 12.04 LTS. | |
ESPRIMA="$HOME/github/ariya/esprima" | |
ESCODEGEN="$HOME/github/Constellation/escodegen" | |
TEMP="$(mktemp)" | |
cat <<'ENDH' > "$TEMP" | |
try{}// | |
finally{} | |
ENDH | |
node <<ENDH | |
var program = require('fs').readFileSync('$TEMP', 'utf8'), | |
inspect = require('util').inspect, | |
parse = require('$ESPRIMA/esprima').parse, | |
options = { | |
comment: true, | |
range: true, | |
loc: true, | |
tokens: true, | |
raw: true | |
}, | |
escodegen = | |
require('$ESCODEGEN/escodegen'), | |
tree = parse(program, options), | |
code; | |
console.log("#### The original program"); | |
console.log(program); | |
console.log("#### The original tree"); | |
console.log(inspect(tree, null, null)); | |
tree = escodegen.attachComments(tree, tree.comments, tree.tokens); | |
console.log("#### The tree with comments attached"); | |
console.log(inspect(tree, null, null)); | |
code = escodegen.generate(tree, {comment: true}); | |
console.log("#### Generated code"); | |
console.log(code); | |
console.log("#### The tree for the generated code"); | |
console.log(inspect(parse(code, options))); | |
ENDH | |
echo "#### Node version" | |
node -v | |
echo "#### Esprima version" | |
cd "$ESPRIMA" | |
git branch | grep '\*' | |
git log --pretty=oneline | head -1 | |
echo "#### escodegen version" | |
cd "$ESCODEGEN" | |
git branch | grep '\*' | |
git log --pretty=oneline | head -1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment