LiveScript icon indicating copy to clipboard operation
LiveScript copied to clipboard

require! dashes-without-quotes

Open KSXGitHub opened this issue 8 years ago • 9 comments
trafficstars

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')

KSXGitHub avatar Jun 18 '17 14:06 KSXGitHub

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.

determin1st avatar Jun 19 '17 05:06 determin1st

The point is, no one is gonna name a npm package in camelCase, so, require('camelCasePackageName') is doing no one's favour

KSXGitHub avatar Jun 19 '17 13:06 KSXGitHub

it's even forbidden nowadays (iirc).

vendethiel avatar Jun 19 '17 13:06 vendethiel

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 avatar Jun 19 '17 14:06 rhendric

@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)

KSXGitHub avatar Jun 20 '17 04:06 KSXGitHub

That shouldn't be an issue; require! ./lib/camelCaseNamedFile isn't valid syntax. Any requirements with slashes in them already need to be quoted.

rhendric avatar Jun 20 '17 20:06 rhendric

The only issue are custom modules in node_modules, not from npm. I sometimes use that, although I keep names in the kebab-case.

pepkin88 avatar Mar 20 '18 23:03 pepkin88

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?

pepkin88 avatar Mar 31 '18 17:03 pepkin88

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.

rhendric avatar Apr 02 '18 19:04 rhendric