forked from developit/htm
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbabel.test.js
More file actions
60 lines (55 loc) · 1.49 KB
/
Copy pathbabel.test.js
File metadata and controls
60 lines (55 loc) · 1.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/**
* @jest-environment node
*/
const { transform } = require('@babel/core');
const htmBabelPlugin = require('babel-plugin-htm');
describe('htm/babel', () => {
test('basic transformation', () => {
expect(
transform('html`<div id=hello>hello</div>`;', {
babelrc: false,
compact: true,
plugins: [
htmBabelPlugin
]
}).code
).toBe(`h("div",{id:"hello"},["hello"]);`);
});
test('basic transformation with variable', () => {
expect(
transform('var name="world";html`<div id=hello>hello, ${name}</div>`;', {
babelrc: false,
compact: true,
plugins: [
htmBabelPlugin
]
}).code
).toBe(`var name="world";h("div",{id:"hello"},["hello, ",name]);`);
});
test('inline vnode transformation: (pragma:false)', () => {
expect(
transform('var name="world",vnode=html`<div id=hello>hello, ${name}</div>`;', {
babelrc: false,
compact: true,
plugins: [
[htmBabelPlugin, {
pragma: false
}]
]
}).code
).toBe(`var name="world",vnode={tag:"div",props:{id:"hello"},children:["hello, ",name]};`);
});
test('monomorphic transformation', () => {
expect(
transform('var name="world",vnode=html`<div id=hello>hello, ${name}</div>`;', {
babelrc: false,
compact: true,
plugins: [
[htmBabelPlugin, {
monomorphic: true
}]
]
}).code
).toBe(`var name="world",vnode={type:1,tag:"div",props:{id:"hello"},children:[{type:3,tag:null,props:null,children:null,text:"hello, "},name],text:null};`);
});
});