-
-
Notifications
You must be signed in to change notification settings - Fork 21
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
Feature Tagged Template 'literal' #47
Conversation
There was a problem hiding this 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
src/helpers/literal.ts
Outdated
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 } | ||
} |
There was a problem hiding this comment.
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?
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 |
There was a problem hiding this comment.
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:
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
tests/helpers/literal.test.ts
Outdated
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') | ||
}) |
There was a problem hiding this comment.
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 ""
There was a problem hiding this comment.
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 congrats on the test runs, they're 100% |
Description of the Change
Issue -> #40
With this modification, a function named 'literal' was added, which is nothing more than an abbreviation for the
Where we can use it as follows.
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