mirror of
https://github.com/hanzoai/next.js.git
synced 2026-09-24 17:00:51 +00:00
25 lines
589 B
JavaScript
25 lines
589 B
JavaScript
import { createTwoslasher } from 'twoslash'
|
|
import ts from 'typescript'
|
|
|
|
export function GET(request) {
|
|
try {
|
|
const options = request.nextUrl.searchParams.has('esnext')
|
|
? {
|
|
target: ts.ScriptTarget.ESNext,
|
|
lib: ['ESNext', 'DOM', 'esnext', 'dom', 'es2020'],
|
|
}
|
|
: {}
|
|
|
|
const code = `type X = Promise<number>;
|
|
'hello'.toUpperCase()`
|
|
const twoslasher = createTwoslasher({
|
|
compilerOptions: options,
|
|
})
|
|
const result = twoslasher(code)
|
|
|
|
return Response.json(result)
|
|
} catch (e) {
|
|
return Response.json({ error: e })
|
|
}
|
|
}
|