0

我正在 Visual Studio 中使用 Aurelia 构建一个网站,它具有 babel 转译器,我的配置文件如下所示

babelOptions: {
        "optional": [
              "optimisation.modules.system",
    "es7.decorators",
    "es7.classProperties",
    "es7.asyncFunctions",
    "runtime"
        ]
    },

Visual Studio 报告错误。Expected ';'在第 4 行。然而,这似乎是正确的语法,app.js 可以工作,我可以浏览到 app.html,而不会在控制台中出现任何问题。这是有问题的代码。

export class App {
    message = "Hello Aurelia";

    configureRouter(config, router) { /// <--- Expected ';'
        this.router = router;
        config.title = 'Aurelia';
        config.map([
          { route: ['', 'home'],       name: 'home',       moduleId: 'home/index' },
        ]);
    };
};

如果我尝试使用更标准的 javascript 行

let configureRouter = function(config, router) {};

或者

this.configureRouter = function(config, router) {};

Visual Studio 没有报告任何问题,但 AureliaError: (SystemJS) http://localhost:57366/src/app.js: Unexpected token (4:8)在控制台中抛出了上述两个问题。

知道如何让 Visual Studio 使用与 babel 转译器相同的智能感知吗?或者可能是什么问题?

4

2 回答 2

0

我不是 Aurelia 的专家,但我知道有时 Visual Studio 会告诉您 X 行有错误,而真正的错误在代码的更下方。

我认为第 8 行的末尾不应该有一个“,”:

config.map([
      { route: ['', 'home'],       name: 'home',       moduleId: 'home/index' },
]);

应该看起来像:

config.map([
      { route: ['', 'home'],       name: 'home',       moduleId: 'home/index' }
]);

Visual Studio 认为:

Foo({ "bar",
      "bar",
      "bar",
      "bar",
      });

只是一行。

于 2016-10-09T02:13:49.337 回答
0

这更像是一种解决方法而不是答案。看起来 Visual Studio 不支持 es6 的模块。下面的解决方案将起作用,而不是寻找 Visual Studio 的配置文件,或使用第三方工具/扩展。

在文件末尾定义导出将起作用。

class App {
    message = "Hello Aurelia";
    villy = "lawrence";

    configureRouter(config, router) {
        this.router = router;
        config.title = 'Aurelia';
        config.map([
          { route: ['', 'home'],       name: 'home',       moduleId: 'home/index' },
        ]);
    };
}

export { App };
于 2016-10-09T02:14:50.187 回答