preact-render-to-string 3.7.1 → 3.8.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +1 -292
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/index.mjs.map +1 -1
- package/dist/jsx.js +1 -721
- package/dist/jsx.js.map +1 -1
- package/dist/jsx.mjs +2 -0
- package/dist/jsx.mjs.map +1 -0
- package/package.json +46 -26
- package/src/index.js +33 -51
- package/src/jsx.js +1 -1
- package/src/util.js +37 -41
- package/.babelrc +0 -10
- package/.eslintrc +0 -55
- package/.travis.yml +0 -3
- package/rollup.config.js +0 -35
- package/test/index.js +0 -19
- package/test/jsx.js +0 -187
- package/test/pretty.js +0 -68
- package/test/render.js +0 -571
- package/test/shallowRender.js +0 -36
package/.eslintrc
DELETED
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"parser": "babel-eslint",
|
|
3
|
-
"extends": "eslint:recommended",
|
|
4
|
-
"env": {
|
|
5
|
-
"browser": true,
|
|
6
|
-
"mocha": true,
|
|
7
|
-
"node": true,
|
|
8
|
-
"es6": true
|
|
9
|
-
},
|
|
10
|
-
"parserOptions": {
|
|
11
|
-
"ecmaFeatures": {
|
|
12
|
-
"modules": true,
|
|
13
|
-
"jsx": true
|
|
14
|
-
}
|
|
15
|
-
},
|
|
16
|
-
"rules": {
|
|
17
|
-
"no-empty": 0,
|
|
18
|
-
"no-console": 0,
|
|
19
|
-
"no-unused-vars": [0, { "varsIgnorePattern": "^h$" }],
|
|
20
|
-
"no-cond-assign": 1,
|
|
21
|
-
"semi": 2,
|
|
22
|
-
"camelcase": 0,
|
|
23
|
-
"comma-style": 2,
|
|
24
|
-
"comma-dangle": [2, "never"],
|
|
25
|
-
"indent": [2, "tab", {"SwitchCase": 1}],
|
|
26
|
-
"no-mixed-spaces-and-tabs": [2, "smart-tabs"],
|
|
27
|
-
"no-trailing-spaces": [2, { "skipBlankLines": true }],
|
|
28
|
-
"no-eval": 2,
|
|
29
|
-
"no-implied-eval": 2,
|
|
30
|
-
"no-new-func": 2,
|
|
31
|
-
"guard-for-in": 0,
|
|
32
|
-
"eqeqeq": [2, "smart"],
|
|
33
|
-
"no-else-return": 2,
|
|
34
|
-
"no-redeclare": 2,
|
|
35
|
-
"no-dupe-keys": 2,
|
|
36
|
-
"radix": 2,
|
|
37
|
-
"strict": [2, "never"],
|
|
38
|
-
"no-shadow": 0,
|
|
39
|
-
"no-delete-var": 2,
|
|
40
|
-
"no-undef-init": 2,
|
|
41
|
-
"no-shadow-restricted-names": 2,
|
|
42
|
-
"handle-callback-err": 0,
|
|
43
|
-
"no-lonely-if": 2,
|
|
44
|
-
"keyword-spacing": 2,
|
|
45
|
-
"constructor-super": 2,
|
|
46
|
-
"no-this-before-super": 2,
|
|
47
|
-
"no-dupe-class-members": 2,
|
|
48
|
-
"no-const-assign": 2,
|
|
49
|
-
"prefer-spread": 2,
|
|
50
|
-
"no-useless-concat": 2,
|
|
51
|
-
"no-var": 2,
|
|
52
|
-
"object-shorthand": 2,
|
|
53
|
-
"prefer-arrow-callback": 2
|
|
54
|
-
}
|
|
55
|
-
}
|
package/.travis.yml
DELETED
package/rollup.config.js
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import fs from 'fs';
|
|
2
|
-
import nodeResolve from 'rollup-plugin-node-resolve';
|
|
3
|
-
import commonjs from 'rollup-plugin-commonjs';
|
|
4
|
-
import memory from 'rollup-plugin-memory';
|
|
5
|
-
import babel from 'rollup-plugin-babel';
|
|
6
|
-
|
|
7
|
-
let babelRc = JSON.parse(fs.readFileSync('./.babelrc'));
|
|
8
|
-
babelRc.presets[0][1].modules = false;
|
|
9
|
-
|
|
10
|
-
let entry = process.env.ENTRY || 'index';
|
|
11
|
-
|
|
12
|
-
export default {
|
|
13
|
-
entry: 'src/'+entry+'.js',
|
|
14
|
-
exports: 'default',
|
|
15
|
-
useStrict: false,
|
|
16
|
-
external: ['preact'],
|
|
17
|
-
plugins: [
|
|
18
|
-
memory({
|
|
19
|
-
path: 'src/'+entry+'.js',
|
|
20
|
-
contents: "export { default } from './"+entry+"';"
|
|
21
|
-
}),
|
|
22
|
-
nodeResolve({
|
|
23
|
-
skip: ['preact'],
|
|
24
|
-
main: true
|
|
25
|
-
}),
|
|
26
|
-
commonjs(),
|
|
27
|
-
babel({
|
|
28
|
-
babelrc: false,
|
|
29
|
-
comments: false,
|
|
30
|
-
exclude: [],
|
|
31
|
-
presets: babelRc.presets,
|
|
32
|
-
plugins: babelRc.plugins
|
|
33
|
-
})
|
|
34
|
-
]
|
|
35
|
-
};
|
package/test/index.js
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import renderToString, { render, shallowRender } from '../src';
|
|
2
|
-
import { expect } from 'chai';
|
|
3
|
-
|
|
4
|
-
describe('render-to-string', () => {
|
|
5
|
-
describe('exports', () => {
|
|
6
|
-
it('exposes renderToString as default', () => {
|
|
7
|
-
expect(renderToString).to.be.a('function');
|
|
8
|
-
});
|
|
9
|
-
|
|
10
|
-
it('exposes render as a named export', () => {
|
|
11
|
-
expect(render).to.be.a('function');
|
|
12
|
-
expect(render).to.equal(renderToString);
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
it('exposes shallowRender as a named export', () => {
|
|
16
|
-
expect(shallowRender).to.be.a('function');
|
|
17
|
-
});
|
|
18
|
-
});
|
|
19
|
-
});
|
package/test/jsx.js
DELETED
|
@@ -1,187 +0,0 @@
|
|
|
1
|
-
import render from '../src/jsx';
|
|
2
|
-
import { h, Component } from 'preact';
|
|
3
|
-
import chai, { expect } from 'chai';
|
|
4
|
-
import { spy, match } from 'sinon';
|
|
5
|
-
import sinonChai from 'sinon-chai';
|
|
6
|
-
chai.use(sinonChai);
|
|
7
|
-
|
|
8
|
-
// tag to remove leading whitespace from tagged template literal
|
|
9
|
-
function dedent([str]) {
|
|
10
|
-
return str.split( '\n'+str.match(/^\n*(\s+)/)[1] ).join('\n').replace(/(^\n+|\n+\s*$)/g, '');
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
describe('jsx', () => {
|
|
14
|
-
let renderJsx = (jsx, opts) => render(jsx, null, opts).replace(/ {2}/g, '\t');
|
|
15
|
-
|
|
16
|
-
it('should render as JSX', () => {
|
|
17
|
-
let rendered = renderJsx(
|
|
18
|
-
<section>
|
|
19
|
-
<a href="/foo">foo</a>
|
|
20
|
-
bar
|
|
21
|
-
<p>hello</p>
|
|
22
|
-
</section>
|
|
23
|
-
);
|
|
24
|
-
|
|
25
|
-
expect(rendered).to.equal(dedent`
|
|
26
|
-
<section>
|
|
27
|
-
<a href="/foo">foo</a>
|
|
28
|
-
bar
|
|
29
|
-
<p>hello</p>
|
|
30
|
-
</section>
|
|
31
|
-
`);
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
it('should not render empty class or style DOM attributes', () => {
|
|
35
|
-
expect(renderJsx(<a b={false} />)).to.equal('<a></a>');
|
|
36
|
-
expect(renderJsx(<a b="" />)).to.equal('<a b=""></a>');
|
|
37
|
-
expect(renderJsx(<a class={false} />)).to.equal('<a></a>');
|
|
38
|
-
expect(renderJsx(<a style={false} />)).to.equal('<a></a>');
|
|
39
|
-
expect(renderJsx(<a class="" />)).to.equal('<a></a>');
|
|
40
|
-
expect(renderJsx(<a style="" />)).to.equal('<a></a>');
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
it('should render JSX attributes inline if short enough', () => {
|
|
44
|
-
expect(renderJsx(
|
|
45
|
-
<a b="c">bar</a>
|
|
46
|
-
)).to.equal(dedent`
|
|
47
|
-
<a b="c">bar</a>
|
|
48
|
-
`);
|
|
49
|
-
|
|
50
|
-
expect(renderJsx(
|
|
51
|
-
<a b>bar</a>
|
|
52
|
-
)).to.equal(dedent`
|
|
53
|
-
<a b={true}>bar</a>
|
|
54
|
-
`);
|
|
55
|
-
|
|
56
|
-
expect(renderJsx(
|
|
57
|
-
<a b={false}>bar</a>
|
|
58
|
-
)).to.equal(dedent`
|
|
59
|
-
<a>bar</a>
|
|
60
|
-
`);
|
|
61
|
-
|
|
62
|
-
function F(){}
|
|
63
|
-
expect(renderJsx(
|
|
64
|
-
<F b={false}>bar</F>,
|
|
65
|
-
{ shallow:true, renderRootComponent:false }
|
|
66
|
-
)).to.equal(dedent`
|
|
67
|
-
<F b={false}>bar</F>
|
|
68
|
-
`);
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
it('should render JSX attributes as multiline if complex', () => {
|
|
72
|
-
expect(renderJsx(
|
|
73
|
-
<a b={['a','b','c','d']}>bar</a>
|
|
74
|
-
)).to.equal(dedent`
|
|
75
|
-
<a
|
|
76
|
-
b={
|
|
77
|
-
Array [
|
|
78
|
-
"a",
|
|
79
|
-
"b",
|
|
80
|
-
"c",
|
|
81
|
-
"d"
|
|
82
|
-
]
|
|
83
|
-
}
|
|
84
|
-
>
|
|
85
|
-
bar
|
|
86
|
-
</a>
|
|
87
|
-
`);
|
|
88
|
-
});
|
|
89
|
-
|
|
90
|
-
it('should skip null and undefined attributes', () => {
|
|
91
|
-
expect(renderJsx(
|
|
92
|
-
<a b={null}>bar</a>
|
|
93
|
-
)).to.equal(`<a>bar</a>`);
|
|
94
|
-
|
|
95
|
-
expect(renderJsx(
|
|
96
|
-
<a b={undefined}>bar</a>
|
|
97
|
-
)).to.equal(`<a>bar</a>`);
|
|
98
|
-
});
|
|
99
|
-
|
|
100
|
-
it('should render attributes containing VNodes', () => {
|
|
101
|
-
expect(renderJsx(
|
|
102
|
-
<a b={<c />}>bar</a>
|
|
103
|
-
)).to.equal(dedent`
|
|
104
|
-
<a b={<c></c>}>bar</a>
|
|
105
|
-
`);
|
|
106
|
-
|
|
107
|
-
expect(renderJsx(
|
|
108
|
-
<a b={[
|
|
109
|
-
<c />,
|
|
110
|
-
<d f="g" />
|
|
111
|
-
]}>bar</a>
|
|
112
|
-
)).to.equal(dedent`
|
|
113
|
-
<a
|
|
114
|
-
b={
|
|
115
|
-
Array [
|
|
116
|
-
<c></c>,
|
|
117
|
-
<d f="g"></d>
|
|
118
|
-
]
|
|
119
|
-
}
|
|
120
|
-
>
|
|
121
|
-
bar
|
|
122
|
-
</a>
|
|
123
|
-
`);
|
|
124
|
-
});
|
|
125
|
-
|
|
126
|
-
it('should render empty resolved children identically to no children', () => {
|
|
127
|
-
const Empty = () => null;
|
|
128
|
-
const False = () => false;
|
|
129
|
-
expect(renderJsx(
|
|
130
|
-
<div>
|
|
131
|
-
<a />
|
|
132
|
-
<b>{null}</b>
|
|
133
|
-
<c><Empty /></c>
|
|
134
|
-
<d>{false}</d>
|
|
135
|
-
<e><False /></e>
|
|
136
|
-
</div>
|
|
137
|
-
)).to.equal(dedent`
|
|
138
|
-
<div>
|
|
139
|
-
<a></a>
|
|
140
|
-
<b></b>
|
|
141
|
-
<c></c>
|
|
142
|
-
<d></d>
|
|
143
|
-
<e></e>
|
|
144
|
-
</div>
|
|
145
|
-
`);
|
|
146
|
-
});
|
|
147
|
-
|
|
148
|
-
it('should skip null siblings', () => {
|
|
149
|
-
expect(renderJsx(
|
|
150
|
-
<jsx>
|
|
151
|
-
<span/>
|
|
152
|
-
{null}
|
|
153
|
-
</jsx>
|
|
154
|
-
)).to.deep.equal(dedent`
|
|
155
|
-
<jsx>
|
|
156
|
-
<span></span>
|
|
157
|
-
</jsx>
|
|
158
|
-
`);
|
|
159
|
-
});
|
|
160
|
-
|
|
161
|
-
it('should skip functions if functions=false', () => {
|
|
162
|
-
expect(renderJsx(
|
|
163
|
-
<div onClick={() => {}} />,
|
|
164
|
-
{ functions:false }
|
|
165
|
-
)).to.equal('<div></div>');
|
|
166
|
-
});
|
|
167
|
-
|
|
168
|
-
it('should skip function names if functionNames=false', () => {
|
|
169
|
-
expect(renderJsx(
|
|
170
|
-
<div onClick={() => {}} />,
|
|
171
|
-
{ functionNames:false }
|
|
172
|
-
)).to.equal('<div onClick={Function}></div>');
|
|
173
|
-
|
|
174
|
-
expect(renderJsx(
|
|
175
|
-
<div onClick={function foo(){}} />,
|
|
176
|
-
{ functionNames:false }
|
|
177
|
-
)).to.equal('<div onClick={Function}></div>');
|
|
178
|
-
});
|
|
179
|
-
|
|
180
|
-
it('should render self-closing elements', () => {
|
|
181
|
-
expect(renderJsx(
|
|
182
|
-
<meta charset="utf-8" />
|
|
183
|
-
)).to.deep.equal(dedent`
|
|
184
|
-
<meta charset="utf-8" />
|
|
185
|
-
`);
|
|
186
|
-
});
|
|
187
|
-
});
|
package/test/pretty.js
DELETED
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
import { render, shallowRender } from '../src';
|
|
2
|
-
import { h, Component } from 'preact';
|
|
3
|
-
import chai, { expect } from 'chai';
|
|
4
|
-
import { spy, match } from 'sinon';
|
|
5
|
-
import sinonChai from 'sinon-chai';
|
|
6
|
-
chai.use(sinonChai);
|
|
7
|
-
|
|
8
|
-
describe('pretty', () => {
|
|
9
|
-
let prettyRender = jsx => render(jsx, {}, { pretty:true });
|
|
10
|
-
|
|
11
|
-
it('should render no whitespace by default', () => {
|
|
12
|
-
let rendered = render(
|
|
13
|
-
<section>
|
|
14
|
-
<a href="/foo">foo</a>
|
|
15
|
-
bar
|
|
16
|
-
<p>hello</p>
|
|
17
|
-
</section>
|
|
18
|
-
);
|
|
19
|
-
|
|
20
|
-
expect(rendered).to.equal(`<section><a href="/foo">foo</a>bar<p>hello</p></section>`);
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
it('should render whitespace when pretty=true', () => {
|
|
24
|
-
let rendered = prettyRender(
|
|
25
|
-
<section>
|
|
26
|
-
<a href="/foo">foo</a>
|
|
27
|
-
bar
|
|
28
|
-
<p>hello</p>
|
|
29
|
-
</section>
|
|
30
|
-
);
|
|
31
|
-
|
|
32
|
-
expect(rendered).to.equal(`<section>\n\t<a href="/foo">foo</a>\n\tbar\n\t<p>hello</p>\n</section>`);
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
it('should not indent for short children', () => {
|
|
36
|
-
let fourty = '';
|
|
37
|
-
for (let i=40; i--; ) fourty += 'x';
|
|
38
|
-
|
|
39
|
-
expect(
|
|
40
|
-
prettyRender(<a href="/foo">{fourty}</a>),
|
|
41
|
-
'<=40 characters'
|
|
42
|
-
).to.equal(`<a href="/foo">${fourty}</a>`);
|
|
43
|
-
|
|
44
|
-
expect(
|
|
45
|
-
prettyRender(<a href="/foo">{fourty+'a'}</a>),
|
|
46
|
-
'>40 characters'
|
|
47
|
-
).to.equal(`<a href="/foo">\n\t${fourty+'a'}\n</a>`);
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
it('should handle self-closing tags', () => {
|
|
51
|
-
expect(prettyRender(
|
|
52
|
-
<div>
|
|
53
|
-
hi
|
|
54
|
-
<img src="a.jpg" />
|
|
55
|
-
<img src="b.jpg" />
|
|
56
|
-
<b>hi</b>
|
|
57
|
-
</div>
|
|
58
|
-
)).to.equal(`<div>\n\thi\n\t<img src="a.jpg" />\n\t<img src="b.jpg" />\n\t<b>hi</b>\n</div>`);
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
it('should support empty tags', () => {
|
|
62
|
-
expect(prettyRender(
|
|
63
|
-
<div>
|
|
64
|
-
<span />
|
|
65
|
-
</div>
|
|
66
|
-
)).to.equal(`<div>\n\t<span></span>\n</div>`);
|
|
67
|
-
});
|
|
68
|
-
});
|