Skip to content
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

Improve typings: ESM, AcornJsxParser class and tokTypes const #130

Merged
merged 19 commits into from
Nov 14, 2022
Merged
Changes from 7 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 Feb 10, 2022
dda96cc
feat: add missing `tokContexts` property on `acornJsx`
brettz9 Feb 12, 2022
baa0a61
feat: add missing jsx_ methods to `AcornJsxParser`
brettz9 Feb 12, 2022
8526524
feat: add instance properties to `AcornJsxParser`
brettz9 Feb 12, 2022
def9edd
fix: return `AcornJsxParser` from constructor
brettz9 Feb 12, 2022
2383cca
drop properties belonging on Acorn instead
brettz9 Feb 13, 2022
e4eca02
fix: use import with namespace specifier for acorn (avoids interop li…
brettz9 Apr 25, 2022
d97bd96
fix: switch `tokContexts` to type `TokContexts` (as not available as …
brettz9 May 6, 2022
620551b
refactor: avoid exporting `jsx` as named export
brettz9 May 6, 2022
835ea91
fix: in place of exporting non-existent class, export constructor and…
brettz9 May 6, 2022
5459984
refactor: use without prefix
brettz9 May 12, 2022
af6247d
refactor: export `TokTypes` interface and a single `jsx` export with …
brettz9 May 12, 2022
d80ceef
fix: drop extra `export as namespace`
brettz9 May 12, 2022
1c2fa2c
fix: use `exports = jsx` (and use jsx.Options)
brettz9 May 12, 2022
4cfaf9f
refactor: prefer interface over type, avoid redundant `export` on typ…
brettz9 May 15, 2022
41e8fcd
refactor: avoid extra type alias
brettz9 May 15, 2022
71b7e61
refactor: avoid exporting `tokTypes` and use CamelCase
brettz9 May 15, 2022
b976601
refactor: for now add a commit which redundantly but safely indicates…
brettz9 May 15, 2022
fd68170
refactor: remove some redundancy
brettz9 May 15, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 45 additions & 8 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,49 @@
import { Parser } from 'acorn'
import * as acorn from 'acorn';

declare const jsx: (options?: jsx.Options) => (BaseParser: typeof Parser) => typeof Parser;
export const jsx: (options?: jsx.Options) => (BaseParser: typeof acorn.Parser) => typeof AcornJsxParser
brettz9 marked this conversation as resolved.
Show resolved Hide resolved

declare namespace jsx {
interface Options {
allowNamespacedObjects?: boolean;
allowNamespaces?: boolean;
}
export interface Options {
allowNamespacedObjects?: boolean;
allowNamespaces?: boolean;
}

export = jsx;
export const tokTypes: {
jsxName: acorn.TokenType,
jsxText: acorn.TokenType,
jsxTagEnd: acorn.TokenType,
jsxTagStart: acorn.TokenType
} & typeof acorn.tokTypes;

export const tokContexts: {
brettz9 marked this conversation as resolved.
Show resolved Hide resolved
tc_oTag: acorn.TokContext,
tc_cTag: acorn.TokContext,
tc_expr: acorn.TokContext
};

export class AcornJsxParser extends acorn.Parser {
brettz9 marked this conversation as resolved.
Show resolved Hide resolved
static readonly acornJsx: {
tokTypes: typeof tokTypes;
tokContexts: typeof tokContexts
};

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 as namespace jsx;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting, TIL this works.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This declares jsx is available as a global namespace, which is incorrect.

export default jsx;
brettz9 marked this conversation as resolved.
Show resolved Hide resolved