Uploaded image for project: 'CouchDB'
  1. CouchDB
  2. COUCHDB-1875

CoffeeScript CommonJS Functions Don't Work

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Won't Fix
    • None
    • None
    • JavaScript View Server
    • None

    Description

      Reusable CommonJS functions written in CoffeeScript raise exceptions when referenced from map functions.

      Consider the following Javascript code:

      {
        lib: {
          simple: "exports.callback = function() { return 'Simple' }"
        },
        test: {
          map: "function(doc) { emit(require('views/lib/simple').callback(), doc) }"
        }
      }
      

      As expected, "Simple" is emitted for the key of every document.

      Now the equivalent CoffeeScript code:

      {
        lib: {
          simple: "exports.callback = () -> 'Simple'"
        },
        test: {
          map: "(doc) -> emit(require('views/lib/simple').callback(), doc)"
        }
      }
      

      The view returns no results and an error for every document is printed to the log file. For example:

      [info] [<0.7270.11>] OS Process #Port<0.96999> Log :: function raised exception (new TypeError("require(\"views/lib/simple\").callback is not a function", "undefined", 3)) with doc._id 8117

      Attachments

        Activity

          People

            Unassigned Unassigned
            anthony.kaufman Anthony Kaufman
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: