Skip to content

Commit e9bf29e

Browse files
committed
Refactor code-style
1 parent b6ca06b commit e9bf29e

36 files changed

+187
-231
lines changed

lib/configure.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
export function configure(base, extension) {
2-
var index = -1
3-
var key
2+
let index = -1
3+
let key
44

55
// First do subextensions.
66
if (extension.extensions) {

lib/handle/blockquote.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import {containerFlow} from '../util/container-flow.js'
22
import {indentLines} from '../util/indent-lines.js'
33

44
export function blockquote(node, _, context) {
5-
var exit = context.enter('blockquote')
6-
var value = indentLines(containerFlow(node, context), map)
5+
const exit = context.enter('blockquote')
6+
const value = indentLines(containerFlow(node, context), map)
77
exit()
88
return value
99
}

lib/handle/break.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {patternInScope} from '../util/pattern-in-scope.js'
22

33
export function hardBreak(node, _, context, safe) {
4-
var index = -1
4+
let index = -1
55

66
while (++index < context.unsafe.length) {
77
// If we can’t put eols in this construct (setext headings, tables), use a

lib/handle/code.js

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,18 @@ import {indentLines} from '../util/indent-lines.js'
66
import {safe} from '../util/safe.js'
77

88
export function code(node, _, context) {
9-
var marker = checkFence(context)
10-
var raw = node.value || ''
11-
var suffix = marker === '`' ? 'GraveAccent' : 'Tilde'
12-
var value
13-
var sequence
14-
var exit
15-
var subexit
9+
const marker = checkFence(context)
10+
const raw = node.value || ''
11+
const suffix = marker === '`' ? 'GraveAccent' : 'Tilde'
12+
let value
13+
let exit
1614

1715
if (formatCodeAsIndented(node, context)) {
1816
exit = context.enter('codeIndented')
1917
value = indentLines(raw, map)
2018
} else {
21-
sequence = repeat(marker, Math.max(longestStreak(raw, marker) + 1, 3))
19+
const sequence = repeat(marker, Math.max(longestStreak(raw, marker) + 1, 3))
20+
let subexit
2221
exit = context.enter('codeFenced')
2322
value = sequence
2423

lib/handle/definition.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ import {checkQuote} from '../util/check-quote.js'
33
import {safe} from '../util/safe.js'
44

55
export function definition(node, _, context) {
6-
var marker = checkQuote(context)
7-
var suffix = marker === '"' ? 'Quote' : 'Apostrophe'
8-
var exit = context.enter('definition')
9-
var subexit = context.enter('label')
10-
var value =
6+
const marker = checkQuote(context)
7+
const suffix = marker === '"' ? 'Quote' : 'Apostrophe'
8+
const exit = context.enter('definition')
9+
let subexit = context.enter('label')
10+
let value =
1111
'[' + safe(context, association(node), {before: '[', after: ']'}) + ']: '
1212

1313
subexit()

lib/handle/emphasis.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,12 @@ emphasis.peek = emphasisPeek
88
// There’s no way around that though, except for injecting zero-width stuff.
99
// Do we need to safeguard against that?
1010
export function emphasis(node, _, context) {
11-
var marker = checkEmphasis(context)
12-
var exit = context.enter('emphasis')
13-
var value = containerPhrasing(node, context, {before: marker, after: marker})
11+
const marker = checkEmphasis(context)
12+
const exit = context.enter('emphasis')
13+
const value = containerPhrasing(node, context, {
14+
before: marker,
15+
after: marker
16+
})
1417
exit()
1518
return marker + value + marker
1619
}

lib/handle/heading.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,10 @@ import {formatHeadingAsSetext} from '../util/format-heading-as-setext.js'
33
import {containerPhrasing} from '../util/container-phrasing.js'
44

55
export function heading(node, _, context) {
6-
var rank = Math.max(Math.min(6, node.depth || 1), 1)
7-
var exit
8-
var subexit
9-
var value
10-
var sequence
6+
const rank = Math.max(Math.min(6, node.depth || 1), 1)
7+
let exit
8+
let subexit
9+
let value
1110

1211
if (formatHeadingAsSetext(node, context)) {
1312
exit = context.enter('headingSetext')
@@ -30,7 +29,7 @@ export function heading(node, _, context) {
3029
)
3130
}
3231

33-
sequence = repeat('#', rank)
32+
const sequence = repeat('#', rank)
3433
exit = context.enter('headingAtx')
3534
subexit = context.enter('phrasing')
3635
value = containerPhrasing(node, context, {before: '# ', after: '\n'})

lib/handle/image-reference.js

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,18 @@ import {safe} from '../util/safe.js'
44
imageReference.peek = imageReferencePeek
55

66
export function imageReference(node, _, context) {
7-
var type = node.referenceType
8-
var exit = context.enter('imageReference')
9-
var subexit = context.enter('label')
10-
var alt = safe(context, node.alt, {before: '[', after: ']'})
11-
var value = '![' + alt + ']'
12-
var reference
13-
var stack
7+
const type = node.referenceType
8+
const exit = context.enter('imageReference')
9+
let subexit = context.enter('label')
10+
const alt = safe(context, node.alt, {before: '[', after: ']'})
11+
let value = '![' + alt + ']'
1412

1513
subexit()
1614
// Hide the fact that we’re in phrasing, because escapes don’t work.
17-
stack = context.stack
15+
const stack = context.stack
1816
context.stack = []
1917
subexit = context.enter('reference')
20-
reference = safe(context, association(node), {before: '[', after: ']'})
18+
const reference = safe(context, association(node), {before: '[', after: ']'})
2119
subexit()
2220
context.stack = stack
2321
exit()

lib/handle/image.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ import {safe} from '../util/safe.js'
44
image.peek = imagePeek
55

66
export function image(node, _, context) {
7-
var quote = checkQuote(context)
8-
var suffix = quote === '"' ? 'Quote' : 'Apostrophe'
9-
var exit = context.enter('image')
10-
var subexit = context.enter('label')
11-
var value = '![' + safe(context, node.alt, {before: '[', after: ']'}) + ']('
7+
const quote = checkQuote(context)
8+
const suffix = quote === '"' ? 'Quote' : 'Apostrophe'
9+
const exit = context.enter('image')
10+
let subexit = context.enter('label')
11+
let value = '![' + safe(context, node.alt, {before: '[', after: ']'}) + ']('
1212

1313
subexit()
1414

lib/handle/inline-code.js

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,9 @@ import {patternCompile} from '../util/pattern-compile.js'
33
inlineCode.peek = inlineCodePeek
44

55
export function inlineCode(node, parent, context) {
6-
var value = node.value || ''
7-
var sequence = '`'
8-
var index = -1
9-
var pattern
10-
var expression
11-
var match
12-
var position
6+
let value = node.value || ''
7+
let sequence = '`'
8+
let index = -1
139

1410
// If there is a single grave accent on its own in the code, use a fence of
1511
// two.
@@ -36,17 +32,17 @@ export function inlineCode(node, parent, context) {
3632
// transformed to spaces when going from markdown to HTML anyway, we can swap
3733
// them out.
3834
while (++index < context.unsafe.length) {
39-
pattern = context.unsafe[index]
35+
const pattern = context.unsafe[index]
36+
const expression = patternCompile(pattern)
37+
let match
4038

4139
// Only look for `atBreak`s.
4240
// Btw: note that `atBreak` patterns will always start the regex at LF or
4341
// CR.
4442
if (!pattern.atBreak) continue
4543

46-
expression = patternCompile(pattern)
47-
4844
while ((match = expression.exec(value))) {
49-
position = match.index
45+
let position = match.index
5046

5147
// Support CRLF (patterns only look for one of the characters).
5248
if (

lib/handle/link-reference.js

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,18 @@ import {safe} from '../util/safe.js'
55
linkReference.peek = linkReferencePeek
66

77
export function linkReference(node, _, context) {
8-
var type = node.referenceType
9-
var exit = context.enter('linkReference')
10-
var subexit = context.enter('label')
11-
var text = containerPhrasing(node, context, {before: '[', after: ']'})
12-
var value = '[' + text + ']'
13-
var reference
14-
var stack
8+
const type = node.referenceType
9+
const exit = context.enter('linkReference')
10+
let subexit = context.enter('label')
11+
const text = containerPhrasing(node, context, {before: '[', after: ']'})
12+
let value = '[' + text + ']'
1513

1614
subexit()
1715
// Hide the fact that we’re in phrasing, because escapes don’t work.
18-
stack = context.stack
16+
const stack = context.stack
1917
context.stack = []
2018
subexit = context.enter('reference')
21-
reference = safe(context, association(node), {before: '[', after: ']'})
19+
const reference = safe(context, association(node), {before: '[', after: ']'})
2220
subexit()
2321
context.stack = stack
2422
exit()

lib/handle/link.js

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,15 @@ import {safe} from '../util/safe.js'
66
link.peek = linkPeek
77

88
export function link(node, _, context) {
9-
var quote = checkQuote(context)
10-
var suffix = quote === '"' ? 'Quote' : 'Apostrophe'
11-
var exit
12-
var subexit
13-
var value
14-
var stack
9+
const quote = checkQuote(context)
10+
const suffix = quote === '"' ? 'Quote' : 'Apostrophe'
11+
let exit
12+
let subexit
13+
let value
1514

1615
if (formatLinkAsAutolink(node, context)) {
1716
// Hide the fact that we’re in phrasing, because escapes don’t work.
18-
stack = context.stack
17+
const stack = context.stack
1918
context.stack = []
2019
exit = context.enter('autolink')
2120
value =

lib/handle/list-item.js

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,8 @@ import {containerFlow} from '../util/container-flow.js'
55
import {indentLines} from '../util/indent-lines.js'
66

77
export function listItem(node, parent, context) {
8-
var bullet = checkBullet(context)
9-
var listItemIndent = checkListItemIndent(context)
10-
var size
11-
var value
12-
var exit
8+
const listItemIndent = checkListItemIndent(context)
9+
let bullet = checkBullet(context)
1310

1411
if (parent && parent.ordered) {
1512
bullet =
@@ -20,7 +17,7 @@ export function listItem(node, parent, context) {
2017
'.'
2118
}
2219

23-
size = bullet.length + 1
20+
let size = bullet.length + 1
2421

2522
if (
2623
listItemIndent === 'tab' ||
@@ -29,8 +26,8 @@ export function listItem(node, parent, context) {
2926
size = Math.ceil(size / 4) * 4
3027
}
3128

32-
exit = context.enter('listItem')
33-
value = indentLines(containerFlow(node, context), map)
29+
const exit = context.enter('listItem')
30+
const value = indentLines(containerFlow(node, context), map)
3431
exit()
3532

3633
return value

lib/handle/list.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import {containerFlow} from '../util/container-flow.js'
22

33
export function list(node, _, context) {
4-
var exit = context.enter('list')
5-
var value = containerFlow(node, context)
4+
const exit = context.enter('list')
5+
const value = containerFlow(node, context)
66
exit()
77
return value
88
}

lib/handle/paragraph.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import {containerPhrasing} from '../util/container-phrasing.js'
22

33
export function paragraph(node, _, context) {
4-
var exit = context.enter('paragraph')
5-
var subexit = context.enter('phrasing')
6-
var value = containerPhrasing(node, context, {before: '\n', after: '\n'})
4+
const exit = context.enter('paragraph')
5+
const subexit = context.enter('phrasing')
6+
const value = containerPhrasing(node, context, {before: '\n', after: '\n'})
77
subexit()
88
exit()
99
return value

lib/handle/strong.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,12 @@ strong.peek = strongPeek
88
// There’s no way around that though, except for injecting zero-width stuff.
99
// Do we need to safeguard against that?
1010
export function strong(node, _, context) {
11-
var marker = checkStrong(context)
12-
var exit = context.enter('strong')
13-
var value = containerPhrasing(node, context, {before: marker, after: marker})
11+
const marker = checkStrong(context)
12+
const exit = context.enter('strong')
13+
const value = containerPhrasing(node, context, {
14+
before: marker,
15+
after: marker
16+
})
1417
exit()
1518
return marker + marker + value + marker + marker
1619
}

lib/handle/thematic-break.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import {checkRuleRepeat} from '../util/check-rule-repeat.js'
33
import {checkRule} from '../util/check-rule.js'
44

55
export function thematicBreak(node, parent, context) {
6-
var value = repeat(
6+
const value = repeat(
77
checkRule(context) + (context.options.ruleSpaces ? ' ' : ''),
88
checkRuleRepeat(context)
99
)

lib/index.js

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,21 @@
11
import {zwitch} from 'zwitch'
22
import {configure} from './configure.js'
3-
import {handle as defaultHandle} from './handle/index.js'
4-
import {join as defaultJoin} from './join.js'
5-
import {unsafe as defaultUnsafe} from './unsafe.js'
3+
import {handle} from './handle/index.js'
4+
import {join} from './join.js'
5+
import {unsafe} from './unsafe.js'
66

7-
export function toMarkdown(tree, options) {
8-
var settings = options || {}
9-
var context = {
7+
export function toMarkdown(tree, options = {}) {
8+
const context = {
109
enter,
1110
stack: [],
1211
unsafe: [],
1312
join: [],
1413
handlers: {},
1514
options: {}
1615
}
17-
var result
1816

19-
configure(context, {
20-
unsafe: defaultUnsafe,
21-
join: defaultJoin,
22-
handlers: defaultHandle
23-
})
24-
configure(context, settings)
17+
configure(context, {unsafe, join, handlers: handle})
18+
configure(context, options)
2519

2620
if (context.options.tightDefinitions) {
2721
context.join = [joinDefinition].concat(context.join)
@@ -33,7 +27,7 @@ export function toMarkdown(tree, options) {
3327
handlers: context.handlers
3428
})
3529

36-
result = context.handle(tree, null, context, {before: '\n', after: '\n'})
30+
let result = context.handle(tree, null, context, {before: '\n', after: '\n'})
3731

3832
if (
3933
result &&

lib/util/association.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {decodeEntity} from 'parse-entities/decode-entity.js'
22

3-
var characterEscape = /\\([!-/:-@[-`{-~])/g
4-
var characterReference = /&(#(\d{1,7}|x[\da-f]{1,6})|[\da-z]{1,31});/gi
3+
const characterEscape = /\\([!-/:-@[-`{-~])/g
4+
const characterReference = /&(#(\d{1,7}|x[\da-f]{1,6})|[\da-z]{1,31});/gi
55

66
// The `label` of an association is the string value: character escapes and
77
// references work, and casing is intact.

lib/util/check-bullet.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
export function checkBullet(context) {
2-
var marker = context.options.bullet || '*'
2+
const marker = context.options.bullet || '*'
33

44
if (marker !== '*' && marker !== '+' && marker !== '-') {
55
throw new Error(

lib/util/check-emphasis.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
export function checkEmphasis(context) {
2-
var marker = context.options.emphasis || '*'
2+
const marker = context.options.emphasis || '*'
33

44
if (marker !== '*' && marker !== '_') {
55
throw new Error(

0 commit comments

Comments
 (0)