Socket
Socket
Sign inDemoInstall

riot-compiler

Package Overview
Dependencies
Maintainers
4
Versions
50
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

riot-compiler - npm Package Compare versions

Comparing version 2.3.23 to 2.4.1

lib/parsers/pug.js

6

CHANGELOG.md
# Compiler Changes
### v2.4.1
- Add the `pug` parser (it will replace completely `jade` in the next major release)
- Add the possibility to pass custom parsers options directly via the `compiler.compile` method through the `parserOptions: {js: {}, template: {}, style: {}}` key [more info](https://github.com/riot/compiler/issues/64)
- Fix un-escape parser options in html [more info](https://github.com/riot/compiler/issues/63)
### v2.3.23

@@ -4,0 +10,0 @@ - The parsers are moved to its own directory in the node version. The load is on first use.

82

dist/es6.compiler.js
/**
* Compiler for riot custom tags
* @version v2.3.23
* @version v2.4.1
*/

@@ -33,11 +33,21 @@

function renderPug (compilerName, html, opts, url) {
opts = extend({
pretty: true,
filename: url,
doctype: 'html'
}, opts)
return _req(compilerName).render(html, opts)
}
var _p = {
html: {
jade: function (html, opts, url) {
opts = extend({
pretty: true,
filename: url,
doctype: 'html'
}, opts)
return _req('jade').render(html, opts)
/* eslint-disable */
console.log('DEPRECATION WARNING: jade was renamed "pug" - the jade parser will be removed in riot@3.0.0!')
/* eslint-enable */
return renderPug('jade', html, opts, url)
},
pug: function (html, opts, url) {
return renderPug('pug', html, opts, url)
}

@@ -94,2 +104,6 @@ },

_p.utils = {
extend: extend
}
return _p

@@ -103,2 +117,7 @@

/* eslint-disable */
var extend = parsers.utils.extend
/* eslint-enable */
var S_LINESTR = /"[^"\n\\]*(?:\\[\S\s][^"\n\\]*)*"|'[^'\n\\]*(?:\\[\S\s][^'\n\\]*)*'/.source

@@ -504,4 +523,13 @@

function unescapeHTML (str) {
return str
.replace(/&/g, '&')
.replace(/&lt;/g, '<')
.replace(/&gt;/g, '>')
.replace(/&quot;/g, '"')
.replace(/&#039;/g, '\'')
}
function getParserOptions (attribs) {
var opts = getAttrib(attribs, 'options')
var opts = unescapeHTML(getAttrib(attribs, 'options'))

@@ -514,14 +542,24 @@ return opts ? JSON.parse(opts) : null

type = getType(attribs),
src = getAttrib(attribs, 'src')
src = getAttrib(attribs, 'src'),
jsParserOptions = extend({}, opts.parserOptions.js)
if (src) return false
return _compileJS(code, opts, type, getParserOptions(attribs), base)
return _compileJS(
code,
opts,
type,
extend(jsParserOptions, getParserOptions(attribs)),
base
)
}
function cssCode (code, opts, attribs, url, tag) {
var extraOpts = {
parserOpts: getParserOptions(attribs),
scoped: attribs && /\sscoped(\s|=|$)/i.test(attribs),
url: url
}
var
parserStyleOptions = extend({}, opts.parserOptions.style),
extraOpts = {
parserOpts: extend(parserStyleOptions, getParserOptions(attribs)),
scoped: attribs && /\sscoped(\s|=|$)/i.test(attribs),
url: url
}

@@ -552,6 +590,14 @@ return _compileCSS(code, tag, getType(attribs) || opts.style, extraOpts)

parts = [],
included
included,
defaultParserptions = {
template: {},
js: {},
style: {}
}
if (!opts) opts = {}
opts.parserOptions = extend(defaultParserptions, opts.parserOptions || {})
included = opts.exclude

@@ -565,3 +611,3 @@ ? function (s) { return opts.exclude.indexOf(s) < 0 } : function () { return 1 }

if (opts.template) {
src = compileTemplate(src, url, opts.template, opts.templateOptions)
src = compileTemplate(src, url, opts.template, opts.parserOptions.template)
}

@@ -647,3 +693,3 @@

var version = 'v2.3.23'
var version = 'v2.4.1'

@@ -650,0 +696,0 @@ export default {

@@ -27,11 +27,21 @@

function renderPug (compilerName, html, opts, url) {
opts = extend({
pretty: true,
filename: url,
doctype: 'html'
}, opts)
return _req(compilerName).render(html, opts)
}
var _p = {
html: {
jade: function (html, opts, url) {
opts = extend({
pretty: true,
filename: url,
doctype: 'html'
}, opts)
return _req('jade').render(html, opts)
/* eslint-disable */
console.log('DEPRECATION WARNING: jade was renamed "pug" - the jade parser will be removed in riot@3.0.0!')
/* eslint-enable */
return renderPug('jade', html, opts, url)
},
pug: function (html, opts, url) {
return renderPug('pug', html, opts, url)
}

@@ -88,2 +98,6 @@ },

_p.utils = {
extend: extend
}
return _p

@@ -97,6 +111,11 @@

* Compiler for riot custom tags
* @version v2.3.23
* @version v2.4.1
*/
var compile = (function () {
/* eslint-disable */
var extend = parsers.utils.extend
/* eslint-enable */
var S_LINESTR = /"[^"\n\\]*(?:\\[\S\s][^"\n\\]*)*"|'[^'\n\\]*(?:\\[\S\s][^'\n\\]*)*'/.source

@@ -502,4 +521,13 @@

function unescapeHTML (str) {
return str
.replace(/&amp;/g, '&')
.replace(/&lt;/g, '<')
.replace(/&gt;/g, '>')
.replace(/&quot;/g, '"')
.replace(/&#039;/g, '\'')
}
function getParserOptions (attribs) {
var opts = getAttrib(attribs, 'options')
var opts = unescapeHTML(getAttrib(attribs, 'options'))

@@ -512,14 +540,24 @@ return opts ? JSON.parse(opts) : null

type = getType(attribs),
src = getAttrib(attribs, 'src')
src = getAttrib(attribs, 'src'),
jsParserOptions = extend({}, opts.parserOptions.js)
if (src) return false
return _compileJS(code, opts, type, getParserOptions(attribs), base)
return _compileJS(
code,
opts,
type,
extend(jsParserOptions, getParserOptions(attribs)),
base
)
}
function cssCode (code, opts, attribs, url, tag) {
var extraOpts = {
parserOpts: getParserOptions(attribs),
scoped: attribs && /\sscoped(\s|=|$)/i.test(attribs),
url: url
}
var
parserStyleOptions = extend({}, opts.parserOptions.style),
extraOpts = {
parserOpts: extend(parserStyleOptions, getParserOptions(attribs)),
scoped: attribs && /\sscoped(\s|=|$)/i.test(attribs),
url: url
}

@@ -550,6 +588,14 @@ return _compileCSS(code, tag, getType(attribs) || opts.style, extraOpts)

parts = [],
included
included,
defaultParserptions = {
template: {},
js: {},
style: {}
}
if (!opts) opts = {}
opts.parserOptions = extend(defaultParserptions, opts.parserOptions || {})
included = opts.exclude

@@ -563,3 +609,3 @@ ? function (s) { return opts.exclude.indexOf(s) < 0 } : function () { return 1 }

if (opts.template) {
src = compileTemplate(src, url, opts.template, opts.templateOptions)
src = compileTemplate(src, url, opts.template, opts.parserOptions.template)
}

@@ -650,3 +696,3 @@

js: compileJS,
version: 'v2.3.23'
version: 'v2.4.1'
}

@@ -653,0 +699,0 @@ return compile

/**
* The riot-compiler v2.3.23
* The riot-compiler v2.4.1
*
* @module compiler
* @version v2.3.23
* @version v2.4.1
* @license MIT
* @copyright 2015 Muut Inc. + contributors
* @copyright Muut Inc. + contributors
*/
'use strict'
var brackets = require('./brackets')

@@ -15,2 +14,6 @@ var parsers = require('./parsers')

/* eslint-disable */
var extend = require('./parsers/_utils').mixobj
/* eslint-enable */
/**

@@ -738,2 +741,16 @@ * Source for creating regexes matching valid quoted, single-line JavaScript strings.

/**
* Unescape any html string
* @param {string} str escaped html string
* @returns {string} unescaped html string
*/
function unescapeHTML (str) {
return str
.replace(/&amp;/g, '&')
.replace(/&lt;/g, '<')
.replace(/&gt;/g, '>')
.replace(/&quot;/g, '"')
.replace(/&#039;/g, '\'')
}
/**
* Gets the parser options from the "options" attribute.

@@ -745,3 +762,3 @@ *

function getParserOptions (attribs) {
var opts = getAttrib(attribs, 'options')
var opts = unescapeHTML(getAttrib(attribs, 'options'))

@@ -765,3 +782,4 @@ return opts ? JSON.parse(opts) : null

type = getType(attribs),
src = getAttrib(attribs, 'src')
src = getAttrib(attribs, 'src'),
jsParserOptions = extend({}, opts.parserOptions.js)

@@ -776,3 +794,10 @@ if (src) {

}
return _compileJS(code, opts, type, getParserOptions(attribs), base)
return _compileJS(
code,
opts,
type,
extend(jsParserOptions, getParserOptions(attribs)),
base
)
}

@@ -791,7 +816,9 @@

function cssCode (code, opts, attribs, url, tag) {
var extraOpts = {
parserOpts: getParserOptions(attribs),
scoped: attribs && /\sscoped(\s|=|$)/i.test(attribs),
url: url
}
var
parserStyleOptions = extend({}, opts.parserOptions.style),
extraOpts = {
parserOpts: extend(parserStyleOptions, getParserOptions(attribs)),
scoped: attribs && /\sscoped(\s|=|$)/i.test(attribs),
url: url
}

@@ -875,6 +902,14 @@ return _compileCSS(code, tag, getType(attribs) || opts.style, extraOpts)

parts = [],
included
included,
defaultParserptions = {
template: {},
js: {},
style: {}
}
if (!opts) opts = {}
opts.parserOptions = extend(defaultParserptions, opts.parserOptions || {})
included = opts.exclude

@@ -888,3 +923,3 @@ ? function (s) { return opts.exclude.indexOf(s) < 0 } : function () { return 1 }

if (opts.template) {
src = compileTemplate(src, url, opts.template, opts.templateOptions)
src = compileTemplate(src, url, opts.template, opts.parserOptions.template)
}

@@ -982,3 +1017,3 @@

parsers: parsers,
version: 'v2.3.23'
version: 'v2.4.1'
}

@@ -46,3 +46,3 @@ /**

var names = {
html: ['jade'],
html: ['jade', 'pug'],
css: ['sass', 'scss', 'less', 'stylus'],

@@ -49,0 +49,0 @@ js: ['es6', 'babel', 'coffee', 'livescript', 'typescript']

@@ -18,2 +18,6 @@ /*

/* eslint-disable */
console.log('DEPRECATION WARNING: jade was renamed "pug" - the jade parser will be removed in riot@3.0.0!')
/* eslint-enable */
module.exports = function _jade (html, opts, url) {

@@ -20,0 +24,0 @@

{
"name": "riot-compiler",
"version": "2.3.23",
"version": "2.4.1",
"description": "Compiler for riot .tag files",

@@ -33,6 +33,6 @@ "main": "lib/compiler.js",

"devDependencies": {
"coveralls": "^2.11.8",
"eslint": "^2.2.0",
"coveralls": "^2.11.9",
"eslint": "^2.9.0",
"expect.js": "^0.3.1",
"istanbul": "^0.4.2",
"istanbul": "^0.4.3",
"jspreproc": "^0.2.7",

@@ -39,0 +39,0 @@ "mocha": "^2.4.5",

@@ -8,11 +8,19 @@ //#if NODE

* @license MIT
* @copyright 2015 Muut Inc. + contributors
* @copyright Muut Inc. + contributors
*/
'use strict'
var brackets = require('./brackets')
var parsers = require('./parsers')
var path = require('path') // used by getCode()
var path = require('path') // used by getCode()
//#endif
/* eslint-disable */
//#if NODE
var extend = require('./parsers/_utils').mixobj
//#else
// shortcut to enable the use of the parsers util methods
var extend = parsers.utils.extend
//#endif
/* eslint-enable */
//#set $_RIX_TEST = 4

@@ -793,2 +801,16 @@ //#ifndef $_RIX_TEST

/**
* Unescape any html string
* @param {string} str escaped html string
* @returns {string} unescaped html string
*/
function unescapeHTML (str) {
return str
.replace(/&amp;/g, '&')
.replace(/&lt;/g, '<')
.replace(/&gt;/g, '>')
.replace(/&quot;/g, '"')
.replace(/&#039;/g, '\'')
}
/**
* Gets the parser options from the "options" attribute.

@@ -800,3 +822,3 @@ *

function getParserOptions (attribs) {
var opts = getAttrib(attribs, 'options')
var opts = unescapeHTML(getAttrib(attribs, 'options'))

@@ -821,3 +843,4 @@ // convert the string into a valid js object

type = getType(attribs),
src = getAttrib(attribs, 'src')
src = getAttrib(attribs, 'src'),
jsParserOptions = extend({}, opts.parserOptions.js)

@@ -833,6 +856,14 @@ //#if NODE

}
//#else
if (src) return false
//#endif
return _compileJS(code, opts, type, getParserOptions(attribs), base)
return _compileJS(
code,
opts,
type,
extend(jsParserOptions, getParserOptions(attribs)),
base
)
}

@@ -851,7 +882,9 @@

function cssCode (code, opts, attribs, url, tag) {
var extraOpts = {
parserOpts: getParserOptions(attribs),
scoped: attribs && /\sscoped(\s|=|$)/i.test(attribs),
url: url
}
var
parserStyleOptions = extend({}, opts.parserOptions.style),
extraOpts = {
parserOpts: extend(parserStyleOptions, getParserOptions(attribs)),
scoped: attribs && /\sscoped(\s|=|$)/i.test(attribs),
url: url
}

@@ -940,6 +973,15 @@ return _compileCSS(code, tag, getType(attribs) || opts.style, extraOpts)

parts = [],
included
included,
defaultParserptions = {
// TODO: rename this key from `template` to `html`in the next major release
template: {},
js: {},
style: {}
}
if (!opts) opts = {}
// make sure the custom parser options are always objects
opts.parserOptions = extend(defaultParserptions, opts.parserOptions || {})
// for excluding certain parts, `ops.exclude` can be a string or array

@@ -963,3 +1005,3 @@ included = opts.exclude

if (opts.template) {
src = compileTemplate(src, url, opts.template, opts.templateOptions)
src = compileTemplate(src, url, opts.template, opts.parserOptions.template)
}

@@ -966,0 +1008,0 @@

@@ -45,2 +45,11 @@ //#if 0

function renderPug (compilerName, html, opts, url) {
opts = extend({
pretty: true,
filename: url,
doctype: 'html'
}, opts)
return _req(compilerName).render(html, opts)
}
//// The parsers object --

@@ -51,8 +60,9 @@

jade: function (html, opts, url) {
opts = extend({
pretty: true,
filename: url,
doctype: 'html'
}, opts)
return _req('jade').render(html, opts)
/* eslint-disable */
console.log('DEPRECATION WARNING: jade was renamed "pug" - the jade parser will be removed in riot@3.0.0!')
/* eslint-enable */
return renderPug('jade', html, opts, url)
},
pug: function (html, opts, url) {
return renderPug('pug', html, opts, url)
}

@@ -109,4 +119,8 @@ },

_p.utils = {
extend: extend
}
return _p
})()

@@ -64,2 +64,8 @@ //

})
it('pug', function () {
if (have('pug') && have('coffee')) {
testParser('test.pug', { template: 'pug' })
testParser('slide.pug', { template: 'pug' })
}
})

@@ -277,2 +283,28 @@ describe('Custom parser in expressions', function () {

it('the style parser options can be passed directly to the compiler', function () {
var
source = [
'<style-option>',
' <style>',
' p {top:0}',
' </style>',
'</style-option>'
].join('\n')
parsers.css.myParser2 = function (tag, css, opts) {
expect(opts.flag).to.be(true)
// don't do anything
return css
}
compiler.compile(source, {
style: 'myParser2',
parserOptions: {
style: {
flag: true
}
}
})
})
})

@@ -303,2 +335,52 @@

it('the js parser options can be passed directly to the compiler', function () {
var
tag = [
'<custom-options>',
'this.foo = () => null',
'<custom-options>'
].join('\n')
parsers.js.foo = function (js, opts) {
expect(opts.flag).to.be(true)
// don't do anything
return js
}
compiler.compile(tag, {
js: 'foo',
parserOptions: {
js: {
flag: true
}
}
})
})
it('the template parser options can be passed directly to the compiler', function () {
var
tag = [
'<custom-options>',
'this.foo = () => null',
'<custom-options>'
].join('\n')
parsers.html.foo = function (html, opts) {
expect(opts.flag).to.be(true)
// don't do anything
return ''
}
expect(compiler.compile(tag, {
template: 'foo',
parserOptions: {
template: {
flag: true
}
}
})).to.be('')
})
// brackets.tag

@@ -305,0 +387,0 @@ it('using different brackets', function () {

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc