|
1 |
| -import { Parser } from 'acorn' |
| 1 | +import * as acorn from 'acorn'; |
2 | 2 |
|
3 |
| -declare const jsx: (options?: jsx.Options) => (BaseParser: typeof Parser) => typeof Parser; |
| 3 | +interface JsxTokTypes extends AcornTokTypes { |
| 4 | + jsxName: acorn.TokenType, |
| 5 | + jsxText: acorn.TokenType, |
| 6 | + jsxTagEnd: acorn.TokenType, |
| 7 | + jsxTagStart: acorn.TokenType |
| 8 | +} |
| 9 | + |
| 10 | +declare const jsx: { |
| 11 | + tokTypes: JsxTokTypes; |
| 12 | + (options?: jsx.Options): (BaseParser: typeof acorn.Parser) => jsx.AcornJsxParserCtor |
| 13 | +} |
| 14 | + |
| 15 | +type AcornTokTypes = typeof acorn.tokTypes; |
4 | 16 |
|
5 | 17 | declare namespace jsx {
|
| 18 | + |
| 19 | + type TokTypes = JsxTokTypes |
| 20 | + |
6 | 21 | interface Options {
|
7 | 22 | allowNamespacedObjects?: boolean;
|
8 | 23 | allowNamespaces?: boolean;
|
9 | 24 | }
|
| 25 | + |
| 26 | + interface TokContexts { |
| 27 | + tc_oTag: acorn.TokContext, |
| 28 | + tc_cTag: acorn.TokContext, |
| 29 | + tc_expr: acorn.TokContext |
| 30 | + } |
| 31 | + |
| 32 | + // We pick (statics) from acorn rather than plain extending to avoid complaint |
| 33 | + // about base constructors needing the same return type (i.e., we return |
| 34 | + // `AcornJsxParser` here) |
| 35 | + interface AcornJsxParserCtor extends Pick<typeof acorn.Parser, keyof typeof acorn.Parser> { |
| 36 | + readonly acornJsx: { |
| 37 | + tokTypes: TokTypes; |
| 38 | + tokContexts: TokContexts |
| 39 | + }; |
| 40 | + |
| 41 | + new (options: acorn.Options, input: string, startPos?: number): AcornJsxParser; |
| 42 | + } |
| 43 | + |
| 44 | + interface AcornJsxParser extends acorn.Parser { |
| 45 | + jsx_readToken(): string; |
| 46 | + jsx_readNewLine(normalizeCRLF: boolean): void; |
| 47 | + jsx_readString(quote: number): void; |
| 48 | + jsx_readEntity(): string; |
| 49 | + jsx_readWord(): void; |
| 50 | + jsx_parseIdentifier(): acorn.Node; |
| 51 | + jsx_parseNamespacedName(): acorn.Node; |
| 52 | + jsx_parseElementName(): acorn.Node | string; |
| 53 | + jsx_parseAttributeValue(): acorn.Node; |
| 54 | + jsx_parseEmptyExpression(): acorn.Node; |
| 55 | + jsx_parseExpressionContainer(): acorn.Node; |
| 56 | + jsx_parseAttribute(): acorn.Node; |
| 57 | + jsx_parseOpeningElementAt(startPos: number, startLoc?: acorn.SourceLocation): acorn.Node; |
| 58 | + jsx_parseClosingElementAt(startPos: number, startLoc?: acorn.SourceLocation): acorn.Node; |
| 59 | + jsx_parseElementAt(startPos: number, startLoc?: acorn.SourceLocation): acorn.Node; |
| 60 | + jsx_parseText(): acorn.Node; |
| 61 | + jsx_parseElement(): acorn.Node; |
| 62 | + } |
10 | 63 | }
|
11 | 64 |
|
12 | 65 | export = jsx;
|
0 commit comments