Skip to content

Commit d306f87

Browse files
committed
Replace periscopic with estree-util-scope
1 parent 2ecebb0 commit d306f87

File tree

7 files changed

+170
-184
lines changed

7 files changed

+170
-184
lines changed

package-lock.json

Lines changed: 64 additions & 75 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,9 @@
5555
"eslint-plugin-react": "^7.0.0",
5656
"eslint-plugin-react-hooks": "^4.0.0",
5757
"estree-to-babel": "^9.0.0",
58+
"estree-util-scope": "^1.0.0",
5859
"estree-util-value-to-estree": "^3.0.0",
60+
"estree-walker": "^3.0.0",
5961
"globby": "^14.0.0",
6062
"hast-util-from-html": "^2.0.0",
6163
"hast-util-sanitize": "^5.0.0",
@@ -67,7 +69,6 @@
6769
"ink": "^5.0.0",
6870
"lz-string": "^1.0.0",
6971
"p-all": "^5.0.0",
70-
"periscopic": "^3.0.0",
7172
"postcss": "^8.0.0",
7273
"postcss-cli": "^11.0.0",
7374
"preact": "^10.0.0",

packages/mdx/lib/plugin/recma-document.js

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@
3030
*/
3131

3232
import {ok as assert} from 'devlop'
33+
import {createVisitors} from 'estree-util-scope'
3334
import {walk} from 'estree-walker'
34-
import {analyze} from 'periscopic'
3535
import {positionFromEstree} from 'unist-util-position-from-estree'
3636
import {stringifyPosition} from 'unist-util-stringify-position'
3737
import {create} from '../util/estree-util-create.js'
@@ -433,9 +433,24 @@ export function recmaDocument(options) {
433433
// export var a = 1
434434
// ```
435435
if (node.declaration) {
436-
exportedIdentifiers.push(
437-
...analyze(node.declaration).scope.declarations.keys()
438-
)
436+
const visitors = createVisitors()
437+
// Walk the top-level scope.
438+
walk(node, {
439+
enter(node) {
440+
visitors.enter(node)
441+
442+
if (
443+
node.type === 'ArrowFunctionExpression' ||
444+
node.type === 'FunctionDeclaration' ||
445+
node.type === 'FunctionExpression'
446+
) {
447+
this.skip()
448+
visitors.exit(node)
449+
}
450+
},
451+
leave: visitors.exit
452+
})
453+
exportedIdentifiers.push(...visitors.scopes[0].defined)
439454
}
440455

441456
// ```tsx

0 commit comments

Comments
 (0)