Skip to content

Commit 2116d1f

Browse files
committed
Add raw to hast registry
When using this utility, the raw node type will automatically be added to hast in the correct places. See DefinitelyTyped/DefinitelyTyped#54421 for more information.
1 parent 766c459 commit 2116d1f

File tree

7 files changed

+23
-6
lines changed

7 files changed

+23
-6
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
.DS_Store
2-
*.d.ts
2+
lib/**/*.d.ts
3+
test/**/*.d.ts
4+
index.d.ts
35
*.log
46
coverage/
57
node_modules/

complex-types.d.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import {Literal} from 'hast'
2+
3+
export interface Raw extends Literal {
4+
type: 'raw'
5+
}
6+
7+
declare module 'hast' {
8+
interface RootContentMap {
9+
raw: Raw
10+
}
11+
12+
interface ElementContentMap {
13+
raw: Raw
14+
}
15+
}

index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* @typedef {import('./lib/index.js').Handler} Handler
44
* @typedef {import('./lib/index.js').Handlers} Handlers
55
* @typedef {import('./lib/index.js').H} H
6+
* @typedef {import('./complex-types').Raw} Raw
67
*/
78

89
export {one, all} from './lib/traverse.js'

lib/handlers/html.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,5 @@ import {u} from 'unist-builder'
1212
* @param {HTML} node
1313
*/
1414
export function html(h, node) {
15-
// @ts-expect-error non-standard raw nodes.
1615
return h.dangerous ? h.augment(node, u('raw', node.value)) : null
1716
}

lib/index.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,9 @@
99
* @typedef {import('hast').Comment} Comment
1010
* @typedef {import('hast').Element} Element
1111
* @typedef {import('hast').Root} Root
12+
* @typedef {import('hast').ElementContent} Content
1213
* @typedef {import('unist-util-position').PositionLike} PositionLike
1314
*
14-
* @typedef {Element|Text|Comment} Content
15-
*
1615
* @typedef EmbeddedHastFields
1716
* @property {string} [hName] Defines the tag name of an element
1817
* @property {Properties} [hProperties] Defines the properties of an element

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
"types": "index.d.ts",
3131
"files": [
3232
"lib/",
33+
"complex-types.d.ts",
3334
"index.d.ts",
3435
"index.js"
3536
],
@@ -64,7 +65,7 @@
6465
},
6566
"scripts": {
6667
"prepack": "npm run build && npm run format",
67-
"build": "rimraf \"{lib/**/**,test/**,}*.d.ts\" && tsc && type-coverage",
68+
"build": "rimraf \"{lib/**/**,test/**}*.d.ts\" \"index.d.ts\" && tsc && type-coverage",
6869
"format": "remark . -qfo && prettier -w . --loglevel warn && xo --fix",
6970
"test-api": "node test/index.js",
7071
"test-coverage": "c8 --check-coverage --branches 100 --functions 100 --lines 100 --statements 100 --reporter lcov node test/index.js",

tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"include": ["*.js", "lib/**/*.js", "test/**/*.js"],
2+
"include": ["lib/**/*.js", "test/**/*.js", "index.js"],
33
"compilerOptions": {
44
"target": "ES2020",
55
"lib": ["ES2020"],

0 commit comments

Comments
 (0)