Skip to content

Commit

Permalink
🐛 fix name conflicts between array.slice and string.slice (#191)
Browse files Browse the repository at this point in the history
* 🐛 fix name conflicts between array.slice and string.slice

* ♻️ Consistent aliased names on seq.chain

* 💡 Mention aliased names in JSDoc
  • Loading branch information
nlepage committed Dec 28, 2017
1 parent 308ef9e commit f4dabbd
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 11 deletions.
40 changes: 35 additions & 5 deletions misc/generate-flow.js
Expand Up @@ -39,6 +39,16 @@ const generateFlow = async () => {

const namespaces = _.keys(itemsByNamespace)

const conflicts = _.chain(items)
.filter('flow')
.reduce((acc, { name }) => ({
...acc,
[name]: acc[name] !== undefined,
}), {})
.pickBy()
.keys()
.value()

await Promise.all(namespaces.map(async namespace => {
const nsDir = path.resolve(flowDir, namespace)
await ensureDir(nsDir)
Expand Down Expand Up @@ -66,15 +76,13 @@ export { curried as ${name} }
)
}))

const exportedNames = new Set()
await writeFile(
path.resolve(flowDir, 'exports.js'),
`${namespaces.map(namespace => {
const nsItems = itemsByNamespace[namespace].filter(({ name }) => !exportedNames.has(name))
nsItems.forEach(({ name }) => exportedNames.add(name))
const nsItems = itemsByNamespace[namespace]
/* eslint-disable comma-spacing,indent */
return `export {
${nsItems.map(({ name }) => ` ${name},`).join('\n')}
${nsItems.map(({ name }) => ` ${name}${conflicts.includes(name) ? ` as ${namespace}${_.capitalize(name)}` : ''},`).join('\n')}
} from './${namespace}'`
}).join('\n\n')}
`, /* eslint-enable */
Expand All @@ -100,21 +108,43 @@ ChainWrapper.prototype.${name} = function(path, ...args) {
}
`, /* eslint-enable */
)

if (conflicts.includes(name)) {
await writeFile(
path.resolve(nsDir, `${name}.ns.js`),
/* eslint-disable indent */
`import { ChainWrapper } from '${external ? 'immutadot/' : ''}seq/ChainWrapper'
import { ${name} } from '${namespace}/${name}'
ChainWrapper.prototype.${namespace}${_.capitalize(name)} = function(path, ...args) {
return this._call(${name}, path, args)
}
`, /* eslint-enable */
)
}
}
})()

await writeFile(
path.resolve(nsDir, 'index.js'),
/* eslint-disable indent */
`${nsItems.map(({ name }) => `import './${name}'`).join('\n')}
`, /* eslint-enable */
)

await writeFile(
path.resolve(nsDir, 'ns.js'),
/* eslint-disable indent */
`${nsItems.map(({ name }) => `import './${name}${conflicts.includes(name) ? '.ns' : ''}'`).join('\n')}
`, /* eslint-enable */
)
}))

await writeFile(
path.resolve(seqDir, 'all.js'),
/* eslint-disable indent */
`${namespaces.map(namespace => `import './${namespace}'`).join('\n')}
`${namespaces.map(namespace => `import './${namespace}/ns'`).join('\n')}
`, /* eslint-enable */
)
} catch (e) {
Expand Down
3 changes: 2 additions & 1 deletion packages/immutadot/src/array/concat.js
@@ -1,7 +1,8 @@
import { convertArrayMethod } from './convertArrayMethod'

/**
* Replaces an array concatenating the former array with additional arrays and/or values.
* Replaces an array concatenating the former array with additional arrays and/or values.<br/>
* ⚠ Due to name conflicts, this function is named <code>arrayConcat</code> when imported from top level (<code>import { arrayConcat } from 'immutadot'</code>).
* @function
* @memberof array
* @param {Object} object The object to modify.
Expand Down
3 changes: 2 additions & 1 deletion packages/immutadot/src/array/slice.js
@@ -1,7 +1,8 @@
import { convertArrayMethod } from './convertArrayMethod'

/**
* Replaces an array by a slice of the former array from <code>start</code> up to, but not including, <code>end</code>.
* Replaces an array by a slice of the former array from <code>start</code> up to, but not including, <code>end</code>.<br/>
* ⚠ Due to name conflicts, this function is named <code>arraySlice</code> when imported from top level (<code>import { arraySlice } from 'immutadot'</code>).
* @function
* @memberof array
* @param {Object} object The object to modify.
Expand Down
32 changes: 30 additions & 2 deletions packages/immutadot/src/index.js
@@ -1,7 +1,35 @@
export * from './array'
export {
concat as arrayConcat,
fill,
filter,
map,
pop,
push,
reverse,
shift,
slice as arraySlice,
sort,
splice,
unshift,
} from './array'
export * from './core'
export * from './lang'
export * from './object'
export * from './seq'
export * from './string'
export {
concat as stringConcat,
padEnd,
padStart,
replace,
slice as stringSlice,
substr,
substring,
toLocaleLowerCase,
toLocaleUpperCase,
toLowerCase,
toUpperCase,
trim,
trimLeft,
trimRight,
} from './string'
export * from './util'
3 changes: 2 additions & 1 deletion packages/immutadot/src/string/concat.js
@@ -1,7 +1,8 @@
import { convertStringMethod } from './convertStringMethod'

/**
* Replaces by former string concatenated with <code>strings</code>.
* Replaces by former string concatenated with <code>strings</code>.<br/>
* ⚠ Due to name conflicts, this function is named <code>stringConcat</code> when imported from top level (<code>import { stringConcat } from 'immutadot'</code>).
* @function
* @memberof string
* @param {Object} object The object to modify.
Expand Down
3 changes: 2 additions & 1 deletion packages/immutadot/src/string/slice.js
@@ -1,7 +1,8 @@
import { convertStringMethod } from './convertStringMethod'

/**
* Replaces by a slice of former string starting at <code>beginIndex</code> and ending at <code>endIndex</code> or end of the string.
* Replaces by a slice of former string starting at <code>beginIndex</code> and ending at <code>endIndex</code> or end of the string.<br/>
* ⚠ Due to name conflicts, this function is named <code>stringSlice</code> when imported from top level (<code>import { stringSlice } from 'immutadot'</code>).
* @function
* @memberof string
* @param {Object} object The object to modify.
Expand Down

0 comments on commit f4dabbd

Please sign in to comment.