我在Visual Studio中使用Aurelia构建一个网站,它有babel转换程序,我的配置文件如下所示
babelOptions: {
"optional": [
"optimisation.modules.system",
"es7.decorators",
"es7.classProperties",
"es7.asyncFunctions",
"runtime"
]
},
Visual Studio报告错误。第4行Expected ';'
。但这似乎是正确的语法,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使用与babel转换器使用相同的智能感知?或者问题是什么?
答案 0 :(得分:0)
我不是Aurelia的专家,但我知道有时Visual Studio会告诉您X行X上有错误,而代码中的实际错误更低。
我认为有一个&#39;&#39;那不应该是第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",
});
只是一行。
答案 1 :(得分: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 };