Skip to content

Commit 6dc311a

Browse files
committed
Add export of Map type
* Fix to exactly match `source-map`’s type * Refactor definition identifiers
1 parent 69134c2 commit 6dc311a

File tree

2 files changed

+29
-27
lines changed

2 files changed

+29
-27
lines changed

lib/index.js

+1-11
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/**
22
* @typedef {import('estree-jsx').Program} Program
33
* @typedef {typeof import('source-map').SourceMapGenerator} SourceMapGenerator
4+
* @typedef {import('source-map').RawSourceMap} Map
45
* @typedef {import('./types.js').Handlers} Handlers
56
*/
67

@@ -43,17 +44,6 @@
4344
* @typedef {OptionsWithMaybeMapGenerator} Options
4445
* Configuration (optional).
4546
*
46-
* @typedef Map
47-
* Raw source map, see:
48-
* <https://github.com/mozilla/source-map/blob/58819f0/source-map.d.ts#L15-L23>.
49-
* @property {number} version
50-
* @property {Array<string>} sources
51-
* @property {Array<string>} names
52-
* @property {string | null | undefined} [sourceRoot]
53-
* @property {Array<string> | null | undefined} [sourcesContent]
54-
* @property {string} mappings
55-
* @property {string} file
56-
*
5747
* @typedef BaseResultFields
5848
* @property {string} value
5949
* Serialized JavaScript.

readme.md

+28-16
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
* [`jsx`](#jsx)
2222
* [`Handler`](#handler)
2323
* [`Handlers`](#handlers)
24+
* [`Map`](#map)
2425
* [`Options`](#options)
2526
* [`Result`](#result)
2627
* [`State`](#state)
@@ -101,7 +102,7 @@ Yields:
101102

102103
## API
103104

104-
This package exports the identifiers [`jsx`][jsx] and [`toJs`][tojs].
105+
This package exports the identifiers [`jsx`][api-jsx] and [`toJs`][api-to-js].
105106
There is no default export.
106107

107108
### `toJs(tree[, options])`
@@ -112,16 +113,17 @@ Serialize an estree as JavaScript.
112113

113114
* `tree` ([`Program`][program])
114115
— estree
115-
* `options` ([`Options`][options])
116+
* `options` ([`Options`][api-options])
116117
— configuration
117118

118119
###### Returns
119120

120-
Result, optionally with source map ([`Result`][result]).
121+
Result, optionally with source map ([`Result`][api-result]).
121122

122123
### `jsx`
123124

124-
Map of handlers to handle the nodes of JSX extensions in JavaScript ([`Handlers`][handlers]).
125+
Map of handlers to handle the nodes of JSX extensions in JavaScript
126+
([`Handlers`][api-handlers]).
125127

126128
### `Handler`
127129

@@ -133,7 +135,7 @@ Handle a particular node (TypeScript type).
133135
`astring` generator
134136
* `node` ([`Node`][node])
135137
— node to serialize
136-
* `state` ([`State`][state])
138+
* `state` ([`State`][api-state])
137139
— info passed around
138140

139141
###### Returns
@@ -150,6 +152,10 @@ Handlers of nodes (TypeScript type).
150152
type Handlers = Partial<Record<Node['type'], Handler>>
151153
```
152154
155+
### `Map`
156+
157+
Raw source map from `source-map` (TypeScript type).
158+
153159
### `Options`
154160
155161
Configuration (TypeScript type).
@@ -160,7 +166,7 @@ Configuration (TypeScript type).
160166
— generate a source map with this class
161167
* `filePath` (`string`)
162168
— path to original input file
163-
* `handlers` ([`Handlers`][handlers])
169+
* `handlers` ([`Handlers`][api-handlers])
164170
— extra handlers
165171
166172
### `Result`
@@ -171,7 +177,7 @@ Result (TypeScript type).
171177
172178
* `value` (`string`)
173179
— serialized JavaScript
174-
* `map` (`object` or `undefined`)
180+
* `map` ([`Map`][api-map] or `undefined`)
175181
— source map as (parsed) JSON
176182
177183
### `State`
@@ -307,8 +313,12 @@ Yields:
307313
## Types
308314

309315
This package is fully typed with [TypeScript][].
310-
It exports the additional types [`Handler`][handler], [`Handlers`][handlers],
311-
[`Options`][options], [`Result`][result], and `State`.
316+
It exports the additional types [`Handler`][api-handler],
317+
[`Handlers`][api-handlers],
318+
[`Map`][api-map],
319+
[`Options`][api-options],
320+
[`Result`][api-result], and
321+
[`State`][api-state].
312322

313323
## Compatibility
314324

@@ -393,16 +403,18 @@ abide by its terms.
393403

394404
[source-map]: https://github.com/mozilla/source-map
395405

396-
[jsx]: #jsx
406+
[api-jsx]: #jsx
407+
408+
[api-to-js]: #tojstree-options
397409

398-
[tojs]: #tojstree-options
410+
[api-handler]: #handler
399411

400-
[handler]: #handler
412+
[api-handlers]: #handlers
401413

402-
[handlers]: #handlers
414+
[api-map]: #map
403415

404-
[options]: #options
416+
[api-options]: #options
405417

406-
[state]: #state
418+
[api-state]: #state
407419

408-
[result]: #result
420+
[api-result]: #result

0 commit comments

Comments
 (0)