Skip to content

Commit

Permalink
Add strict to tsconfig.json
Browse files Browse the repository at this point in the history
  • Loading branch information
wooorm committed Jul 26, 2021
1 parent e2fa2fd commit 33e7950
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 19 deletions.
40 changes: 22 additions & 18 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,35 +25,25 @@ const markerExpression = new RegExp(

/**
* Parse a comment marker.
* @param {unknown} node
* @param {unknown} value
* @returns {Marker|null}
*/
export function commentMarker(node) {
if (
node &&
typeof node === 'object' &&
// @ts-ignore hush
(node.type === 'html' || node.type === 'comment')
) {
// @ts-ignore hush
const match = node.value.match(
// @ts-ignore hush
node.type === 'comment' ? commentExpression : markerExpression
export function commentMarker(value) {
if (applicable(value)) {
const match = value.value.match(
value.type === 'comment' ? commentExpression : markerExpression
)

// @ts-ignore hush
if (match && match[0].length === node.value.length) {
// @ts-ignore hush
const offset = node.type === 'comment' ? 1 : 2
if (match && match[0].length === value.value.length) {
const offset = value.type === 'comment' ? 1 : 2
const parameters = parseParameters(match[offset + 1] || '')

if (parameters) {
return {
name: match[offset],
attributes: match[offset + 2] || '',
parameters,
// @ts-ignore hush
node
node: value
}
}
}
Expand Down Expand Up @@ -106,3 +96,17 @@ function parseParameters(value) {
return ''
}
}

/**
* @param {unknown} value
* @returns {value is HtmlNode | CommentNode}
*/
function applicable(value) {
return Boolean(
value &&
typeof value === 'object' &&
'type' in value &&
// @ts-expect-error hush
(value.type === 'html' || value.type === 'comment')
)
}
1 change: 1 addition & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import test from 'tape'
import {commentMarker} from './index.js'

test('commentMaker(node)', (t) => {
// @ts-expect-error: runtime: not enough arguments.
t.equal(commentMarker(), null, 'should work without node')

/** @type {Paragraph} */
Expand Down
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"declaration": true,
"emitDeclarationOnly": true,
"allowSyntheticDefaultImports": true,
"skipLibCheck": true
"skipLibCheck": true,
"strict": true
}
}

0 comments on commit 33e7950

Please sign in to comment.