Visual Studio认为存在语法错误,但事实并非如此。



我正在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报告没有问题,但是Aurelia在控制台中抛出Error: (SystemJS) http://localhost:57366/src/app.js: Unexpected token (4:8)

任何想法如何让Visual Studio使用相同的智能感知巴别塔转译器正在使用?或者是什么问题?

这更像是一种变通而不是答案。看起来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 };

我不是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",
      });

只有一行

相关内容

最新更新