Skip to content
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

Fix issue #31 #32

Merged
merged 3 commits into from
Sep 26, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/emmetHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -490,8 +490,8 @@ export function isAbbreviationValid(syntax: string, abbreviation: string): boole
return parseInt(multipleMatch[1], 10) <= 100
}
// Its common for users to type (sometextinsidebrackets), this should not be treated as an abbreviation
// Grouping in abbreviation is valid only if preceeded/succeeded with one of the symbols for nesting, sibling, repeater or climb up
if (!/\(.*\)[>\+\*\^]/.test(abbreviation) && !/[>\+\*\^]\(.*\)/.test(abbreviation) && /\(/.test(abbreviation) && /\)/.test(abbreviation)) {
// Grouping in abbreviation is valid only if it's inside a text node or preceeded/succeeded with one of the symbols for nesting, sibling, repeater or climb up
if ((/\(/.test(abbreviation) || /\)/.test(abbreviation)) && !/\{[^\}\{]*[\(\)]+[^\}\{]*\}(?:[>\+\*\^]|$)/.test(abbreviation) && !/\(.*\)[>\+\*\^]/.test(abbreviation) && !/[>\+\*\^]\(.*\)/.test(abbreviation)) {
Copy link
Contributor Author

@devanshj devanshj Jul 22, 2019

Choose a reason for hiding this comment

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

If it's not obvious then the (?:[>\+\*\^]|$) part is to invalidate abbreviations like div{ a }( b ){ c }.

return false;
}

Expand Down
31 changes: 27 additions & 4 deletions src/test/emmetHelper.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,30 @@ const expectedBemCommentFilterOutputDocs = expectedBemCommentFilterOutput.replac

describe('Validate Abbreviations', () => {
it('should return true for valid abbreviations', () => {
const htmlAbbreviations = ['ul>li', 'ul', 'h1', 'ul>li*3', '(ul>li)+div', '.hello', '!', '#hello', '.item[id=ok]', '.', '.foo'];
const htmlAbbreviations = [
'ul>li',
'ul',
'h1',
'ul>li*3',
'(ul>li)+div',
'.hello',
'!',
'#hello',
'.item[id=ok]',
'.',
'.foo',
'div{ foo (bar) baz }',
'div{ foo ((( abc }',
'div{()}',
'div{ a (b) c}',
'div{ a (b) c}+div{ a (( }'
];
const cssAbbreviations = ['#123', '#abc'];
htmlAbbreviations.forEach(abbr => {
assert(isAbbreviationValid('html', abbr));
assert(isAbbreviationValid('html', abbr), `${abbr} should be treated as valid abbreviation`);
});
htmlAbbreviations.forEach(abbr => {
assert(isAbbreviationValid('haml', abbr));
assert(isAbbreviationValid('haml', abbr), `${abbr} should be treated as valid abbreviation`);
});
cssAbbreviations.forEach(abbr => {
assert(isAbbreviationValid('css', abbr), `${abbr} should be treated as valid abbreviation`);
Expand All @@ -61,6 +78,12 @@ describe('Validate Abbreviations', () => {
'if(!ok)',
'while(!ok)',
'(!ok)',
'div{ foo }(bar){ baz }',
'div{ foo ((}( abc }',
'div{ a}(b) c}',
'div{ a (b){c}',
'div{ a}(b){c}',
'div{ a (( dsf} d (( sf )) }'
];
const cssAbbreviations = ['123', '#xyz'];
htmlAbbreviations.forEach(abbr => {
Expand Down Expand Up @@ -1126,4 +1149,4 @@ describe('Test completions', () => {
assert.equal(completionList.items[0].label, 'abbr');
});
});
})
})