意外的令牌在ES6模板字符串上是非法的

JSDoc 3.3.3 Unexpected token ILLEGAL on ES6 template string tick mark

本文关键字:字符串 非法 令牌 ES6 意外      更新时间:2023-09-26

在终端中,我运行以下命令:

$ node sample.js
hello, Stephen MC
$ node_modules/.bin/jsdoc --version
JSDoc 3.3.3 (Tue, 22 Sep 2015 23:14:17 GMT)
$ node_modules/.bin/jsdoc -c jsdocConf.json
Parsing /**/sample.js ...ERROR: Unable to parse /**/sample.js: Line 14: Unexpected token ILLEGAL
complete.
Generating output files...complete.
Finished running in 0.29 seconds.

我的sample.js文件看起来像这样:

/** @module myjsdoc/sample */
"use strict";
const me = "Stephen MC";
/** This function logs the parameter.
 * @param {string} param - The string to log.
 */
const myFunc = function ( param ) {
  console.log( param );
};
myFunc( `hello, ${me}` );

jsdoc的conf.json是这样的:

{
    "tags": {
        "allowUnknownTags": true,
        "dictionaries": ["jsdoc","closure"]
    },
    "source": {
        "include": [ "./" ],
        "exclude": [ "documentation", "node_modules" ],
        "includePattern": ".+''.js(doc)?$",
        "excludePattern": "(^|''/|'''')_|.+[Ss]pec''.js"
    },
    "templates": {
        "cleverLinks": false,
        "monospaceLinks": false
    },
    "opts": {
      "destination": "./documentation/",
      "readme": "./README.md",
      "recurse": true,
      "verbose": true
    }
}

是否有办法配置jsdoc 3.3.3容忍ES6模板字符串?也许有一个插件可以工作?

主分支中的jsdoc使用不同的解析器,这可以更好地处理es6:

npm install git+https://github.com/jsdoc3/jsdoc.git

对我来说工作得很好,我将切换到3.4.0版本

通过使用npm install安装esprima 2.6.0并将该目录从node_modules/esprima复制到node_modules/jsdoc/node_modules/esprima(覆盖过时的1.2.6 esprima版本),jsdoc能够解析'标记并发出警告。

我知道从esprima的v1跳到v2是一个突破性的变化,但它为我完成了工作。