用了个第三方zip压缩库,正常html用标签方式引入没有问题,用npm引入后发现不支持import,于是跑去github上翻了下issue,结果作者认为import不是正式标准,不打算支持,甚至有人push了修改后的代码,仍然被拒了,原因是破坏了原有的require路径。

这个也好办,把dist下的代码复制过来,加个export default就行了。结果发现下在打包时出现了奇怪的语法错误“SyntaxError: Unexpected token”,通过大段删代码的方式总算定位到一个注释的问题:

const _tr_tally = (s, dist, lc) =>
//    deflate_state *s;
//    unsigned dist;  /* distance of matched string */
//    unsigned lc;    /* match length-MIN_MATCH or unmatched char (if dist==0) */
{

这种方式的注释会导致打包出现语法错误,更改为下面的代码后没有问题了:

//    deflate_state *s;
//    unsigned dist;  /* distance of matched string */
//    unsigned lc;    /* match length-MIN_MATCH or unmatched char (if dist==0) */
const _tr_tally = (s, dist, lc) =>
{

仔细一想,这个不科学啊,于是再试:

const _tr_tally = (s, dist, lc) =>
//    deflate_state *s;
{

没有问题,再试:

const _tr_tally = (s, dist, lc) =>
//    deflate_state *s;
//    unsigned dist;  /* distance of matched string */
{

依然没有问题。难道说问题在第三行那个括号:

const _tr_tally = (s, dist, lc) =>
//    deflate_state *s;
//    unsigned dist;  /* distance of matched string */
//    unsigned lc;    /* match length-MIN_MATCH or unmatched char */
{

果然没有问题!看来这个就是bug所在了。

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.