Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
GianlucaGuarini committed Nov 9, 2015
2 parents 5c70d12 + 271d604 commit f7b9358
Show file tree
Hide file tree
Showing 16 changed files with 110 additions and 67 deletions.
6 changes: 4 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,17 @@ branches:

install:
- npm i jade
- npm i babel@5.8
- npm i babel-core@5.8
- npm i babel
- npm i babel-core
- npm i babel-preset-es2015
- npm i coffee-script
- npm i livescript
- npm i typescript-simple
- npm i stylus
- npm i nib
- npm i node-sass
- npm i less
- npm i postcss autoprefixer
- npm i

after_success: make send-coverage
Expand Down
24 changes: 18 additions & 6 deletions dist/compiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,16 @@
outputStyle: 'compact'
}, opts)).css + ''
},
scss: function(tag, css, opts) {
var sass = _req('sass')

return sass.renderSync(extend({
data: css,
indentedSyntax: false,
omitSourceMapUrl: true,
outputStyle: 'compact'
}, opts)).css + ''
},
less: function(tag, css, opts) {
var less = _req('less'),
ret
Expand Down Expand Up @@ -117,22 +127,24 @@
typescript: function (js, opts) {
return _req('typescript')(js, opts).replace(/\r\n?/g, '\n')
},
es6: function (js, opts) {
es6: /* istanbul ignore next */ function (js, opts) {
return _req('es6').transform(js, extend({
blacklist: ['useStrict', 'strict', 'react'], sourceMaps: false, comments: false
}, opts)).code
},
babel: /* istanbul ignore next */ function (js, opts) {
return _req('babel').transform(js, extend({
presets: ['es2015'], ast: false, sourceMaps: false, comments: false
}, opts)).code.replace(/"use strict";[\r\n]+/, '')
babel: function (js, opts) {
js = 'function __parser_babel_wrapper__(){' + js + '}'
return _req('babel').transform(js,
extend({
presets: ['es2015']
}, opts)
).code.replace(/["']use strict["'];[\r\n]+/, '').slice(38, -2)
},
coffee: function (js, opts) {
return _req('coffee').compile(js, extend({bare: true}, opts))
}
}

_css.scss = _css.sass
_js.javascript = _js.none
_js.coffeescript = _js.coffee

Expand Down
14 changes: 8 additions & 6 deletions dist/riot.compiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,22 +56,24 @@ var parsers = (function () {
typescript: function (js, opts) {
return _req('typescript')(js, opts).replace(/\r\n?/g, '\n')
},
es6: function (js, opts) {
es6: /* istanbul ignore next */ function (js, opts) {
return _req('es6').transform(js, extend({
blacklist: ['useStrict', 'strict', 'react'], sourceMaps: false, comments: false
}, opts)).code
},
babel: /* istanbul ignore next */ function (js, opts) {
return _req('babel').transform(js, extend({
presets: ['es2015'], ast: false, sourceMaps: false, comments: false
}, opts)).code.replace(/"use strict";[\r\n]+/, '')
babel: function (js, opts) {
js = 'function __parser_babel_wrapper__(){' + js + '}'
return _req('babel').transform(js,
extend({
presets: ['es2015']
}, opts)
).code.replace(/["']use strict["'];[\r\n]+/, '').slice(38, -2)
},
coffee: function (js, opts) {
return _req('coffee').compile(js, extend({bare: true}, opts))
}
}

_css.scss = _css.sass
_js.javascript = _js.none
_js.coffeescript = _js.coffee

Expand Down
24 changes: 18 additions & 6 deletions lib/parsers.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,16 @@ var parsers = (function () {
outputStyle: 'compact'
}, opts)).css + ''
},
scss: function(tag, css, opts) { // there's no standard sass for browsers
var sass = _req('sass')

return sass.renderSync(extend({
data: css,
indentedSyntax: false,
omitSourceMapUrl: true,
outputStyle: 'compact'
}, opts)).css + ''
},
less: function(tag, css, opts) {
var less = _req('less'),
ret
Expand Down Expand Up @@ -129,22 +139,24 @@ var parsers = (function () {
typescript: function (js, opts) {
return _req('typescript')(js, opts).replace(/\r\n?/g, '\n')
},
es6: function (js, opts) {
es6: /* istanbul ignore next */ function (js, opts) {
return _req('es6').transform(js, extend({
blacklist: ['useStrict', 'strict', 'react'], sourceMaps: false, comments: false
}, opts)).code
},
babel: /* istanbul ignore next */ function (js, opts) {
return _req('babel').transform(js, extend({
presets: ['es2015'], ast: false, sourceMaps: false, comments: false
}, opts)).code.replace(/"use strict";[\r\n]+/, '')
babel: function (js, opts) {
js = 'function __parser_babel_wrapper__(){' + js + '}'
return _req('babel').transform(js,
extend({
presets: ['es2015']
}, opts)
).code.replace(/["']use strict["'];[\r\n]+/, '').slice(38, -2)
},
coffee: function (js, opts) {
return _req('coffee').compile(js, extend({bare: true}, opts))
}
}

_css.scss = _css.sass // fix possible issues
_js.javascript = _js.none
_js.coffeescript = _js.coffee // 4 the nostalgics

Expand Down
3 changes: 3 additions & 0 deletions test/specs/parsers/js/postcss.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
riot.tag2('postcss', '<h3>postcss</h3>', 'postcss,[riot-tag="postcss"] { -webkit-transition: all 0.3s; transition: all 0.3s; }', '', function(opts) {
this.foo = function() {}.bind(this)
});
3 changes: 3 additions & 0 deletions test/specs/parsers/js/scss.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
riot.tag2('scss-test', '<h3>scss</h3>', 'h1 { color: red; } h2 { color: orange; }', '', function(opts) {
this.foo = function() {}.bind(this)
});
File renamed without changes.
5 changes: 2 additions & 3 deletions test/specs/parsers/js/test.babel.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
riot.tag2('babel', '<h3>{test}</h3>', '', '', function(opts) {

var type = 'JavaScript';
this.test = 'This is ' + type;
var type = 'JavaScript';
this.test = 'This is ' + type;
}, '{ }');
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
riot.tag2('babelcore', '<h3>{test}</h3>', '', '', function(opts) {

var type = 'JavaScript';
this.test = 'This is ' + type;
var foo
}, '{ }');
5 changes: 0 additions & 5 deletions test/specs/parsers/js/test.es6.js

This file was deleted.

11 changes: 11 additions & 0 deletions test/specs/parsers/postcss.tag
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<postcss>
<h3>postcss</h3>
<style scoped type='postcss'>
:scope {
transition: all 0.3s;
}
</style>
<script>
foo () {}
</script>
</postcss>
14 changes: 14 additions & 0 deletions test/specs/parsers/scss.tag
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<scss-test>
<h3>scss</h3>
<style type='scss'>
h1 {
color: red
}
h2 {
color: orange
}
</style>
<script>
foo () {}
</script>
</scss-test>
55 changes: 28 additions & 27 deletions test/specs/parsers/suite.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,8 @@ describe('HTML parsers', function () {

describe('JavaScript parsers', function () {

function _babel(js) {
return compiler.parsers._req('babelcore').transform(js, {
blacklist: ['useStrict', 'strict', 'react'], sourceMaps: false, comments: false
}).code
function _custom(js) {
return 'var foo'
}

this.timeout(25000) // first call to babel-core is slooooow!
Expand Down Expand Up @@ -146,26 +144,26 @@ describe('JavaScript parsers', function () {
}
})

// testParser.es6.tag
it('es6 (for babel 5.8.x)', function () {
// testParser.babel.tag
it('babel', function () {
if (have('es6')) {
testParser('test', { type: 'es6' })
testParser('test', { type: 'babel' })
}
})

// testParser-attr.es6.tag
// testParser-attr.babel.tag
it('babel with shorthands (fix #1090)', function () {
if (have('es6')) {
testParser('test-attr', { type: 'es6', expr: true })
testParser('test-attr', { type: 'babel', expr: true })
}
})

// test.babel-core.tag
it('css.babel-core as custom parser (babel-core 5.8)', function () {
if (have('babelcore', 'babel-core')) {
compiler.parsers.js.babelcore = _babel
testParser('test', { type: 'babelcore' })
}
// test.random.tag
it('custom js parser', function () {

compiler.parsers.js.custom = _custom
testParser('test', { type: 'custom' })

})

})
Expand All @@ -175,12 +173,9 @@ describe('Style parsers', function () {

this.timeout(12000)

function _sass(tag, css) {
return '' + compiler.parsers._req('sass').renderSync({
data: css,
indentedSyntax: true,
omitSourceMapUrl: true,
outputStyle: 'compact' }).css
// custom parser
compiler.parsers.css.postcss = function(tag, css, opts) {
return require('postcss')([require('autoprefixer')]).process(css).css
}

// style.tag
Expand All @@ -207,15 +202,21 @@ describe('Style parsers', function () {
}
})

// sass.tag
it('sass, indented 2, margin 0 (custom parser)', function () {
if (have('sass', 'node-sass')) {
compiler.parsers.css.sass = _sass
testParser('sass', {})
// scss.tag
it('scss, indented 2, margin 0', function () {
if (have('scss', 'node-sass')) {
testParser('scss', {})
}
})

// sass.tag
// scss.tag
it('custom parser using postcss + autoprefixer', function () {
if (have('postcss', 'postcss')) {
testParser('postcss', {})
}
})

// less.tag
it('less', function () {
if (have('less')) {
testParser('less', {})
Expand Down
File renamed without changes.
File renamed without changes.
9 changes: 0 additions & 9 deletions test/specs/parsers/test.es6.tag

This file was deleted.

0 comments on commit f7b9358

Please sign in to comment.