Skip to content

Feature Tagged Template 'literal' #47

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jul 27, 2020
Merged

Feature Tagged Template 'literal' #47

merged 7 commits into from
Jul 27, 2020

Conversation

tiago154
Copy link
Contributor

Description of the Change

Issue -> #40
With this modification, a function named 'literal' was added, which is nothing more than an abbreviation for the

{ value: string, escape: false }

Where we can use it as follows.

literal`example_pkey` // return { value: 'example_pkey', escape: false }

The test of this function was written in typescript, aiming to close this PR here #46

Benefits

Shortens the object that needs to be used literally

Applicable Issues

#40

@khaosdoctor khaosdoctor linked an issue Jul 27, 2020 that may be closed by this pull request
@khaosdoctor khaosdoctor self-assigned this Jul 27, 2020
Copy link
Owner

@khaosdoctor khaosdoctor left a comment

Choose a reason for hiding this comment

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

Thanks a lot for the contribution! That will help a lot for the new version! I really appreciate the work you're doing ❤️

I haven't properly tested it yet because I'm on my cellphone, but I'll clone ASAP

Comment on lines 12 to 15
export const literal = (literalValue: TemplateStringsArray): LiteralObject => {
if (!literalValue || !literalValue[0]) throw new Error('literalValue cannot be null or empty')
return { value: literalValue[0], escape: false }
}
Copy link
Owner

Choose a reason for hiding this comment

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

Can you please change this definition to a function definition to follow the code style?

Suggested change
export const literal = (literalValue: TemplateStringsArray): LiteralObject => {
if (!literalValue || !literalValue[0]) throw new Error('literalValue cannot be null or empty')
return { value: literalValue[0], escape: false }
}
function literal (literalValue: TemplateStringsArray): LiteralObject {
if (!literalValue || !literalValue[0]) throw new Error('Value for the literal argument cannot be null or empty')
return { value: literalValue[0], escape: false }
}
export literal

Copy link
Owner

Choose a reason for hiding this comment

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

Actually, I think there are empty arguments (as of #39), so probably, we would want something like this:

Suggested change
export const literal = (literalValue: TemplateStringsArray): LiteralObject => {
if (!literalValue || !literalValue[0]) throw new Error('literalValue cannot be null or empty')
return { value: literalValue[0], escape: false }
}
function literal (literalValue: TemplateStringsArray): LiteralObject {
return { value: literalValue[0] || "", escape: false }
}
export literal

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

Comment on lines 21 to 28
it('should return an error when the argument is empty', () => {
expect(() => literal``).toThrowError('literalValue cannot be null or empty')
})

it('should return an error when the argument is null', () => {
const nullValue = null as unknown as TemplateStringsArray
expect(() => literal(nullValue)).toThrowError('literalValue cannot be null or empty')
})
Copy link
Owner

Choose a reason for hiding this comment

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

Then you could change these tests to assert the value is ""

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed the tests. Check if you agree or need any more cases.

@tiago154 tiago154 requested a review from khaosdoctor July 27, 2020 17:11
@khaosdoctor
Copy link
Owner

khaosdoctor commented Jul 27, 2020

@tiago154 congrats on the test runs, they're 100%

image

@khaosdoctor khaosdoctor merged commit e565615 into khaosdoctor:main Jul 27, 2020
@tiago154 tiago154 deleted the feature/literal-tagged-template branch July 27, 2020 18:42
@khaosdoctor khaosdoctor mentioned this pull request Jul 27, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[FEATURE] Add suport for literal template function
2 participants