File tree Expand file tree Collapse file tree 2 files changed +14
-3
lines changed Expand file tree Collapse file tree 2 files changed +14
-3
lines changed Original file line number Diff line number Diff line change 1
1
{
2
2
"name" : " simple-tsx" ,
3
- "version" : " 1.0.0 " ,
3
+ "version" : " 1.0.1 " ,
4
4
"description" : " A simple way to write tsx files. No babel required!" ,
5
5
"main" : " dist/index.js" ,
6
6
"type" : " commonjs" ,
Original file line number Diff line number Diff line change @@ -6,7 +6,7 @@ export default class Element {
6
6
constructor (
7
7
name : string ,
8
8
attributes : AttributesType | null ,
9
- ...children : Element [ ]
9
+ ...children : ( Element | string | number ) [ ]
10
10
) {
11
11
this . element = document . createElement ( name ) ;
12
12
const trueAttributes = attributes || { } ;
@@ -20,7 +20,18 @@ export default class Element {
20
20
this . element . setAttribute ( name , value . toString ( ) ) ;
21
21
}
22
22
} ) ;
23
- children . forEach ( ( child ) => this . element . appendChild ( child . element ) ) ;
23
+ children . forEach ( ( child ) => {
24
+ let node : Node ;
25
+ if ( typeof child === "string" ) {
26
+ node = document . createTextNode ( child ) ;
27
+ } else if ( typeof child === "number" ) {
28
+ node = document . createTextNode ( child . toString ( ) ) ;
29
+ } else {
30
+ node = child . element ;
31
+ }
32
+
33
+ this . element . appendChild ( node ) ;
34
+ } ) ;
24
35
}
25
36
}
26
37
You can’t perform that action at this time.
0 commit comments