【发布时间】:2016-11-20 15:12:26
【问题描述】:
我正在尝试使用类将我现有的 Angular 应用程序转换为 es6。但是 eslint 在遇到导入/导出语句时无法编译我的 js 文件。
class HeaderController {
constructor($rootScope, $scope) {
this.$rootScope = $rootScope;
this.$scope = $scope;
}
changeNavItem(selectedTab) {
this.activeNavItem = selectedTab;
}
init() {
this.activeNavItem = 'All';
} }
HeaderController.$inject = ['$rootScope', '$scope'];
angular.module('app')
.controller('HeaderController', HeaderController);
export default HeaderController; // fails on this line
ESlint 抛出此错误'由于解析错误无法处理源代码 'import' 和 'export' 可能只出现在 'sourceType: module''
我已经为 ESlint 添加了必要的配置,但仍然失败。
我在我的 eslintrc.json 中添加了以下内容
"parserOptions": {
"ecmaVersion": 6,
"sourceType": "module",
"allowImportExportEverywhere": true,
"ecmaFeatures": {
"modules": true,
"arrowFunctions": true,
"classes": true
}
}
请帮助我如何解决这个问题,还有一个使用 gulp 以角度设置 es6 的完整示例将非常有帮助。
【问题讨论】:
标签: javascript angularjs gulp ecmascript-6 eslint