-
Notifications
You must be signed in to change notification settings - Fork 78
Improve typings: ESM, AcornJsxParser class and tokTypes const
#130
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 13 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
7b59516
feat: Support ESM declaration imports; add an `AcornJsxParser` class …
brettz9 dda96cc
feat: add missing `tokContexts` property on `acornJsx`
brettz9 baa0a61
feat: add missing jsx_ methods to `AcornJsxParser`
brettz9 8526524
feat: add instance properties to `AcornJsxParser`
brettz9 def9edd
fix: return `AcornJsxParser` from constructor
brettz9 2383cca
drop properties belonging on Acorn instead
brettz9 e4eca02
fix: use import with namespace specifier for acorn (avoids interop li…
brettz9 d97bd96
fix: switch `tokContexts` to type `TokContexts` (as not available as …
brettz9 620551b
refactor: avoid exporting `jsx` as named export
brettz9 835ea91
fix: in place of exporting non-existent class, export constructor and…
brettz9 5459984
refactor: use without prefix
brettz9 af6247d
refactor: export `TokTypes` interface and a single `jsx` export with …
brettz9 d80ceef
fix: drop extra `export as namespace`
brettz9 1c2fa2c
fix: use `exports = jsx` (and use jsx.Options)
brettz9 4cfaf9f
refactor: prefer interface over type, avoid redundant `export` on typ…
brettz9 41e8fcd
refactor: avoid extra type alias
brettz9 71b7e61
refactor: avoid exporting `tokTypes` and use CamelCase
brettz9 b976601
refactor: for now add a commit which redundantly but safely indicates…
brettz9 fd68170
refactor: remove some redundancy
brettz9 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,12 +1,62 @@ | ||
| import { Parser } from 'acorn' | ||
| import * as acorn from 'acorn'; | ||
|
|
||
| declare const jsx: (options?: jsx.Options) => (BaseParser: typeof Parser) => typeof Parser; | ||
| type tokTypes = typeof acorn.tokTypes; | ||
|
|
||
| declare namespace jsx { | ||
| interface Options { | ||
| allowNamespacedObjects?: boolean; | ||
| allowNamespaces?: boolean; | ||
| } | ||
| export interface Options { | ||
| allowNamespacedObjects?: boolean; | ||
| allowNamespaces?: boolean; | ||
| } | ||
|
|
||
| export = jsx; | ||
| export interface TokTypes extends tokTypes { | ||
| jsxName: acorn.TokenType, | ||
| jsxText: acorn.TokenType, | ||
| jsxTagEnd: acorn.TokenType, | ||
| jsxTagStart: acorn.TokenType | ||
| } | ||
|
|
||
| declare const jsx: { | ||
| tokTypes: TokTypes; | ||
| (options?: acorn.Options): (BaseParser: typeof acorn.Parser) => AcornJsxParser | ||
| } | ||
|
|
||
| export type TokContexts = { | ||
| tc_oTag: acorn.TokContext, | ||
| tc_cTag: acorn.TokContext, | ||
| tc_expr: acorn.TokContext | ||
| }; | ||
|
|
||
| type P = typeof acorn.Parser; | ||
|
|
||
| // We pick (statics) from acorn rather than plain extending to avoid complaint | ||
| // about base constructors needing the same return type (i.e., we return | ||
| // `IAcornJsxParser` here) | ||
| export interface AcornJsxParser extends Pick<P, keyof P> { | ||
| readonly acornJsx: { | ||
| tokTypes: TokTypes; | ||
| tokContexts: TokContexts | ||
| }; | ||
|
|
||
| new (options: acorn.Options, input: string, startPos?: number): IAcornJsxParser; | ||
| } | ||
|
|
||
| export interface IAcornJsxParser extends acorn.Parser { | ||
| jsx_readToken(): string; | ||
| jsx_readNewLine(normalizeCRLF: boolean): void; | ||
| jsx_readString(quote: number): void; | ||
| jsx_readEntity(): string; | ||
| jsx_readWord(): void; | ||
| jsx_parseIdentifier(): acorn.Node; | ||
| jsx_parseNamespacedName(): acorn.Node; | ||
| jsx_parseElementName(): acorn.Node | string; | ||
| jsx_parseAttributeValue(): acorn.Node; | ||
| jsx_parseEmptyExpression(): acorn.Node; | ||
| jsx_parseExpressionContainer(): acorn.Node; | ||
| jsx_parseAttribute(): acorn.Node; | ||
| jsx_parseOpeningElementAt(startPos: number, startLoc?: acorn.SourceLocation): acorn.Node; | ||
| jsx_parseClosingElementAt(startPos: number, startLoc?: acorn.SourceLocation): acorn.Node; | ||
| jsx_parseElementAt(startPos: number, startLoc?: acorn.SourceLocation): acorn.Node; | ||
| jsx_parseText(): acorn.Node; | ||
| jsx_parseElement(): acorn.Node; | ||
| } | ||
|
|
||
| export default jsx; | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.