neodoc npm 模块抛出的错误会导致 ClojureScript 出现问题(但不会影响 node)。
$ java -cp cljs.jar cljs.main --repl-env node
ClojureScript 1.10.758
cljs.user=> (def neodoc (js/require "neodoc"))
#'cljs.user/neodoc
cljs.user=> (.run neodoc "Usage:\n foo" (clj->js {:argv []}))
#js {}
cljs.user=> (.run neodoc "Usage:\n foo" (clj->js {:argv ["bar"] :dontExit true}))
Execution error () at (<cljs repl>:1).
null
cljs.user=> (try (.run neodoc "Usage:\n foo" (clj->js {:argv ["bar"] :dontExit true})) (catch :default e (prn :e e)))
Execution error (TypeError) at (<cljs repl>:1).
Function.prototype.toString requires that 'this' be a Function
这在 node 中是可行的(尽管抛出的对象很奇怪)
Welcome to Node.js v16.13.2.
Type ".help" for more information.
> neodoc = require("neodoc")
{
run: [Function: run],
parse: [Function: parse],
default: { run: [Function: run], parse: [Function: parse] }
}
> neodoc.run("Usage:\n foo", {argv: ["bar"], dontExit: true})
Uncaught:
Function {
message: 'foo: unknown command bar\n' +
'Usage:\n' +
' foo\n' +
'See foo -h/--help for more information',
payload: {}
}
> try { neodoc.run("Usage:\n foo", {argv: ["bar"], dontExit: true}) } catch (e) { console.log("e:", e) }
e: Function {
message: 'foo: unknown command bar\n' +
'Usage:\n' +
' foo\n' +
'See foo -h/--help for more information',
payload: {}
}
undefined