[{"data":1,"prerenderedAt":529},["ShallowReactive",2],{"page:\u002Fextensions\u002Fkubb-labs\u002Fparser-ts":3},{"id":4,"frontmatter":5,"title":6,"heading":6,"body":7,"path":528,"source":4},"extensions\u002Fkubb-labs\u002Fparser-ts\u002Findex.md",{},"TypeScript",{"type":8,"value":9,"toc":519},"minimark",[10,23,37,42,128,149,153,190,194,226,237,245,249,260],[11,12,13,14,18,19,22],"p",{},"The TypeScript parser writes ",[15,16,17],"code",{},".ts"," and ",[15,20,21],{},".js"," files. It turns each file's AST into source text with imports, exports, declarations, and JSDoc, and resolves relative import paths.",[11,24,25,26,29,30,18,33,36],{},"The package also exports ",[15,27,28],{},"parserTsx",", which writes ",[15,31,32],{},".tsx",[15,34,35],{},".jsx"," files with the same options.",[38,39,41],"h2",{"id":40},"installation","Installation",[43,44,46,75,93,111],"code-group",{"sync":45},"package-manager",[47,48,53],"pre",{"language":49,"filename":50,"code":51,"class":52},"shell","bun","bun add -d @kubb\u002Fparser-ts","highlights",[15,54,56],{"class":55},"language-shell",[57,58,61,65,69,72],"span",{"class":59,"style":60},"line","display: inline",[57,62,64],{"style":63},"color:#6f42c1;--hls-dark:#b392f0","bun ",[57,66,68],{"style":67},"color:#24292e;--hls-dark:#e1e4e8","add -d ",[57,70,71],{"style":67},"@",[57,73,74],{"style":67},"kubb\u002Fparser-ts",[47,76,79],{"language":49,"filename":77,"code":78,"class":52},"pnpm","pnpm add -D @kubb\u002Fparser-ts",[15,80,81],{"class":55},[57,82,83,86,89,91],{"class":59,"style":60},[57,84,85],{"style":63},"pnpm ",[57,87,88],{"style":67},"add -D ",[57,90,71],{"style":67},[57,92,74],{"style":67},[47,94,97],{"language":49,"filename":95,"code":96,"class":52},"npm","npm install --save-dev @kubb\u002Fparser-ts",[15,98,99],{"class":55},[57,100,101,104,107,109],{"class":59,"style":60},[57,102,103],{"style":63},"npm ",[57,105,106],{"style":67},"install --save-dev ",[57,108,71],{"style":67},[57,110,74],{"style":67},[47,112,115],{"language":49,"filename":113,"code":114,"class":52},"yarn","yarn add -D @kubb\u002Fparser-ts",[15,116,117],{"class":55},[57,118,119,122,124,126],{"class":59,"style":60},[57,120,121],{"style":63},"yarn ",[57,123,88],{"style":67},[57,125,71],{"style":67},[57,127,74],{"style":67},[11,129,130,131,134,135,140,141,144,145,148],{},"Or run ",[15,132,133],{},"kubb add parser-ts"," to install the version the ",[136,137,139],"a",{"href":138},"\u002Fregistry","Kubb registry"," pins and add ",[15,142,143],{},"parserTs()"," to ",[15,146,147],{},"kubb.config.ts",".",[38,150,152],{"id":151},"setup","Setup",[11,154,155,156,159,160,163,164,167,168,170,171,174,175,18,177,179,180,183,184,186,187,189],{},"With ",[15,157,158],{},"defineConfig"," from ",[15,161,162],{},"kubb\u002Fconfig",", Kubb registers ",[15,165,166],{},"parserTs",", ",[15,169,28],{},", and ",[15,172,173],{},"parserMd"," by default, so no setup is needed. Bundler integrations register only ",[15,176,166],{},[15,178,28],{},". Set ",[15,181,182],{},"parsers"," in ",[15,185,158],{}," only to change an option or add a parser. A custom ",[15,188,182],{}," array replaces the default set, so list every parser your plugins need. Files that no parser claims are written as their source text only, without imports, exports, banner, or footer.",[38,191,193],{"id":192},"options-worth-knowing","Options worth knowing",[195,196,197],"ul",{},[198,199,200,203,204,207,208,210,211,214,215,218,219,221,222,225],"li",{},[15,201,202],{},"extension"," rewrites the extension of relative imports and exports. Each key is a generated file's extension, and each value is the extension its relative imports and exports get. ",[15,205,206],{},"''"," drops it. By default, imports in ",[15,209,17],{}," files have no extension. Use ",[15,212,213],{},"{ '.ts': '.js' }"," for ESM packages. Use ",[15,216,217],{},"{ '.ts': '.ts' }"," when Node.js runs the ",[15,220,17],{}," files directly, or when you compile with ",[15,223,224],{},"rewriteRelativeImportExtensions",". Package imports stay unchanged.",[11,227,228,230,231,233,234,236],{},[15,229,28],{}," reads its own ",[15,232,202],{}," map, so set the ",[15,235,32],{}," key on it as well.",[11,238,239,240,244],{},"See ",[136,241,243],{"href":242},"https:\u002F\u002Fkubb.dev\u002Fextensions\u002Fkubb-labs\u002Fparser-ts\u002Foptions","Options"," for its type and default.",[38,246,248],{"id":247},"example","Example",[11,250,251,252,254,255,18,257,259],{},"The config below adds ",[15,253,21],{}," to relative imports in ",[15,256,17],{},[15,258,32],{}," files and keeps every default parser registered.",[47,261,264],{"language":262,"filename":147,"code":263,"class":52},"typescript","import { defineConfig } from 'kubb\u002Fconfig'\nimport { parserMd } from '@kubb\u002Fparser-md'\nimport { parserTs, parserTsx } from '@kubb\u002Fparser-ts'\nimport { pluginTs } from '@kubb\u002Fplugin-ts'\n\nexport default defineConfig({\n  input: '.\u002FpetStore.yaml',\n  output: { path: '.\u002Fsrc\u002Fgen' },\n  parsers: [\n    parserTs({ extension: { '.ts': '.js' } }),\n    parserTsx({ extension: { '.tsx': '.js' } }),\n    parserMd(),\n  ],\n  plugins: [\n    pluginTs(),\n  ],\n})",[15,265,267,290,291,290,307,290,327,290,343,290,345,290,358,290,375,290,399,290,410,290,439,290,464,290,475,290,484,290,495,290,506,290,514],{"class":266},"language-typescript",[57,268,269,273,277,280,283,286],{"class":59,"style":60},[57,270,272],{"style":271},"color:#d73a49;--hls-dark:#f97583","import ",[57,274,276],{"style":275},"color:#005cc5;--hls-dark:#79b8ff","{ ",[57,278,279],{"style":67},"defineConfig ",[57,281,282],{"style":275},"} ",[57,284,285],{"style":271},"from ",[57,287,289],{"style":288},"color:#032f62;--hls-dark:#9ecbff","'kubb\u002Fconfig'","\n",[57,292,293,295,297,300,302,304],{"class":59,"style":60},[57,294,272],{"style":271},[57,296,276],{"style":275},[57,298,299],{"style":67},"parserMd ",[57,301,282],{"style":275},[57,303,285],{"style":271},[57,305,306],{"style":288},"'@kubb\u002Fparser-md'",[57,308,309,311,313,315,317,320,322,324],{"class":59,"style":60},[57,310,272],{"style":271},[57,312,276],{"style":275},[57,314,166],{"style":67},[57,316,167],{"style":271},[57,318,319],{"style":67},"parserTsx ",[57,321,282],{"style":275},[57,323,285],{"style":271},[57,325,326],{"style":288},"'@kubb\u002Fparser-ts'",[57,328,329,331,333,336,338,340],{"class":59,"style":60},[57,330,272],{"style":271},[57,332,276],{"style":275},[57,334,335],{"style":67},"pluginTs ",[57,337,282],{"style":275},[57,339,285],{"style":271},[57,341,342],{"style":288},"'@kubb\u002Fplugin-ts'",[57,344],{"class":59,"style":60},[57,346,347,350,353,355],{"class":59,"style":60},[57,348,349],{"style":271},"export ",[57,351,352],{"style":271},"default ",[57,354,158],{"style":63},[57,356,357],{"style":275},"({",[57,359,360,363,366,369,372],{"class":59,"style":60},[57,361,362],{"style":275},"  ",[57,364,365],{"style":275},"input",[57,367,368],{"style":271},": ",[57,370,371],{"style":288},"'.\u002FpetStore.yaml'",[57,373,374],{"style":271},",",[57,376,377,379,382,384,386,389,391,394,397],{"class":59,"style":60},[57,378,362],{"style":271},[57,380,381],{"style":275},"output",[57,383,368],{"style":271},[57,385,276],{"style":275},[57,387,388],{"style":275},"path",[57,390,368],{"style":271},[57,392,393],{"style":288},"'.\u002Fsrc\u002Fgen' ",[57,395,396],{"style":275},"}",[57,398,374],{"style":271},[57,400,401,403,405,407],{"class":59,"style":60},[57,402,362],{"style":271},[57,404,182],{"style":275},[57,406,368],{"style":271},[57,408,409],{"style":275},"[",[57,411,412,415,417,420,422,424,426,429,431,434,437],{"class":59,"style":60},[57,413,414],{"style":275},"    ",[57,416,166],{"style":63},[57,418,419],{"style":275},"({ ",[57,421,202],{"style":275},[57,423,368],{"style":271},[57,425,276],{"style":275},[57,427,428],{"style":288},"'.ts'",[57,430,368],{"style":271},[57,432,433],{"style":288},"'.js' ",[57,435,436],{"style":275},"} })",[57,438,374],{"style":271},[57,440,441,443,445,447,449,451,453,456,458,460,462],{"class":59,"style":60},[57,442,414],{"style":271},[57,444,28],{"style":63},[57,446,419],{"style":275},[57,448,202],{"style":275},[57,450,368],{"style":271},[57,452,276],{"style":275},[57,454,455],{"style":288},"'.tsx'",[57,457,368],{"style":271},[57,459,433],{"style":288},[57,461,436],{"style":275},[57,463,374],{"style":271},[57,465,466,468,470,473],{"class":59,"style":60},[57,467,414],{"style":271},[57,469,173],{"style":63},[57,471,472],{"style":275},"()",[57,474,374],{"style":271},[57,476,477,479,482],{"class":59,"style":60},[57,478,362],{"style":271},[57,480,481],{"style":275},"]",[57,483,374],{"style":271},[57,485,486,488,491,493],{"class":59,"style":60},[57,487,362],{"style":271},[57,489,490],{"style":275},"plugins",[57,492,368],{"style":271},[57,494,409],{"style":275},[57,496,497,499,502,504],{"class":59,"style":60},[57,498,414],{"style":275},[57,500,501],{"style":63},"pluginTs",[57,503,472],{"style":275},[57,505,374],{"style":271},[57,507,508,510,512],{"class":59,"style":60},[57,509,362],{"style":271},[57,511,481],{"style":275},[57,513,374],{"style":271},[57,515,516],{"class":59,"style":60},[57,517,518],{"style":275},"})",{"title":520,"searchDepth":521,"depth":521,"links":522},"",5,[523,525,526,527],{"id":40,"depth":524,"text":41},2,{"id":151,"depth":524,"text":152},{"id":192,"depth":524,"text":193},{"id":247,"depth":524,"text":248},"\u002Fextensions\u002Fkubb-labs\u002Fparser-ts",1793639044172]