Skip to content

Commit

Permalink
Merge pull request #9 from riot/dev
Browse files Browse the repository at this point in the history
v2.3.0-beta.6
  • Loading branch information
aMarCruz committed Oct 29, 2015
2 parents a50a717 + e3aa58b commit 760e585
Show file tree
Hide file tree
Showing 20 changed files with 74 additions and 61 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ branches:
install:
- npm i jade
- npm i babel-core
- npm i babel-preset-es2015
- npm i coffee-script
- npm i livescript
- npm i typescript-simple
Expand Down
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@

`$ bower install riot-compiler --save`

### For babel users

From v2.3.0-beta.6, `compiler.parsers.css.es6` supports `babel-core` only, and its new API, you need also `npm install babel-preset-es2015` for this works. Temporal support for babel version 5.8.x is through the `compiler.parsers.css.babel` (`<script type="babel">`). It is recommended that you update your installation of babel as soon as possible.


[travis-image]:https://img.shields.io/travis/riot/compiler.svg?style=flat-square
[travis-url]:https://travis-ci.org/riot/compiler
[license-image]:http://img.shields.io/badge/license-MIT-000000.svg?style=flat-square
Expand Down
14 changes: 8 additions & 6 deletions dist/compiler.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* riot-compiler 2.3.0-beta.5, @license MIT, (c) 2015 Muut Inc. + contributors */
/* riot-compiler 2.3.0-beta.6, @license MIT, (c) 2015 Muut Inc. + contributors */
;(function (root, factory) {

/* istanbul ignore else */
Expand Down Expand Up @@ -35,9 +35,8 @@

switch (name) {
case 'es6':
// istanbul ignore next: we have babel-core in test
case 'babel':
return fn('babel-core') || fn('babel')
req = 'babel-core'
break
case 'none':
case 'javascript':
return _js.none
Expand Down Expand Up @@ -87,6 +86,11 @@
},
es6: function (js) {
return _req('es6').transform(js, {
presets: ['es2015'], ast: false, sourceMaps: false, comments: false
}).code
},
babel: /* istanbul ignore next */ function (js) {
return _req('babel').transform(js, {
blacklist: ['useStrict', 'react'], sourceMaps: false, comments: false
}).code
},
Expand All @@ -95,7 +99,6 @@
}
}

_js.babel = _js.es6
_js.javascript = _js.none
_js.coffeescript = _js.coffee

Expand Down Expand Up @@ -349,7 +352,6 @@
else if (parsers.css[type]) {
style = parsers.css[type](tag, style)
}
// istanbul ignore else: fallback to nothing
else if (type !== 'css') {
throw new Error('CSS parser not found: "' + type + '"')
}
Expand Down
9 changes: 6 additions & 3 deletions dist/riot.compiler.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

/**
* Compiler for riot custom tags
* @version 2.3.0-beta.5
* @version 2.3.0-beta.6
*/

/**
Expand Down Expand Up @@ -58,6 +58,11 @@ var parsers = (function () {
},
es6: function (js) {
return _req('es6').transform(js, {
presets: ['es2015'], ast: false, sourceMaps: false, comments: false
}).code
},
babel: /* istanbul ignore next */ function (js) {
return _req('babel').transform(js, {
blacklist: ['useStrict', 'react'], sourceMaps: false, comments: false
}).code
},
Expand All @@ -66,7 +71,6 @@ var parsers = (function () {
}
}

_js.babel = _js.es6
_js.javascript = _js.none
_js.coffeescript = _js.coffee

