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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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