我在我的asp.net核心打字稿文件的打包过程中对grunt-contrib-jshint
使用grunt。
我有这个超级简单的打字稿代码:
function delay(delay: number) {
return new Promise(r => {
setTimeout(r,delay);
})
}
class Timer {
constructor(public counter: number = 3,public delayMs: number = 1000) {
this.doTimer();
}
async doTimer() {
for (let i = 0; i < this.counter; i++) {
await delay(this.delayMs);
this.counter = this.counter - 1;
console.log(this.counter);
}
}
}
结果js看起来像这样:
var __awaiter = (this && this.__awaiter) || function (thisArg,_arguments,P,generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve,reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled,rejected); }
step((generator = generator.apply(thisArg,_arguments || [])).next());
});
};
function delay(delay) {
return new Promise(r => {
setTimeout(r,delay);
});
}
class Timer {
constructor(counter = 3,delayMs = 1000) {
this.counter = counter;
this.delayMs = delayMs;
this.doTimer();
}
doTimer() {
return __awaiter(this,void 0,function* () {
for (let i = 0; i < this.counter; i++) {
yield delay(this.delayMs);
this.counter = this.counter - 1;
console.log(this.counter);
}
});
}
}
//# sourceMappingURL=Timer.js.map
grunt-contrib-jshint
的配置与我的Gruntfile.js
中的配置相同:
module.exports = function (grunt) {
grunt.initConfig({
concat: {
all: {
src: ['Script/Timer.js'],dest: 'temp/app.js'
}
},jshint: {
files: ['temp/app.js'],options: {
'-W069': false,'esversion': 6,}
},}
});
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks('grunt-contrib-jshint');
};
grunt-contrib-jshint
输出以下错误:
temp/app.js
3 | return new (P || (P = Promise))(function (resolve,reject) {
^ Bad constructor.
6 | function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled,rejected); }
^ Expected an
我还尝试用esversion
9配置jshint。grunt-contrib-jshint
是2.1.0
版本。
怎么了?