Expand Down Expand Up @@ -321,7 +325,6 @@ var compile = (function () {
else if (parsers.css[type]) {
style = parsers.css[type](tag, style)
}
// istanbul ignore else: fallback to nothing
else if (type !== 'css') {
throw new Error('CSS parser not found: "' + type + '"')
}
Expand Down
1 change: 0 additions & 1 deletion lib/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,6 @@ var compile = (function () {
else if (parsers.css[type]) {
style = parsers.css[type](tag, style)
}
// istanbul ignore else: fallback to nothing
else if (type !== 'css') {
throw new Error('CSS parser not found: "' + type + '"')
}
Expand Down
4 changes: 2 additions & 2 deletions lib/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//#if NODE
//#undef RIOT
/* riot-compiler 2.3.0-beta.5, @license MIT, (c) 2015 Muut Inc. + contributors */
/* riot-compiler 2.3.0-beta.6, @license MIT, (c) 2015 Muut Inc. + contributors */
;(function (root, factory) {

/* istanbul ignore else */
Expand All @@ -22,7 +22,7 @@

/**
* Compiler for riot custom tags
* @version 2.3.0-beta.5
* @version 2.3.0-beta.6
*/
//#endif

Expand Down
11 changes: 7 additions & 4 deletions lib/parsers.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,8 @@ var parsers = (function () {

switch (name) {
case 'es6':
// istanbul ignore next: we have babel-core in test
case 'babel':
return fn('babel-core') || fn('babel')
req = 'babel-core'
break
case 'none':
case 'javascript':
return _js.none
Expand Down Expand Up @@ -97,6 +96,11 @@ var parsers = (function () {
},
es6: function (js) {
return _req('es6').transform(js, {
presets: ['es2015'], ast: false, sourceMaps: false, comments: false
}).code
},
babel: /* istanbul ignore next */ function (js) {
return _req('babel').transform(js, {
blacklist: ['useStrict', 'react'], sourceMaps: false, comments: false
}).code
},
Expand All @@ -105,7 +109,6 @@ var parsers = (function () {
}
}

_js.babel = _js.es6
_js.javascript = _js.none
_js.coffeescript = _js.coffee // 4 the nostalgics

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "riot-compiler",
"version": "2.3.0-beta.5",
"version": "2.3.0-beta.6",
"description": "Compiler for riot .tag files",
"main": "dist/compiler.js",
"directories": {
Expand Down
6 changes: 0 additions & 6 deletions test/specs/expect/html-block1.js

This file was deleted.

5 changes: 0 additions & 5 deletions test/specs/expect/html-block2.js

This file was deleted.

12 changes: 12 additions & 0 deletions test/specs/expect/html-blocks.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
//src: html-blocks.tag
// <y && y> can be confused with a closing html tag

riot.tag2('html-block1', '', '', '', function(opts) {
var n = x <y && y>
z
});

riot.tag2('html-block2', '<input>', '', '', function(opts) {
var n = x<1 ,5 >
z
});
4 changes: 0 additions & 4 deletions test/specs/fixtures/html-block1.tag

This file was deleted.

5 changes: 0 additions & 5 deletions test/specs/fixtures/html-block2.tag

This file was deleted.

12 changes: 12 additions & 0 deletions test/specs/fixtures/html-blocks.tag
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// <y && y> can be confused with a closing html tag

<html-block1>
var n = x <y && y>
z
</html-block1>

<html-block2>
<input>
var n = x<1 ,5 >
z
</html-block2>
2 changes: 1 addition & 1 deletion test/specs/parsers/js/test-attr.es6.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
riot.tag2('es6', '<div class="{className: true}">Hello</div>', '', '', function(opts) {
riot.tag2('es6', '<div class="{className: true}" str="{className: true}" foo="{&quot;foo&quot; + bar}">Hello</div>', '', '', function(opts) {
}, '{ }');
10 changes: 5 additions & 5 deletions test/specs/parsers/suite.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ function testParser(name, opts) {

describe('HTML parsers', function () {

this.timeout(10000)
this.timeout(12000)

function testStr(str, resStr, opts) {
expect(compiler.html(str, opts || {})).to.be(resStr)
Expand Down Expand Up @@ -92,7 +92,7 @@ describe('HTML parsers', function () {

describe('JavaScript parsers', function () {

this.timeout(10000)
this.timeout(20000) // first call to babel-core is slooooow!

// complex.tag
it('complex tag structure', function () {
Expand Down Expand Up @@ -141,15 +141,15 @@ describe('JavaScript parsers', function () {
})

// testParser.es6.tag
it('es6 (babel-core or babel)', function () {
it('es6 (babel-core 6.0.2+)', function () {
if (have('es6')) {
testParser('test', { type: 'es6' })
}
})

// testParser-attr.es6.tag
it('es6 with shorthands (fix #1090)', function () {
if (have('babel')) {
if (have('es6')) {
testParser('test-attr', { type: 'es6', expr: true })
}
})
Expand All @@ -159,7 +159,7 @@ describe('JavaScript parsers', function () {

describe('Style parsers', function () {

this.timeout(10000)
this.timeout(12000)

function _sass(tag, css) {
return '' + compiler.parsers._req('sass').renderSync({
Expand Down
2 changes: 1 addition & 1 deletion test/specs/parsers/test-attr.es6.tag
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@

<es6> <!-- fix to riot #1090 -->
<div class={^ className: true }>Hello</div>
<div class={^ className: true } str={ className: true } foo={ `foo${ bar }` }>Hello</div>
</es6>
6 changes: 3 additions & 3 deletions test/specs/riotjs.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
var fs = require('fs'),
path = require('path')

describe('riotjs', function () {
var
path = require('path'),
fs = require('fs')

function render(str) {
return compiler.js(str, {})
Expand Down
6 changes: 3 additions & 3 deletions test/specs/scoped-css.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ describe('Scoped CSS', function() {
expect(render('i[class=twitter] { background: #55ACEE }'))
.to.equal('my-tag i[class=twitter],[riot-tag="my-tag"] i[class=twitter] { background: #55ACEE }')
})
it('add my-tag to the selector with a backslash', function() {
it('add my-tag to the selector with a pseudo-class', function() {
expect(render('a:after { content: "*" }'))
.to.equal('my-tag a:after,[riot-tag="my-tag"] a:after { content: "*" }')
})
Expand All @@ -40,7 +40,7 @@ describe('Scoped CSS', function() {
expect(render(':scope > ul { padding: 0 }'))
.to.equal('my-tag > ul,[riot-tag="my-tag"] > ul { padding: 0 }')
})
it('add my-tag to the root selector with attr', function() {
it('add my-tag to the root selector with attribute', function() {
expect(render(':scope[disabled] { color: gray }'))
.to.equal('my-tag[disabled],[riot-tag="my-tag"][disabled] { color: gray }')
})
Expand All @@ -60,7 +60,7 @@ describe('Scoped CSS', function() {
expect(render('@keyframes fade { from { opacity: 1; } to { opacity: 0; } }'))
.to.equal('@keyframes fade { from { opacity: 1; } to { opacity: 0; } }')
})
it('not add my-tag to parsentage values in @keyframes', function() {
it('not add my-tag to parcentage values in @keyframes', function() {
expect(render('@keyframes fade { 10% { opacity: 1; } 85% { opacity: 0; } }'))
.to.equal('@keyframes fade { 10% { opacity: 1; } 85% { opacity: 0; } }')
})
Expand Down
18 changes: 7 additions & 11 deletions test/specs/tag.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
describe('Compile tags', function() {
var
path = require('path'),
fs = require('fs')
var fs = require('fs'),
path = require('path')

//var basedir = path.join(__dirname, 'fixtures')
describe('Compile tags', function() {

// adding some custom riot parsers
// css
Expand All @@ -16,16 +14,15 @@ describe('Compile tags', function() {
}

function render(str, name) {
return compiler.compile(str, /*{ basedir: basedir }*/{}, name)
return compiler.compile(str, {}, name)
}

function cat(dir, filename) {
return fs.readFileSync(path.join(__dirname, dir, filename)).toString()
}

function testFile(name) {
var
src = cat('fixtures', name + '.tag'),
var src = cat('fixtures', name + '.tag'),
js = render(src, name + '.tag')

expect(js).to.equal(cat('expect', name + '.js'))
Expand Down Expand Up @@ -55,13 +52,12 @@ describe('Compile tags', function() {
testFile('box')
})

it('More freedom in the format (v2.3)', function() {
it('Flexible method style (v2.3)', function() {
testFile('free-style')
})

it('Detect some fake closing html tags', function () {
testFile('html-block1')
testFile('html-block2')
testFile('html-blocks')
})

it('The treeview question', function () {
Expand Down

0 comments on commit 760e585

Please sign in to comment.