LiveScript
LiveScript copied to clipboard
require! dashes-without-quotes
LiveScript
require! dashes-without-quotes
Expected behaviour
var dashesWithoutQuotes;
dashesWithoutQuotes = require('dashes-without-quotes');
Actual behaviour
var dashesWithoutQuotes;
dashesWithoutQuotes = require('dashesWithoutQuotes'); // Cannot find module 'dashesWithoutQuotes' (which is actually 'dash-without-quotes')
well, it takes a static value anyway.. you may specify that with quotes or \ it also looks like
typeof! var-name-converted-to-camel-case
which gives an error if varNameCovertedToCamelCase is not defined( personally, i expect it to act like typeof operator, which will give "Undefined" or something alike.
The point is, no one is gonna name a npm package in camelCase, so, require('camelCasePackageName') is doing no one's favour
it's even forbidden nowadays (iirc).
You can get what you want with
require! \dashes-without-quotes
Even for a special form like require!, I wouldn't want to break the rule that kebab-cased names are always equivalent to their camelCased versions. One extra character is a small price to pay for language consistency.
Edit:
However, I would endorse changing both require! some-package and require! somePackage to compile to somePackage = require('some-package'). It would be a breaking change but, given the state of the npm ecosystem, one unlikely to affect many projects. require! \somePackage and require! \some-package would continue to do what they do now, which gives an escape hatch for anyone who needs to require camelCased packages.
@rhendric require! somePackage sounds super sweet
Another thing, if that some-package is from npm, it would not break; if it is a local file (require! ./lib/camelCaseNamedFile) however, you need to deprecate (print warning) the use of require! on camelCaseNamedFile (user would either change it to somePackage = require './lib/somePackage' or rename the file to contain only dashes and lower-case characters)
That shouldn't be an issue; require! ./lib/camelCaseNamedFile isn't valid syntax. Any requirements with slashes in them already need to be quoted.
The only issue are custom modules in node_modules, not from npm. I sometimes use that, although I keep names in the kebab-case.
I'd like to propose one more feature, if require! will end up mangling casing.
A common use case, to be able to write:
require! \./Some-class-name
obj = new SomeClassName!
or even
require! \./SomeClassName
obj = new SomeClassName!
instead of
require! \./some-class-name : SomeClassName
obj = new SomeClassName!
As for an escape hatch, ordinary require will work as always. After all, require! was meant to ease things up with common use cases, right?
I'm not crazy about require! rewriting quoted strings. The mangling I proposed only applied to the bare-identifier-to-string conversion. Strings (including backslash literals) should be what they are.