Skip to content

Commit

Permalink
replaced Object.assign with custom extend function because we still s…
Browse files Browse the repository at this point in the history
…upport ancient node versions
  • Loading branch information
GianlucaGuarini committed May 5, 2016
1 parent 124e620 commit 7df5c49
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 18 deletions.
4 changes: 1 addition & 3 deletions dist/es6.compiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,7 @@ var parsers = (function () {
/**
* @module compiler
*/
var extend

extend = parsers.util.extend
var extend = parsers.util.extend

var S_LINESTR = /"[^"\n\\]*(?:\\[\S\s][^"\n\\]*)*"|'[^'\n\\]*(?:\\[\S\s][^'\n\\]*)*'/.source

Expand Down
4 changes: 1 addition & 3 deletions dist/riot.compiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,7 @@ riot.parsers = parsers
*/
var compile = (function () {

var extend

extend = parsers.util.extend
var extend = parsers.util.extend

var S_LINESTR = /"[^"\n\\]*(?:\\[\S\s][^"\n\\]*)*"|'[^'\n\\]*(?:\\[\S\s][^'\n\\]*)*'/.source

Expand Down
4 changes: 1 addition & 3 deletions lib/compiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@
var brackets = require('./brackets')
var parsers = require('./parsers')
var path = require('path')
var extend

extend = Object.assign
var extend = parsers.util.extend

/**
* Source for creating regexes matching valid quoted, single-line JavaScript strings.
Expand Down
26 changes: 25 additions & 1 deletion lib/parsers.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,27 @@ function _none (src) {
// Initialize the cache with parsers that cannot be required
var _mods = { none: _none, javascript: _none }

/**
* Merge two javascript object extending the properties of the first one with
* the second.
* TODO: remove this function replacing it with Object.assign in the next major release
*
* @param {object} obj - source object
* @param {object} props - extra properties
* @returns {object} source object containing the new properties
*/
function extend (obj, props) {
if (props) {
for (var prop in props) {
/* istanbul ignore next */
if (props.hasOwnProperty(prop)) {
obj[prop] = props[prop]
}
}
}
return obj
}

/**
* Returns a parser instance by its name, requiring the module without generating error.
*
Expand Down Expand Up @@ -70,7 +91,10 @@ module.exports = _makelist({
_req: _req,
html: {},
css: {},
js: { none: _none, javascript: _none }
js: { none: _none, javascript: _none },
util: {
extend: extend
}
})

module.exports.js.coffeescript = module.exports.js.coffee // 4 the nostalgics
9 changes: 1 addition & 8 deletions src/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,7 @@ var brackets = require('./brackets')
var parsers = require('./parsers')
var path = require('path') // used by getCode()
//#endif
var extend
//#if NODE
// prefer the Object assign method 100% supported in node
extend = Object.assign
//#else
// shortcut to enable the use of the parsers util methods
extend = parsers.util.extend
//#endif
var extend = parsers.util.extend

//#set $_RIX_TEST = 4
//#ifndef $_RIX_TEST
Expand Down

0 comments on commit 7df5c49

Please sign in to comment.