File tree Expand file tree Collapse file tree 2 files changed +17
-0
lines changed Expand file tree Collapse file tree 2 files changed +17
-0
lines changed Original file line number Diff line number Diff line change @@ -4,6 +4,12 @@ class Ctx {
4
4
this . _parentTemp = `"use strict";return @temp;` ;
5
5
this . _defaultCom = null ;
6
6
this . _com = null ;
7
+ if ( ! ( window . hasOwnProperty ( 'Babel' ) && typeof window . Babel === 'object' ) ) {
8
+ throw new Error ( `
9
+ string-to-react-component package needs @babel/standalone for working correctly.
10
+ you should load @babel/standalone in the browser.
11
+ ` ) ;
12
+ }
7
13
this . _b = window . Babel ;
8
14
this . _babelpresets = [ 'react' ] ;
9
15
}
@@ -15,7 +21,16 @@ class Ctx {
15
21
_generateCom ( ) {
16
22
this . _com = this . _temp ? Function ( this . _parentTemp . replace ( '@temp' , this . _transpile ( ) ) ) ( ) : this . _defaultCom ;
17
23
}
24
+ _validateTemplate ( temp ) {
25
+ if ( typeof temp !== 'string' ) {
26
+ throw `passed child into string-to-react-component element should b a string` ;
27
+ }
28
+ if ( temp === '' ) {
29
+ throw `passed string into string-to-react-component element can not be empty` ;
30
+ }
31
+ }
18
32
updateTemplate ( template ) {
33
+ this . _validateTemplate ( template ) ;
19
34
template = template || '' ;
20
35
if ( template !== this . _temp ) {
21
36
this . _temp = template ;
Original file line number Diff line number Diff line change @@ -11,6 +11,7 @@ beforeAll(() => {
11
11
document . body . appendChild ( container ) ;
12
12
} ) ;
13
13
beforeEach ( ( ) => {
14
+ window . Babel = window . Babel || { } ;
14
15
renderApp = ( temp , deps , rerender , temp2 ) => {
15
16
let secondRender = false ;
16
17
const StrintToReactCom = StrintToReact . bind ( undefined , deps ) ;
@@ -30,6 +31,7 @@ beforeEach(() => {
30
31
} ;
31
32
} ) ;
32
33
afterEach ( ( ) => {
34
+ delete window . Babel ;
33
35
unmountComponentAtNode ( container ) ;
34
36
container . innerHTML = '' ;
35
37
renderApp = null ;
You can’t perform that action at this time.
0 commit comments