LiveScript icon indicating copy to clipboard operation
LiveScript copied to clipboard

Can `require!` automatically rename variable if the required package name conflicts with LiveScript keyword?

Open evanmeng opened this issue 10 years ago • 3 comments

For example when I using when.js, I will do something like

require! \when

when.reduce(...) 

This will cause error like [Error: Parse error on line 1: Unexpected 'CASE'] because require! will put the imported package in a variable when, which is a keyword of LiveScript. The error message is not quite related with the root cause, it takes me some time before realizing when is a keyword.

So I wonder is it possible to enhance require! to make it auto detect package name conflicts with built-in keywords, and auto rename the corresponding variable (e.g., put when package to when_)?

evanmeng avatar Jul 17 '15 02:07 evanmeng

Auto renaming might not be a good idea. I propose that an error should be thrown on trying to require! keyword with a message asking user to rename the module. require! {'when':when_} can be used to import the module as when_. The error message should be descriptive and provide the workaround clearly.

phanimahesh avatar Jul 17 '15 03:07 phanimahesh

:+1:@ better error message :-1:@ auto-keyword renaming which can be easily forgotten

gabeio avatar Jul 17 '15 03:07 gabeio

Thanks for comment. Now I also agree that better error message is better.

evanmeng avatar Jul 20 '15 03:07 evanmeng