Skip to content

Commit

Permalink
fix(syntax): correctly tokenize if, show, view-model, repeat.for, bin…
Browse files Browse the repository at this point in the history
…ding, controller, data bindings, resolves #6 (#8)

* fix(syntax): correctly tokenize show attribute

* fix(syntax): correctly tokenize if attribute

* fix(syntax): correctly tokenize view-model attribute

* fix(syntax): correctly tokenize repeat.for attribute

* test(databindings): clean up duplicated tests

* fix(syntax): correctly tokenize binding attribute

* fix(syntax): correctly tokenize controller attribute

* fix(syntax): correctly tokenize data bindings
  • Loading branch information
Erik Lieben authored Oct 13, 2016
1 parent 7a09f40 commit 2f10ee2
Show file tree
Hide file tree
Showing 8 changed files with 904 additions and 84 deletions.
59 changes: 31 additions & 28 deletions syntaxes/html.json
Original file line number Diff line number Diff line change
Expand Up @@ -217,21 +217,21 @@
]
},
"tag-aurelia-attribute-with-databinding-attribute": {
"match": "[^=](([a-zA-Z0-9:-]+)(\\.)(bind|one-way|two-way|one-time))",
"match": "(?<![\"'-])([a-zA-Z0-9:-]+)(?<!controller|bindable|view-model|show|if|naive-if)(\\.)(bind|one-way|two-way|one-time)(?![\"'-;])",
"captures": {
"2": {
"1": {
"name": "entity.other.attribute-name.html"
},
"3": {
"2": {
"name": "punctuation.definition.tag.begin.html"
},
"4": {
"3": {
"name": "databinding.attribute.html.au"
}
}
},
"tag-aurelia-attribute-with-ref-attribute": {
"match": "[^=](([a-zA-Z0-9:-]+)(?<!view)(\\.)(ref))",
"match": "[^=](([a-zA-Z0-9:-]+)(?<!controller|view|view-model)(\\.)(ref))",
"captures": {
"2": {
"name": "entity.other.attribute-name.html"
Expand Down Expand Up @@ -259,32 +259,32 @@
}
},
"tag-aurelia-repeat-for-attribute" : {
"match": "[^=]((repeat)(\\.)(for))",
"match": "(?<=[^\"-])(repeat)(\\.)(for)(?![-])",
"captures": {
"2": {
"1": {
"name": "repeat.attribute.html.au"
},
"3": {
"2": {
"name": "punctuation.definition.tag.begin.html"
},
"4": {
"3": {
"name": "for.attribute.html.au"
}
}
},
"tag-aurelia-view-model-attribute" : {
"match": "[^=]((view-model)(\\.)?((bind|one-time|one-way|two-way)|(ref))?)",
"match": "(?<=[^\"-])(view-model)(?![-])(\\.)?((bind|one-way|two-way|one-time)|(ref))?",
"captures": {
"2": {
"1": {
"name": "view-model.attribute.html.au"
},
"3": {
"2": {
"name": "punctuation.definition.tag.begin.html"
},
"5": {
"4": {
"name": "databinding.attribute.html.au"
},
"6": {
"5": {
"name": "ref.attribute.html.au"
}
}
Expand Down Expand Up @@ -321,23 +321,26 @@
}
},
"tag-aurelia-controller-attribute" : {
"match": "[^=-]((controller)[^!-](\\.)?(ref)?)",
"match": "(?<![\"'-])(controller)(?![\\-])(?=(\\.ref|=))((\\.)?(ref))?",
"captures": {
"2": {
"1": {
"name": "controller.attribute.html.au"
},
"3": {
"2": {
"name": "punctuation.definition.tag.begin.html"
},
},
"4": {
"name": "punctuation.definition.tag.begin.html"
},
"5": {
"name": "ref.attribute.html.au"
}
}
},
"tag-aurelia-bindable-attribute" : {
"match": "[^=-]((bindable)[^!-])",
"match": "(?<![\\-\"])(bindable)(?![\\.\\-\"])",
"captures": {
"2": {
"1": {
"name": "bindable.attribute.html.au"
}
}
Expand All @@ -351,29 +354,29 @@
}
},
"tag-aurelia-if-attribute" : {
"match": "[^=-]((naive-if|if)(?!-)(\\.)?(bind|one-way|two-way|one-time)?)",
"match": "(?<=[^\"-])(if|naive-if)(?![-])(\\.)?(bind|one-way|two-way|one-time)?",
"captures": {
"2": {
"1": {
"name": "if.attribute.html.au"
},
"3": {
"2": {
"name": "punctuation.definition.tag.begin.html"
},
"4": {
"3": {
"name": "databinding.attribute.html.au"
}
}
},
"tag-aurelia-show-attribute" : {
"match": "[^=-]((show)(?!-)(\\.)?(bind|one-way|two-way|one-time)?)",
"match": "(?<=[^\"-])(show)(?![-])(\\.)?(bind|one-way|two-way|one-time)?",
"captures": {
"2": {
"1": {
"name": "show.attribute.html.au"
},
"3": {
"2": {
"name": "punctuation.definition.tag.begin.html"
},
"4": {
"3": {
"name": "databinding.attribute.html.au"
}
}
Expand Down
135 changes: 133 additions & 2 deletions test/syntax.html/bindable.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { assert } from 'chai';
import { getTokenOnCharRange, hasScope, tokenizeLine } from './test.utils';

describe('The Aurelia HTML syntax bindable attribute', function() {
describe(`The Aurelia HTML syntax bindable attribute`, function() {

it('must tokenize bindable attribute with scope "bindable.attribute.html.au"', function() {
it(`must tokenize (bindable)="greeting,name" attribute with scope "bindable.attribute.html.au"`, () => {

// arrange
let scope = 'bindable.attribute.html.au';
Expand All @@ -15,4 +15,135 @@ describe('The Aurelia HTML syntax bindable attribute', function() {
let token = getTokenOnCharRange(lineToken, 10, 18);
assert.isOk(hasScope(token.scopes, scope));
});

it(`must not tokenize (bindable).bind="foo" attribute with scope "bindable.attribute.html.au"`, () => {

// arrange
let scope = 'bindable.attribute.html.au';

// act
let lineToken = tokenizeLine('<div bindable.bind="foo">');

// assert
let token = getTokenOnCharRange(lineToken, 5, 13);
assert.isOk(!hasScope(token.scopes, scope));
});

it(`must not tokenize (bindable).one-way="foo" attribute with scope "bindable.attribute.html.au"`, () => {

// arrange
let scope = 'bindable.attribute.html.au';

// act
let lineToken = tokenizeLine('<div bindable.one-way="foo">');

// assert
let token = getTokenOnCharRange(lineToken, 5, 13);
assert.isOk(!hasScope(token.scopes, scope));
});

it(`must not tokenize (bindable).two-way="foo" attribute with scope "bindable.attribute.html.au"`, () => {

// arrange
let scope = 'bindable.attribute.html.au';

// act
let lineToken = tokenizeLine('<div bindable.two-way="foo">');

// assert
let token = getTokenOnCharRange(lineToken, 5, 13);
assert.isOk(!hasScope(token.scopes, scope));
});

it(`must not tokenize (bindable).one-time="foo" attribute with scope "bindable.attribute.html.au"`, () => {

// arrange
let scope = 'bindable.attribute.html.au';

// act
let lineToken = tokenizeLine('<div bindable.one-time="foo">');

// assert
let token = getTokenOnCharRange(lineToken, 5, 13);
assert.isOk(!hasScope(token.scopes, scope));
});

it(`must not tokenize (bindable).foo="foo" attribute with scope "bindable.attribute.html.au"`, () => {

// arrange
let scope = 'bindable.attribute.html.au';

// act
let lineToken = tokenizeLine('<div bindable.foo="foo">');

// assert
let token = getTokenOnCharRange(lineToken, 5, 13);
assert.isOk(!hasScope(token.scopes, scope));
});

it(`must not tokenize (bindable).ref="foo" attribute with scope "bindable.attribute.html.au"`, () => {

// arrange
let scope = 'bindable.attribute.html.au';

// act
let lineToken = tokenizeLine('<div bindable.ref="foo">');

// assert
let token = getTokenOnCharRange(lineToken, 5, 13);
assert.isOk(!hasScope(token.scopes, scope));
});

it(`must not tokenize (foo-bindable)="foo" attribute with scope "bindable.attribute.html.au"`, () => {

// arrange
let scope = 'bindable.attribute.html.au';

// act
let lineToken = tokenizeLine('<div foo-bindable="foo">');

// assert
let token = getTokenOnCharRange(lineToken, 5, 17);
assert.isOk(!hasScope(token.scopes, scope));
});

it(`must not tokenize (bindable-foo)="foo" attribute with scope "bindable.attribute.html.au"`, () => {

// arrange
let scope = 'bindable.attribute.html.au';

// act
let lineToken = tokenizeLine('<div bindable-foo="foo">');

// assert
let token = getTokenOnCharRange(lineToken, 5, 17);
assert.isOk(!hasScope(token.scopes, scope));
});

it(`must not tokenize a="(bindable)" attribute with scope "bindable.attribute.html.au"`, () => {

// arrange
let scope = 'bindable.attribute.html.au';

// act
let lineToken = tokenizeLine('<div a="bindable">');

// assert
let token = getTokenOnCharRange(lineToken, 8, 16);
assert.isOk(!hasScope(token.scopes, scope));
});

it(`must not tokenize a='(bindable)' attribute with scope "bindable.attribute.html.au"`, () => {

// arrange
let scope = 'bindable.attribute.html.au';

// act
let lineToken = tokenizeLine('<div a=\'bindable\'>');

// assert
let token = getTokenOnCharRange(lineToken, 8, 16);
assert.isOk(!hasScope(token.scopes, scope));
});

});
Loading

0 comments on commit 2f10ee2

Please sign in to comment.