-
Notifications
You must be signed in to change notification settings - Fork 6
1.2 Mask
Mask is
reversed
HTML with little CSS and JavaScript syntax. But not the syntax is the key point of the MaskJS - but the performance: the way how the Parser works, how the Builder creates a Shadow DOM and then inserts into the live DOM - these all make the application start up significant faster then any other approach. Also, worth to mention, the Parser works same on Node.js and a modified Builder creates the Shadow DOM-alike AST, and then renders HTML. And the 2-Phase initialization of a Component allows it to be truly isomorphic.
-
1
Comments -
2
Literals -
3
Nodes-
3.1
Declaration -
3.2
Attributes -
3.3
Expression
-
-
4
ChildNodes -
5
Custom Syntax
// single line comment
/*
Multiline comment
*/
'Foo'
"Foo"
"""
Multiline with any '"' inside
"""
'''
Multiline with any '"' inside
'''
<!-- html -->
<div id='foo' class='bar qux' name='quux' hidden></div>
// mask
div id='foo' class='bar qux' name='quux' hidden;
Pretty similar, right? Any formatting possible in HTML, is also possible in Mask: new lines, spaces, etc.
-
sugar
For theid
andclass
attributes can be used CSS syntax:#id
,.class
div#foo.bar.qux name='quux' hidden;
-
sugar
If a tag begins with#id
or.class
, the the tag name can be omitted. Mask Parser will guess the tagName. Default isdiv
, insideul
the guessed tagName isli
, and so on.#foo.bar.qux name='quux' hidden;
Like in HTML:
-
'
and"
are used for values, - When attributes value contains no whitespace, quotes are not required.
- Attributes value is also not required, like in HTML.
- Attributes value can contain new lines
section
name=foo
style = '
border: 1px solid green;
background: url("foo.png") no-repeat;
';
A node can have an expression enclosed in Parentheses ()
, and the syntax inside depends on the particular node type
log (foo.name);
-
No childnodes. As from examples above, if a tag has no children, it should be closed with
;
(semicolon)
. -
Childnodes. To define children of a tag,
{}
(brackets)
blocks are used, just like in JS, CSS, LESS, etc.<section> <input type='text' placeholder='Lorem ipsum' /> <input type = submit value = 'Do some work' /> </section>
section { input type='text' placeholder='Lorem ipsum'; input type = submit value = 'Do some work' ; }
-
sugar
(Better readability)
You can use>
(like in CSS) if a node has only one child.<div class='dialog-backdrop'> <div class='dialog-panel'> <header> Hello </header> <section> <img src='/baz.png' /> </section> </div> </div>
// blocks .dialog-backdrop { .dialog-panel { header { 'Hello' } section { img src='/baz.png'; } } }
.dialog-backdrop > .dialog-panel { header > 'Hello' section > img src='/baz.png'; }
There are Node Handlers, which implement some custom syntax parsing.
script {
console.log('That is javascript');
}
style {
#foo {
background: red;
}
}
function barQux (txt) {
console.log(txt);
}
button {
event click (event) {
event.currentTarget.style.display = 'none';
}
}
slot logSelf () {
console.log(this);
}
button x-tap='logSelf' >
'Print component to the console'
var myArr = [1, 2, 3, 4];
ul > each(myArr) > 'Number: ~[.]'
🏁