javascript - Transpiling es7 to es6 error unexpected identifier -


i have transpiled javascript code es7 es6 since need use

node.js 6.9.5

but keep getting error when transpiling:

unexpected identifier keyvalues[key] = yield dbstorage.get(key);

my code looks this:

getmany: function (keys) {     return new promise((resolve, reject) => {         let keyvalues = {};          for(let key of keys){             keyvalues[key] = await dbstorage.get(key);         }          resolve(keyvalues);     }); }, 

and transpiled code looks this:

 getmany: function (keys) {     return new promise((resolve, reject) => {         let keyvalues = {};         (let key of keys) {             keyvalues[key] = yield dbstorage.get(key);         }         resolve(keyvalues);     }); }, 

i using typescript transpile tsconfig.json looks this:

{ "allowjs" : true, "compileroptions": {     "target": "es6",     "sourcemap": true,     "removecomments": false,     "listfiles" : false,     "diagnostics" : false,      "outdir" : "build",     "allowjs" : true,     "inlinesourcemap" : false }, "include" : ["collaboration/*"], "exclude": [ "build", "node_modules" ] 

}

so what's wrong ?

you're using await in non-async function, incorrect. getmany should async, amongst other things means don't need new promise:

getmany: async function (keys) { //       ^^^^^     let keyvalues = {};      (let key of keys){         keyvalues[key] = await dbstorage.get(key);     }      return keyvalues; }, 

it's strange of typescript compiler turn erroneous await erroneous yield, edge-case bug in typescript compiler. if fix usage, transpile correctly.


Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -