Babel を使用して ES6 にトランスパイルすると奇妙なエラーが発生しますng-annotate
。ソースをオンラインのバベル コンパイラにコピーしたところ、問題なく動作しました。ng-annotate
gulp パイプ チェーンをコメント アウトすると、エラーが解消されます。ファイル内のコメントを削除して/* @ngAnnotate */
手動で挿入しても、何も変わりません。
一気飲みセクション:
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'))
問題のソース:
var [min, max] = values.map(val => +val);
// let/var doesn't make a difference.
ngModelCtrl.$modelValue = [min, max];
の依存関係からエラーが発生していng-annotate
ます:
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
問題の関数:
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;
}
};
ログアウトして上記の関数を実行するkey
とvalue
、次のように返されます。
undefined {
kind: 'var',
node: {
type: 'ArrayPattern',
start: 1178,
end: 1188,
loc: { start: [Object], end: [Object] },
range: [ 1178, 1188 ],
elements: [ [Object], [Object] ]
},
from: 1215
}
明らかにkey
引数は定義されていませんが、なぜ気にするのでしょうか?