业力打字稿:使用Async关键字导入JS文件 [英] karma-typescript: import JS file with Async keyword

查看:109
本文介绍了业力打字稿:使用Async关键字导入JS文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用业力打字稿,并带有以下业力配置文件:

I'm using karma-typescript, with this karma config file :

karmaTypescriptConfig: {
  compilerOptions: {
    target: "es5",
    lib: ["dom", "es2015", "es2017"]
  },
  bundlerOptions: {
    transforms: [require("karma-typescript-es6-transform")()]
  }
},

在我的规格文件中,我有以下代码:

In my spec files, I have this code :

import {} from './local/lib.js'

在我的lib.js中,我有以下代码:

In my lib.js, I have this code :

async function() {}

使用npm test执行测试时,出现此错误:

When executing my tests with npm test, I have this error :

ERROR [source-reader.karma-typescript] Error parsing code: Unexpected token (X:Y) in /local/lib.js

如果我删除async关键字,那么一切都很好.

If I remove the async keyword, everything is alright.

如何编辑我的业力配置文件以修复错误?

How can I edit my karma config file to fix the error ?

推荐答案

根据karma-typescript软件包的Github中的一个问题(

According to an issue in the Github of the karma-typescript package (https://github.com/monounity/karma-typescript/issues/344), there is an undocumented flag which may help you test code which contains ES2017 code:

karmaTypescriptConfig: {
  compilerOptions: {
    target: "es5",
    lib: ["dom", "es2015", "es2017"]
  },
  bundlerOptions: {
    acornOptions: {
      ecmaVersion: 8,
    },
    transforms: [require("karma-typescript-es6-transform")()]
  }
},

此标志使我们出现了async关键字的问题.但是,即使使用此标志,我们的代码中的扩展语法(...array)仍然存在问题.如果有人知道答案也可以解决该问题,我会很乐意扩展我的答案.

This flag made appear our issues with the async keyword. However, there is still an issue with the spread syntax (...array) in our code, even using this flag. If anyone knows an answer how to also fix that, I will happily extend my answer.

这篇关于业力打字稿:使用Async关键字导入JS文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