File tree Expand file tree Collapse file tree 6 files changed +105
-0
lines changed Expand file tree Collapse file tree 6 files changed +105
-0
lines changed Original file line number Diff line number Diff line change 1+ # ast-grep napi language for tsx  
2+ 
3+ ## Installation  
4+ 
5+ In a pnpm project, run:
6+ 
7+ ``` bash 
8+ pnpm install @ast-grep/lang-tsx
9+ pnpm install @ast-grep/napi
10+ #  install the tree-sitter-cli if no prebuild is available
11+ pnpm install @tree-sitter/cli --save-dev
12+ ``` 
13+ 
14+ ## Usage  
15+ 
16+ ``` js 
17+ import  tsx  from  ' @ast-grep/lang-tsx' 
18+ import  { registerDynamicLanguage , parse  } from  ' @ast-grep/napi' 
19+ 
20+ registerDynamicLanguage ({ tsx })
21+ 
22+ const  sg  =  parse (' tsx'  , ` your code`  )
23+ sg .root ().kind ()
24+ ``` 
Original file line number Diff line number Diff line change 1+ type  LanguageRegistration  =  { 
2+   libraryPath : string 
3+   extensions : string [ ] 
4+   languageSymbol ?: string 
5+   metaVarChar ?: string 
6+   expandoChar ?: string 
7+ } 
8+ 
9+ declare  const  registration : LanguageRegistration 
10+ export  default  registration 
Original file line number Diff line number Diff line change 1+ const  path  =  require ( 'node:path' ) 
2+ const  libPath  =  path . join ( __dirname ,  'parser.so' ) 
3+ 
4+ module . exports  =  { 
5+   libraryPath : libPath , 
6+   extensions : [ 'tsx' ] , 
7+   languageSymbol : 'tree_sitter_tsx' , 
8+   expandoChar : '$' , 
9+ } 
Original file line number Diff line number Diff line change 1+ const  {  setup }  =  require ( '@ast-grep/nursery' ) 
2+ const  languageRegistration  =  require ( './index' ) 
3+ 
4+ setup ( { 
5+   dirname : __dirname , 
6+   name : 'tsx' , 
7+   treeSitterPackage : 'tree-sitter-tsx' , 
8+   languageRegistration, 
9+   testRunner : parse  =>  { 
10+     // add test here 
11+   } , 
12+ } ) 
Original file line number Diff line number Diff line change 1+ {
2+   "name" : " @ast-grep/lang-tsx"  ,
3+   "version" : " 0.0.1"  ,
4+   "description" : " "  ,
5+   "main" : " index.js"  ,
6+   "scripts" : {
7+     "build" : " tree-sitter build -o parser.so"  ,
8+     "source" : " node nursery.js source"  ,
9+     "prepublishOnly" : " node nursery.js source"  ,
10+     "postinstall" : " node postinstall.js"  ,
11+     "test" : " node nursery.js test" 
12+   },
13+   "files" : [
14+     " index.js"  ,
15+     " index.d.ts"  ,
16+     " type.d.ts"  ,
17+     " postinstall.js"  ,
18+     " src"  ,
19+     " prebuilds" 
20+   ],
21+   "keywords" : [" ast-grep"  ],
22+   "author" : " "  ,
23+   "license" : " ISC"  ,
24+   "dependencies" : {
25+     "@ast-grep/setup-lang" : " 0.0.3" 
26+   },
27+   "peerDependencies" : {
28+     "tree-sitter-cli" : " 0.24.6" 
29+   },
30+   "peerDependenciesMeta" : {
31+     "tree-sitter-cli" : {
32+       "optional" : true 
33+     }
34+   },
35+   "devDependencies" : {
36+     "@ast-grep/nursery" : " 0.0.2"  ,
37+     "tree-sitter-cli" : " 0.24.6" 
38+   },
39+   "publishConfig" : {
40+     "access" : " public"  ,
41+     "registry" : " https://registry.npmjs.org/" 
42+   },
43+   "pnpm" : {
44+     "onlyBuiltDependencies" : [" @ast-grep/lang-tsx"  , " tree-sitter-cli"  ]
45+   }
46+ }
Original file line number Diff line number Diff line change 1+ const  {  postinstall }  =  require ( '@ast-grep/setup-lang' ) 
2+ postinstall ( { 
3+   dirname : __dirname , 
4+ } ) 
    
 
   
 
     
   
   
          
     
  
    
     
 
    
      
     
 
     
    You can’t perform that action at this time.
  
 
    
  
     
    
      
        
     
 
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments