-
-
Notifications
You must be signed in to change notification settings - Fork 273
feat: inline comment tag #514
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
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
cadb0f1
style: remove unnecessary intermediate constant
jg-rp 0ae7d86
feat: add inline comment tag
jg-rp bc300d0
Merge branch 'harttle:master' into inlinecomment
jg-rp 200fb36
refactor: use readIdentifier when reading tag names
jg-rp 134a66a
docs: add inline comment tag
jg-rp File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| import { TagToken } from '../../tokens/tag-token' | ||
| import { TopLevelToken } from '../../tokens/toplevel-token' | ||
| import { TagImplOptions } from '../../template/tag/tag-impl-options' | ||
|
|
||
| export default { | ||
| parse: function (tagToken: TagToken, remainTokens: TopLevelToken[]) { | ||
| if (tagToken.args.search(/\n\s*[^#\s]/g) !== -1) { | ||
| throw new Error('every line of an inline comment must start with a \'#\' character') | ||
| } | ||
| } | ||
| } as TagImplOptions |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,95 @@ | ||
| import { Liquid } from '../../../../src/liquid' | ||
| import { expect, use } from 'chai' | ||
| import * as chaiAsPromised from 'chai-as-promised' | ||
|
|
||
| use(chaiAsPromised) | ||
|
|
||
| describe('tags/inline-comment', function () { | ||
| const liquid = new Liquid() | ||
| it('should ignore plain string', async function () { | ||
| const src = 'My name is {% # super %} Shopify.' | ||
| const html = await liquid.parseAndRender(src) | ||
| return expect(html).to.equal('My name is Shopify.') | ||
| }) | ||
| it('should ignore output tokens', async function () { | ||
| const src = '{% #\n{{ foo}} \n %}' | ||
| const html = await liquid.parseAndRender(src) | ||
| return expect(html).to.equal('') | ||
| }) | ||
| it('should support whitespace control', async function () { | ||
| const src = '{%- # some comment \n -%}\nfoo' | ||
| const html = await liquid.parseAndRender(src) | ||
| return expect(html).to.equal('foo') | ||
| }) | ||
| it('should handle hash without trailing whitespace', async function () { | ||
| const src = '{% #some comment %}' | ||
| const html = await liquid.parseAndRender(src) | ||
| return expect(html).to.equal('') | ||
| }) | ||
| it('should handle hash without leading whitespace', async function () { | ||
| const src = '{%#some comment %}' | ||
| const html = await liquid.parseAndRender(src) | ||
| return expect(html).to.equal('') | ||
| }) | ||
| it('should handle empty comment', async function () { | ||
| const src = '{%#%}' | ||
| const html = await liquid.parseAndRender(src) | ||
| return expect(html).to.equal('') | ||
| }) | ||
| it('should support multiple lines', async function () { | ||
| const src = [ | ||
| '{%-', | ||
| ' # spread inline comments', | ||
| ' # over multiple lines', | ||
| '-%}' | ||
| ].join('\n') | ||
| const html = await liquid.parseAndRender(src) | ||
| return expect(html).to.equal('') | ||
| }) | ||
| it('should enforce leading hashes', async function () { | ||
| const src = [ | ||
| '{%-', | ||
| ' # spread inline comments', | ||
| ' over multiple lines', | ||
| '-%}' | ||
| ].join('\n') | ||
| return expect(liquid.parseAndRender(src)) | ||
| .to.be.rejectedWith(/every line of an inline comment must start with a '#' character/) | ||
| }) | ||
| describe('sync support', function () { | ||
| it('should ignore plain string', function () { | ||
| const src = 'My name is {% # super %} Shopify.' | ||
| const html = liquid.parseAndRenderSync(src) | ||
| return expect(html).to.equal('My name is Shopify.') | ||
| }) | ||
| }) | ||
| describe('liquid tag', function () { | ||
| it('should treat lines starting with a hash as a comment', async function () { | ||
| const src = [ | ||
| '{% liquid ', | ||
| ' # first comment line', | ||
| ' # second comment line', | ||
| '', | ||
| ' # another comment line', | ||
| ' echo \'Hello \'', | ||
| '', | ||
| ' # more comments', | ||
| ' echo \'goodbye\'', | ||
| '-%}' | ||
| ].join('\n') | ||
| const html = await liquid.parseAndRender(src) | ||
| return expect(html).to.equal('Hello goodbye') | ||
| }) | ||
| it('should handle lots of hashes', async function () { | ||
| const src = [ | ||
| '{% liquid', | ||
| ' ##########################', | ||
| ' # spread inline comments #', | ||
| ' ##########################', | ||
| '-%}' | ||
| ].join('\n') | ||
| const html = await liquid.parseAndRender(src) | ||
| return expect(html).to.equal('') | ||
| }) | ||
| }) | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.