Skip to content

Commit

Permalink
prep for estree-toolkit converter
Browse files Browse the repository at this point in the history
  • Loading branch information
retorquere committed May 13, 2024
1 parent 5612b92 commit 06e7397
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
10 changes: 10 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@
"kuroshiro-analyzer-kuromoji": "^1.1.0",
"lodash.template": "^4.5.0",
"lokijs": "^1.5.12",
"meriyah": "^4.4.2",
"moment": "^2.30.1",
"node-eta": "^0.9.0",
"npm-run-all": "^4.1.5",
Expand Down
10 changes: 9 additions & 1 deletion setup/extract-apis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import * as fs from 'fs'
import stringify from 'fast-safe-stringify'
import _ from 'lodash'
import jsesc from 'jsesc'
import { parseScript } from 'meriyah'

import Showdown from 'showdown'
const showdown = new Showdown.Converter()
Expand All @@ -24,14 +25,21 @@ class FormatterAPI {
const key = name.toLowerCase()

if (this.signature[key]) throw new Error(`duplicate ${kind} ${key}`)
this.signature[name.toLowerCase()] = _.cloneDeep({
this.signature[key] = _.cloneDeep({
name,
parameters: method.parameters.map(p => p.name),
defaults: method.parameters.map(p => p.default),
rest: method.parameters.find(p => p.rest)?.name,
schema: method.schema,
})
if (!this.signature[key].rest) delete this.signature[key].rest
const defaults = parseScript(jsesc(this.signature[key].defaults)).body[0]
if (defaults.type === 'ExpressionStatement' && defaults.expression.type === 'ArrayExpression') {
this.signature[key].ast = defaults.expression.elements
}
else {
throw new Error(jsesc(this.signature[key].defaults))
}

const description = method.parameters.find(param => param.doc)
let params = method.parameters.map(p => {
Expand Down

0 comments on commit 06e7397

Please sign in to comment.