forked from jashkenas/coffeescript
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add output testing script for debugging compiles
- Loading branch information
1 parent
817c39a
commit a7c9f2b
Showing
1 changed file
with
55 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
assert = require 'assert' | ||
process = require 'process' | ||
coffee = require './lib/coffeescript/index.js' | ||
|
||
[input, ...] = process.argv[2..] | ||
|
||
|
||
rawTokens = (input) -> {type, value} for [type, value] in coffee.tokens input | ||
|
||
encodeTokens = (input) -> for {type, value} in rawTokens input | ||
value = value.toString() | ||
if type.match(/^[A-Z_]+$/) or type is 'BIN?' | ||
if value.match /^\s+$/ | ||
{whitespace: type, value: encodeURIComponent value} | ||
else | ||
{type, value} | ||
else | ||
assert (type is value), JSON.stringify {type, value} | ||
{punct: value} | ||
|
||
tokenPrint = (input) -> for {punct, whitespace, type, value} in encodeTokens input | ||
if punct? | ||
": #{punct}" | ||
else if whitespace? | ||
"#{whitespace}('#{value}')" | ||
else | ||
"#{type}(#{value})" | ||
|
||
nodes = (input) -> coffee.nodes input | ||
# .body.expressions[0].params[0].name.properties[0] | ||
|
||
compiled = (input) -> coffee.compile input, bare: yes | ||
|
||
evaled = (input) -> coffee.eval input | ||
|
||
|
||
{TOK, AST, AST_PATH, COMP, EV} = process.env | ||
output = if TOK? | ||
switch TOK | ||
when 'raw' then rawTokens input | ||
when 'enc' then encodeTokens input | ||
else (tokenPrint input).join '\n' | ||
else if AST? | ||
ret = nodes input | ||
if AST_PATH? | ||
eval "ret#{AST_PATH}" | ||
else | ||
ret | ||
else if COMP? | ||
compiled input | ||
else if EV? | ||
evaled input | ||
else throw new Error('wtf') | ||
|
||
console.log output |