Skip to content

Commit

Permalink
Refactor code-style
Browse files Browse the repository at this point in the history
  • Loading branch information
wooorm committed Jul 26, 2021
1 parent 0f64921 commit e2fa2fd
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 21 deletions.
21 changes: 7 additions & 14 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
* @property {HtmlNode|CommentNode} node
*/

var commentExpression = /\s*([a-zA-Z\d-]+)(\s+([\s\S]*))?\s*/
const commentExpression = /\s*([a-zA-Z\d-]+)(\s+([\s\S]*))?\s*/

var markerExpression = new RegExp(
const markerExpression = new RegExp(
'(\\s*<!--' + commentExpression.source + '-->\\s*)'
)

Expand All @@ -29,30 +29,23 @@ var markerExpression = new RegExp(
* @returns {Marker|null}
*/
export function commentMarker(node) {
/** @type {RegExpMatchArray} */
var match
/** @type {number} */
var offset
/** @type {MarkerParameters} */
var parameters

if (
node &&
typeof node === 'object' &&
// @ts-ignore hush
(node.type === 'html' || node.type === 'comment')
) {
// @ts-ignore hush
match = node.value.match(
const match = node.value.match(
// @ts-ignore hush
node.type === 'comment' ? commentExpression : markerExpression
)

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

if (parameters) {
return {
Expand All @@ -77,7 +70,7 @@ export function commentMarker(node) {
*/
function parseParameters(value) {
/** @type {MarkerParameters} */
var parameters = {}
const parameters = {}

return value
.replace(
Expand All @@ -98,7 +91,7 @@ function parseParameters(value) {
// eslint-disable-next-line max-params
function replacer(_, $1, $2, $3, $4) {
/** @type {MarkerParameterValue} */
var value = $2 || $3 || $4 || ''
let value = $2 || $3 || $4 || ''

if (value === 'true' || value === '') {
value = true
Expand Down
6 changes: 1 addition & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,7 @@
"trailingComma": "none"
},
"xo": {
"prettier": true,
"rules": {
"no-var": "off",
"prefer-arrow-callback": "off"
}
"prettier": true
},
"remarkConfig": {
"plugins": [
Expand Down
4 changes: 2 additions & 2 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import test from 'tape'
import {commentMarker} from './index.js'

test('commentMaker(node)', function (t) {
test('commentMaker(node)', (t) => {
t.equal(commentMarker(), null, 'should work without node')

/** @type {Paragraph} */
Expand Down Expand Up @@ -145,7 +145,7 @@ test('commentMaker(node)', function (t) {
t.end()
})

test('comment node', function (t) {
test('comment node', (t) => {
/** @type {Literal & {type: 'comment'}} */
let comment = {type: 'comment', value: ' '}

Expand Down

0 comments on commit e2fa2fd

Please sign in to comment.