Skip to content

Commit

Permalink
chore: remove deps of asserts
Browse files Browse the repository at this point in the history
  • Loading branch information
antfu committed Sep 15, 2023
1 parent c3c5d0d commit 5b74037
Showing 1 changed file with 20 additions and 18 deletions.
38 changes: 20 additions & 18 deletions scripts/vendor.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* eslint-disable unicorn/prefer-top-level-await */
import fs from 'node:fs'
import fsp from 'node:fs/promises'
import { join } from 'node:path'
import { downloadTemplate } from 'giget'

// This script clones recast and patches, and then re-bundle it so we get rid of the unnecessary polyfills
Expand All @@ -19,24 +20,21 @@ async function cloneRecast() {
await fsp.rm('vendor/recast/tsconfig.json')

// Remove the assert import and usage
await filterLines('vendor/recast/lib/patcher.ts', (line) => {
if (line.startsWith('import assert from')) {
return false
}
if (/^\s*assert\./.test(line)) {
return `false && ` + line
}
return line
})
await filterLines('vendor/recast/lib/patcher.ts', (line) => {
if (line.startsWith('import assert from')) {
return false
}
if (/^\s*assert\./.test(line)) {
return `false && ` + line
}
return line
})
await Promise.all(fs.readdirSync('vendor/recast/lib', { withFileTypes: true }).map(async (file) => {

Check failure on line 23 in scripts/vendor.ts

View workflow job for this annotation

GitHub Actions / ci

Async arrow function has no 'await' expression
if (!file.isFile()) { return }
return filterLines(join(file.path, file.name), (line) => {
if (line.startsWith('import assert from')) {
return false
}
if (/^\s*assert\./.test(line)) {
if (line.endsWith(';')) {
return false
}
return `// @ts-ignore \n false && ` + line
}
return line
})
}))

// Remove the require(), and since we are providing our own parser anyway
await filterLines('vendor/recast/lib/options.ts', (line) => {
Expand All @@ -46,6 +44,10 @@ async function cloneRecast() {
return line
})

await filterLines('vendor/recast/lib/parser.ts', (line) => {
return line.replace('require("esprima")', `false && require("")`)
})

await filterLines('vendor/recast/lib/util.ts', (line) => {
if (line.includes('isBrowser() ? "\\n"')) { return 'return "\\n"' }
return line
Expand Down

0 comments on commit 5b74037

Please sign in to comment.