Skip to content

Commit

Permalink
Split file
Browse files Browse the repository at this point in the history
  • Loading branch information
ehmicky committed May 29, 2022
1 parent 0a7cd18 commit 6dd1c89
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 26 deletions.
31 changes: 31 additions & 0 deletions src/config/normalize/lib/keywords/definition.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { callFunc } from '../call.js'

// The property name is defined by `name`.
// `aliases` can be defined to either:
// - Augment the behavior of another keyword
// - Rename a keyword
export const getDefinition = function (rule, name, aliases) {
const definition = rule[name]

if (definition !== undefined || aliases === undefined) {
return definition
}

const aliasA = aliases.find((alias) => rule[alias] !== undefined)
return aliasA === undefined ? undefined : rule[aliasA]
}

// Apply `keyword.normalize()`
export const normalizeDefinition = async function (
definition,
normalize,
info,
) {
return normalize === undefined
? definition
: await callFunc({
func: () => normalize(definition),
info,
hasInput: false,
})
}
27 changes: 1 addition & 26 deletions src/config/normalize/lib/keywords/main.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { callFunc } from '../call.js'

import { getDefinition, normalizeDefinition } from './definition.js'
import { KEYWORDS } from './list/main.js'
import { applyReturnValue } from './return.js'
import { shouldSkipKeyword, shouldSkipMain } from './skip.js'
Expand Down Expand Up @@ -112,29 +113,3 @@ const applyKeyword = async function ({
})
return applyReturnValue({ returnValue, state })
}

// The property name is defined by `name`.
// `aliases` can be defined to either:
// - Augment the behavior of another keyword
// - Rename a keyword
const getDefinition = function (rule, name, aliases) {
const definition = rule[name]

if (definition !== undefined || aliases === undefined) {
return definition
}

const aliasA = aliases.find((alias) => rule[alias] !== undefined)
return aliasA === undefined ? undefined : rule[aliasA]
}

// Apply `keyword.normalize()`
const normalizeDefinition = async function (definition, normalize, info) {
return normalize === undefined
? definition
: await callFunc({
func: () => normalize(definition),
info,
hasInput: false,
})
}

0 comments on commit 6dd1c89

Please sign in to comment.