Skip to content

Commit 46ca76e

Browse files
committed
Merge branch 'master' into esm
* master: Improve typings: ESM, `AcornJsxParser` class and `tokTypes` const (#130) Update README.md Add Ukrainian badge 5.3.2 Rename AcornJSXOptions to Options in index.d.ts (#124) Add TypeScript type definitions (#122) # Conflicts: # package.json
2 parents 12f4a5b + 8ed96d6 commit 46ca76e

File tree

3 files changed

+68
-1
lines changed

3 files changed

+68
-1
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
[![Build Status](https://travis-ci.org/acornjs/acorn-jsx.svg?branch=master)](https://travis-ci.org/acornjs/acorn-jsx)
44
[![NPM version](https://img.shields.io/npm/v/acorn-jsx.svg)](https://www.npmjs.org/package/acorn-jsx)
55

6+
<a href="https://stand-with-ukraine.pp.ua/"><img src="https://raw.githubusercontent.com/vshymanskyy/StandWithUkraine/main/banner-direct.svg" width="800"></a>
7+
68
This is plugin for [Acorn](http://marijnhaverbeke.nl/acorn/) - a tiny, fast JavaScript parser, written completely in JavaScript.
79

810
It was created as an experimental alternative, faster [React.js JSX](http://facebook.github.io/react/docs/jsx-in-depth.html) parser. Later, it replaced the [official parser](https://github.com/facebookarchive/esprima) and these days is used by many prominent development tools.

index.d.ts

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
import * as acorn from 'acorn';
2+
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;
16+
17+
declare namespace jsx {
18+
19+
type TokTypes = JsxTokTypes
20+
21+
interface Options {
22+
allowNamespacedObjects?: boolean;
23+
allowNamespaces?: boolean;
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+
}
63+
}
64+
65+
export = jsx;

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "acorn-jsx",
33
"description": "Modern, fast React.js JSX parser",
44
"homepage": "https://github.com/acornjs/acorn-jsx",
5-
"version": "5.3.1",
5+
"version": "5.3.2",
66
"main": "index.cjs.js",
77
"module": "index.js",
88
"maintainers": [

0 commit comments

Comments
 (0)