Refactor code-style

This commit is contained in:
Titus Wormer 2021-06-08 15:39:19 +02:00
parent 76b54c3924
commit 51ed9a4b78
No known key found for this signature in database
GPG key ID: E6E581152ED04E2E
9 changed files with 60 additions and 60 deletions

View file

@ -10,18 +10,18 @@ export const directiveContainer = {
concrete: true
}
var label = {tokenize: tokenizeLabel, partial: true}
var attributes = {tokenize: tokenizeAttributes, partial: true}
const label = {tokenize: tokenizeLabel, partial: true}
const attributes = {tokenize: tokenizeAttributes, partial: true}
function tokenizeDirectiveContainer(effects, ok, nok) {
var self = this
const self = this
const tail = self.events[self.events.length - 1]
const initialSize =
tail && tail[1].type === 'linePrefix'
? tail[2].sliceSerialize(tail[1], true).length
: 0
var sizeOpen = 0
var previous
let sizeOpen = 0
let previous
return start
@ -114,13 +114,14 @@ function tokenizeDirectiveContainer(effects, ok, nok) {
}
function chunkStart(code) {
var token
if (code === null) {
return after(code)
}
token = effects.enter('chunkDocument', {contentType: 'document', previous})
const token = effects.enter('chunkDocument', {
contentType: 'document',
previous
})
if (previous) previous.next = token
previous = token
return contentContinue(code)
@ -149,7 +150,7 @@ function tokenizeDirectiveContainer(effects, ok, nok) {
}
function tokenizeClosingFence(effects, ok, nok) {
var size = 0
let size = 0
return factorySpace(effects, closingPrefixAfter, 'linePrefix', 4)

View file

@ -8,11 +8,11 @@ export const directiveLeaf = {
tokenize: tokenizeDirectiveLeaf
}
var label = {tokenize: tokenizeLabel, partial: true}
var attributes = {tokenize: tokenizeAttributes, partial: true}
const label = {tokenize: tokenizeLabel, partial: true}
const attributes = {tokenize: tokenizeAttributes, partial: true}
function tokenizeDirectiveLeaf(effects, ok, nok) {
var self = this
const self = this
return start

View file

@ -7,8 +7,8 @@ export const directiveText = {
previous
}
var label = {tokenize: tokenizeLabel, partial: true}
var attributes = {tokenize: tokenizeAttributes, partial: true}
const label = {tokenize: tokenizeLabel, partial: true}
const attributes = {tokenize: tokenizeAttributes, partial: true}
function previous(code) {
// If there is a previous code, there will always be a tail.
@ -19,7 +19,7 @@ function previous(code) {
}
function tokenizeDirectiveText(effects, ok, nok) {
var self = this
const self = this
return start

View file

@ -26,8 +26,8 @@ export function factoryAttributes(
attributeValueData,
disallowEol
) {
var type
var marker
let type
let marker
return start

View file

@ -15,8 +15,8 @@ export function factoryLabel(
stringType,
disallowEol
) {
var size = 0
var balance = 0
let size = 0
let balance = 0
return start

View file

@ -1,7 +1,7 @@
import {asciiAlpha, asciiAlphanumeric} from 'micromark-util-character'
export function factoryName(effects, ok, nok, nameType) {
var self = this
const self = this
return start

View file

@ -1,9 +1,9 @@
import {decodeEntity} from 'parse-entities/decode-entity.js'
var own = {}.hasOwnProperty
const own = {}.hasOwnProperty
export function directiveHtml(options) {
var extensions = options || {}
const extensions = options || {}
return {
enter: {
@ -65,13 +65,13 @@ export function directiveHtml(options) {
}
function enter(type) {
var stack = this.getData('directiveStack')
let stack = this.getData('directiveStack')
if (!stack) this.setData('directiveStack', (stack = []))
stack.push({type})
}
function exitName(token) {
var stack = this.getData('directiveStack')
const stack = this.getData('directiveStack')
stack[stack.length - 1].name = this.sliceSerialize(token)
}
@ -80,8 +80,8 @@ export function directiveHtml(options) {
}
function exitLabel() {
var data = this.resume()
var stack = this.getData('directiveStack')
const data = this.resume()
const stack = this.getData('directiveStack')
stack[stack.length - 1].label = data
}
@ -111,18 +111,18 @@ export function directiveHtml(options) {
}
function exitAttributeValue(token) {
var attributes = this.getData('directiveAttributes')
const attributes = this.getData('directiveAttributes')
attributes[attributes.length - 1][1] = decodeLight(
this.sliceSerialize(token)
)
}
function exitAttributes() {
var stack = this.getData('directiveStack')
var attributes = this.getData('directiveAttributes')
var cleaned = {}
var index = -1
var attribute
const stack = this.getData('directiveStack')
const attributes = this.getData('directiveAttributes')
const cleaned = {}
let index = -1
let attribute
while (++index < attributes.length) {
attribute = attributes[index]
@ -144,23 +144,23 @@ export function directiveHtml(options) {
}
function exitContainerContent() {
var data = this.resume()
var stack = this.getData('directiveStack')
const data = this.resume()
const stack = this.getData('directiveStack')
stack[stack.length - 1].content = data
}
function exitContainerFence() {
var stack = this.getData('directiveStack')
var directive = stack[stack.length - 1]
const stack = this.getData('directiveStack')
const directive = stack[stack.length - 1]
if (!directive.fenceCount) directive.fenceCount = 0
directive.fenceCount++
if (directive.fenceCount === 1) this.setData('slurpOneLineEnding', true)
}
function exit() {
var directive = this.getData('directiveStack').pop()
var found
var result
const directive = this.getData('directiveStack').pop()
let found
let result
if (own.call(extensions, directive.name)) {
result = extensions[directive.name].call(this, directive)

View file

@ -63,10 +63,6 @@
"xo": {
"prettier": true,
"rules": {
"no-var": "off",
"prefer-arrow-callback": "off",
"guard-for-in": "off",
"unicorn/explicit-length-check": "off",
"unicorn/no-this-assignment": "off"
}
},

View file

@ -3,8 +3,10 @@ import {micromark} from 'micromark'
import {htmlVoidElements} from 'html-void-elements'
import {directive as syntax, directiveHtml as html} from '../index.js'
test('micromark-extension-directive (syntax)', function (t) {
t.test('text', function (t) {
const own = {}.hasOwnProperty
test('micromark-extension-directive (syntax)', (t) => {
t.test('text', (t) => {
t.equal(
micromark('\\:a', options()),
'<p>:a</p>',
@ -362,7 +364,7 @@ test('micromark-extension-directive (syntax)', function (t) {
t.end()
})
t.test('leaf', function (t) {
t.test('leaf', (t) => {
t.equal(micromark('::b', options()), '', 'should support a directive')
t.equal(
@ -696,7 +698,7 @@ test('micromark-extension-directive (syntax)', function (t) {
t.end()
})
t.test('container', function (t) {
t.test('container', (t) => {
t.equal(micromark(':::b', options()), '', 'should support a directive')
t.equal(
@ -1103,7 +1105,7 @@ test('micromark-extension-directive (syntax)', function (t) {
t.end()
})
test('micromark-extension-directive (compile)', function (t) {
test('micromark-extension-directive (compile)', (t) => {
t.equal(
micromark(
[
@ -1179,7 +1181,7 @@ test('micromark-extension-directive (compile)', function (t) {
t.end()
})
test('content', function (t) {
test('content', (t) => {
t.equal(
micromark(':abbr[x\\&y&amp;z]', options({abbr})),
'<p><abbr>x&amp;y&amp;z</abbr></p>',
@ -1372,14 +1374,13 @@ function abbr(d) {
}
function youtube(d) {
var attrs = d.attributes || {}
var v = attrs.v
var list
var prop
const attrs = d.attributes || {}
const v = attrs.v
let prop
if (!v) return false
list = [
const list = [
'src="https://www.youtube.com/embed/' + this.encode(v) + '"',
'allowfullscreen'
]
@ -1406,17 +1407,19 @@ function youtube(d) {
}
function h(d) {
var content = d.content || d.label
var attrs = d.attributes || {}
var list = []
var prop
const content = d.content || d.label
const attrs = d.attributes || {}
const list = []
let prop
for (prop in attrs) {
list.push(this.encode(prop) + '="' + this.encode(attrs[prop]) + '"')
if (own.call(attrs, prop)) {
list.push(this.encode(prop) + '="' + this.encode(attrs[prop]) + '"')
}
}
this.tag('<' + d.name)
if (list.length) this.tag(' ' + list.join(' '))
if (list.length > 0) this.tag(' ' + list.join(' '))
this.tag('>')
if (content) {