简体   繁体   English

Visual Studio认为存在语法错误,但没有

[英]Visual Studio thinks there is a Syntax Error, but there isn't

I am building a website using Aurelia within Visual Studio, it has the babel transpiler and my config file looks as follows 我正在Visual Studio中使用Aurelia构建网站,它具有babel Transpiler,我的配置文件如下所示

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

Visual Studio is reporting an error. Visual Studio正在报告错误。 Expected ';' on line 4. However this seems to be the correct syntax, the app.js works, and I can browse to the app.html without any issues in the console. 在第4行上。但是,这似乎是正确的语法,app.js可以正常工作,并且我可以浏览到app.html而不在控制台中出现任何问题。 Here is the offending code. 这是有问题的代码。

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' },
        ]);
    };
};

If i try to use the more standard javascript lines 如果我尝试使用更标准的javascript行

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

or 要么

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

Visual studio reports no issue, but Aurelia throws Error: (SystemJS) http://localhost:57366/src/app.js: Unexpected token (4:8) in the console for both above. Visual Studio没报告任何问题,但是Aurelia抛出Error: (SystemJS) http://localhost:57366/src/app.js: Unexpected token (4:8)上面两个控制台中的Error: (SystemJS) http://localhost:57366/src/app.js: Unexpected token (4:8)

Any idea how to get Visual Studio to be using the same intellisense as the babel transpiler is using? 任何想法如何使Visual Studio使用与Babel Transpiler使用的相同的智能感知? Or what the issue could be? 或者可能是什么问题?

I am no expert of Aurelia but I know that sometimes Visual Studio tells you that there is an error at the line X while the real error is further down in the code. 我不是Aurelia的专家,但我知道有时Visual Studio会告诉您X行有错误,而真正的错误在代码中更进一步。

I think there is a ',' that should not be there a the end of line 8: 我认为第8行的末尾不应有',':

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

shoud probably looks like: 应该看起来像:

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

Visual Studio thinks this: Visual Studio认为:

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

is only a single line. 只是一行。

This is more of a work around than an answer. 这更多的是工作而不是答案。 It looks like Visual Studio does not support the module piece of es6. 看起来Visual Studio不支持es6模块。 Rather than hunting down the configuration file for Visual Studio, or using a third party tool/extension, the below solution will work. 以下解决方案将有效,而不是寻找Visual Studio的配置文件或使用第三方工具/扩展名。

Defining the export at the end of the file instead will work. 相反,在文件末尾定义导出将起作用。

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 };

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM