Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Don't allow duplicate `addNamespace()` calls #8

Merged
merged 1 commit into from

2 participants

Ben Gourley Paul Serby
Ben Gourley

If the same namespace is created in two different places their contents are merged.

This pull request makes addNamespace() throw if it is called twice with the same name. I think this is the ideal behaviour. If not, it should at least warn.

Paul Serby serby merged commit dd5fd51 into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on May 4, 2012
  1. Ben Gourley
This page is out of date. Refresh to see the latest.
Showing with 23 additions and 9 deletions.
  1. +13 −9 lib/compact.js
  2. +10 −0 test/compact.test.js
22 lib/compact.js
View
@@ -38,16 +38,20 @@ module.exports.createCompact = function(options) {
throw new Error('Invalid namespace');
}
- if (!namespaces[name]) {
- var newNamespace = {};
- Object.defineProperty(namespaces, name, {
- get: function() { return newNamespace; },
- configurable: false,
- enumerable: true,
- set: function(value) {
- throw new Error('You can not alter a registered namespace \'' + name + '\''); }
- });
+ if (namespaces[name]) {
+ throw new Error('The namespace \'' +
+ name + '\' has already been added');
}
+
+
+ var newNamespace = {};
+ Object.defineProperty(namespaces, name, {
+ get: function() { return newNamespace; },
+ configurable: false,
+ enumerable: true,
+ set: function(value) {
+ throw new Error('You can not alter a registered namespace \'' + name + '\''); }
+ });
var namespace = namespaces[name];
function addJs(filePath) {
10 test/compact.test.js
View
@@ -122,6 +122,16 @@ describe('compact.js', function() {
.addJs('b.js');
});
});
+
+ describe('#addNamespace()', function () {
+ it('should not allow a namespace to be added more than once', function () {
+ (function () {
+ compact.addNamespace('foo');
+ compact.addNamespace('foo');
+ }).should.throw('The namespace \'foo\' has already been added');
+ });
+ });
+
});
describe('#js()', function() {
Something went wrong with that request. Please try again.