-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
nodent fails to parse js file #50
Comments
Works me for: http://nodent.mailed.me.uk/#if%20(await%20myAsyncFunction(args))%20%7B%0A%7D%20else%20%7B%0A%7D%0A Can you provide more details? Nodent version? Maybe a larger code sample? |
My nodent version is 2.5.0, but when i paste this code snippet in the web version it displays the problem: async function StartTournament() {
if (await redisClient.get("lock") == null) {
await redisClient.set("lock", "")
await redisClient.incr("tournamentid")
await redisClient.del("boosts")
var playerAmount = await redisClient.zcard("scores:current")
var index = 1
var cursor = 0
do {
var result = await redisClient.zscan("scores:current", cursor)
var profile_index = 0
var score_index = 1
while (profile_index < result[1].length) {
var profile_id = result[1][profile_index]
var score = result[1][score_index]
var percent = index * 100.0 / playerAmount
var reward = null
if (percent >= (100 - 1)) {
await redisClient.hset("boosts", profile_id, "gold")
await redisClient.hincrby("top_reached", profile_id, 1)
reward = settings.rewards[0] //3 items
} else if (percent >= (100 - 2)) {
await redisClient.hset("boosts", profile_id, "silver")
reward = settings.rewards[1] //3 items
} else if (percent >= (100 - 15)) {
await redisClient.hset("boosts", profile_id, "bronze")
reward = settings.rewards[2] //3 items
} else if (percent >= (100 - 30)) {
reward = settings.rewards[3] //crystals
} else if (percent >= (100 - 50)) {
reward = settings.rewards[4] //coins
}
var topReached = await redisClient.hget("top_reached", profile_id)
var alltimeScore = await redisClient.zscore("scores:alltime", profile_id)
var stars = await redisClient.hget("stars", profile_id)
var unclaimedRewardsRes = await StatsfindOne({ 'profile_id': profile_id }, 'unclaimedRewards')
var unclaimedRewards = null
if (unclaimedRewardsRes != null) {
unclaimedRewards = unclaimedRewardsRes.unclaimedRewards
await StatsModel.findOneAndUpdate(
{ 'profile_id': profile_id },
{
"$set":
{
"topReached": (topReached == null ? 0 : topReached),
"alltimeScore": (alltimeScore == null ? 0 : alltimeScore),
"stars": (stars == null ? 0 : stars),
"unclaimedRewards": ((reward == null) ? unclaimedRewards : unclaimedRewards.concat(reward))
}
})
} else {
await StatsModel.create(
{
'profile_id': profile_id,
'topReached': (topReached == null ? 0 : topReached),
'alltimeScore': (alltimeScore == null ? 0 : alltimeScore),
'stars': (stars == null ? 0 : stars),
'unclaimedRewards': []
})
}
profile_index += 2
score_index += 2
index++
}
cursor = result[0]
} while (cursor != 0)
await redisClient.del("scores:current")
await redisClient.del("last_played")
await redisClient.set("started", (Date.now() + tournamentDuration).toString())
await redisClient.del("stopped")
await redisClient.del("lock")
} else {
}
} After adding console.log("locked") into the last else everything seems to be working fine |
Thanks for the snippet. I'm away for a couple of weeks, but will have a look when I return. If you find a work-around in the meanwhile, please post it too as it may help me spot the bug |
Fixed by be09271 in release 2.6.3 |
The isolated pattern which led to crash:
if (await myAsyncFunction(args)) {
} else {
}
Notice, that else clause is empty
Output at startup:
/node_modules/nodent/lib/arboriculture.js:2352
throw ex;
^
TypeError: Cannot read property 'type' of undefined
at /node_modules/nodent/lib/arboriculture.js:671:39
at Array.forEach (native)
at mapIfStmt (/node_modules/nodent/lib/arboriculture.js:663:58)
at /node_modules/nodent/lib/arboriculture.js:902:21
at Array.forEach (native)
at /node_modules/nodent/lib/arboriculture.js:901:24
at treeWalker (/node_modules/nodent/lib/parser.js:156:5)
at goDown (/node_modules/nodent/lib/parser.js:122:9)
at down (/node_modules/nodent/lib/parser.js:139:25)
at Object.base.Program.base.BlockStatement (/node_modules/acorn/dist/walk.js:180:5)
at descend (/node_modules/nodent/lib/parser.js:131:30)
at /node_modules/nodent/lib/arboriculture.js:907:13
at treeWalker (/node_modules/nodent/lib/parser.js:156:5)
at goDown (/node_modules/nodent/lib/parser.js:122:9)
at down (/node_modules/nodent/lib/parser.js:146:25)
at Object.base.Function (/node_modules/acorn/dist/walk.js:262:4)
The text was updated successfully, but these errors were encountered: