Skip to content

Commit

Permalink
Update comments describing property string generation
Browse files Browse the repository at this point in the history
  • Loading branch information
christopherthielen committed Dec 15, 2016
1 parent bb546d3 commit b1e4384
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/finalisers/iife.js
Expand Up @@ -5,10 +5,10 @@ import getExportBlock from './shared/getExportBlock.js';
import getGlobalNameMaker from './shared/getGlobalNameMaker.js';
import propertyStringFor from './shared/propertyStringFor';

// thisProp('foo.bar.baz') === "this['foo']['bar']['baz']"
// thisProp('foo.bar-baz.qux') === "this.foo['bar-baz'].qux"
const thisProp = propertyStringFor('this');

// propString('foo.bar') === "['foo']['bar']"
// propString('foo.bar-baz.qux') === ".foo['bar-baz'].qux"
const propString = propertyStringFor('');

function setupNamespace ( keypath ) {
Expand Down
5 changes: 3 additions & 2 deletions src/finalisers/shared/propertyStringFor.js
@@ -1,4 +1,5 @@
// Generate strings which dereference dotted properties, but use array notation
// Generate strings which dereference dotted properties, but use array notation `['prop-deref']`
// if the property name isn't trivial

const shouldUseDot = /^[a-zA-Z$_][a-zA-Z0-9$_]*$/;
const dereferenceString = prop =>
Expand All @@ -8,7 +9,7 @@ const dereferenceString = prop =>
* returns a function which generates property dereference strings for the given name
*
* const getGlobalProp = propertyStringFor('global');
* getGlobalProp('foo.bar.baz') => `global['foo']['bar']['baz']`
* getGlobalProp('foo.bar-baz.qux') => `global.bar['bar-baz'].qux`
*/
const propertyStringFor = objName => propName =>
objName + propName.split('.').map(dereferenceString).join('');
Expand Down
4 changes: 2 additions & 2 deletions src/finalisers/umd.js
Expand Up @@ -6,10 +6,10 @@ import getGlobalNameMaker from './shared/getGlobalNameMaker.js';
import esModuleExport from './shared/esModuleExport.js';
import propertyStringFor from './shared/propertyStringFor.js';

// globalProp('foo.bar') === "global['foo']['bar']"
// globalProp('foo.bar-baz') === "global.foo['bar-baz']"
const globalProp = propertyStringFor('global');

// propString('foo.bar') === "['foo']['bar']"
// propString('foo.bar-baz') === ".foo['bar']"
const propString = propertyStringFor('');

function setupNamespace ( name ) {
Expand Down

0 comments on commit b1e4384

Please sign in to comment.