带有打字稿的Systemjs转译异步函数

Systemjs transpile async function with typescript

我可以使用 tsc 工具手动构建 .ts 文件。我看到为 async/await 个关键字生成的包装器。

但是我在使用 systemjs 即时设置转译时遇到问题。

index.htm:

<script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.16/system.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/typescript/1.7.5/typescript.min.js"></script>

<script>
  System.config({
    transpiler: 'typescript',
    typescriptOptions: {
      target: 'es6'
      },
    packages: {
      '': {
        defaultJSExtensions: 'ts'
      }
    }
  });

  System.import('app').catch(console.error.bind(console));
</script>

app.ts:

console.log('hello');

async function run() {
  console.log('world');
}

run();

开发者控制台错误:

SyntaxError: missing ; before statement

plnkr

问题出在指定格式 'esm' 上。或者添加一些关键字,如 import.ts 文件,以便 systemjs 可以选择正确的加载器。

System.config({
  transpiler: 'typescript',
  meta: {
    'app.ts': {
      format: 'esm'
    }
  }
});

System.import('app.ts').catch(console.error.bind(console));

已更新plnkr

现在它就像一个魅力!