@@ -3,7 +3,6 @@ var fs = require("fs");
33var path = require ( "path" ) ;
44var types = require ( "../lib/types" ) ;
55var parse = require ( "../lib/parser" ) . parse ;
6- var Visitor = require ( "../lib/visitor" ) . Visitor ;
76
87describe ( "syntax" , function ( ) {
98 // Make sure we handle all possible node types in Syntax, and no additional
@@ -17,49 +16,39 @@ describe("syntax", function() {
1716 var ast = parse ( data ) ;
1817 assert . ok ( ast ) ;
1918
20- var types = { } ;
21- new GenericPrintVisitor ( types ) . visit ( ast ) ;
19+ var typeNames = { } ;
20+ types . visit ( ast , {
21+ visitFunctionDeclaration : function ( path ) {
22+ var decl = path . node ;
23+ if ( types . namedTypes . Identifier . check ( decl . id ) &&
24+ decl . id . name === "genericPrintNoParens" ) {
25+ this . traverse ( path , {
26+ visitSwitchCase : function ( path ) {
27+ var test = path . node . test ;
28+ if ( test &&
29+ test . type === "Literal" &&
30+ typeof test . value === "string" ) {
31+ var name = test . value ;
32+ typeNames [ name ] = name ;
33+ }
34+ return false ;
35+ }
36+ } ) ;
37+ } else {
38+ this . traverse ( path ) ;
39+ }
40+ }
41+ } ) ;
2242
2343 for ( var name in types . namedTypes ) {
2444 if ( types . namedTypes . hasOwnProperty ( name ) ) {
25- assert . ok ( types . hasOwnProperty ( name ) , "unhandled type: " + name ) ;
26- assert . strictEqual ( name , types [ name ] ) ;
27- delete types [ name ] ;
45+ assert . ok ( typeNames . hasOwnProperty ( name ) , "unhandled type: " + name ) ;
46+ assert . strictEqual ( name , typeNames [ name ] ) ;
47+ delete typeNames [ name ] ;
2848 }
2949 }
3050
3151 done ( ) ;
3252 } ) ;
3353 } ) ;
34-
35- var GenericPrintVisitor = Visitor . extend ( {
36- init : function ( types ) {
37- this . types = types ;
38- } ,
39-
40- visitFunctionDeclaration : function ( decl ) {
41- if ( types . namedTypes . Identifier . check ( decl . id ) &&
42- decl . id . name === "genericPrintNoParens" )
43- {
44- new CaseVisitor ( this . types ) . visit ( decl ) ;
45- }
46- }
47- } )
48-
49- var CaseVisitor = Visitor . extend ( {
50- init : function ( types ) {
51- this . types = types ;
52- } ,
53-
54- visitSwitchCase : function ( expr ) {
55- var test = expr . test ;
56- if ( test &&
57- test . type === "Literal" &&
58- typeof test . value === "string" )
59- {
60- var name = test . value ;
61- this . types [ name ] = name ;
62- }
63- }
64- } ) ;
6554} ) ;
0 commit comments