Skip to content

Commit

Permalink
Add raw to hast registry
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
wooorm committed Sep 23, 2021
1 parent 766c459 commit 2116d1f
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 6 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
.DS_Store
*.d.ts
lib/**/*.d.ts
test/**/*.d.ts
index.d.ts
*.log
coverage/
node_modules/
Expand Down
15 changes: 15 additions & 0 deletions complex-types.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import {Literal} from 'hast'

export interface Raw extends Literal {
type: 'raw'
}

declare module 'hast' {
interface RootContentMap {
raw: Raw
}

interface ElementContentMap {
raw: Raw
}
}
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* @typedef {import('./lib/index.js').Handler} Handler
* @typedef {import('./lib/index.js').Handlers} Handlers
* @typedef {import('./lib/index.js').H} H
* @typedef {import('./complex-types').Raw} Raw
*/

export {one, all} from './lib/traverse.js'
Expand Down
1 change: 0 additions & 1 deletion lib/handlers/html.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,5 @@ import {u} from 'unist-builder'
* @param {HTML} node
*/
export function html(h, node) {
// @ts-expect-error non-standard raw nodes.
return h.dangerous ? h.augment(node, u('raw', node.value)) : null
}
3 changes: 1 addition & 2 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@
* @typedef {import('hast').Comment} Comment
* @typedef {import('hast').Element} Element
* @typedef {import('hast').Root} Root
* @typedef {import('hast').ElementContent} Content
* @typedef {import('unist-util-position').PositionLike} PositionLike
*
* @typedef {Element|Text|Comment} Content
*
* @typedef EmbeddedHastFields
* @property {string} [hName] Defines the tag name of an element
* @property {Properties} [hProperties] Defines the properties of an element
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"types": "index.d.ts",
"files": [
"lib/",
"complex-types.d.ts",
"index.d.ts",
"index.js"
],
Expand Down Expand Up @@ -64,7 +65,7 @@
},
"scripts": {
"prepack": "npm run build && npm run format",
"build": "rimraf \"{lib/**/**,test/**,}*.d.ts\" && tsc && type-coverage",
"build": "rimraf \"{lib/**/**,test/**}*.d.ts\" \"index.d.ts\" && tsc && type-coverage",
"format": "remark . -qfo && prettier -w . --loglevel warn && xo --fix",
"test-api": "node test/index.js",
"test-coverage": "c8 --check-coverage --branches 100 --functions 100 --lines 100 --statements 100 --reporter lcov node test/index.js",
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"include": ["*.js", "lib/**/*.js", "test/**/*.js"],
"include": ["lib/**/*.js", "test/**/*.js", "index.js"],
"compilerOptions": {
"target": "ES2020",
"lib": ["ES2020"],
Expand Down

0 comments on commit 2116d1f

Please sign in to comment.