schmod / babel-plugin-angularjs-annotate

Add Angular 1.x dependency injection annotations to ES6 code
http://schmod.github.io/babel-plugin-angularjs-annotate
MIT License
240 stars 29 forks source link

Unexpected token #45

Closed iamdevlinph closed 6 years ago

iamdevlinph commented 6 years ago
"babel-core": "^6.26.3",
"babel-plugin-angularjs-annotate": "^0.9.0",
"gulp-babel": "^7.0.1",

The code snippet that causes an issue is this

$scope.test = () => {
    const { row } = $stateParams;
    if (row && row.id) {
        vm.dataId = { ...row };
    }
};

$scope.test();

After switching to BPAA

gulpfile.js

// .pipe($.ngAnnotate({ add: true }))
.pipe($.babel({
    compact: false,
    presets:['es2015'],
    plugins: [["angularjs-annotate", { explicitOnly : true}]]
}))

Error:

[10:24:38] Plumber found unhandled error:
 SyntaxError in plugin "gulp-babel"
Message:
    /mnt/e/aca/src/client/js/app.js: Unexpected token (7712:30)

The problem is that the app.js file is not generated so I dont know how to know which token it is exactly.


Before I switched to BPAA gulp-annotate.

gulpfile.js

.pipe($.ngAnnotate({ add: true }))
.pipe($.babel({
    compact: false,
    presets:['es2015'],
    // plugins: [["angularjs-annotate", { explicitOnly : true}]]
}))

Error

[10:45:20] Plumber found unhandled error:
 Error in plugin 'gulp-ng-annotate'
Message:
    js/app.js: error: couldn't process source due to parse error
Unexpected token (7712:30)

This is because ng-annotate doesn't support some es6 syntax.

Though, while still using the above configuration (pre BPAA) I was using an arrow function but gulp-ng-annotate didn't complain.

return ParamsService.getContinents().then(data => data);

iamdevlinph commented 6 years ago

After narrowing it down, the issue seems to be caused by the { ...row }

But when I switched to array [ ...row ] there seems to be no problem

iamdevlinph commented 6 years ago

I got it now,

I added a plugin "babel-plugin-transform-object-rest-spread": "^6.26.0",.