简体   繁体   中英

SyntaxError using Babel and JSX when using class

I'm trying to create classes using webpack, babel and jsx

import Observable from '../../observable';


abstract class AbstractClient implements Observable  {
    var _name: string,
    var _config: object,

    function constructor(config: object) : variant,

    ...
}
export default AbstractClient;

And here is the error I get:

ERROR in ./app/adapter/AbstractAdapter/aclient.jsx
Module build failed: SyntaxError: /home/vinz243/Documents/nTorrent/app/adapter/AbstractAdapter/aclient.jsx: Unexpected token (5:9)
  3 | 
  4 | 
> 5 | abstract class AbstractClient implements Observable  {
    |          ^
  6 |   var _name: string,
  7 |   var _config: object,
  8 | 

My babel presets

 presets:['es2015','stage-0','react']

There's no syntax support in ES2015 for abstract classes, that's why you get an unexpected token error. abstract is not a keyword in es2015 either, so the interpreter is probably interpreting abstract as a variable name.

There are methods of implementing an abstract class pattern in Javascript.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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