Skip to content

Commit

Permalink
Merge pull request #578 from rollaball/fix-comments-new-line
Browse files Browse the repository at this point in the history
Fix: comment adds a line between previous and later components
  • Loading branch information
mathisonian authored Aug 3, 2019
2 parents 61db95d + 5651da9 commit a3b4cf6
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
3 changes: 3 additions & 0 deletions packages/idyll-compiler/src/lexer.js
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,9 @@ const lex = function(options) {

lexer.addRule(/(\n\s*\/\/[^\n]*|\/\/\s+[^\n]*)/, function(lexeme) {
updatePosition(lexeme);
if (lexeme.startsWith('\n')) {
return ['BREAK'];
}
});

lexer.addRule(/\/(\n?[^`\*\[\/\n\]!\\\d_])*/gm, function(lexeme) {
Expand Down
13 changes: 4 additions & 9 deletions packages/idyll-compiler/test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ describe('compiler', function() {
not a comment: https://stuff.com
`);
expect(results.tokens.join(' ')).to.eql(
'WORDS TOKEN_VALUE_START "Text. " TOKEN_VALUE_END WORDS TOKEN_VALUE_START "/ Not a comment.\n " TOKEN_VALUE_END OPEN_BRACKET COMPONENT_NAME TOKEN_VALUE_START "component" TOKEN_VALUE_END CLOSE_BRACKET WORDS TOKEN_VALUE_START "/" TOKEN_VALUE_END WORDS TOKEN_VALUE_START "/not a comment\n " TOKEN_VALUE_END OPEN_BRACKET FORWARD_SLASH COMPONENT_NAME TOKEN_VALUE_START "component" TOKEN_VALUE_END CLOSE_BRACKET BREAK WORDS TOKEN_VALUE_START "not a comment: https:" TOKEN_VALUE_END WORDS TOKEN_VALUE_START "/" TOKEN_VALUE_END WORDS TOKEN_VALUE_START "/stuff.com" TOKEN_VALUE_END EOF'
'WORDS TOKEN_VALUE_START "Text. " TOKEN_VALUE_END WORDS TOKEN_VALUE_START "/ Not a comment.\n " TOKEN_VALUE_END BREAK OPEN_BRACKET COMPONENT_NAME TOKEN_VALUE_START "component" TOKEN_VALUE_END CLOSE_BRACKET WORDS TOKEN_VALUE_START "/" TOKEN_VALUE_END WORDS TOKEN_VALUE_START "/not a comment\n " TOKEN_VALUE_END OPEN_BRACKET FORWARD_SLASH COMPONENT_NAME TOKEN_VALUE_START "component" TOKEN_VALUE_END CLOSE_BRACKET BREAK WORDS TOKEN_VALUE_START "not a comment: https:" TOKEN_VALUE_END WORDS TOKEN_VALUE_START "/" TOKEN_VALUE_END WORDS TOKEN_VALUE_START "/stuff.com" TOKEN_VALUE_END EOF'
);
});

Expand Down Expand Up @@ -606,20 +606,15 @@ End text
not a comment: https://stuff.com
`;

expect(compile(input, { async: false })).to.eql(
AST.convertV1ToV2([
[
'TextContainer',
[],
[
[
'p',
[],
[
'Text. / Not a comment.\n ',
['component', [], ['//not a comment\n ']]
]
],
['p', [], ['Text. / Not a comment.\n ']],
['component', [], ['//not a comment\n ']],
[
'p',
[],
Expand Down

0 comments on commit a3b4cf6

Please sign in to comment.