Browse Source

Update comments describing property string generation

gh-1132
Chris Thielen 8 years ago
parent
commit
b1e4384865
  1. 4
      src/finalisers/iife.js
  2. 5
      src/finalisers/shared/propertyStringFor.js
  3. 4
      src/finalisers/umd.js

4
src/finalisers/iife.js

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

5
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 =>
@ -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('');

4
src/finalisers/umd.js

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

Loading…
Cancel
Save