preact-render-to-string
Advanced tools
Comparing version 3.6.3 to 3.7.0
@@ -27,16 +27,16 @@ (function (global, factory) { | ||
var encodeEntities = function (s) { | ||
var encodeEntities = function encodeEntities(s) { | ||
return String(s).replace(/[<>"&]/g, escapeChar); | ||
}; | ||
var escapeChar = function (a) { | ||
var escapeChar = function escapeChar(a) { | ||
return ESC[a] || a; | ||
}; | ||
var falsey = function (v) { | ||
var falsey = function falsey(v) { | ||
return v == null || v === false; | ||
}; | ||
var memoize = function (fn) { | ||
var mem = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1]; | ||
var memoize = function memoize(fn) { | ||
var mem = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
return function (v) { | ||
@@ -47,7 +47,7 @@ return mem[v] || (mem[v] = fn(v)); | ||
var indent = function (s, char) { | ||
var indent = function indent(s, char) { | ||
return String(s).replace(/(\n+)/g, '$1' + (char || '\t')); | ||
}; | ||
var isLargeString = function (s, length, ignoreLines) { | ||
var isLargeString = function isLargeString(s, length, ignoreLines) { | ||
return String(s).length > (length || 40) || !ignoreLines && String(s).indexOf('\n') !== -1 || String(s).indexOf('<') !== -1; | ||
@@ -103,2 +103,4 @@ }; | ||
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; | ||
var SHALLOW = { shallow: true }; | ||
@@ -114,3 +116,3 @@ | ||
var shallowRender = function (vnode, context) { | ||
var shallowRender = function shallowRender(vnode, context) { | ||
return renderToString(vnode, context, SHALLOW); | ||
@@ -120,8 +122,8 @@ }; | ||
function renderToString(vnode, context, opts, inner, isSvgMode) { | ||
var _ref = vnode || EMPTY; | ||
var _ref = vnode || EMPTY, | ||
nodeName = _ref.nodeName, | ||
attributes = _ref.attributes, | ||
children = _ref.children, | ||
isComponent = false; | ||
var nodeName = _ref.nodeName; | ||
var attributes = _ref.attributes; | ||
var children = _ref.children; | ||
var isComponent = false; | ||
context = context || {}; | ||
@@ -133,7 +135,7 @@ opts = opts || {}; | ||
if (vnode == null || vnode === false) { | ||
if (vnode == null || typeof vnode === 'boolean') { | ||
return ''; | ||
} | ||
if (!nodeName) { | ||
if ((typeof vnode === 'undefined' ? 'undefined' : _typeof(vnode)) !== 'object' && !nodeName) { | ||
return encodeEntities(vnode); | ||
@@ -191,5 +193,5 @@ } | ||
if (name === 'class' && v && typeof v === 'object') { | ||
if (name === 'class' && v && (typeof v === 'undefined' ? 'undefined' : _typeof(v)) === 'object') { | ||
v = hashToClassName(v); | ||
} else if (name === 'style' && v && typeof v === 'object') { | ||
} else if (name === 'style' && v && (typeof v === 'undefined' ? 'undefined' : _typeof(v)) === 'object') { | ||
v = styleObjToCss(v); | ||
@@ -259,3 +261,3 @@ } | ||
if (opts.jsx || VOID_ELEMENTS.indexOf(nodeName) === -1) { | ||
if (VOID_ELEMENTS.indexOf(nodeName) === -1) { | ||
if (pretty && ~s.indexOf('\n')) s += '\n'; | ||
@@ -269,5 +271,3 @@ s += '</' + nodeName + '>'; | ||
function getComponentName(component) { | ||
var proto = component.prototype, | ||
ctor = proto && proto.constructor; | ||
return component.displayName || component.name || proto && (proto.displayName || proto.name) || getFallbackComponentName(component); | ||
return component.displayName || component !== Function && component.name || getFallbackComponentName(component); | ||
} | ||
@@ -274,0 +274,0 @@ |
@@ -8,11 +8,9 @@ (function (global, factory) { | ||
if (typeof Symbol !== 'function') { | ||
(function () { | ||
var c = 0; | ||
Symbol = function (s) { | ||
return '@@' + s + ++c; | ||
}; | ||
Symbol.for = function (s) { | ||
return '@@' + s; | ||
}; | ||
})(); | ||
var c = 0; | ||
Symbol = function Symbol(s) { | ||
return '@@' + s + ++c; | ||
}; | ||
Symbol.for = function (s) { | ||
return '@@' + s; | ||
}; | ||
} | ||
@@ -40,16 +38,16 @@ | ||
var encodeEntities = function (s) { | ||
var encodeEntities = function encodeEntities(s) { | ||
return String(s).replace(/[<>"&]/g, escapeChar); | ||
}; | ||
var escapeChar = function (a) { | ||
var escapeChar = function escapeChar(a) { | ||
return ESC[a] || a; | ||
}; | ||
var falsey = function (v) { | ||
var falsey = function falsey(v) { | ||
return v == null || v === false; | ||
}; | ||
var memoize = function (fn) { | ||
var mem = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1]; | ||
var memoize = function memoize(fn) { | ||
var mem = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
return function (v) { | ||
@@ -60,7 +58,7 @@ return mem[v] || (mem[v] = fn(v)); | ||
var indent = function (s, char) { | ||
var indent = function indent(s, char) { | ||
return String(s).replace(/(\n+)/g, '$1' + (char || '\t')); | ||
}; | ||
var isLargeString = function (s, length, ignoreLines) { | ||
var isLargeString = function isLargeString(s, length, ignoreLines) { | ||
return String(s).length > (length || 40) || !ignoreLines && String(s).indexOf('\n') !== -1 || String(s).indexOf('<') !== -1; | ||
@@ -116,2 +114,4 @@ }; | ||
var _typeof$1 = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; | ||
var SHALLOW = { shallow: true }; | ||
@@ -127,3 +127,3 @@ | ||
var shallowRender = function (vnode, context) { | ||
var shallowRender = function shallowRender(vnode, context) { | ||
return renderToString(vnode, context, SHALLOW); | ||
@@ -133,8 +133,8 @@ }; | ||
function renderToString(vnode, context, opts, inner, isSvgMode) { | ||
var _ref = vnode || EMPTY; | ||
var _ref = vnode || EMPTY, | ||
nodeName = _ref.nodeName, | ||
attributes = _ref.attributes, | ||
children = _ref.children, | ||
isComponent = false; | ||
var nodeName = _ref.nodeName; | ||
var attributes = _ref.attributes; | ||
var children = _ref.children; | ||
var isComponent = false; | ||
context = context || {}; | ||
@@ -146,7 +146,7 @@ opts = opts || {}; | ||
if (vnode == null || vnode === false) { | ||
if (vnode == null || typeof vnode === 'boolean') { | ||
return ''; | ||
} | ||
if (!nodeName) { | ||
if ((typeof vnode === 'undefined' ? 'undefined' : _typeof$1(vnode)) !== 'object' && !nodeName) { | ||
return encodeEntities(vnode); | ||
@@ -204,5 +204,5 @@ } | ||
if (name === 'class' && v && typeof v === 'object') { | ||
if (name === 'class' && v && (typeof v === 'undefined' ? 'undefined' : _typeof$1(v)) === 'object') { | ||
v = hashToClassName(v); | ||
} else if (name === 'style' && v && typeof v === 'object') { | ||
} else if (name === 'style' && v && (typeof v === 'undefined' ? 'undefined' : _typeof$1(v)) === 'object') { | ||
v = styleObjToCss(v); | ||
@@ -272,3 +272,3 @@ } | ||
if (opts.jsx || VOID_ELEMENTS.indexOf(nodeName) === -1) { | ||
if (VOID_ELEMENTS.indexOf(nodeName) === -1) { | ||
if (pretty && ~s.indexOf('\n')) s += '\n'; | ||
@@ -282,5 +282,3 @@ s += '</' + nodeName + '>'; | ||
function getComponentName(component) { | ||
var proto = component.prototype, | ||
ctor = proto && proto.constructor; | ||
return component.displayName || component.name || proto && (proto.displayName || proto.name) || getFallbackComponentName(component); | ||
return component.displayName || component !== Function && component.name || getFallbackComponentName(component); | ||
} | ||
@@ -333,2 +331,4 @@ | ||
var _typeof$2 = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; | ||
var index = createCommonjsModule(function (module) { | ||
@@ -383,3 +383,3 @@ 'use strict'; | ||
var typeOf = typeof val; | ||
var typeOf = typeof val === 'undefined' ? 'undefined' : _typeof$2(val); | ||
@@ -475,3 +475,3 @@ if (typeOf === 'number') return printNumber(val); | ||
keys = keys.filter(function (key) { | ||
return !(typeof key === 'symbol' || toString.call(key) === '[object Symbol]'); | ||
return !((typeof key === 'undefined' ? 'undefined' : _typeof$2(key)) === 'symbol' || toString.call(key) === '[object Symbol]'); | ||
}).concat(symbols); | ||
@@ -554,3 +554,3 @@ } | ||
return hitMaxDepth ? '[Set]' : printSet(val, indent, prevIndent, spacing, edgeSpacing, refs, maxDepth, currentDepth, plugins, min); | ||
} else if (typeof val === 'object') { | ||
} else if ((typeof val === 'undefined' ? 'undefined' : _typeof$2(val)) === 'object') { | ||
return hitMaxDepth ? '[Object]' : printObject(val, indent, prevIndent, spacing, edgeSpacing, refs, maxDepth, currentDepth, plugins, min); | ||
@@ -674,7 +674,9 @@ } | ||
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; | ||
var preactPlugin = { | ||
test: function (object) { | ||
return object && typeof object === 'object' && 'nodeName' in object && 'attributes' in object && 'children' in object && !('nodeType' in object); | ||
test: function test(object) { | ||
return object && (typeof object === 'undefined' ? 'undefined' : _typeof(object)) === 'object' && 'nodeName' in object && 'attributes' in object && 'children' in object && !('nodeType' in object); | ||
}, | ||
print: function (val, print, indent) { | ||
print: function print(val, _print, indent) { | ||
return renderToString(val, preactPlugin.context, preactPlugin.opts, true); | ||
@@ -689,4 +691,6 @@ } | ||
function attributeHook(name, value, context, opts, isComponent) { | ||
var type = typeof value; | ||
var type = typeof value === 'undefined' ? 'undefined' : _typeof(value); | ||
if (name === 'dangerouslySetInnerHTML') return false; | ||
if (value == null || type === 'function' && !opts.functions) return ''; | ||
@@ -693,0 +697,0 @@ |
{ | ||
"name": "preact-render-to-string", | ||
"amdName": "preactRenderToString", | ||
"version": "3.6.3", | ||
"version": "3.7.0", | ||
"description": "Render JSX to an HTML string, with support for Preact components.", | ||
@@ -9,3 +9,4 @@ "main": "dist/index.js", | ||
"scripts": { | ||
"build": "npm run -s transpile && npm run -s transpile:jsx", | ||
"build": "npm run -s transpile && npm run -s transpile:jsx && npm run -s copy-typescript-definition", | ||
"copy-typescript-definition": "copyfiles -f src/index.d.ts dist", | ||
"transpile": "rollup -c rollup.config.js -m ${npm_package_main}.map -f umd -n $npm_package_amdName $npm_package_jsnext_main -o $npm_package_main", | ||
@@ -25,2 +26,3 @@ "transpile:jsx": "ENTRY=jsx rollup -c rollup.config.js -m dist/jsx.js.map -f umd -n $npm_package_amdName src/jsx.js -o dist/jsx.js", | ||
"license": "MIT", | ||
"typings": "src/index.d.ts", | ||
"repository": { | ||
@@ -44,7 +46,6 @@ "type": "git", | ||
"babel-preset-es2015": "^6.9.0", | ||
"babel-preset-es2015-minimal": "^2.0.0", | ||
"babel-preset-es2015-minimal-rollup": "^2.1.0", | ||
"babel-preset-stage-0": "^6.5.0", | ||
"babel-register": "^6.9.0", | ||
"chai": "^3.5.0", | ||
"copyfiles": "^1.2.0", | ||
"eslint": "^3.2.2", | ||
@@ -51,0 +52,0 @@ "mocha": "^3.0.0", |
@@ -8,2 +8,3 @@ import fs from 'fs'; | ||
let babelRc = JSON.parse(fs.readFileSync('./.babelrc')); | ||
babelRc.presets[0][1].modules = false; | ||
@@ -31,3 +32,3 @@ let entry = process.env.ENTRY || 'index'; | ||
exclude: [], | ||
presets: ['es2015-minimal-rollup'].concat(babelRc.presets.slice(1)), | ||
presets: babelRc.presets, | ||
plugins: babelRc.plugins | ||
@@ -34,0 +35,0 @@ }) |
@@ -61,3 +61,3 @@ import { objectKeys, encodeEntities, falsey, memoize, indent, isLargeString, styleObjToCss, hashToClassName, assign, getNodeProps } from './util'; | ||
if (vnode==null || vnode===false) { | ||
if (vnode==null || typeof vnode==='boolean') { | ||
return ''; | ||
@@ -67,3 +67,3 @@ } | ||
// #text nodes | ||
if (!nodeName) { | ||
if (typeof vnode!=='object' && !nodeName) { | ||
return encodeEntities(vnode); | ||
@@ -202,3 +202,3 @@ } | ||
if (opts.jsx || VOID_ELEMENTS.indexOf(nodeName)===-1) { | ||
if (VOID_ELEMENTS.indexOf(nodeName)===-1) { | ||
if (pretty && ~s.indexOf('\n')) s += '\n'; | ||
@@ -212,5 +212,3 @@ s += `</${nodeName}>`; | ||
function getComponentName(component) { | ||
let proto = component.prototype, | ||
ctor = proto && proto.constructor; | ||
return component.displayName || component.name || (proto && (proto.displayName || proto.name)) || getFallbackComponentName(component); | ||
return component.displayName || component!==Function && component.name || getFallbackComponentName(component); | ||
} | ||
@@ -217,0 +215,0 @@ |
@@ -25,2 +25,5 @@ import './polyfills'; | ||
let type = typeof value; | ||
// Use render-to-string's built-in handling for these properties | ||
if (name==='dangerouslySetInnerHTML') return false; | ||
@@ -27,0 +30,0 @@ // always skip null & undefined values, skip false DOM attributes, skip functions if told to |
@@ -99,3 +99,3 @@ import render from '../src/jsx'; | ||
}); | ||
it('should render attributes containing VNodes', () => { | ||
@@ -180,2 +180,10 @@ expect(renderJsx( | ||
}); | ||
it('should render self-closing elements', () => { | ||
expect(renderJsx( | ||
<meta charset="utf-8" /> | ||
)).to.deep.equal(dedent` | ||
<meta charset="utf-8" /> | ||
`); | ||
}); | ||
}); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
134660
20
25
1905