首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >ng-使用Babel注释错误和销毁

ng-使用Babel注释错误和销毁
EN

Stack Overflow用户
提问于 2015-12-04 19:58:10
回答 1查看 4.1K关注 0票数 17

当使用Babel转移到ES6时出现奇怪的错误,ng-annotate不喜欢破坏。我将我的源代码复制到在线babel编译器中,它运行得很好。在我的吞咽管道链中注释掉ng-annotate可以消除错误。删除文件中的/* @ngAnnotate */注释并手动注入也不会改变任何事情。

咽喉区:

代码语言:javascript
复制
return gulp.src(config.scripts.app)
    .pipe(changed(config.dist + '/scripts'))
    .pipe(plumber())
    .pipe(annotate())

    // Filter out and transpile only .es6.js files
    .pipe(es6)
    .pipe(babel({
        presets: ['es2015'],
        plugins: ['extensible-destructuring'],
        comments: false
    }))
    .pipe(es6.restore)

    .pipe(concat('scripts.js'))
    .pipe(gulp.dest(config.dist + '/scripts'))

资料来源:

代码语言:javascript
复制
var [min, max] = values.map(val => +val);
// let/var doesn't make a difference.

ngModelCtrl.$modelValue = [min, max];

错误来自ng-annotate中的依赖项

代码语言:javascript
复制
Error: StringMap expected string key
    at stringmap.set (/Users/macbookair/Places/app/places/frontend/node_modules/gulp-ng-annotate/node_modules/ng-annotate/node_modules/stringmap/stringmap.js:101:19)
    at Scope.add (/Users/macbookair/Places/app/places/frontend/node_modules/gulp-ng-annotate/node_modules/ng-annotate/build/es5/scope.js:102:17)
    at /Users/macbookair/Places/app/places/frontend/node_modules/gulp-ng-annotate/node_modules/ng-annotate/build/es5/scopetools.js:38:25
    at Array.forEach (native)
    .... more

有问题的stringmap.js函数:

代码语言:javascript
复制
stringmap.prototype.set = function(key, value) {    
    if (typeof key !== "string") {
        throw new Error("StringMap expected string key");
    }
    if (key === "__proto__") {
        this.hasProto = true;
        this.proto = value;
    } else {
        this.obj[key] = value;
    }
};

在上述函数中注销keyvalue将返回以下内容:

代码语言:javascript
复制
undefined { 
    kind: 'var', 
    node: { 
        type: 'ArrayPattern',
        start: 1178,
        end: 1188,
        loc: { start: [Object], end: [Object] },
        range: [ 1178, 1188 ],
        elements: [ [Object], [Object] ] 
    },
    from: 1215 
}

显然,key的论点是没有定义的,但是为什么它会在意呢?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-12-13 13:42:18

我也有类似的问题,我只是简单地将吞咽管道中的顺序更改为: babel ->注释。ng-注释不支持新的JS版本:Github.com/olov/ng-注释/issues/237

最初由@illagrenan在上面的评论部分回答

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/34096440

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档