Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is CoffeeScript converting the code wrong?

I am using Mongoose + CoffeeScript and when I try to add embedded documents to my Schema, the code is wrongly converted.

e.g:

AccountSchema = new Schema # Companhia
    name : String
    users  : [UserSchema]
    custphones  : [CustphoneSchema]

becomes

AccountSchema = new Schema({
    name: String({
      users: [UserSchema],
      custphones: [CustphoneSchema]
    })
  });

and should have become

AccountSchema = new Schema({
    name: String,
    users: [UserSchema],
    custphones: [CustphoneSchema]
 });

Why is this happening?

Thanks

like image 236
donald Avatar asked Jun 02 '26 16:06

donald


2 Answers

Did you check that the indentations are consistent in their use of tabs and spaces? This is a common problem when whitespace is part of the syntax.

To get your your particular (broken) output, you probably indented with tab on name, and spaces on users and custphones.

like image 62
vhallac Avatar answered Jun 05 '26 13:06

vhallac


Your code compiles correctly on my machine. What you still can do is to add commas to the hash entries to help coffee script compile your code:

AccountSchema = new Schema # Companhia
    name : String,
    users  : [UserSchema],
    custphones  : [CustphoneSchema]
like image 31
topek Avatar answered Jun 05 '26 12:06

topek



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!