You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
48 lines
997 B
48 lines
997 B
export default combineExtensions |
|
|
|
import own from '../constant/has-own-property.mjs' |
|
import chunkedSplice from './chunked-splice.mjs' |
|
import miniflat from './miniflat.mjs' |
|
|
|
// Combine several syntax extensions into one. |
|
function combineExtensions(extensions) { |
|
var all = {} |
|
var index = -1 |
|
|
|
while (++index < extensions.length) { |
|
extension(all, extensions[index]) |
|
} |
|
|
|
return all |
|
} |
|
|
|
function extension(all, extension) { |
|
var hook |
|
var left |
|
var right |
|
var code |
|
|
|
for (hook in extension) { |
|
left = own.call(all, hook) ? all[hook] : (all[hook] = {}) |
|
right = extension[hook] |
|
|
|
for (code in right) { |
|
left[code] = constructs( |
|
miniflat(right[code]), |
|
own.call(left, code) ? left[code] : [] |
|
) |
|
} |
|
} |
|
} |
|
|
|
function constructs(list, existing) { |
|
var index = -1 |
|
var before = [] |
|
|
|
while (++index < list.length) { |
|
;(list[index].add === 'after' ? existing : before).push(list[index]) |
|
} |
|
|
|
chunkedSplice(existing, 0, 0, before) |
|
return existing |
|
}
|
|
|