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

Require function doesnt fullfil specification

    XMLWordPrintableJSON

Details

    Description

      According CommonJS Modules specification [1]:

      > 4. Module identifiers may be "relative" or "top-level". A module identifier is "relative" if the first term is "." or "..".
      > 5. Top-level identifiers are resolved off the conceptual module name space root.

      This specification is broken in current realization at those terms. See design test case.

      Actually problems:
      1. Module id is broken if module imports from same level (as via '.') or from parent level (as via '..'). AFAIK, module id should be valid to make require(mod.id) call successful. See`_show/relative-id`, `_show/require-relative-id` and `_show/relative-parent-id` function.
      2. Absolute module import is broken from relative imported module. See`_show/absolute-require` function.
      3. Multiple relative imports from same level(as via '.') breaks require function. See `_show/maze` function.

      Those problems makes require function works unexpectedly and obstructs solving at least one more issue #1075 [2]

      I know that all relative imports are discouraged, but if they are supported, why they shouldn't work properly?(:

      [1] http://wiki.commonjs.org/wiki/Modules/1.1.1
      [2] https://issues.apache.org/jira/browse/COUCHDB-1075

      Attachments

        1. design.require.txt
          1 kB
          Alexander Shorin
        2. utils.js.patch
          1 kB
          Alexander Shorin
        3. design_docs.js.patch
          4 kB
          Alexander Shorin
        4. id_and_require_fixes.patch
          5 kB
          Caolan McMahon

        Activity

          People

            Unassigned Unassigned
            kxepal Alexander Shorin
            Votes:
            1 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Time Tracking

                Estimated:
                Original Estimate - 1h
                1h
                Remaining:
                Remaining Estimate - 1h
                1h
                Logged:
                Time Spent - Not Specified
                Not Specified