index.d.ts 86 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273
  1. declare const wrapperJs: string;
  2. // Type definitions for non-npm package estree 1.0
  3. // Project: https://github.com/estree/estree
  4. // Definitions by: RReverser <https://github.com/RReverser>
  5. // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
  6. // This definition file follows a somewhat unusual format. ESTree allows
  7. // runtime type checks based on the `type` parameter. In order to explain this
  8. // to typescript we want to use discriminated union types:
  9. // https://github.com/Microsoft/TypeScript/pull/9163
  10. //
  11. // For ESTree this is a bit tricky because the high level interfaces like
  12. // Node or Function are pulling double duty. We want to pass common fields down
  13. // to the interfaces that extend them (like Identifier or
  14. // ArrowFunctionExpression), but you can't extend a type union or enforce
  15. // common fields on them. So we've split the high level interfaces into two
  16. // types, a base type which passes down inherited fields, and a type union of
  17. // all types which extend the base type. Only the type union is exported, and
  18. // the union is how other types refer to the collection of inheriting types.
  19. //
  20. // This makes the definitions file here somewhat more difficult to maintain,
  21. // but it has the notable advantage of making ESTree much easier to use as
  22. // an end user.
  23. interface BaseNodeWithoutComments {
  24. // Every leaf interface that extends BaseNode must specify a type property.
  25. // The type property should be a string literal. For example, Identifier
  26. // has: `type: "Identifier"`
  27. type: string;
  28. loc?: SourceLocation | null | undefined;
  29. range?: [number, number] | undefined;
  30. }
  31. interface BaseNode extends BaseNodeWithoutComments {
  32. leadingComments?: Comment$1[] | undefined;
  33. trailingComments?: Comment$1[] | undefined;
  34. }
  35. interface Comment$1 extends BaseNodeWithoutComments {
  36. type: 'Line' | 'Block';
  37. value: string;
  38. }
  39. interface SourceLocation {
  40. source?: string | null | undefined;
  41. start: Position$4;
  42. end: Position$4;
  43. }
  44. interface Position$4 {
  45. /** >= 1 */
  46. line: number;
  47. /** >= 0 */
  48. column: number;
  49. }
  50. interface BaseFunction extends BaseNode {
  51. params: Pattern[];
  52. generator?: boolean | undefined;
  53. async?: boolean | undefined;
  54. // The body is either BlockStatement or Expression because arrow functions
  55. // can have a body that's either. FunctionDeclarations and
  56. // FunctionExpressions have only BlockStatement bodies.
  57. body: BlockStatement | Expression;
  58. }
  59. type Statement =
  60. | ExpressionStatement
  61. | BlockStatement
  62. | StaticBlock
  63. | EmptyStatement
  64. | DebuggerStatement
  65. | WithStatement
  66. | ReturnStatement
  67. | LabeledStatement
  68. | BreakStatement
  69. | ContinueStatement
  70. | IfStatement
  71. | SwitchStatement
  72. | ThrowStatement
  73. | TryStatement
  74. | WhileStatement
  75. | DoWhileStatement
  76. | ForStatement
  77. | ForInStatement
  78. | ForOfStatement
  79. | Declaration;
  80. interface BaseStatement extends BaseNode {}
  81. interface EmptyStatement extends BaseStatement {
  82. type: 'EmptyStatement';
  83. }
  84. interface BlockStatement extends BaseStatement {
  85. type: 'BlockStatement';
  86. body: Statement[];
  87. innerComments?: Comment$1[] | undefined;
  88. }
  89. interface StaticBlock extends Omit<BlockStatement, 'type'> {
  90. type: 'StaticBlock';
  91. }
  92. interface ExpressionStatement extends BaseStatement {
  93. type: 'ExpressionStatement';
  94. expression: Expression;
  95. }
  96. interface IfStatement extends BaseStatement {
  97. type: 'IfStatement';
  98. test: Expression;
  99. consequent: Statement;
  100. alternate?: Statement | null | undefined;
  101. }
  102. interface LabeledStatement extends BaseStatement {
  103. type: 'LabeledStatement';
  104. label: Identifier;
  105. body: Statement;
  106. }
  107. interface BreakStatement extends BaseStatement {
  108. type: 'BreakStatement';
  109. label?: Identifier | null | undefined;
  110. }
  111. interface ContinueStatement extends BaseStatement {
  112. type: 'ContinueStatement';
  113. label?: Identifier | null | undefined;
  114. }
  115. interface WithStatement extends BaseStatement {
  116. type: 'WithStatement';
  117. object: Expression;
  118. body: Statement;
  119. }
  120. interface SwitchStatement extends BaseStatement {
  121. type: 'SwitchStatement';
  122. discriminant: Expression;
  123. cases: SwitchCase[];
  124. }
  125. interface ReturnStatement extends BaseStatement {
  126. type: 'ReturnStatement';
  127. argument?: Expression | null | undefined;
  128. }
  129. interface ThrowStatement extends BaseStatement {
  130. type: 'ThrowStatement';
  131. argument: Expression;
  132. }
  133. interface TryStatement extends BaseStatement {
  134. type: 'TryStatement';
  135. block: BlockStatement;
  136. handler?: CatchClause | null | undefined;
  137. finalizer?: BlockStatement | null | undefined;
  138. }
  139. interface WhileStatement extends BaseStatement {
  140. type: 'WhileStatement';
  141. test: Expression;
  142. body: Statement;
  143. }
  144. interface DoWhileStatement extends BaseStatement {
  145. type: 'DoWhileStatement';
  146. body: Statement;
  147. test: Expression;
  148. }
  149. interface ForStatement extends BaseStatement {
  150. type: 'ForStatement';
  151. init?: VariableDeclaration | Expression | null | undefined;
  152. test?: Expression | null | undefined;
  153. update?: Expression | null | undefined;
  154. body: Statement;
  155. }
  156. interface BaseForXStatement extends BaseStatement {
  157. left: VariableDeclaration | Pattern;
  158. right: Expression;
  159. body: Statement;
  160. }
  161. interface ForInStatement extends BaseForXStatement {
  162. type: 'ForInStatement';
  163. }
  164. interface DebuggerStatement extends BaseStatement {
  165. type: 'DebuggerStatement';
  166. }
  167. type Declaration = FunctionDeclaration | VariableDeclaration | ClassDeclaration;
  168. interface BaseDeclaration extends BaseStatement {}
  169. interface FunctionDeclaration extends BaseFunction, BaseDeclaration {
  170. type: 'FunctionDeclaration';
  171. /** It is null when a function declaration is a part of the `export default function` statement */
  172. id: Identifier | null;
  173. body: BlockStatement;
  174. }
  175. interface VariableDeclaration extends BaseDeclaration {
  176. type: 'VariableDeclaration';
  177. declarations: VariableDeclarator[];
  178. kind: 'var' | 'let' | 'const';
  179. }
  180. interface VariableDeclarator extends BaseNode {
  181. type: 'VariableDeclarator';
  182. id: Pattern;
  183. init?: Expression | null | undefined;
  184. }
  185. interface ExpressionMap {
  186. ArrayExpression: ArrayExpression;
  187. ArrowFunctionExpression: ArrowFunctionExpression;
  188. AssignmentExpression: AssignmentExpression;
  189. AwaitExpression: AwaitExpression;
  190. BinaryExpression: BinaryExpression;
  191. CallExpression: CallExpression;
  192. ChainExpression: ChainExpression;
  193. ClassExpression: ClassExpression;
  194. ConditionalExpression: ConditionalExpression;
  195. FunctionExpression: FunctionExpression;
  196. Identifier: Identifier;
  197. ImportExpression: ImportExpression;
  198. Literal: Literal$3;
  199. LogicalExpression: LogicalExpression;
  200. MemberExpression: MemberExpression;
  201. MetaProperty: MetaProperty;
  202. NewExpression: NewExpression;
  203. ObjectExpression: ObjectExpression;
  204. SequenceExpression: SequenceExpression;
  205. TaggedTemplateExpression: TaggedTemplateExpression;
  206. TemplateLiteral: TemplateLiteral;
  207. ThisExpression: ThisExpression;
  208. UnaryExpression: UnaryExpression;
  209. UpdateExpression: UpdateExpression;
  210. YieldExpression: YieldExpression;
  211. }
  212. type Expression = ExpressionMap[keyof ExpressionMap];
  213. interface BaseExpression extends BaseNode {}
  214. type ChainElement = SimpleCallExpression | MemberExpression;
  215. interface ChainExpression extends BaseExpression {
  216. type: 'ChainExpression';
  217. expression: ChainElement;
  218. }
  219. interface ThisExpression extends BaseExpression {
  220. type: 'ThisExpression';
  221. }
  222. interface ArrayExpression extends BaseExpression {
  223. type: 'ArrayExpression';
  224. elements: Array<Expression | SpreadElement | null>;
  225. }
  226. interface ObjectExpression extends BaseExpression {
  227. type: 'ObjectExpression';
  228. properties: Array<Property | SpreadElement>;
  229. }
  230. interface PrivateIdentifier extends BaseNode {
  231. type: 'PrivateIdentifier';
  232. name: string;
  233. }
  234. interface Property extends BaseNode {
  235. type: 'Property';
  236. key: Expression | PrivateIdentifier;
  237. value: Expression | Pattern; // Could be an AssignmentProperty
  238. kind: 'init' | 'get' | 'set';
  239. method: boolean;
  240. shorthand: boolean;
  241. computed: boolean;
  242. }
  243. interface PropertyDefinition extends BaseNode {
  244. type: 'PropertyDefinition';
  245. key: Expression | PrivateIdentifier;
  246. value?: Expression | null | undefined;
  247. computed: boolean;
  248. static: boolean;
  249. }
  250. interface FunctionExpression extends BaseFunction, BaseExpression {
  251. id?: Identifier | null | undefined;
  252. type: 'FunctionExpression';
  253. body: BlockStatement;
  254. }
  255. interface SequenceExpression extends BaseExpression {
  256. type: 'SequenceExpression';
  257. expressions: Expression[];
  258. }
  259. interface UnaryExpression extends BaseExpression {
  260. type: 'UnaryExpression';
  261. operator: UnaryOperator;
  262. prefix: true;
  263. argument: Expression;
  264. }
  265. interface BinaryExpression extends BaseExpression {
  266. type: 'BinaryExpression';
  267. operator: BinaryOperator;
  268. left: Expression;
  269. right: Expression;
  270. }
  271. interface AssignmentExpression extends BaseExpression {
  272. type: 'AssignmentExpression';
  273. operator: AssignmentOperator;
  274. left: Pattern | MemberExpression;
  275. right: Expression;
  276. }
  277. interface UpdateExpression extends BaseExpression {
  278. type: 'UpdateExpression';
  279. operator: UpdateOperator;
  280. argument: Expression;
  281. prefix: boolean;
  282. }
  283. interface LogicalExpression extends BaseExpression {
  284. type: 'LogicalExpression';
  285. operator: LogicalOperator;
  286. left: Expression;
  287. right: Expression;
  288. }
  289. interface ConditionalExpression extends BaseExpression {
  290. type: 'ConditionalExpression';
  291. test: Expression;
  292. alternate: Expression;
  293. consequent: Expression;
  294. }
  295. interface BaseCallExpression extends BaseExpression {
  296. callee: Expression | Super;
  297. arguments: Array<Expression | SpreadElement>;
  298. }
  299. type CallExpression = SimpleCallExpression | NewExpression;
  300. interface SimpleCallExpression extends BaseCallExpression {
  301. type: 'CallExpression';
  302. optional: boolean;
  303. }
  304. interface NewExpression extends BaseCallExpression {
  305. type: 'NewExpression';
  306. }
  307. interface MemberExpression extends BaseExpression, BasePattern {
  308. type: 'MemberExpression';
  309. object: Expression | Super;
  310. property: Expression | PrivateIdentifier;
  311. computed: boolean;
  312. optional: boolean;
  313. }
  314. type Pattern = Identifier | ObjectPattern | ArrayPattern | RestElement | AssignmentPattern | MemberExpression;
  315. interface BasePattern extends BaseNode {}
  316. interface SwitchCase extends BaseNode {
  317. type: 'SwitchCase';
  318. test?: Expression | null | undefined;
  319. consequent: Statement[];
  320. }
  321. interface CatchClause extends BaseNode {
  322. type: 'CatchClause';
  323. param: Pattern | null;
  324. body: BlockStatement;
  325. }
  326. interface Identifier extends BaseNode, BaseExpression, BasePattern {
  327. type: 'Identifier';
  328. name: string;
  329. }
  330. type Literal$3 = SimpleLiteral | RegExpLiteral | BigIntLiteral;
  331. interface SimpleLiteral extends BaseNode, BaseExpression {
  332. type: 'Literal';
  333. value: string | boolean | number | null;
  334. raw?: string | undefined;
  335. }
  336. interface RegExpLiteral extends BaseNode, BaseExpression {
  337. type: 'Literal';
  338. value?: RegExp | null | undefined;
  339. regex: {
  340. pattern: string;
  341. flags: string;
  342. };
  343. raw?: string | undefined;
  344. }
  345. interface BigIntLiteral extends BaseNode, BaseExpression {
  346. type: 'Literal';
  347. value?: bigint | null | undefined;
  348. bigint: string;
  349. raw?: string | undefined;
  350. }
  351. type UnaryOperator = '-' | '+' | '!' | '~' | 'typeof' | 'void' | 'delete';
  352. type BinaryOperator =
  353. | '=='
  354. | '!='
  355. | '==='
  356. | '!=='
  357. | '<'
  358. | '<='
  359. | '>'
  360. | '>='
  361. | '<<'
  362. | '>>'
  363. | '>>>'
  364. | '+'
  365. | '-'
  366. | '*'
  367. | '/'
  368. | '%'
  369. | '**'
  370. | '|'
  371. | '^'
  372. | '&'
  373. | 'in'
  374. | 'instanceof';
  375. type LogicalOperator = '||' | '&&' | '??';
  376. type AssignmentOperator =
  377. | '='
  378. | '+='
  379. | '-='
  380. | '*='
  381. | '/='
  382. | '%='
  383. | '**='
  384. | '<<='
  385. | '>>='
  386. | '>>>='
  387. | '|='
  388. | '^='
  389. | '&=';
  390. type UpdateOperator = '++' | '--';
  391. interface ForOfStatement extends BaseForXStatement {
  392. type: 'ForOfStatement';
  393. await: boolean;
  394. }
  395. interface Super extends BaseNode {
  396. type: 'Super';
  397. }
  398. interface SpreadElement extends BaseNode {
  399. type: 'SpreadElement';
  400. argument: Expression;
  401. }
  402. interface ArrowFunctionExpression extends BaseExpression, BaseFunction {
  403. type: 'ArrowFunctionExpression';
  404. expression: boolean;
  405. body: BlockStatement | Expression;
  406. }
  407. interface YieldExpression extends BaseExpression {
  408. type: 'YieldExpression';
  409. argument?: Expression | null | undefined;
  410. delegate: boolean;
  411. }
  412. interface TemplateLiteral extends BaseExpression {
  413. type: 'TemplateLiteral';
  414. quasis: TemplateElement[];
  415. expressions: Expression[];
  416. }
  417. interface TaggedTemplateExpression extends BaseExpression {
  418. type: 'TaggedTemplateExpression';
  419. tag: Expression;
  420. quasi: TemplateLiteral;
  421. }
  422. interface TemplateElement extends BaseNode {
  423. type: 'TemplateElement';
  424. tail: boolean;
  425. value: {
  426. /** It is null when the template literal is tagged and the text has an invalid escape (e.g. - tag`\unicode and \u{55}`) */
  427. cooked?: string | null | undefined;
  428. raw: string;
  429. };
  430. }
  431. interface AssignmentProperty extends Property {
  432. value: Pattern;
  433. kind: 'init';
  434. method: boolean; // false
  435. }
  436. interface ObjectPattern extends BasePattern {
  437. type: 'ObjectPattern';
  438. properties: Array<AssignmentProperty | RestElement>;
  439. }
  440. interface ArrayPattern extends BasePattern {
  441. type: 'ArrayPattern';
  442. elements: Array<Pattern | null>;
  443. }
  444. interface RestElement extends BasePattern {
  445. type: 'RestElement';
  446. argument: Pattern;
  447. }
  448. interface AssignmentPattern extends BasePattern {
  449. type: 'AssignmentPattern';
  450. left: Pattern;
  451. right: Expression;
  452. }
  453. interface BaseClass extends BaseNode {
  454. superClass?: Expression | null | undefined;
  455. body: ClassBody;
  456. }
  457. interface ClassBody extends BaseNode {
  458. type: 'ClassBody';
  459. body: Array<MethodDefinition | PropertyDefinition | StaticBlock>;
  460. }
  461. interface MethodDefinition extends BaseNode {
  462. type: 'MethodDefinition';
  463. key: Expression | PrivateIdentifier;
  464. value: FunctionExpression;
  465. kind: 'constructor' | 'method' | 'get' | 'set';
  466. computed: boolean;
  467. static: boolean;
  468. }
  469. interface ClassDeclaration extends BaseClass, BaseDeclaration {
  470. type: 'ClassDeclaration';
  471. /** It is null when a class declaration is a part of the `export default class` statement */
  472. id: Identifier | null;
  473. }
  474. interface ClassExpression extends BaseClass, BaseExpression {
  475. type: 'ClassExpression';
  476. id?: Identifier | null | undefined;
  477. }
  478. interface MetaProperty extends BaseExpression {
  479. type: 'MetaProperty';
  480. meta: Identifier;
  481. property: Identifier;
  482. }
  483. interface ImportExpression extends BaseExpression {
  484. type: 'ImportExpression';
  485. source: Expression;
  486. }
  487. interface AwaitExpression extends BaseExpression {
  488. type: 'AwaitExpression';
  489. argument: Expression;
  490. }
  491. // Type definitions for non-npm package estree-jsx 1.0
  492. declare module 'estree' {
  493. interface ExpressionMap {
  494. JSXElement: JSXElement;
  495. }
  496. interface NodeMap {
  497. JSXIdentifier: JSXIdentifier;
  498. JSXNamespacedName: JSXNamespacedName;
  499. JSXMemberExpression: JSXMemberExpression;
  500. JSXEmptyExpression: JSXEmptyExpression;
  501. JSXExpressionContainer: JSXExpressionContainer;
  502. JSXSpreadAttribute: JSXSpreadAttribute;
  503. JSXAttribute: JSXAttribute;
  504. JSXOpeningElement: JSXOpeningElement;
  505. JSXOpeningFragment: JSXOpeningFragment;
  506. JSXClosingElement: JSXClosingElement;
  507. JSXClosingFragment: JSXClosingFragment;
  508. JSXElement: JSXElement;
  509. JSXFragment: JSXFragment;
  510. JSXText: JSXText;
  511. }
  512. }
  513. interface JSXIdentifier extends BaseNode {
  514. type: 'JSXIdentifier';
  515. name: string;
  516. }
  517. interface JSXMemberExpression extends BaseExpression {
  518. type: 'JSXMemberExpression';
  519. object: JSXMemberExpression | JSXIdentifier;
  520. property: JSXIdentifier;
  521. }
  522. interface JSXNamespacedName extends BaseExpression {
  523. type: 'JSXNamespacedName';
  524. namespace: JSXIdentifier;
  525. name: JSXIdentifier;
  526. }
  527. interface JSXEmptyExpression extends BaseNode {
  528. type: 'JSXEmptyExpression';
  529. }
  530. interface JSXExpressionContainer extends BaseNode {
  531. type: 'JSXExpressionContainer';
  532. expression: Expression | JSXEmptyExpression;
  533. }
  534. interface JSXSpreadChild extends BaseNode {
  535. type: 'JSXSpreadChild';
  536. expression: Expression;
  537. }
  538. interface JSXBoundaryElement extends BaseNode {
  539. name: JSXIdentifier | JSXMemberExpression | JSXNamespacedName;
  540. }
  541. interface JSXOpeningElement extends JSXBoundaryElement {
  542. type: 'JSXOpeningElement';
  543. attributes: Array<JSXAttribute | JSXSpreadAttribute>;
  544. selfClosing: boolean;
  545. }
  546. interface JSXClosingElement extends JSXBoundaryElement {
  547. type: 'JSXClosingElement';
  548. }
  549. interface JSXAttribute extends BaseNode {
  550. type: 'JSXAttribute';
  551. name: JSXIdentifier | JSXNamespacedName;
  552. value: Literal$3 | JSXExpressionContainer | JSXElement | JSXFragment | null;
  553. }
  554. interface JSXSpreadAttribute extends BaseNode {
  555. type: 'JSXSpreadAttribute';
  556. argument: Expression;
  557. }
  558. interface JSXText extends BaseNode {
  559. type: 'JSXText';
  560. value: string;
  561. raw: string;
  562. }
  563. interface JSXElement extends BaseExpression {
  564. type: 'JSXElement';
  565. openingElement: JSXOpeningElement;
  566. children: Array<JSXText | JSXExpressionContainer | JSXSpreadChild | JSXElement | JSXFragment>;
  567. closingElement: JSXClosingElement | null;
  568. }
  569. interface JSXFragment extends BaseExpression {
  570. type: 'JSXFragment';
  571. openingFragment: JSXOpeningFragment;
  572. children: Array<JSXText | JSXExpressionContainer | JSXSpreadChild | JSXElement | JSXFragment>;
  573. closingFragment: JSXClosingFragment;
  574. }
  575. interface JSXOpeningFragment extends BaseNode {
  576. type: 'JSXOpeningFragment';
  577. }
  578. interface JSXClosingFragment extends BaseNode {
  579. type: 'JSXClosingFragment';
  580. }
  581. // Type definitions for non-npm package Unist 2.0
  582. // Project: https://github.com/syntax-tree/unist
  583. // Definitions by: bizen241 <https://github.com/bizen241>
  584. // Jun Lu <https://github.com/lujun2>
  585. // Hernan Rajchert <https://github.com/hrajchert>
  586. // Titus Wormer <https://github.com/wooorm>
  587. // Junyoung Choi <https://github.com/rokt33r>
  588. // Ben Moon <https://github.com/GuiltyDolphin>
  589. // JounQin <https://github.com/JounQin>
  590. // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
  591. // TypeScript Version: 3.0
  592. /**
  593. * Syntactic units in unist syntax trees are called nodes.
  594. *
  595. * @typeParam TData Information from the ecosystem. Useful for more specific {@link Node.data}.
  596. */
  597. interface Node$2<TData extends object = Data$2> {
  598. /**
  599. * The variant of a node.
  600. */
  601. type: string;
  602. /**
  603. * Information from the ecosystem.
  604. */
  605. data?: TData | undefined;
  606. /**
  607. * Location of a node in a source document.
  608. * Must not be present if a node is generated.
  609. */
  610. position?: Position$3 | undefined;
  611. }
  612. /**
  613. * Information associated by the ecosystem with the node.
  614. * Space is guaranteed to never be specified by unist or specifications
  615. * implementing unist.
  616. */
  617. interface Data$2 {
  618. [key: string]: unknown;
  619. }
  620. /**
  621. * Location of a node in a source file.
  622. */
  623. interface Position$3 {
  624. /**
  625. * Place of the first character of the parsed source region.
  626. */
  627. start: Point$2;
  628. /**
  629. * Place of the first character after the parsed source region.
  630. */
  631. end: Point$2;
  632. /**
  633. * Start column at each index (plus start line) in the source region,
  634. * for elements that span multiple lines.
  635. */
  636. indent?: number[] | undefined;
  637. }
  638. /**
  639. * One place in a source file.
  640. */
  641. interface Point$2 {
  642. /**
  643. * Line in a source file (1-indexed integer).
  644. */
  645. line: number;
  646. /**
  647. * Column in a source file (1-indexed integer).
  648. */
  649. column: number;
  650. /**
  651. * Character in a source file (0-indexed integer).
  652. */
  653. offset?: number | undefined;
  654. }
  655. /**
  656. * Util for extracting type of {@link Node.data}
  657. *
  658. * @typeParam TNode Specific node type such as {@link Node} with {@link Data}, {@link Literal}, etc.
  659. *
  660. * @example `NodeData<Node<{ key: string }>>` -> `{ key: string }`
  661. */
  662. type NodeData<TNode extends Node$2<object>> = TNode extends Node$2<infer TData> ? TData : never;
  663. /**
  664. * Nodes containing other nodes.
  665. *
  666. * @typeParam ChildNode Node item of {@link Parent.children}
  667. */
  668. interface Parent$2<ChildNode extends Node$2<object> = Node$2, TData extends object = NodeData<ChildNode>>
  669. extends Node$2<TData> {
  670. /**
  671. * List representing the children of a node.
  672. */
  673. children: ChildNode[];
  674. }
  675. /**
  676. * Nodes containing a value.
  677. *
  678. * @typeParam Value Specific value type of {@link Literal.value} such as `string` for `Text` node
  679. */
  680. interface Literal$2<Value = unknown, TData extends object = Data$2> extends Node$2<TData> {
  681. value: Value;
  682. }
  683. /**
  684. * This is the same as `Buffer` if node types are included, `never` otherwise.
  685. */
  686. // eslint-disable-next-line @typescript-eslint/ban-ts-comment, @typescript-eslint/prefer-ts-expect-error
  687. // @ts-ignore It’s important to preserve this ignore statement. This makes sure
  688. // it works both with and without node types.
  689. // eslint-disable-next-line n/prefer-global/buffer
  690. type MaybeBuffer = any extends Buffer ? never : Buffer
  691. /**
  692. * Contents of the file.
  693. *
  694. * Can either be text or a `Buffer` structure.
  695. */
  696. // Note: this does not directly use type `Buffer`, because it can also be used
  697. // in a browser context.
  698. // Instead this leverages `Uint8Array` which is the base type for `Buffer`,
  699. // and a native JavaScript construct.
  700. type Value$1 = string | MaybeBuffer
  701. /**
  702. * This map registers the type of the `data` key of a `VFile`.
  703. *
  704. * This type can be augmented to register custom `data` types.
  705. *
  706. * @example
  707. * declare module 'vfile' {
  708. * interface DataMap {
  709. * // `file.data.name` is typed as `string`
  710. * name: string
  711. * }
  712. * }
  713. */
  714. // eslint-disable-next-line @typescript-eslint/consistent-type-definitions, @typescript-eslint/no-empty-interface
  715. interface DataMap {}
  716. /**
  717. * Custom information.
  718. *
  719. * Known attributes can be added to @see {@link DataMap}
  720. */
  721. type Data$1 = Record<string, unknown> & Partial<DataMap>
  722. type URL$1 = {
  723. hash: string
  724. host: string
  725. hostname: string
  726. href: string
  727. origin: string
  728. password: string
  729. pathname: string
  730. port: string
  731. protocol: string
  732. search: string
  733. searchParams: any
  734. username: string
  735. toString: () => string
  736. toJSON: () => string
  737. }
  738. /**
  739. * Message.
  740. */
  741. declare class VFileMessage extends Error {
  742. /**
  743. * Create a message for `reason` at `place` from `origin`.
  744. *
  745. * When an error is passed in as `reason`, the `stack` is copied.
  746. *
  747. * @param {string | Error | VFileMessage} reason
  748. * Reason for message, uses the stack and message of the error if given.
  749. *
  750. * > 👉 **Note**: you should use markdown.
  751. * @param {Node | NodeLike | Position | Point | null | undefined} [place]
  752. * Place in file where the message occurred.
  753. * @param {string | null | undefined} [origin]
  754. * Place in code where the message originates (example:
  755. * `'my-package:my-rule'` or `'my-rule'`).
  756. * @returns
  757. * Instance of `VFileMessage`.
  758. */
  759. constructor(
  760. reason: string | Error | VFileMessage,
  761. place?: Node$1 | NodeLike$1 | Position$2 | Point$1 | null | undefined,
  762. origin?: string | null | undefined
  763. )
  764. /**
  765. * Stack of message.
  766. *
  767. * This is used by normal errors to show where something happened in
  768. * programming code, irrelevant for `VFile` messages,
  769. *
  770. * @type {string}
  771. */
  772. stack: string
  773. /**
  774. * Reason for message.
  775. *
  776. * > 👉 **Note**: you should use markdown.
  777. *
  778. * @type {string}
  779. */
  780. reason: string
  781. /**
  782. * State of problem.
  783. *
  784. * * `true` — marks associated file as no longer processable (error)
  785. * * `false` — necessitates a (potential) change (warning)
  786. * * `null | undefined` — for things that might not need changing (info)
  787. *
  788. * @type {boolean | null | undefined}
  789. */
  790. fatal: boolean | null | undefined
  791. /**
  792. * Starting line of error.
  793. *
  794. * @type {number | null}
  795. */
  796. line: number | null
  797. /**
  798. * Starting column of error.
  799. *
  800. * @type {number | null}
  801. */
  802. column: number | null
  803. /**
  804. * Full unist position.
  805. *
  806. * @type {Position | null}
  807. */
  808. position: Position$2 | null
  809. /**
  810. * Namespace of message (example: `'my-package'`).
  811. *
  812. * @type {string | null}
  813. */
  814. source: string | null
  815. /**
  816. * Category of message (example: `'my-rule'`).
  817. *
  818. * @type {string | null}
  819. */
  820. ruleId: string | null
  821. /**
  822. * Path of a file (used throughout the `VFile` ecosystem).
  823. *
  824. * @type {string | null}
  825. */
  826. file: string | null
  827. /**
  828. * Specify the source value that’s being reported, which is deemed
  829. * incorrect.
  830. *
  831. * @type {string | null}
  832. */
  833. actual: string | null
  834. /**
  835. * Suggest acceptable values that can be used instead of `actual`.
  836. *
  837. * @type {Array<string> | null}
  838. */
  839. expected: Array<string> | null
  840. /**
  841. * Link to docs for the message.
  842. *
  843. * > 👉 **Note**: this must be an absolute URL that can be passed as `x`
  844. * > to `new URL(x)`.
  845. *
  846. * @type {string | null}
  847. */
  848. url: string | null
  849. /**
  850. * Long form description of the message (you should use markdown).
  851. *
  852. * @type {string | null}
  853. */
  854. note: string | null
  855. }
  856. type Node$1 = Node$2
  857. type Position$2 = Position$3
  858. type Point$1 = Point$2
  859. type NodeLike$1 = object & {
  860. type: string
  861. position?: Position$2 | undefined
  862. }
  863. declare class VFile$1 {
  864. /**
  865. * Create a new virtual file.
  866. *
  867. * `options` is treated as:
  868. *
  869. * * `string` or `Buffer` — `{value: options}`
  870. * * `URL` — `{path: options}`
  871. * * `VFile` — shallow copies its data over to the new file
  872. * * `object` — all fields are shallow copied over to the new file
  873. *
  874. * Path related fields are set in the following order (least specific to
  875. * most specific): `history`, `path`, `basename`, `stem`, `extname`,
  876. * `dirname`.
  877. *
  878. * You cannot set `dirname` or `extname` without setting either `history`,
  879. * `path`, `basename`, or `stem` too.
  880. *
  881. * @param {Compatible | null | undefined} [value]
  882. * File value.
  883. * @returns
  884. * New instance.
  885. */
  886. constructor(value?: Compatible | null | undefined)
  887. /**
  888. * Place to store custom information (default: `{}`).
  889. *
  890. * It’s OK to store custom data directly on the file but moving it to
  891. * `data` is recommended.
  892. *
  893. * @type {Data}
  894. */
  895. data: Data
  896. /**
  897. * List of messages associated with the file.
  898. *
  899. * @type {Array<VFileMessage>}
  900. */
  901. messages: Array<VFileMessage>
  902. /**
  903. * List of filepaths the file moved between.
  904. *
  905. * The first is the original path and the last is the current path.
  906. *
  907. * @type {Array<string>}
  908. */
  909. history: Array<string>
  910. /**
  911. * Base of `path` (default: `process.cwd()` or `'/'` in browsers).
  912. *
  913. * @type {string}
  914. */
  915. cwd: string
  916. /**
  917. * Raw value.
  918. *
  919. * @type {Value}
  920. */
  921. value: Value
  922. /**
  923. * Whether a file was saved to disk.
  924. *
  925. * This is used by vfile reporters.
  926. *
  927. * @type {boolean}
  928. */
  929. stored: boolean
  930. /**
  931. * Custom, non-string, compiled, representation.
  932. *
  933. * This is used by unified to store non-string results.
  934. * One example is when turning markdown into React nodes.
  935. *
  936. * @type {unknown}
  937. */
  938. result: unknown
  939. /**
  940. * Source map.
  941. *
  942. * This type is equivalent to the `RawSourceMap` type from the `source-map`
  943. * module.
  944. *
  945. * @type {Map | null | undefined}
  946. */
  947. map: Map | null | undefined
  948. /**
  949. * Set the full path (example: `'~/index.min.js'`).
  950. *
  951. * Cannot be nullified.
  952. * You can set a file URL (a `URL` object with a `file:` protocol) which will
  953. * be turned into a path with `url.fileURLToPath`.
  954. *
  955. * @param {string | URL} path
  956. */
  957. set path(arg: string)
  958. /**
  959. * Get the full path (example: `'~/index.min.js'`).
  960. *
  961. * @returns {string}
  962. */
  963. get path(): string
  964. /**
  965. * Set the parent path (example: `'~'`).
  966. *
  967. * Cannot be set if there’s no `path` yet.
  968. */
  969. set dirname(arg: string | undefined)
  970. /**
  971. * Get the parent path (example: `'~'`).
  972. */
  973. get dirname(): string | undefined
  974. /**
  975. * Set basename (including extname) (`'index.min.js'`).
  976. *
  977. * Cannot contain path separators (`'/'` on unix, macOS, and browsers, `'\'`
  978. * on windows).
  979. * Cannot be nullified (use `file.path = file.dirname` instead).
  980. */
  981. set basename(arg: string | undefined)
  982. /**
  983. * Get the basename (including extname) (example: `'index.min.js'`).
  984. */
  985. get basename(): string | undefined
  986. /**
  987. * Set the extname (including dot) (example: `'.js'`).
  988. *
  989. * Cannot contain path separators (`'/'` on unix, macOS, and browsers, `'\'`
  990. * on windows).
  991. * Cannot be set if there’s no `path` yet.
  992. */
  993. set extname(arg: string | undefined)
  994. /**
  995. * Get the extname (including dot) (example: `'.js'`).
  996. */
  997. get extname(): string | undefined
  998. /**
  999. * Set the stem (basename w/o extname) (example: `'index.min'`).
  1000. *
  1001. * Cannot contain path separators (`'/'` on unix, macOS, and browsers, `'\'`
  1002. * on windows).
  1003. * Cannot be nullified (use `file.path = file.dirname` instead).
  1004. */
  1005. set stem(arg: string | undefined)
  1006. /**
  1007. * Get the stem (basename w/o extname) (example: `'index.min'`).
  1008. */
  1009. get stem(): string | undefined
  1010. /**
  1011. * Serialize the file.
  1012. *
  1013. * @param {BufferEncoding | null | undefined} [encoding='utf8']
  1014. * Character encoding to understand `value` as when it’s a `Buffer`
  1015. * (default: `'utf8'`).
  1016. * @returns {string}
  1017. * Serialized file.
  1018. */
  1019. toString(encoding?: BufferEncoding | null | undefined): string
  1020. /**
  1021. * Create a warning message associated with the file.
  1022. *
  1023. * Its `fatal` is set to `false` and `file` is set to the current file path.
  1024. * Its added to `file.messages`.
  1025. *
  1026. * @param {string | Error | VFileMessage} reason
  1027. * Reason for message, uses the stack and message of the error if given.
  1028. * @param {Node | NodeLike | Position | Point | null | undefined} [place]
  1029. * Place in file where the message occurred.
  1030. * @param {string | null | undefined} [origin]
  1031. * Place in code where the message originates (example:
  1032. * `'my-package:my-rule'` or `'my-rule'`).
  1033. * @returns {VFileMessage}
  1034. * Message.
  1035. */
  1036. message(
  1037. reason: string | Error | VFileMessage,
  1038. place?: Node | NodeLike | Position$1 | Point | null | undefined,
  1039. origin?: string | null | undefined
  1040. ): VFileMessage
  1041. /**
  1042. * Create an info message associated with the file.
  1043. *
  1044. * Its `fatal` is set to `null` and `file` is set to the current file path.
  1045. * Its added to `file.messages`.
  1046. *
  1047. * @param {string | Error | VFileMessage} reason
  1048. * Reason for message, uses the stack and message of the error if given.
  1049. * @param {Node | NodeLike | Position | Point | null | undefined} [place]
  1050. * Place in file where the message occurred.
  1051. * @param {string | null | undefined} [origin]
  1052. * Place in code where the message originates (example:
  1053. * `'my-package:my-rule'` or `'my-rule'`).
  1054. * @returns {VFileMessage}
  1055. * Message.
  1056. */
  1057. info(
  1058. reason: string | Error | VFileMessage,
  1059. place?: Node | NodeLike | Position$1 | Point | null | undefined,
  1060. origin?: string | null | undefined
  1061. ): VFileMessage
  1062. /**
  1063. * Create a fatal error associated with the file.
  1064. *
  1065. * Its `fatal` is set to `true` and `file` is set to the current file path.
  1066. * Its added to `file.messages`.
  1067. *
  1068. * > 👉 **Note**: a fatal error means that a file is no longer processable.
  1069. *
  1070. * @param {string | Error | VFileMessage} reason
  1071. * Reason for message, uses the stack and message of the error if given.
  1072. * @param {Node | NodeLike | Position | Point | null | undefined} [place]
  1073. * Place in file where the message occurred.
  1074. * @param {string | null | undefined} [origin]
  1075. * Place in code where the message originates (example:
  1076. * `'my-package:my-rule'` or `'my-rule'`).
  1077. * @returns {never}
  1078. * Message.
  1079. * @throws {VFileMessage}
  1080. * Message.
  1081. */
  1082. fail(
  1083. reason: string | Error | VFileMessage,
  1084. place?: Node | NodeLike | Position$1 | Point | null | undefined,
  1085. origin?: string | null | undefined
  1086. ): never
  1087. }
  1088. type Node = Node$2
  1089. type Position$1 = Position$3
  1090. type Point = Point$2
  1091. type URL = URL$1
  1092. type Data = Data$1
  1093. type Value = Value$1
  1094. type NodeLike = Record<string, unknown> & {
  1095. type: string
  1096. position?: Position$1 | undefined
  1097. }
  1098. /**
  1099. * Encodings supported by the buffer class.
  1100. *
  1101. * This is a copy of the types from Node, copied to prevent Node globals from
  1102. * being needed.
  1103. * Copied from: <https://github.com/DefinitelyTyped/DefinitelyTyped/blob/90a4ec8/types/node/buffer.d.ts#L170>
  1104. */
  1105. type BufferEncoding =
  1106. | 'ascii'
  1107. | 'utf8'
  1108. | 'utf-8'
  1109. | 'utf16le'
  1110. | 'ucs2'
  1111. | 'ucs-2'
  1112. | 'base64'
  1113. | 'base64url'
  1114. | 'latin1'
  1115. | 'binary'
  1116. | 'hex'
  1117. /**
  1118. * Things that can be passed to the constructor.
  1119. */
  1120. type Compatible = Options$4 | URL | Value | VFile$1
  1121. /**
  1122. * Set multiple values.
  1123. */
  1124. type VFileCoreOptions = {
  1125. /**
  1126. * Set `value`.
  1127. */
  1128. value?: Value | null | undefined
  1129. /**
  1130. * Set `cwd`.
  1131. */
  1132. cwd?: string | null | undefined
  1133. /**
  1134. * Set `history`.
  1135. */
  1136. history?: Array<string> | null | undefined
  1137. /**
  1138. * Set `path`.
  1139. */
  1140. path?: URL | string | null | undefined
  1141. /**
  1142. * Set `basename`.
  1143. */
  1144. basename?: string | null | undefined
  1145. /**
  1146. * Set `stem`.
  1147. */
  1148. stem?: string | null | undefined
  1149. /**
  1150. * Set `extname`.
  1151. */
  1152. extname?: string | null | undefined
  1153. /**
  1154. * Set `dirname`.
  1155. */
  1156. dirname?: string | null | undefined
  1157. /**
  1158. * Set `data`.
  1159. */
  1160. data?: Data | null | undefined
  1161. }
  1162. /**
  1163. * Raw source map.
  1164. *
  1165. * See:
  1166. * <https://github.com/mozilla/source-map/blob/58819f0/source-map.d.ts#L15-L23>.
  1167. */
  1168. type Map = {
  1169. /**
  1170. * Which version of the source map spec this map is following.
  1171. */
  1172. version: number
  1173. /**
  1174. * An array of URLs to the original source files.
  1175. */
  1176. sources: Array<string>
  1177. /**
  1178. * An array of identifiers which can be referenced by individual mappings.
  1179. */
  1180. names: Array<string>
  1181. /**
  1182. * The URL root from which all sources are relative.
  1183. */
  1184. sourceRoot?: string | undefined
  1185. /**
  1186. * An array of contents of the original source files.
  1187. */
  1188. sourcesContent?: Array<string> | undefined
  1189. /**
  1190. * A string of base64 VLQs which contain the actual mappings.
  1191. */
  1192. mappings: string
  1193. /**
  1194. * The generated file this source map is associated with.
  1195. */
  1196. file: string
  1197. }
  1198. /**
  1199. * Configuration.
  1200. *
  1201. * A bunch of keys that will be shallow copied over to the new file.
  1202. */
  1203. type Options$4 = {
  1204. [key: string]: unknown
  1205. } & VFileCoreOptions
  1206. // TypeScript Version: 4.0
  1207. /* eslint-disable @typescript-eslint/naming-convention */
  1208. type VFileWithOutput<Result> = Result extends Uint8Array // Buffer.
  1209. ? VFile$1
  1210. : Result extends object // Custom result type
  1211. ? VFile$1 & {result: Result}
  1212. : VFile$1
  1213. // Get the right most non-void thing.
  1214. type Specific<Left = void, Right = void> = Right extends void ? Left : Right
  1215. // Create a processor based on the input/output of a plugin.
  1216. type UsePlugin<
  1217. ParseTree extends Node$2 | void = void,
  1218. CurrentTree extends Node$2 | void = void,
  1219. CompileTree extends Node$2 | void = void,
  1220. CompileResult = void,
  1221. Input = void,
  1222. Output = void
  1223. > = Output extends Node$2
  1224. ? Input extends string
  1225. ? // If `Input` is `string` and `Output` is `Node`, then this plugin
  1226. // defines a parser, so set `ParseTree`.
  1227. Processor<
  1228. Output,
  1229. Specific<Output, CurrentTree>,
  1230. Specific<Output, CompileTree>,
  1231. CompileResult
  1232. >
  1233. : Input extends Node$2
  1234. ? // If `Input` is `Node` and `Output` is `Node`, then this plugin defines a
  1235. // transformer, its output defines the input of the next, so set
  1236. // `CurrentTree`.
  1237. Processor<
  1238. Specific<Input, ParseTree>,
  1239. Output,
  1240. Specific<CompileTree, Output>,
  1241. CompileResult
  1242. >
  1243. : // Else, `Input` is something else and `Output` is `Node`:
  1244. never
  1245. : Input extends Node$2
  1246. ? // If `Input` is `Node` and `Output` is not a `Node`, then this plugin
  1247. // defines a compiler, so set `CompileTree` and `CompileResult`
  1248. Processor<
  1249. Specific<Input, ParseTree>,
  1250. Specific<Input, CurrentTree>,
  1251. Input,
  1252. Output
  1253. >
  1254. : // Else, `Input` is not a `Node` and `Output` is not a `Node`.
  1255. // Maybe it’s untyped, or the plugin throws an error (`never`), so lets
  1256. // just keep it as it was.
  1257. Processor<ParseTree, CurrentTree, CompileTree, CompileResult>
  1258. /* eslint-enable @typescript-eslint/naming-convention */
  1259. /**
  1260. * Processor allows plugins to be chained together to transform content.
  1261. * The chain of plugins defines how content flows through it.
  1262. *
  1263. * @typeParam ParseTree
  1264. * The node that the parser yields (and `run` receives).
  1265. * @typeParam CurrentTree
  1266. * The node that the last attached plugin yields.
  1267. * @typeParam CompileTree
  1268. * The node that the compiler receives (and `run` yields).
  1269. * @typeParam CompileResult
  1270. * The thing that the compiler yields.
  1271. */
  1272. interface Processor<
  1273. ParseTree extends Node$2 | void = void,
  1274. CurrentTree extends Node$2 | void = void,
  1275. CompileTree extends Node$2 | void = void,
  1276. CompileResult = void
  1277. > extends FrozenProcessor<ParseTree, CurrentTree, CompileTree, CompileResult> {
  1278. /**
  1279. * Configure the processor to use a plugin.
  1280. *
  1281. * @typeParam PluginParameters
  1282. * Plugin settings.
  1283. * @typeParam Input
  1284. * Value that is accepted by the plugin.
  1285. *
  1286. * * If the plugin returns a transformer, then this should be the node
  1287. * type that the transformer expects.
  1288. * * If the plugin sets a parser, then this should be `string`.
  1289. * * If the plugin sets a compiler, then this should be the node type that
  1290. * the compiler expects.
  1291. * @typeParam Output
  1292. * Value that the plugin yields.
  1293. *
  1294. * * If the plugin returns a transformer, then this should be the node
  1295. * type that the transformer yields, and defaults to `Input`.
  1296. * * If the plugin sets a parser, then this should be the node type that
  1297. * the parser yields.
  1298. * * If the plugin sets a compiler, then this should be the result that
  1299. * the compiler yields (`string`, `Buffer`, or something else).
  1300. * @param plugin
  1301. * Plugin (function) to use.
  1302. * Plugins are deduped based on identity: passing a function in twice will
  1303. * cause it to run only once.
  1304. * @param settings
  1305. * Configuration for plugin, optional.
  1306. * Plugins typically receive one options object, but could receive other and
  1307. * more values.
  1308. * It’s also possible to pass a boolean instead of settings: `true` (to turn
  1309. * a plugin on) or `false` (to turn a plugin off).
  1310. * @returns
  1311. * Current processor.
  1312. */
  1313. use<
  1314. PluginParameters extends any[] = any[],
  1315. Input = Specific<Node$2, CurrentTree>,
  1316. Output = Input
  1317. >(
  1318. plugin: Plugin<PluginParameters, Input, Output>,
  1319. ...settings: PluginParameters | [boolean]
  1320. ): UsePlugin<
  1321. ParseTree,
  1322. CurrentTree,
  1323. CompileTree,
  1324. CompileResult,
  1325. Input,
  1326. Output
  1327. >
  1328. /**
  1329. * Configure the processor with a tuple of a plugin and setting(s).
  1330. *
  1331. * @typeParam PluginParameters
  1332. * Plugin settings.
  1333. * @typeParam Input
  1334. * Value that is accepted by the plugin.
  1335. *
  1336. * * If the plugin returns a transformer, then this should be the node
  1337. * type that the transformer expects.
  1338. * * If the plugin sets a parser, then this should be `string`.
  1339. * * If the plugin sets a compiler, then this should be the node type that
  1340. * the compiler expects.
  1341. * @typeParam Output
  1342. * Value that the plugin yields.
  1343. *
  1344. * * If the plugin returns a transformer, then this should be the node
  1345. * type that the transformer yields, and defaults to `Input`.
  1346. * * If the plugin sets a parser, then this should be the node type that
  1347. * the parser yields.
  1348. * * If the plugin sets a compiler, then this should be the result that
  1349. * the compiler yields (`string`, `Buffer`, or something else).
  1350. * @param tuple
  1351. * A tuple where the first item is a plugin (function) to use and other
  1352. * items are options.
  1353. * Plugins are deduped based on identity: passing a function in twice will
  1354. * cause it to run only once.
  1355. * It’s also possible to pass a boolean instead of settings: `true` (to turn
  1356. * a plugin on) or `false` (to turn a plugin off).
  1357. * @returns
  1358. * Current processor.
  1359. */
  1360. use<
  1361. PluginParameters extends any[] = any[],
  1362. Input = Specific<Node$2, CurrentTree>,
  1363. Output = Input
  1364. >(
  1365. tuple:
  1366. | PluginTuple<PluginParameters, Input, Output>
  1367. | [Plugin<PluginParameters, Input, Output>, boolean]
  1368. ): UsePlugin<
  1369. ParseTree,
  1370. CurrentTree,
  1371. CompileTree,
  1372. CompileResult,
  1373. Input,
  1374. Output
  1375. >
  1376. /**
  1377. * Configure the processor with a preset or list of plugins and presets.
  1378. *
  1379. * @param presetOrList
  1380. * Either a list of plugins, presets, and tuples, or a single preset: an
  1381. * object with a `plugins` (list) and/or `settings`
  1382. * (`Record<string, unknown>`).
  1383. * @returns
  1384. * Current processor.
  1385. */
  1386. use(
  1387. presetOrList: Preset | PluggableList
  1388. ): Processor<ParseTree, CurrentTree, CompileTree, CompileResult>
  1389. }
  1390. /**
  1391. * A frozen processor is just like a regular processor, except no additional
  1392. * plugins can be added.
  1393. * A frozen processor can be created by calling `.freeze()` on a processor.
  1394. * An unfrozen processor can be created by calling a processor.
  1395. */
  1396. interface FrozenProcessor<
  1397. ParseTree extends Node$2 | void = void,
  1398. CurrentTree extends Node$2 | void = void,
  1399. CompileTree extends Node$2 | void = void,
  1400. CompileResult = void
  1401. > {
  1402. /**
  1403. * Clone current processor
  1404. *
  1405. * @returns
  1406. * New unfrozen processor that is configured to function the same as its
  1407. * ancestor.
  1408. * But when the descendant processor is configured it does not affect the
  1409. * ancestral processor.
  1410. */
  1411. (): Processor<ParseTree, CurrentTree, CompileTree, CompileResult>
  1412. /**
  1413. * Internal list of configured plugins.
  1414. *
  1415. * @private
  1416. */
  1417. attachers: Array<[Plugin, ...unknown[]]>
  1418. Parser?: Parser<Specific<Node$2, ParseTree>> | undefined
  1419. Compiler?:
  1420. | Compiler<Specific<Node$2, CompileTree>, Specific<unknown, CompileResult>>
  1421. | undefined
  1422. /**
  1423. * Parse a file.
  1424. *
  1425. * @param file
  1426. * File to parse.
  1427. * `VFile` or anything that can be given to `new VFile()`, optional.
  1428. * @returns
  1429. * Resulting tree.
  1430. */
  1431. parse(file?: Compatible | undefined): Specific<Node$2, ParseTree>
  1432. /**
  1433. * Compile a file.
  1434. *
  1435. * @param node
  1436. * Node to compile.
  1437. * @param file
  1438. * `VFile` or anything that can be given to `new VFile()`, optional.
  1439. * @returns
  1440. * New content: compiled text (`string` or `Buffer`) or something else.
  1441. * This depends on which plugins you use: typically text, but could for
  1442. * example be a React node.
  1443. */
  1444. stringify(
  1445. node: Specific<Node$2, CompileTree>,
  1446. file?: Compatible | undefined
  1447. ): CompileTree extends Node$2 ? CompileResult : unknown
  1448. /**
  1449. * Run transforms on the given tree.
  1450. *
  1451. * @param node
  1452. * Tree to transform.
  1453. * @param callback
  1454. * Callback called with an error or the resulting node.
  1455. * @returns
  1456. * Nothing.
  1457. */
  1458. run(
  1459. node: Specific<Node$2, ParseTree>,
  1460. callback: RunCallback<Specific<Node$2, CompileTree>>
  1461. ): void
  1462. /**
  1463. * Run transforms on the given node.
  1464. *
  1465. * @param node
  1466. * Tree to transform.
  1467. * @param file
  1468. * File associated with `node`.
  1469. * `VFile` or anything that can be given to `new VFile()`.
  1470. * @param callback
  1471. * Callback called with an error or the resulting node.
  1472. * @returns
  1473. * Nothing.
  1474. */
  1475. run(
  1476. node: Specific<Node$2, ParseTree>,
  1477. file: Compatible | undefined,
  1478. callback: RunCallback<Specific<Node$2, CompileTree>>
  1479. ): void
  1480. /**
  1481. * Run transforms on the given node.
  1482. *
  1483. * @param node
  1484. * Tree to transform.
  1485. * @param file
  1486. * File associated with `node`.
  1487. * `VFile` or anything that can be given to `new VFile()`.
  1488. * @returns
  1489. * Promise that resolves to the resulting tree.
  1490. */
  1491. run(
  1492. node: Specific<Node$2, ParseTree>,
  1493. file?: Compatible | undefined
  1494. ): Promise<Specific<Node$2, CompileTree>>
  1495. /**
  1496. * Run transforms on the given node, synchronously.
  1497. * Throws when asynchronous transforms are configured.
  1498. *
  1499. * @param node
  1500. * Tree to transform.
  1501. * @param file
  1502. * File associated with `node`.
  1503. * `VFile` or anything that can be given to `new VFile()`, optional.
  1504. * @returns
  1505. * Resulting tree.
  1506. */
  1507. runSync(
  1508. node: Specific<Node$2, ParseTree>,
  1509. file?: Compatible | undefined
  1510. ): Specific<Node$2, CompileTree>
  1511. /**
  1512. * Process a file.
  1513. *
  1514. * This performs all phases of the processor:
  1515. *
  1516. * 1. Parse a file into a unist node using the configured `Parser`
  1517. * 2. Run transforms on that node
  1518. * 3. Compile the resulting node using the `Compiler`
  1519. *
  1520. * The result from the compiler is stored on the file.
  1521. * What the result is depends on which plugins you use.
  1522. * The result is typically text (`string` or `Buffer`), which can be retrieved
  1523. * with `file.toString()` (or `String(file)`).
  1524. * In some cases, such as when using `rehypeReact` to create a React node,
  1525. * the result is stored on `file.result`.
  1526. *
  1527. * @param file
  1528. * `VFile` or anything that can be given to `new VFile()`.
  1529. * @param callback
  1530. * Callback called with an error or the resulting file.
  1531. * @returns
  1532. * Nothing.
  1533. */
  1534. process(
  1535. file: Compatible | undefined,
  1536. callback: ProcessCallback<VFileWithOutput<CompileResult>>
  1537. ): void
  1538. /**
  1539. * Process a file.
  1540. *
  1541. * This performs all phases of the processor:
  1542. *
  1543. * 1. Parse a file into a unist node using the configured `Parser`
  1544. * 2. Run transforms on that node
  1545. * 3. Compile the resulting node using the `Compiler`
  1546. *
  1547. * The result from the compiler is stored on the file.
  1548. * What the result is depends on which plugins you use.
  1549. * The result is typically text (`string` or `Buffer`), which can be retrieved
  1550. * with `file.toString()` (or `String(file)`).
  1551. * In some cases, such as when using `rehypeReact` to create a React node,
  1552. * the result is stored on `file.result`.
  1553. *
  1554. * @param file
  1555. * `VFile` or anything that can be given to `new VFile()`.
  1556. * @returns
  1557. * Promise that resolves to the resulting `VFile`.
  1558. */
  1559. process(file: Compatible): Promise<VFileWithOutput<CompileResult>>
  1560. /**
  1561. * Process a file, synchronously.
  1562. * Throws when asynchronous transforms are configured.
  1563. *
  1564. * This performs all phases of the processor:
  1565. *
  1566. * 1. Parse a file into a unist node using the configured `Parser`
  1567. * 2. Run transforms on that node
  1568. * 3. Compile the resulting node using the `Compiler`
  1569. *
  1570. * The result from the compiler is stored on the file.
  1571. * What the result is depends on which plugins you use.
  1572. * The result is typically text (`string` or `Buffer`), which can be retrieved
  1573. * with `file.toString()` (or `String(file)`).
  1574. * In some cases, such as when using `rehypeReact` to create a React node,
  1575. * the result is stored on `file.result`.
  1576. *
  1577. * @param file
  1578. * `VFile` or anything that can be given to `new VFile()`, optional.
  1579. * @returns
  1580. * Resulting file.
  1581. */
  1582. processSync(
  1583. file?: Compatible | undefined
  1584. ): VFileWithOutput<CompileResult>
  1585. /**
  1586. * Get an in-memory key-value store accessible to all phases of the process.
  1587. *
  1588. * @returns
  1589. * Key-value store.
  1590. */
  1591. data(): Record<string, unknown>
  1592. /**
  1593. * Set an in-memory key-value store accessible to all phases of the process.
  1594. *
  1595. * @param data
  1596. * Key-value store.
  1597. * @returns
  1598. * Current processor.
  1599. */
  1600. data(
  1601. data: Record<string, unknown>
  1602. ): Processor<ParseTree, CurrentTree, CompileTree, CompileResult>
  1603. /**
  1604. * Get an in-memory value by key.
  1605. *
  1606. * @param key
  1607. * Key to get.
  1608. * @returns
  1609. * The value at `key`.
  1610. */
  1611. data(key: string): unknown
  1612. /**
  1613. * Set an in-memory value by key.
  1614. *
  1615. * @param key
  1616. * Key to set.
  1617. * @param value
  1618. * Value to set.
  1619. * @returns
  1620. * Current processor.
  1621. */
  1622. data(
  1623. key: string,
  1624. value: unknown
  1625. ): Processor<ParseTree, CurrentTree, CompileTree, CompileResult>
  1626. /**
  1627. * Freeze a processor.
  1628. * Frozen processors are meant to be extended and not to be configured or
  1629. * processed directly.
  1630. *
  1631. * Once a processor is frozen it cannot be unfrozen.
  1632. * New processors working just like it can be created by calling the
  1633. * processor.
  1634. *
  1635. * It’s possible to freeze processors explicitly, by calling `.freeze()`, but
  1636. * `.parse()`, `.run()`, `.stringify()`, and `.process()` call `.freeze()` to
  1637. * freeze a processor too.
  1638. *
  1639. * @returns
  1640. * Frozen processor.
  1641. */
  1642. freeze(): FrozenProcessor<ParseTree, CurrentTree, CompileTree, CompileResult>
  1643. }
  1644. /**
  1645. * A plugin is a function.
  1646. * It configures the processor and in turn can receive options.
  1647. * Plugins can configure processors by interacting with parsers and compilers
  1648. * (at `this.Parser` or `this.Compiler`) or by specifying how the syntax tree
  1649. * is handled (by returning a `Transformer`).
  1650. *
  1651. * @typeParam PluginParameters
  1652. * Plugin settings.
  1653. * @typeParam Input
  1654. * Value that is accepted by the plugin.
  1655. *
  1656. * * If the plugin returns a transformer, then this should be the node
  1657. * type that the transformer expects.
  1658. * * If the plugin sets a parser, then this should be `string`.
  1659. * * If the plugin sets a compiler, then this should be the node type that
  1660. * the compiler expects.
  1661. * @typeParam Output
  1662. * Value that the plugin yields.
  1663. *
  1664. * * If the plugin returns a transformer, then this should be the node
  1665. * type that the transformer yields, and defaults to `Input`.
  1666. * * If the plugin sets a parser, then this should be the node type that
  1667. * the parser yields.
  1668. * * If the plugin sets a compiler, then this should be the result that
  1669. * the compiler yields (`string`, `Buffer`, or something else).
  1670. * @this
  1671. * The current processor.
  1672. * Plugins can configure the processor by interacting with `this.Parser` or
  1673. * `this.Compiler`, or by accessing the data associated with the whole process
  1674. * (`this.data`).
  1675. * @param settings
  1676. * Configuration for plugin.
  1677. * Plugins typically receive one options object, but could receive other and
  1678. * more values.
  1679. * Users can also pass a boolean instead of settings: `true` (to turn
  1680. * a plugin on) or `false` (to turn a plugin off).
  1681. * When a plugin is turned off, it won’t be called.
  1682. *
  1683. * When creating your own plugins, please accept only a single object!
  1684. * It allows plugins to be reconfigured and it helps users to know that every
  1685. * plugin accepts one options object.
  1686. * @returns
  1687. * Plugins can return a `Transformer` to specify how the syntax tree is
  1688. * handled.
  1689. */
  1690. type Plugin<
  1691. PluginParameters extends any[] = any[],
  1692. Input = Node$2,
  1693. Output = Input
  1694. > = (
  1695. this: Input extends Node$2
  1696. ? Output extends Node$2
  1697. ? // This is a transform, so define `Input` as the current tree.
  1698. Processor<void, Input>
  1699. : // Compiler.
  1700. Processor<void, Input, Input, Output>
  1701. : Output extends Node$2
  1702. ? // Parser.
  1703. Processor<Output, Output>
  1704. : // No clue.
  1705. Processor,
  1706. ...settings: PluginParameters
  1707. ) => // If both `Input` and `Output` are `Node`, expect an optional `Transformer`.
  1708. Input extends Node$2
  1709. ? Output extends Node$2
  1710. ? Transformer<Input, Output> | void
  1711. : void
  1712. : void
  1713. /**
  1714. * Presets provide a sharable way to configure processors with multiple plugins
  1715. * and/or settings.
  1716. */
  1717. interface Preset {
  1718. plugins?: PluggableList
  1719. settings?: Record<string, unknown>
  1720. }
  1721. /**
  1722. * A tuple of a plugin and its setting(s).
  1723. * The first item is a plugin (function) to use and other items are options.
  1724. * Plugins are deduped based on identity: passing a function in twice will
  1725. * cause it to run only once.
  1726. *
  1727. * @typeParam PluginParameters
  1728. * Plugin settings.
  1729. * @typeParam Input
  1730. * Value that is accepted by the plugin.
  1731. *
  1732. * * If the plugin returns a transformer, then this should be the node
  1733. * type that the transformer expects.
  1734. * * If the plugin sets a parser, then this should be `string`.
  1735. * * If the plugin sets a compiler, then this should be the node type that
  1736. * the compiler expects.
  1737. * @typeParam Output
  1738. * Value that the plugin yields.
  1739. *
  1740. * * If the plugin returns a transformer, then this should be the node
  1741. * type that the transformer yields, and defaults to `Input`.
  1742. * * If the plugin sets a parser, then this should be the node type that
  1743. * the parser yields.
  1744. * * If the plugin sets a compiler, then this should be the result that
  1745. * the compiler yields (`string`, `Buffer`, or something else).
  1746. */
  1747. type PluginTuple<
  1748. PluginParameters extends any[] = any[],
  1749. Input = Node$2,
  1750. Output = Input
  1751. > = [Plugin<PluginParameters, Input, Output>, ...PluginParameters]
  1752. /**
  1753. * A union of the different ways to add plugins and settings.
  1754. *
  1755. * @typeParam PluginParameters
  1756. * Plugin settings.
  1757. */
  1758. type Pluggable<PluginParameters extends any[] = any[]> =
  1759. | PluginTuple<PluginParameters, any, any>
  1760. | Plugin<PluginParameters, any, any>
  1761. | Preset
  1762. /**
  1763. * A list of plugins and presets.
  1764. */
  1765. type PluggableList = Pluggable[]
  1766. /**
  1767. * Transformers modify the syntax tree or metadata of a file.
  1768. * A transformer is a function that is called each time a file is passed
  1769. * through the transform phase.
  1770. * If an error occurs (either because it’s thrown, returned, rejected, or passed
  1771. * to `next`), the process stops.
  1772. *
  1773. * @typeParam Input
  1774. * Node type that the transformer expects.
  1775. * @typeParam Output
  1776. * Node type that the transformer yields.
  1777. * @param node
  1778. * Tree to be transformed.
  1779. * @param file
  1780. * File associated with node.
  1781. * @param next
  1782. * Callback that you must call when done.
  1783. * Note: this is given if you accept three parameters in your transformer.
  1784. * If you accept up to two parameters, it’s not given, and you can return
  1785. * a promise.
  1786. * @returns
  1787. * Any of the following:
  1788. *
  1789. * * `void` — If nothing is returned, the next transformer keeps using same
  1790. * tree.
  1791. * * `Error` — Can be returned to stop the process.
  1792. * * `Node` — Can be returned and results in further transformations and
  1793. * `stringify`s to be performed on the new tree.
  1794. * * `Promise` — If a promise is returned, the function is asynchronous, and
  1795. * must be resolved (optionally with a `Node`) or rejected (optionally with
  1796. * an `Error`).
  1797. *
  1798. * If you accept a `next` callback, nothing should be returned.
  1799. */
  1800. type Transformer<
  1801. Input extends Node$2 = Node$2,
  1802. Output extends Node$2 = Input
  1803. > = (
  1804. node: Input,
  1805. file: VFile$1,
  1806. next: TransformCallback<Output>
  1807. ) => Promise<Output | undefined | void> | Output | Error | undefined | void
  1808. /**
  1809. * Callback you must call when a transformer is done.
  1810. *
  1811. * @typeParam Tree
  1812. * Node that the plugin yields.
  1813. * @param error
  1814. * Pass an error to stop the process.
  1815. * @param node
  1816. * Pass a tree to continue transformations (and `stringify`) on the new tree.
  1817. * @param file
  1818. * Pass a file to continue transformations (and `stringify`) on the new file.
  1819. * @returns
  1820. * Nothing.
  1821. */
  1822. type TransformCallback<Tree extends Node$2 = Node$2> = (
  1823. error?: Error | null | undefined,
  1824. node?: Tree | undefined,
  1825. file?: VFile$1 | undefined
  1826. ) => void
  1827. /**
  1828. * Function handling the parsing of text to a syntax tree.
  1829. * Used in the parse phase in the process and called with a `string` and
  1830. * `VFile` representation of the document to parse.
  1831. *
  1832. * `Parser` can be a normal function, in which case it must return a `Node`:
  1833. * the syntax tree representation of the given file.
  1834. *
  1835. * `Parser` can also be a constructor function (a function with keys in its
  1836. * `prototype`), in which case it’s called with `new`.
  1837. * Instances must have a parse method that is called without arguments and
  1838. * must return a `Node`.
  1839. *
  1840. * @typeParam Tree
  1841. * The node that the parser yields (and `run` receives).
  1842. */
  1843. type Parser<Tree extends Node$2 = Node$2> =
  1844. | ParserClass<Tree>
  1845. | ParserFunction<Tree>
  1846. /**
  1847. * A class to parse files.
  1848. *
  1849. * @typeParam Tree
  1850. * The node that the parser yields.
  1851. */
  1852. declare class ParserClass<Tree extends Node$2 = Node$2> {
  1853. prototype: {
  1854. /**
  1855. * Parse a file.
  1856. *
  1857. * @returns
  1858. * Parsed tree.
  1859. */
  1860. parse(): Tree
  1861. }
  1862. /**
  1863. * Constructor.
  1864. *
  1865. * @param document
  1866. * Document to parse.
  1867. * @param file
  1868. * File associated with `document`.
  1869. * @returns
  1870. * Instance.
  1871. */
  1872. constructor(document: string, file: VFile$1)
  1873. }
  1874. /**
  1875. * Normal function to parse a file.
  1876. *
  1877. * @typeParam Tree
  1878. * The node that the parser yields.
  1879. * @param document
  1880. * Document to parse.
  1881. * @param file
  1882. * File associated with `document`.
  1883. * @returns
  1884. * Node representing the given file.
  1885. */
  1886. type ParserFunction<Tree extends Node$2 = Node$2> = (
  1887. document: string,
  1888. file: VFile$1
  1889. ) => Tree
  1890. /**
  1891. * Function handling the compilation of syntax tree to a text.
  1892. * Used in the stringify phase in the process and called with a `Node` and
  1893. * `VFile` representation of the document to stringify.
  1894. *
  1895. * `Compiler` can be a normal function, in which case it must return a
  1896. * `string`: the text representation of the given syntax tree.
  1897. *
  1898. * `Compiler` can also be a constructor function (a function with keys in its
  1899. * `prototype`), in which case it’s called with `new`.
  1900. * Instances must have a `compile` method that is called without arguments
  1901. * and must return a `string`.
  1902. *
  1903. * @typeParam Tree
  1904. * The node that the compiler receives.
  1905. * @typeParam Result
  1906. * The thing that the compiler yields.
  1907. */
  1908. type Compiler<Tree extends Node$2 = Node$2, Result = unknown> =
  1909. | CompilerClass<Tree, Result>
  1910. | CompilerFunction<Tree, Result>
  1911. /**
  1912. * A class to compile trees.
  1913. *
  1914. * @typeParam Tree
  1915. * The node that the compiler receives.
  1916. * @typeParam Result
  1917. * The thing that the compiler yields.
  1918. */
  1919. declare class CompilerClass<Tree extends Node$2 = Node$2, Result = unknown> {
  1920. prototype: {
  1921. /**
  1922. * Compile a tree.
  1923. *
  1924. * @returns
  1925. * New content: compiled text (`string` or `Buffer`, for `file.value`) or
  1926. * something else (for `file.result`).
  1927. */
  1928. compile(): Result
  1929. }
  1930. /**
  1931. * Constructor.
  1932. *
  1933. * @param tree
  1934. * Tree to compile.
  1935. * @param file
  1936. * File associated with `tree`.
  1937. * @returns
  1938. * Instance.
  1939. */
  1940. constructor(tree: Tree, file: VFile$1)
  1941. }
  1942. /**
  1943. * Normal function to compile a tree.
  1944. *
  1945. * @typeParam Tree
  1946. * The node that the compiler receives.
  1947. * @typeParam Result
  1948. * The thing that the compiler yields.
  1949. * @param tree
  1950. * Tree to compile.
  1951. * @param file
  1952. * File associated with `tree`.
  1953. * @returns
  1954. * New content: compiled text (`string` or `Buffer`, for `file.value`) or
  1955. * something else (for `file.result`).
  1956. */
  1957. type CompilerFunction<Tree extends Node$2 = Node$2, Result = unknown> = (
  1958. tree: Tree,
  1959. file: VFile$1
  1960. ) => Result
  1961. /**
  1962. * Callback called when a done running.
  1963. *
  1964. * @typeParam Tree
  1965. * The tree that the callback receives.
  1966. * @param error
  1967. * Error passed when unsuccessful.
  1968. * @param node
  1969. * Tree to transform.
  1970. * @param file
  1971. * File passed when successful.
  1972. * @returns
  1973. * Nothing.
  1974. */
  1975. type RunCallback<Tree extends Node$2 = Node$2> = (
  1976. error?: Error | null | undefined,
  1977. node?: Tree | undefined,
  1978. file?: VFile$1 | undefined
  1979. ) => void
  1980. /**
  1981. * Callback called when a done processing.
  1982. *
  1983. * @typeParam File
  1984. * The file that the callback receives.
  1985. * @param error
  1986. * Error passed when unsuccessful.
  1987. * @param file
  1988. * File passed when successful.
  1989. * @returns
  1990. * Nothing.
  1991. */
  1992. type ProcessCallback<File extends VFile$1 = VFile$1> = (
  1993. error?: Error | null | undefined,
  1994. file?: File | undefined
  1995. ) => void
  1996. /**
  1997. * Configuration for internal plugin `recma-jsx-rewrite`.
  1998. */
  1999. type RecmaJsxRewriteOptions$1 = {
  2000. /**
  2001. * Whether to use an import statement or `arguments[0]` to get the provider.
  2002. */
  2003. outputFormat?: 'function-body' | 'program' | null | undefined;
  2004. /**
  2005. * Place to import a provider from.
  2006. */
  2007. providerImportSource?: string | null | undefined;
  2008. /**
  2009. * Whether to add extra info to error messages in generated code.
  2010. *
  2011. * This also results in the development automatic JSX runtime
  2012. * (`/jsx-dev-runtime`, `jsxDEV`) being used, which passes positional info to
  2013. * nodes.
  2014. * The default can be set to `true` in Node.js through environment variables:
  2015. * set `NODE_ENV=development`.
  2016. */
  2017. development?: boolean | null | undefined;
  2018. };
  2019. interface StartOfSourceMap {
  2020. file?: string;
  2021. sourceRoot?: string;
  2022. }
  2023. interface RawSourceMap extends StartOfSourceMap {
  2024. version: string;
  2025. sources: string[];
  2026. names: string[];
  2027. sourcesContent?: string[];
  2028. mappings: string;
  2029. }
  2030. interface Position {
  2031. line: number;
  2032. column: number;
  2033. }
  2034. interface LineRange extends Position {
  2035. lastColumn: number;
  2036. }
  2037. interface FindPosition extends Position {
  2038. // SourceMapConsumer.GREATEST_LOWER_BOUND or SourceMapConsumer.LEAST_UPPER_BOUND
  2039. bias?: number;
  2040. }
  2041. interface SourceFindPosition extends FindPosition {
  2042. source: string;
  2043. }
  2044. interface MappedPosition extends Position {
  2045. source: string;
  2046. name?: string;
  2047. }
  2048. interface MappingItem {
  2049. source: string;
  2050. generatedLine: number;
  2051. generatedColumn: number;
  2052. originalLine: number;
  2053. originalColumn: number;
  2054. name: string;
  2055. }
  2056. declare class SourceMapConsumer {
  2057. static GENERATED_ORDER: number;
  2058. static ORIGINAL_ORDER: number;
  2059. static GREATEST_LOWER_BOUND: number;
  2060. static LEAST_UPPER_BOUND: number;
  2061. constructor(rawSourceMap: RawSourceMap);
  2062. computeColumnSpans(): void;
  2063. originalPositionFor(generatedPosition: FindPosition): MappedPosition;
  2064. generatedPositionFor(originalPosition: SourceFindPosition): LineRange;
  2065. allGeneratedPositionsFor(originalPosition: MappedPosition): Position[];
  2066. hasContentsOfAllSources(): boolean;
  2067. sourceContentFor(source: string, returnNullOnMissing?: boolean): string;
  2068. eachMapping(callback: (mapping: MappingItem) => void, context?: any, order?: number): void;
  2069. }
  2070. interface Mapping {
  2071. generated: Position;
  2072. original: Position;
  2073. source: string;
  2074. name?: string;
  2075. }
  2076. declare class SourceMapGenerator$1 {
  2077. constructor(startOfSourceMap?: StartOfSourceMap);
  2078. static fromSourceMap(sourceMapConsumer: SourceMapConsumer): SourceMapGenerator$1;
  2079. addMapping(mapping: Mapping): void;
  2080. setSourceContent(sourceFile: string, sourceContent: string): void;
  2081. applySourceMap(sourceMapConsumer: SourceMapConsumer, sourceFile?: string, sourceMapPath?: string): void;
  2082. toString(): string;
  2083. }
  2084. type SourceMapGenerator = typeof SourceMapGenerator$1;
  2085. /**
  2086. * Configuration for internal plugin `recma-stringify`.
  2087. */
  2088. type RecmaStringifyOptions$1 = {
  2089. /**
  2090. * Generate a source map by passing a `SourceMapGenerator` from `source-map`
  2091. * in.
  2092. */
  2093. SourceMapGenerator?: SourceMapGenerator | null | undefined;
  2094. };
  2095. /**
  2096. * Configuration for internal plugin `recma-document`.
  2097. */
  2098. type RecmaDocumentOptions$1 = {
  2099. /**
  2100. * Whether to use either `import` and `export` statements to get the runtime
  2101. * (and optionally provider) and export the content, or get values from
  2102. * `arguments` and return things.
  2103. */
  2104. outputFormat?: 'function-body' | 'program' | null | undefined;
  2105. /**
  2106. * Whether to keep `import` (and `export … from`) statements or compile them
  2107. * to dynamic `import()` instead.
  2108. */
  2109. useDynamicImport?: boolean | null | undefined;
  2110. /**
  2111. * Resolve `import`s (and `export … from`, and `import.meta.url`) relative to
  2112. * this URL.
  2113. */
  2114. baseUrl?: string | null | undefined;
  2115. /**
  2116. * Pragma for JSX (used in classic runtime).
  2117. */
  2118. pragma?: string | null | undefined;
  2119. /**
  2120. * Pragma for JSX fragments (used in classic runtime).
  2121. */
  2122. pragmaFrag?: string | null | undefined;
  2123. /**
  2124. * Where to import the identifier of `pragma` from (used in classic runtime).
  2125. */
  2126. pragmaImportSource?: string | null | undefined;
  2127. /**
  2128. * Place to import automatic JSX runtimes from (used in automatic runtime).
  2129. */
  2130. jsxImportSource?: string | null | undefined;
  2131. /**
  2132. * JSX runtime to use.
  2133. */
  2134. jsxRuntime?: 'automatic' | 'classic' | null | undefined;
  2135. };
  2136. // Type definitions for non-npm package Hast 2.3
  2137. /**
  2138. * This map registers all node types that may be used as top-level content in the document.
  2139. *
  2140. * These types are accepted inside `root` nodes.
  2141. *
  2142. * This interface can be augmented to register custom node types.
  2143. *
  2144. * @example
  2145. * declare module 'hast' {
  2146. * interface RootContentMap {
  2147. * // Allow using raw nodes defined by `rehype-raw`.
  2148. * raw: Raw;
  2149. * }
  2150. * }
  2151. */
  2152. interface RootContentMap {
  2153. comment: Comment;
  2154. doctype: DocType;
  2155. element: Element;
  2156. text: Text$1;
  2157. }
  2158. /**
  2159. * This map registers all node types that may be used as content in an element.
  2160. *
  2161. * These types are accepted inside `element` nodes.
  2162. *
  2163. * This interface can be augmented to register custom node types.
  2164. *
  2165. * @example
  2166. * declare module 'hast' {
  2167. * interface RootContentMap {
  2168. * custom: Custom;
  2169. * }
  2170. * }
  2171. */
  2172. interface ElementContentMap {
  2173. comment: Comment;
  2174. element: Element;
  2175. text: Text$1;
  2176. }
  2177. type Content$1 = RootContent | ElementContent;
  2178. type RootContent = RootContentMap[keyof RootContentMap];
  2179. type ElementContent = ElementContentMap[keyof ElementContentMap];
  2180. /**
  2181. * Node in hast containing other nodes.
  2182. */
  2183. interface Parent$1 extends Parent$2 {
  2184. /**
  2185. * List representing the children of a node.
  2186. */
  2187. children: Content$1[];
  2188. }
  2189. /**
  2190. * Nodes in hast containing a value.
  2191. */
  2192. interface Literal$1 extends Literal$2 {
  2193. value: string;
  2194. }
  2195. /**
  2196. * Root represents a document.
  2197. * Can be used as the rood of a tree, or as a value of the
  2198. * content field on a 'template' Element, never as a child.
  2199. */
  2200. interface Root$1 extends Parent$1 {
  2201. /**
  2202. * Represents this variant of a Node.
  2203. */
  2204. type: 'root';
  2205. /**
  2206. * List representing the children of a node.
  2207. */
  2208. children: RootContent[];
  2209. }
  2210. /**
  2211. * Element represents an HTML Element.
  2212. */
  2213. interface Element extends Parent$1 {
  2214. /**
  2215. * Represents this variant of a Node.
  2216. */
  2217. type: 'element';
  2218. /**
  2219. * Represents the element’s local name.
  2220. */
  2221. tagName: string;
  2222. /**
  2223. * Represents information associated with the element.
  2224. */
  2225. properties?: Properties | undefined;
  2226. /**
  2227. * If the tagName field is 'template', a content field can be present.
  2228. */
  2229. content?: Root$1 | undefined;
  2230. /**
  2231. * List representing the children of a node.
  2232. */
  2233. children: ElementContent[];
  2234. }
  2235. /**
  2236. * Represents information associated with an element.
  2237. */
  2238. interface Properties {
  2239. [PropertyName: string]: boolean | number | string | null | undefined | Array<string | number>;
  2240. }
  2241. /**
  2242. * Represents an HTML DocumentType.
  2243. */
  2244. interface DocType extends Node$2 {
  2245. /**
  2246. * Represents this variant of a Node.
  2247. */
  2248. type: 'doctype';
  2249. name: string;
  2250. }
  2251. /**
  2252. * Represents an HTML Comment.
  2253. */
  2254. interface Comment extends Literal$1 {
  2255. /**
  2256. * Represents this variant of a Literal.
  2257. */
  2258. type: 'comment';
  2259. }
  2260. /**
  2261. * Represents an HTML Text.
  2262. */
  2263. interface Text$1 extends Literal$1 {
  2264. /**
  2265. * Represents this variant of a Literal.
  2266. */
  2267. type: 'text';
  2268. }
  2269. /**
  2270. * Specify casing to use for attribute names.
  2271. *
  2272. * HTML casing is for example `class`, `stroke-linecap`, `xml:lang`.
  2273. * React casing is for example `className`, `strokeLinecap`, `xmlLang`.
  2274. */
  2275. type ElementAttributeNameCase = 'html' | 'react';
  2276. /**
  2277. * Casing to use for property names in `style` objects.
  2278. *
  2279. * CSS casing is for example `background-color` and `-webkit-line-clamp`.
  2280. * DOM casing is for example `backgroundColor` and `WebkitLineClamp`.
  2281. */
  2282. type StylePropertyNameCase = 'css' | 'dom';
  2283. /**
  2284. * Configuration for internal plugin `rehype-recma`.
  2285. */
  2286. type Options$3 = {
  2287. /**
  2288. * Specify casing to use for attribute names.
  2289. *
  2290. * This casing is used for hast elements, not for embedded MDX JSX nodes
  2291. * (components that someone authored manually).
  2292. */
  2293. elementAttributeNameCase?: ElementAttributeNameCase | null | undefined;
  2294. /**
  2295. * Specify casing to use for property names in `style` objects.
  2296. *
  2297. * This casing is used for hast elements, not for embedded MDX JSX nodes
  2298. * (components that someone authored manually).
  2299. */
  2300. stylePropertyNameCase?: StylePropertyNameCase | null | undefined;
  2301. };
  2302. // Type definitions for Mdast 3.0
  2303. type AlignType = 'left' | 'right' | 'center' | null;
  2304. type ReferenceType = 'shortcut' | 'collapsed' | 'full';
  2305. /**
  2306. * This map registers all node types that may be used where markdown block content is accepted.
  2307. *
  2308. * These types are accepted inside block quotes, list items, footnotes, and roots.
  2309. *
  2310. * This interface can be augmented to register custom node types.
  2311. *
  2312. * @example
  2313. * declare module 'mdast' {
  2314. * interface BlockContentMap {
  2315. * // Allow using math nodes defined by `remark-math`.
  2316. * math: Math;
  2317. * }
  2318. * }
  2319. */
  2320. interface BlockContentMap {
  2321. paragraph: Paragraph;
  2322. heading: Heading;
  2323. thematicBreak: ThematicBreak;
  2324. blockquote: Blockquote;
  2325. list: List;
  2326. table: Table;
  2327. html: HTML;
  2328. code: Code;
  2329. }
  2330. /**
  2331. * This map registers all frontmatter node types.
  2332. *
  2333. * This interface can be augmented to register custom node types.
  2334. *
  2335. * @example
  2336. * declare module 'mdast' {
  2337. * interface FrontmatterContentMap {
  2338. * // Allow using toml nodes defined by `remark-frontmatter`.
  2339. * toml: TOML;
  2340. * }
  2341. * }
  2342. */
  2343. interface FrontmatterContentMap {
  2344. yaml: YAML;
  2345. }
  2346. /**
  2347. * This map registers all node definition types.
  2348. *
  2349. * This interface can be augmented to register custom node types.
  2350. *
  2351. * @example
  2352. * declare module 'mdast' {
  2353. * interface DefinitionContentMap {
  2354. * custom: Custom;
  2355. * }
  2356. * }
  2357. */
  2358. interface DefinitionContentMap {
  2359. definition: Definition;
  2360. footnoteDefinition: FootnoteDefinition;
  2361. }
  2362. /**
  2363. * This map registers all node types that are acceptable in a static phrasing context.
  2364. *
  2365. * This interface can be augmented to register custom node types in a phrasing context, including links and link
  2366. * references.
  2367. *
  2368. * @example
  2369. * declare module 'mdast' {
  2370. * interface StaticPhrasingContentMap {
  2371. * mdxJsxTextElement: MDXJSXTextElement;
  2372. * }
  2373. * }
  2374. */
  2375. interface StaticPhrasingContentMap {
  2376. text: Text;
  2377. emphasis: Emphasis;
  2378. strong: Strong;
  2379. delete: Delete;
  2380. html: HTML;
  2381. inlineCode: InlineCode;
  2382. break: Break;
  2383. image: Image;
  2384. imageReference: ImageReference;
  2385. footnote: Footnote;
  2386. footnoteReference: FootnoteReference;
  2387. }
  2388. /**
  2389. * This map registers all node types that are acceptable in a (interactive) phrasing context (so not in links).
  2390. *
  2391. * This interface can be augmented to register custom node types in a phrasing context, excluding links and link
  2392. * references.
  2393. *
  2394. * @example
  2395. * declare module 'mdast' {
  2396. * interface PhrasingContentMap {
  2397. * custom: Custom;
  2398. * }
  2399. * }
  2400. */
  2401. interface PhrasingContentMap extends StaticPhrasingContentMap {
  2402. link: Link;
  2403. linkReference: LinkReference;
  2404. }
  2405. /**
  2406. * This map registers all node types that are acceptable inside lists.
  2407. *
  2408. * This interface can be augmented to register custom node types that are acceptable inside lists.
  2409. *
  2410. * @example
  2411. * declare module 'mdast' {
  2412. * interface ListContentMap {
  2413. * custom: Custom;
  2414. * }
  2415. * }
  2416. */
  2417. interface ListContentMap {
  2418. listItem: ListItem;
  2419. }
  2420. /**
  2421. * This map registers all node types that are acceptable inside tables (not table cells).
  2422. *
  2423. * This interface can be augmented to register custom node types that are acceptable inside tables.
  2424. *
  2425. * @example
  2426. * declare module 'mdast' {
  2427. * interface TableContentMap {
  2428. * custom: Custom;
  2429. * }
  2430. * }
  2431. */
  2432. interface TableContentMap {
  2433. tableRow: TableRow;
  2434. }
  2435. /**
  2436. * This map registers all node types that are acceptable inside tables rows (not table cells).
  2437. *
  2438. * This interface can be augmented to register custom node types that are acceptable inside table rows.
  2439. *
  2440. * @example
  2441. * declare module 'mdast' {
  2442. * interface RowContentMap {
  2443. * custom: Custom;
  2444. * }
  2445. * }
  2446. */
  2447. interface RowContentMap {
  2448. tableCell: TableCell;
  2449. }
  2450. type Content = TopLevelContent | ListContent | TableContent | RowContent | PhrasingContent;
  2451. type TopLevelContent = BlockContent | FrontmatterContent | DefinitionContent;
  2452. type BlockContent = BlockContentMap[keyof BlockContentMap];
  2453. type FrontmatterContent = FrontmatterContentMap[keyof FrontmatterContentMap];
  2454. type DefinitionContent = DefinitionContentMap[keyof DefinitionContentMap];
  2455. type ListContent = ListContentMap[keyof ListContentMap];
  2456. type TableContent = TableContentMap[keyof TableContentMap];
  2457. type RowContent = RowContentMap[keyof RowContentMap];
  2458. type PhrasingContent = PhrasingContentMap[keyof PhrasingContentMap];
  2459. type StaticPhrasingContent = StaticPhrasingContentMap[keyof StaticPhrasingContentMap];
  2460. interface Parent extends Parent$2 {
  2461. children: Content[];
  2462. }
  2463. interface Literal extends Literal$2 {
  2464. value: string;
  2465. }
  2466. interface Root extends Parent {
  2467. type: 'root';
  2468. }
  2469. interface Paragraph extends Parent {
  2470. type: 'paragraph';
  2471. children: PhrasingContent[];
  2472. }
  2473. interface Heading extends Parent {
  2474. type: 'heading';
  2475. depth: 1 | 2 | 3 | 4 | 5 | 6;
  2476. children: PhrasingContent[];
  2477. }
  2478. interface ThematicBreak extends Node$2 {
  2479. type: 'thematicBreak';
  2480. }
  2481. interface Blockquote extends Parent {
  2482. type: 'blockquote';
  2483. children: Array<BlockContent | DefinitionContent>;
  2484. }
  2485. interface List extends Parent {
  2486. type: 'list';
  2487. ordered?: boolean | null | undefined;
  2488. start?: number | null | undefined;
  2489. spread?: boolean | null | undefined;
  2490. children: ListContent[];
  2491. }
  2492. interface ListItem extends Parent {
  2493. type: 'listItem';
  2494. checked?: boolean | null | undefined;
  2495. spread?: boolean | null | undefined;
  2496. children: Array<BlockContent | DefinitionContent>;
  2497. }
  2498. interface Table extends Parent {
  2499. type: 'table';
  2500. align?: AlignType[] | null | undefined;
  2501. children: TableContent[];
  2502. }
  2503. interface TableRow extends Parent {
  2504. type: 'tableRow';
  2505. children: RowContent[];
  2506. }
  2507. interface TableCell extends Parent {
  2508. type: 'tableCell';
  2509. children: PhrasingContent[];
  2510. }
  2511. interface HTML extends Literal {
  2512. type: 'html';
  2513. }
  2514. interface Code extends Literal {
  2515. type: 'code';
  2516. lang?: string | null | undefined;
  2517. meta?: string | null | undefined;
  2518. }
  2519. interface YAML extends Literal {
  2520. type: 'yaml';
  2521. }
  2522. interface Definition extends Node$2, Association, Resource {
  2523. type: 'definition';
  2524. }
  2525. interface FootnoteDefinition extends Parent, Association {
  2526. type: 'footnoteDefinition';
  2527. children: Array<BlockContent | DefinitionContent>;
  2528. }
  2529. interface Text extends Literal {
  2530. type: 'text';
  2531. }
  2532. interface Emphasis extends Parent {
  2533. type: 'emphasis';
  2534. children: PhrasingContent[];
  2535. }
  2536. interface Strong extends Parent {
  2537. type: 'strong';
  2538. children: PhrasingContent[];
  2539. }
  2540. interface Delete extends Parent {
  2541. type: 'delete';
  2542. children: PhrasingContent[];
  2543. }
  2544. interface InlineCode extends Literal {
  2545. type: 'inlineCode';
  2546. }
  2547. interface Break extends Node$2 {
  2548. type: 'break';
  2549. }
  2550. interface Link extends Parent, Resource {
  2551. type: 'link';
  2552. children: StaticPhrasingContent[];
  2553. }
  2554. interface Image extends Node$2, Resource, Alternative {
  2555. type: 'image';
  2556. }
  2557. interface LinkReference extends Parent, Reference {
  2558. type: 'linkReference';
  2559. children: StaticPhrasingContent[];
  2560. }
  2561. interface ImageReference extends Node$2, Reference, Alternative {
  2562. type: 'imageReference';
  2563. }
  2564. interface Footnote extends Parent {
  2565. type: 'footnote';
  2566. children: PhrasingContent[];
  2567. }
  2568. interface FootnoteReference extends Node$2, Association {
  2569. type: 'footnoteReference';
  2570. }
  2571. // Mixin
  2572. interface Resource {
  2573. url: string;
  2574. title?: string | null | undefined;
  2575. }
  2576. interface Association {
  2577. identifier: string;
  2578. label?: string | null | undefined;
  2579. }
  2580. interface Reference extends Association {
  2581. referenceType: ReferenceType;
  2582. }
  2583. interface Alternative {
  2584. alt?: string | null | undefined;
  2585. }
  2586. type HastContent = Content$1
  2587. type HastElement = Element
  2588. type HastElementContent = ElementContent
  2589. type HastProperties = Properties
  2590. type HastRoot = Root$1
  2591. type MdastContent = Content
  2592. type MdastDefinition = Definition
  2593. type MdastFootnoteDefinition = FootnoteDefinition
  2594. type MdastParent = Parent
  2595. type MdastRoot = Root
  2596. type HastNodes = HastRoot | HastContent
  2597. type MdastNodes = MdastRoot | MdastContent
  2598. type MdastParents = Extract<MdastNodes, MdastParent>
  2599. /**
  2600. * hast fields.
  2601. */
  2602. type EmbeddedHastFields = {
  2603. /**
  2604. * Generate a specific element with this tag name instead.
  2605. */
  2606. hName?: string | null | undefined
  2607. /**
  2608. * Generate an element with these properties instead.
  2609. */
  2610. hProperties?: HastProperties | null | undefined
  2611. /**
  2612. * Generate an element with this content instead.
  2613. */
  2614. hChildren?: Array<HastElementContent> | null | undefined
  2615. }
  2616. /**
  2617. * mdast data with embedded hast fields.
  2618. */
  2619. type MdastData = Record<string, unknown> & EmbeddedHastFields
  2620. /**
  2621. * mdast node with embedded hast data.
  2622. */
  2623. type MdastNodeWithData = MdastNodes & {
  2624. data?: MdastData | null | undefined
  2625. }
  2626. /**
  2627. * Point-like value.
  2628. */
  2629. type PointLike = {
  2630. /**
  2631. * Line.
  2632. */
  2633. line?: number | null | undefined
  2634. /**
  2635. * Column.
  2636. */
  2637. column?: number | null | undefined
  2638. /**
  2639. * Offset.
  2640. */
  2641. offset?: number | null | undefined
  2642. }
  2643. /**
  2644. * Position-like value.
  2645. */
  2646. type PositionLike = {
  2647. /**
  2648. * Point-like value.
  2649. */
  2650. start?: PointLike | null | undefined
  2651. /**
  2652. * Point-like value.
  2653. */
  2654. end?: PointLike | null | undefined
  2655. }
  2656. /**
  2657. * Handle a node.
  2658. */
  2659. type Handler = (
  2660. state: State,
  2661. node: any,
  2662. parent: MdastParents | null | undefined
  2663. ) => HastElementContent | Array<HastElementContent> | null | undefined
  2664. /**
  2665. * Signature of `state` for when props are passed.
  2666. */
  2667. type HFunctionProps = (
  2668. node: MdastNodes | PositionLike | null | undefined,
  2669. tagName: string,
  2670. props: HastProperties,
  2671. children?: Array<HastElementContent> | null | undefined
  2672. ) => HastElement
  2673. /**
  2674. * Signature of `state` for when no props are passed.
  2675. */
  2676. type HFunctionNoProps = (
  2677. node: MdastNodes | PositionLike | null | undefined,
  2678. tagName: string,
  2679. children?: Array<HastElementContent> | null | undefined
  2680. ) => HastElement
  2681. /**
  2682. * Info on `state`.
  2683. */
  2684. type HFields = {
  2685. /**
  2686. * Whether HTML is allowed.
  2687. */
  2688. dangerous: boolean
  2689. /**
  2690. * Prefix to use to prevent DOM clobbering.
  2691. */
  2692. clobberPrefix: string
  2693. /**
  2694. * Label to use to introduce the footnote section.
  2695. */
  2696. footnoteLabel: string
  2697. /**
  2698. * HTML used for the footnote label.
  2699. */
  2700. footnoteLabelTagName: string
  2701. /**
  2702. * Properties on the HTML tag used for the footnote label.
  2703. */
  2704. footnoteLabelProperties: HastProperties
  2705. /**
  2706. * Label to use from backreferences back to their footnote call.
  2707. */
  2708. footnoteBackLabel: string
  2709. /**
  2710. * Definition cache.
  2711. */
  2712. definition: (identifier: string) => MdastDefinition | null
  2713. /**
  2714. * Footnote definitions by their identifier.
  2715. */
  2716. footnoteById: Record<string, MdastFootnoteDefinition>
  2717. /**
  2718. * Identifiers of order when footnote calls first appear in tree order.
  2719. */
  2720. footnoteOrder: Array<string>
  2721. /**
  2722. * Counts for how often the same footnote was called.
  2723. */
  2724. footnoteCounts: Record<string, number>
  2725. /**
  2726. * Applied handlers.
  2727. */
  2728. handlers: Handlers
  2729. /**
  2730. * Handler for any none not in `passThrough` or otherwise handled.
  2731. */
  2732. unknownHandler: Handler
  2733. /**
  2734. * Copy a node’s positional info.
  2735. */
  2736. patch: (from: MdastNodes, node: HastNodes) => void
  2737. /**
  2738. * Honor the `data` of `from`, and generate an element instead of `node`.
  2739. */
  2740. applyData: <Type extends HastNodes>(
  2741. from: MdastNodes,
  2742. to: Type
  2743. ) => Element | Type
  2744. /**
  2745. * Transform an mdast node to hast.
  2746. */
  2747. one: (
  2748. node: MdastNodes,
  2749. parent: MdastParents | null | undefined
  2750. ) => HastElementContent | Array<HastElementContent> | null | undefined
  2751. /**
  2752. * Transform the children of an mdast parent to hast.
  2753. */
  2754. all: (node: MdastNodes) => Array<HastElementContent>
  2755. /**
  2756. * Wrap `nodes` with line endings between each node, adds initial/final line endings when `loose`.
  2757. */
  2758. wrap: <Type_1 extends Content$1>(
  2759. nodes: Type_1[],
  2760. loose?: boolean | null | undefined
  2761. ) => (Type_1 | Text$1)[]
  2762. /**
  2763. * Like `state` but lower-level and usable on non-elements.
  2764. * Deprecated: use `patch` and `applyData`.
  2765. */
  2766. augment: (
  2767. left: MdastNodeWithData | PositionLike | null | undefined,
  2768. right: HastElementContent
  2769. ) => HastElementContent
  2770. /**
  2771. * List of node types to pass through untouched (except for their children).
  2772. */
  2773. passThrough: Array<string>
  2774. }
  2775. /**
  2776. * Configuration (optional).
  2777. */
  2778. type Options$2 = {
  2779. /**
  2780. * Whether to persist raw HTML in markdown in the hast tree.
  2781. */
  2782. allowDangerousHtml?: boolean | null | undefined
  2783. /**
  2784. * Prefix to use before the `id` attribute on footnotes to prevent it from
  2785. * *clobbering*.
  2786. */
  2787. clobberPrefix?: string | null | undefined
  2788. /**
  2789. * Label to use from backreferences back to their footnote call (affects
  2790. * screen readers).
  2791. */
  2792. footnoteBackLabel?: string | null | undefined
  2793. /**
  2794. * Label to use for the footnotes section (affects screen readers).
  2795. */
  2796. footnoteLabel?: string | null | undefined
  2797. /**
  2798. * Properties to use on the footnote label (note that `id: 'footnote-label'`
  2799. * is always added as footnote calls use it with `aria-describedby` to
  2800. * provide an accessible label).
  2801. */
  2802. footnoteLabelProperties?: HastProperties | null | undefined
  2803. /**
  2804. * Tag name to use for the footnote label.
  2805. */
  2806. footnoteLabelTagName?: string | null | undefined
  2807. /**
  2808. * Extra handlers for nodes.
  2809. */
  2810. handlers?: Handlers | null | undefined
  2811. /**
  2812. * List of custom mdast node types to pass through (keep) in hast (note that
  2813. * the node itself is passed, but eventual children are transformed).
  2814. */
  2815. passThrough?: Array<string> | null | undefined
  2816. /**
  2817. * Handler for all unknown nodes.
  2818. */
  2819. unknownHandler?: Handler | null | undefined
  2820. }
  2821. /**
  2822. * Handle nodes.
  2823. */
  2824. type Handlers = Record<string, Handler>
  2825. /**
  2826. * Info passed around.
  2827. */
  2828. type State = HFunctionProps & HFunctionNoProps & HFields
  2829. // Expose node type.
  2830. /**
  2831. * Raw string of HTML embedded into HTML AST.
  2832. */
  2833. // eslint-disable-next-line @typescript-eslint/consistent-type-definitions
  2834. interface Raw$1 extends Literal$1 {
  2835. /**
  2836. * Node type.
  2837. */
  2838. type: 'raw'
  2839. }
  2840. // Register nodes in content.
  2841. declare module 'hast' {
  2842. // eslint-disable-next-line @typescript-eslint/consistent-type-definitions
  2843. interface RootContentMap {
  2844. /**
  2845. * Raw string of HTML embedded into HTML AST.
  2846. */
  2847. raw: Raw$1
  2848. }
  2849. // eslint-disable-next-line @typescript-eslint/consistent-type-definitions
  2850. interface ElementContentMap {
  2851. /**
  2852. * Raw string of HTML embedded into HTML AST.
  2853. */
  2854. raw: Raw$1
  2855. }
  2856. }
  2857. // Expose node type.
  2858. /**
  2859. * Raw string of HTML embedded into HTML AST.
  2860. */
  2861. // eslint-disable-next-line @typescript-eslint/consistent-type-definitions
  2862. interface Raw extends Literal$1 {
  2863. /**
  2864. * Node type.
  2865. */
  2866. type: 'raw'
  2867. }
  2868. // Register nodes in content.
  2869. declare module 'hast' {
  2870. // eslint-disable-next-line @typescript-eslint/consistent-type-definitions
  2871. interface RootContentMap {
  2872. /**
  2873. * Raw string of HTML embedded into HTML AST.
  2874. */
  2875. raw: Raw
  2876. }
  2877. // eslint-disable-next-line @typescript-eslint/consistent-type-definitions
  2878. interface ElementContentMap {
  2879. /**
  2880. * Raw string of HTML embedded into HTML AST.
  2881. */
  2882. raw: Raw
  2883. }
  2884. }
  2885. type Options$1 = Options$2
  2886. type Options = Options$1
  2887. type RemarkRehypeOptions = Options;
  2888. type RehypeRecmaOptions = Options$3;
  2889. type RecmaDocumentOptions = RecmaDocumentOptions$1;
  2890. type RecmaStringifyOptions = RecmaStringifyOptions$1;
  2891. type RecmaJsxRewriteOptions = RecmaJsxRewriteOptions$1;
  2892. /**
  2893. * Base configuration.
  2894. */
  2895. type BaseProcessorOptions$1 = {
  2896. /**
  2897. * Whether to keep JSX.
  2898. */
  2899. jsx?: boolean | null | undefined;
  2900. /**
  2901. * Format of the files to be processed.
  2902. */
  2903. format?: 'mdx' | 'md' | null | undefined;
  2904. /**
  2905. * Whether to compile to a whole program or a function body..
  2906. */
  2907. outputFormat?: "function-body" | "program" | undefined;
  2908. /**
  2909. * Extensions (with `.`) for markdown.
  2910. */
  2911. mdExtensions?: Array<string> | null | undefined;
  2912. /**
  2913. * Extensions (with `.`) for MDX.
  2914. */
  2915. mdxExtensions?: Array<string> | null | undefined;
  2916. /**
  2917. * List of recma (esast, JavaScript) plugins.
  2918. */
  2919. recmaPlugins?: PluggableList | null | undefined;
  2920. /**
  2921. * List of remark (mdast, markdown) plugins.
  2922. */
  2923. remarkPlugins?: PluggableList | null | undefined;
  2924. /**
  2925. * List of rehype (hast, HTML) plugins.
  2926. */
  2927. rehypePlugins?: PluggableList | null | undefined;
  2928. /**
  2929. * Options to pass through to `remark-rehype`.
  2930. */
  2931. remarkRehypeOptions?: RemarkRehypeOptions | null | undefined;
  2932. };
  2933. /**
  2934. * Configuration for internal plugins.
  2935. */
  2936. type PluginOptions$1 = Omit<RehypeRecmaOptions & RecmaDocumentOptions & RecmaStringifyOptions & RecmaJsxRewriteOptions, 'outputFormat'>;
  2937. /**
  2938. * Compile MDX to JS.
  2939. *
  2940. * @param {VFileCompatible} vfileCompatible
  2941. * MDX document to parse (`string`, `Buffer`, `vfile`, anything that can be
  2942. * given to `vfile`).
  2943. * @param {CompileOptions | null | undefined} [compileOptions]
  2944. * Compile configuration.
  2945. * @return {Promise<VFile>}
  2946. * File.
  2947. */
  2948. declare function compile$1(vfileCompatible: VFileCompatible, compileOptions?: CompileOptions$1 | null | undefined): Promise<VFile>;
  2949. type VFile = VFile$1;
  2950. type VFileCompatible = Compatible;
  2951. type PluginOptions = PluginOptions$1;
  2952. type BaseProcessorOptions = BaseProcessorOptions$1;
  2953. /**
  2954. * Core configuration.
  2955. */
  2956. type CoreProcessorOptions = Omit<BaseProcessorOptions, 'format'>;
  2957. /**
  2958. * Extra configuration.
  2959. */
  2960. type ExtraOptions = {
  2961. /**
  2962. * Format of `file`.
  2963. */
  2964. format?: 'detect' | 'mdx' | 'md' | null | undefined;
  2965. };
  2966. /**
  2967. * Configuration.
  2968. */
  2969. type CompileOptions$1 = CoreProcessorOptions & PluginOptions & ExtraOptions;
  2970. interface JSXOptions {
  2971. pragma?: string;
  2972. pragmaFrag?: string;
  2973. throwIfNamespace?: false;
  2974. runtime?: 'classic' | 'automatic';
  2975. importSource?: string;
  2976. }
  2977. type MdxCompileOptions = Parameters<typeof compile$1>[1];
  2978. interface CompileOptions {
  2979. skipCsf?: boolean;
  2980. mdxCompileOptions?: MdxCompileOptions;
  2981. jsxOptions?: JSXOptions;
  2982. }
  2983. declare const SEPARATOR = "/* ========= */";
  2984. declare const genBabel: (store: any, root: any) => any;
  2985. declare const plugin: (store: any) => (root: any) => any;
  2986. declare const postprocess: (code: string, extractedExports: string) => string;
  2987. declare const compile: (input: string, { skipCsf, mdxCompileOptions, jsxOptions }?: CompileOptions) => Promise<string>;
  2988. declare const compileSync: (input: string, { skipCsf, mdxCompileOptions, jsxOptions }?: CompileOptions) => string;
  2989. export { CompileOptions, JSXOptions, MdxCompileOptions, SEPARATOR, compile, compileSync, genBabel, plugin, postprocess, wrapperJs };