gpt4 book ai didi

javascript - 第 6 行中未关闭的 INDENT (CoffeeScript) 编译器错误

转载 作者:可可西里 更新时间:2023-11-01 09:28:31 24 4
gpt4 key购买 nike

这是我在 CoffeeScript 中使用 MongoDB 进行简单测试的代码。当我运行时
coffee -c UserDataProvider.coffee
我最终在第 6 行出现错误 UNCLOSED INDENT

这是我的代码:

Db   = require('mongodb/db').Db
ObjectID = require('mongodb/bson/bson').ObjectID
Server = require('mongodb/connection').Server

class UserDataProvider
constructor = (host,port)->
this.db = new Db( 'test' , new Server(host ,port,{}))

getCollection = (callback) ->
this.db.collection('data',(error,data)->
if error then callback(error)
else callback(data)

StackTrace 是:

Error: In UserDataProvider.coffee, unclosed INDENT on line 6
at Error (unknown source)
at Rewriter.ensureBalance (/usr/local/lib/node/.npm/coffee-script/1.0.1/package/lib/rewriter.js:283:17)
at Rewriter.rewrite (/usr/local/lib/node/.npm/coffee-script/1.0.1/package/lib/rewriter.js:21:12)
at Lexer.tokenize (/usr/local/lib/node/.npm/coffee-script/1.0.1/package/lib/lexer.js:37:29)
at Object.compile (/usr/local/lib/node/.npm/coffee-script/1.0.1/package/lib/coffee-script.js:26:34)
at /usr/local/lib/node/.npm/coffee-script/1.0.1/package/lib/command.js:117:33
at /usr/local/lib/node/.npm/coffee-script/1.0.1/package/lib/command.js:85:26
at [object Object].<anonymous> (fs.js:86:5)
at [object Object].emit (events.js:39:17)
at afterRead (fs.js:843:12)

有人能帮忙吗?

最佳答案

此行的第一个左括号永远不会关闭:

this.db.collection('data',(error,data) ->

实际上根本不需要它,所以如果您打算将“data”作为第一个参数传递,并且 function(error, data) { ... } 作为第二个参数。

关于javascript - 第 6 行中未关闭的 INDENT (CoffeeScript) 编译器错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5123846/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com