Skip to content

Commit b5e8987

Browse files
authored
fix: upgrade micromark-util-events-to-acorn (#383)
1 parent c497839 commit b5e8987

File tree

10 files changed

+1698
-805
lines changed

10 files changed

+1698
-805
lines changed

package.json

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"lint": "run-p lint:*",
1818
"lint:es": "eslint . --cache -f friendly",
1919
"lint:tsc": "tsc --noEmit",
20-
"postinstall": "simple-git-hooks && yarn-deduplicate --strategy fewer || exit 0",
20+
"postinstall": "patch-package && simple-git-hooks && yarn-deduplicate --strategy fewer || exit 0",
2121
"prelint": "yarn build",
2222
"prerelease": "yarn build",
2323
"release": "lerna publish --conventional-commits --create-release github --yes",
@@ -30,19 +30,13 @@
3030
"@types/eslint": "^8.4.1",
3131
"@types/eslint-plugin-markdown": "^2.0.0",
3232
"@types/jest": "^27.4.1",
33-
"@types/node": "^17.0.23",
34-
"@types/react": "^17.0.43",
33+
"@types/node": "^17.0.25",
34+
"@types/react": "^18.0.5",
3535
"@types/unist": "^2.0.6",
3636
"lerna": "^4.0.0",
37+
"patch-package": "^6.4.7",
3738
"react": "^18.0.0",
3839
"remark-frontmatter": "4.0.1",
39-
"remark-gfm": "^3.0.1",
40-
"remark-lint": "^9.1.1",
41-
"remark-preset-lint-consistent": "^5.1.1",
42-
"remark-preset-lint-markdown-style-guide": "^5.1.2",
43-
"remark-preset-lint-recommended": "^6.1.2",
44-
"remark-preset-prettier": "^1.0.0",
45-
"remark-validate-links": "^11.0.2",
4640
"ts-jest": "^27.1.4",
4741
"ts-node": "^10.7.0",
4842
"type-coverage": "^2.21.1",
@@ -85,19 +79,9 @@
8579
},
8680
"prettier": "@1stg/prettier-config",
8781
"remarkConfig": {
88-
"settings": {
89-
"emphasis": "_",
90-
"strong": "*"
91-
},
9282
"plugins": [
93-
"frontmatter",
94-
"lint",
95-
"preset-lint-consistent",
96-
"preset-lint-markdown-style-guide",
97-
"preset-lint-recommended",
98-
"preset-prettier",
99-
"gfm",
100-
"validate-links"
83+
"@1stg/config",
84+
"frontmatter"
10185
]
10286
},
10387
"renovate": {

packages/eslint-mdx/src/parser.ts

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,6 @@ import { getPhysicalFilename } from './processor'
1313
import { traverse } from './traverse'
1414
import type { ParserOptions, WorkerParseResult } from './types'
1515

16-
export const AST_PROPS = [
17-
'body',
18-
// disable comments temporarily -- #380
19-
// 'comments'
20-
] as const
21-
2216
export const DEFAULT_EXTENSIONS: readonly string[] = ['.mdx']
2317
export const MARKDOWN_EXTENSIONS: readonly string[] = ['.md']
2418

@@ -85,14 +79,14 @@ export class Parser {
8579
})
8680
}
8781

88-
const { root, tokens, comments } = result
82+
const { root, tokens } = result
8983

9084
this._ast = {
9185
...normalizePosition(root.position),
9286
type: 'Program',
9387
sourceType,
9488
body: [],
95-
comments,
89+
comments: [],
9690
tokens,
9791
}
9892

@@ -102,9 +96,10 @@ export class Parser {
10296
return
10397
}
10498

105-
for (const prop of AST_PROPS) {
106-
this._ast[prop].push(...(node.data?.estree[prop] || []))
107-
}
99+
const estree = node.data?.estree
100+
101+
this._ast.body.push(...(estree?.body || []))
102+
this._ast.comments.push(...(estree?.comments || []))
108103
})
109104
}
110105

packages/eslint-mdx/src/traverse.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,14 @@ export class Traverse {
1717

1818
const children = (node as Parent).children
1919

20+
this._enter(node, parent)
21+
2022
if (children) {
2123
const parent = node as Parent
2224
for (const child of children) {
2325
this.traverse(child, parent)
2426
}
2527
}
26-
27-
this._enter(node, parent)
2828
}
2929
}
3030

packages/eslint-mdx/src/types.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { AST, Linter } from 'eslint'
2-
import type { Comment, Program } from 'estree'
2+
import type { Program } from 'estree'
33
import type { Plugin } from 'unified'
44
import type { Node, Parent } from 'unist'
55
import type { VFileOptions } from 'vfile'
@@ -51,7 +51,6 @@ export interface WorkerOptions {
5151
export interface WorkerParseResult {
5252
root: Parent
5353
tokens: AST.Token[]
54-
comments: Comment[]
5554
}
5655

5756
export interface WorkerProcessResult {

packages/eslint-mdx/src/worker.ts

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,11 @@
22
/* eslint-disable unicorn/no-await-expression-member */
33
import path from 'path'
44

5-
import type { Comment, Token } from 'acorn'
5+
import type { Token } from 'acorn'
66
import { cosmiconfig } from 'cosmiconfig'
77
import type { CosmiconfigResult } from 'cosmiconfig/dist/types'
88
import type { AST } from 'eslint'
99
import type { EsprimaToken } from 'espree/lib/token-translator'
10-
import type { Comment as EsComment } from 'estree'
1110
import type { Options } from 'micromark-extension-mdx-expression'
1211
import { extractProperties, runAsWorker } from 'synckit'
1312
import type { FrozenProcessor } from 'unified'
@@ -33,22 +32,17 @@ const explorer = cosmiconfig('remark', {
3332

3433
export const processorCache = new Map<string, FrozenProcessor>()
3534

36-
const getRemarkMdxOptions = (
37-
tokens: Token[],
38-
comments: Comment[],
39-
): Options => ({
35+
const getRemarkMdxOptions = (tokens: Token[]): Options => ({
4036
acornOptions: {
4137
ecmaVersion: 'latest',
4238
sourceType: 'module',
4339
locations: true,
4440
ranges: true,
4541
onToken: tokens,
46-
onComment: comments,
4742
},
4843
})
4944

5045
const sharedTokens: Token[] = []
51-
const sharedComments: Comment[] = []
5246

5347
export const getRemarkProcessor = async (
5448
searchFrom: string,
@@ -111,10 +105,7 @@ export const getRemarkProcessor = async (
111105
.use(remarkStringify)
112106

113107
if (isMdx) {
114-
initProcessor.use(
115-
remarkMdx,
116-
getRemarkMdxOptions(sharedTokens, sharedComments),
117-
)
108+
initProcessor.use(remarkMdx, getRemarkMdxOptions(sharedTokens))
118109
}
119110

120111
cachedProcessor = (
@@ -136,10 +127,7 @@ export const getRemarkProcessor = async (
136127
const initProcessor = remarkProcessor().use(remarkStringify)
137128

138129
if (isMdx) {
139-
initProcessor.use(
140-
remarkMdx,
141-
getRemarkMdxOptions(sharedTokens, sharedComments),
142-
)
130+
initProcessor.use(remarkMdx, getRemarkMdxOptions(sharedTokens))
143131
}
144132

145133
cachedProcessor = initProcessor.freeze()
@@ -161,7 +149,6 @@ runAsWorker(
161149
ignoreRemarkConfig,
162150
}: WorkerOptions): Promise<WorkerResult> => {
163151
sharedTokens.length = 0
164-
sharedComments.length = 0
165152

166153
const processor = await getRemarkProcessor(
167154
physicalFilename,
@@ -250,7 +237,6 @@ runAsWorker(
250237
return {
251238
root,
252239
tokens,
253-
comments: sharedComments as EsComment[],
254240
}
255241
},
256242
)

packages/eslint-plugin-mdx/src/configs/base.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ import type { Linter } from 'eslint'
22

33
export const base: Linter.Config = {
44
parser: 'eslint-mdx',
5+
parserOptions: {
6+
sourceType: 'module',
7+
ecmaVersion: 'latest',
8+
},
59
plugins: ['mdx'],
610
processor: 'mdx/remark',
711
rules: {

0 commit comments

Comments
 (0)