[Pkg-javascript-commits] [node-umd] 07/10: Support `$` and `_` in module names

Bastien Roucariès rouca at moszumanska.debian.org
Mon Apr 17 07:38:13 UTC 2017


This is an automated email from the git hooks/post-receive script.

rouca pushed a commit to annotated tag 3.0.0
in repository node-umd.

commit 97376de38577f4b653b090c9b9fc6619645759be
Author: Forbes Lindesay <forbes at lindesay.co.uk>
Date:   Wed Feb 4 13:44:51 2015 +0000

    Support `$` and `_` in module names
    
    [closes #21]
---
 index.js      | 9 ++++++++-
 test/index.js | 7 ++++++-
 2 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/index.js b/index.js
index 1917cac..f3cfad3 100644
--- a/index.js
+++ b/index.js
@@ -59,7 +59,14 @@ exports.postlude = function (moduleName, options) {
 
 function camelCase(name) {
   name = name.replace(/\-([a-z])/g, function (_, char) { return char.toUpperCase(); });
-  return name.replace(/[^a-zA-Z0-9]+/g, '')
+  if (!/^[a-zA-Z_$]$/.test(name[0])) {
+    name = name.substr(1);
+  }
+  var result = name.replace(/[^\w$]+/g, '')
+  if (!result) {
+    throw new Error('Invalid JavaScript identifier resulted from camel-casing');
+  }
+  return result
 }
 
 
diff --git a/test/index.js b/test/index.js
index 7594bae..55e7e63 100644
--- a/test/index.js
+++ b/test/index.js
@@ -5,6 +5,7 @@ var umd = require('../')
 var src = umd('sentinel-prime', 'return "sentinel"')
 var namespacedSrc = umd('sentinel.prime', 'return "sentinel"')
 var multiNamespaces = umd('a.b.c.d.e', 'return "sentinel"')
+var dollared = umd('$', 'return "sentinel"')
 
 describe('with CommonJS', function () {
   it('uses module.exports', function () {
@@ -56,5 +57,9 @@ describe('in the absense of a module system', function () {
     Function('window', multiNamespaces)(glob)
     assert(glob.a.b.c.d.e === 'sentinel')
   })
-
+  it('allows the name to be a dollar', function () {
+    var glob = {}
+    Function('window', dollared)(glob)
+    assert(glob.$ === 'sentinel')
+  })
 })

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-umd.git



More information about the Pkg-javascript-commits mailing list