anko / eslisp

un-opinionated S-expression syntax and macro system for JavaScript
ISC License
528 stars 31 forks source link

Error when requiring macros from relative paths #25

Closed stasm closed 8 years ago

stasm commented 8 years ago

I'm not able to require macros from local files defined by a relative path. It seems like eslc tries to resolve the require paths relative to the location of the eslisp package.

[eslisp-require-bug] cat ok.esl
(= (. module exports)
  (lambda () (return 'true)))

[eslisp-require-bug] eslc ok.esl > ok.js

[eslisp-require-bug] cat ok.js
module.exports = function () {
    return { atom: 'true' };
};

[eslisp-require-bug] cat index.esl
(macro ok (require "./ok.js"))
(ok)

[eslisp-require-bug] eslc index.esl
/usr/lib/node_modules/eslisp/lib/cli.js:73
      throw err;
            ^
Error: Cannot find module './ok.js'
    at Function.Module._resolveFilename (module.js:336:15)
    at Function.Module._load (module.js:278:25)
    at Module.require (module.js:365:17)
    at eval (eval at <anonymous> (/usr/lib/node_modules/eslisp/lib/built-in-macros.js:550:50), <anonymous>:1:2)
    at /usr/lib/node_modules/eslisp/lib/built-in-macros.js:550:16
    at compileAsMacro (/usr/lib/node_modules/eslisp/lib/built-in-macros.js:551:9)
    at contents.macro (/usr/lib/node_modules/eslisp/lib/built-in-macros.js:592:26)
    at list.prototype.compile (/usr/lib/node_modules/eslisp/lib/ast.js:188:37)
    at /usr/lib/node_modules/eslisp/lib/translate.js:34:17
    at /usr/lib/node_modules/eslisp/node_modules/prelude-ls/lib/List.js:158:21

[eslisp-require-bug] eslc -v
0.6.0      
anko commented 8 years ago

Confirming. I remember this happening previously, which is why this test exists. Seems like it's not testing what I thought it was testing!

I'll investigate.

anko commented 8 years ago

Hang on, bad tests. Reworking that.

anko commented 8 years ago

The fix is in 0.6.1. Your example should work now. This automated test was changed to match it.

stasm commented 8 years ago

Well, that was quick, thanks!