Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@lrowe
Copy link
Contributor

@lrowe lrowe commented Sep 19, 2021

The function generated by keywordTransform provides does not include switch defaults so a non-keyword that is of the same length as a keyword will be checked against all possible keyword values longer than it.

With the existing output a non keyword like 'x' is checked against both case "a" and case "bb":

//> console.log(moo.keywords({KW: ['a', 'bb'] }).toString())
function anonymous(value
) {
switch (value.length) {
case 1:
switch (value) {
case "a": return "KW"
}
case 2:
switch (value) {
case "bb": return "KW"
}
}

}

With the changes in this commit it is only checked against case "a".

//> console.log(moo.keywords({KW: ['a', 'bb'] }).toString())
function anonymous(value
) {
switch (value.length) {
case 1:
switch (value) {
case "a": return "KW"
default: return
}
case 2:
switch (value) {
case "bb": return "KW"
default: return
}
}

}

Copy link
Collaborator

@tjvr tjvr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Smart! Thanks 🙏

@tjvr tjvr merged commit d8a76f7 into no-context:master Sep 20, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants