-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: don't parse import/export statements in text
- Loading branch information
Showing
5 changed files
with
85 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
dist | ||
vendor |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { Lang, parse } from '@ast-grep/napi' | ||
import denoJson from '../deno.json' with { type: 'json' } | ||
|
||
const version = denoJson.imports.prettier.split('@')[1] | ||
|
||
const res = await fetch(`https://esm.sh/v135/prettier@${version}/es2022/plugins/markdown.js`) | ||
const code = (await res.text()).replace(/\/\/# sourceMappingURL=.*\.js\.map/g, '') | ||
|
||
const root = parse(Lang.JavaScript, code).root() | ||
|
||
const node1 = root.find('$A&&{blocks:[$B]}')! | ||
const n1$A = node1.getMatch('A')!.text() | ||
|
||
const node2 = root.find(`$A.use(${n1$A}?$B:$C).use($D).use`)! | ||
const n2$A = node2.getMatch('A')!.text() | ||
const n2$D = node2.getMatch('D')!.text() | ||
|
||
const edit1 = node2.replace(`${n2$A}.use(${n2$D}).use`) | ||
const transformed = root.commitEdits([edit1]).toString() | ||
|
||
await Deno.writeTextFile('./vendor/prettier-plugin-markdown.js', transformed) | ||
await Deno.writeTextFile( | ||
'./vendor/prettier-plugin-markdown.d.ts', | ||
` | ||
import type { Parser, Plugin, Printer } from 'prettier' | ||
declare const md: Plugin & { | ||
parsers: Record<'markdown' | 'mdx' | 'remark', Parser> | ||
printers: { mdast: Printer & Required<Pick<Printer, 'embed'>> } | ||
} | ||
export default md | ||
`.trimStart(), | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters