diff --git a/tests/mod_test.ts b/tests/mod_test.ts index 00dc096..076e720 100644 --- a/tests/mod_test.ts +++ b/tests/mod_test.ts @@ -1,27 +1,25 @@ -import { twoslasher } from "../vendor/twoslash.ts"; +import { TwoSlashOptions, twoslasher } from "../vendor/twoslash.ts"; import { path } from "../deps.ts"; -import { twoslasher as twoslasherv2 } from "npm:@typescript/twoslash/dist/twoslash.cjs.development.js"; +import { TwoSlashOptions as TwoSlashOptionsV2, twoslasher as twoslasherv2 } from "npm:@typescript/twoslash"; const { dirname, fromFileUrl, join } = path; const __dirname = dirname(fromFileUrl(import.meta.url)); -const twoslash1 = await twoslasher(`\ -// @noErrors -console.t - // ^| Col -`, `ts`, { -}) +let value = `// @noErrors: true \nconsole.t \n// ^| ` -const twoslash2 = await twoslasherv2(`\ -// @noErrors -console.t -// ^| -`, `ts`, { -}) +let opts: TwoSlashOptions = {} + +const twoslash1 = await twoslasher(value, `ts`, opts) console.log({ twoslash1, +}) + +const twoslash2 = await twoslasherv2(value, `ts`, opts as TwoSlashOptionsV2) + + +console.log({ twoslash2, }) \ No newline at end of file diff --git a/vendor/twoslash.ts b/vendor/twoslash.ts index e3e14fb..cee41ec 100644 --- a/vendor/twoslash.ts +++ b/vendor/twoslash.ts @@ -412,15 +412,15 @@ function setOption(name: string, value: string, opts: CompilerOptions, ts: typeo ) } -const booleanConfigRegexp = /^\/\/\s?@(\w+)$/ +const booleanConfigRegexp = /^\/\/\s?@(\w+)\s*$/ // https://regex101.com/r/8B2Wwh/1 -const valuedConfigRegexp = /^\/\/\s?@(\w+):\s?(.+)$/ +const valuedConfigRegexp = /^\/\/\s?@(\w+):\s*(.+)$/ function filterCompilerOptions(codeLines: string[], defaultCompilerOptions: CompilerOptions, ts: typeof Typescript) { const options = { ...defaultCompilerOptions } for (let i = 0; i < codeLines.length;) { - let match + let match; if ((match = booleanConfigRegexp.exec(codeLines[i]))) { options[match[1]] = true setOption(match[1], "true", options, ts)