@@ -5,7 +5,7 @@ function compile(code, { plugins = [], ...options } = {}) {
55 return transform ( code , {
66 babelrc : false ,
77 configFile : false ,
8- sourceType : 'script ' ,
8+ sourceType : 'module ' ,
99 plugins : [
1010 ...plugins ,
1111 [ transformJsxToHtmPlugin , options ]
@@ -14,6 +14,50 @@ function compile(code, { plugins = [], ...options } = {}) {
1414}
1515
1616describe ( 'babel-plugin-transform-jsx-to-htm' , ( ) => {
17+ describe ( 'import' , ( ) => {
18+ test ( 'import shortcut' , ( ) => {
19+ expect (
20+ compile ( `(<div />);` , { import : 'htm/preact' } )
21+ ) . toBe ( 'import { html } from "htm/preact";\nhtml`<div/>`;' ) ;
22+ } ) ;
23+
24+ test ( 'import shortcut, dotted tag' , ( ) => {
25+ expect (
26+ compile ( `(<div />);` , { tag : 'html.bound' , import : 'htm/preact' } )
27+ ) . toBe ( 'import { html } from "htm/preact";\nhtml.bound`<div/>`;' ) ;
28+ } ) ;
29+
30+ test ( 'named import' , ( ) => {
31+ expect (
32+ compile ( `(<div />);` , { import : { module : 'htm/preact' , export : '$html' } } )
33+ ) . toBe ( 'import { $html as html } from "htm/preact";\nhtml`<div/>`;' ) ;
34+ } ) ;
35+
36+ test ( 'named import, dotted tag' , ( ) => {
37+ expect (
38+ compile ( `(<div />);` , { tag : 'html.bound' , import : { module : 'htm/preact' , export : '$html' } } )
39+ ) . toBe ( 'import { $html as html } from "htm/preact";\nhtml.bound`<div/>`;' ) ;
40+ } ) ;
41+
42+ test ( 'default import' , ( ) => {
43+ expect (
44+ compile ( `(<div />);` , { import : { module : 'htm/preact' , export : 'default' } } )
45+ ) . toBe ( 'import html from "htm/preact";\nhtml`<div/>`;' ) ;
46+ } ) ;
47+
48+ test ( 'namespace import' , ( ) => {
49+ expect (
50+ compile ( `(<div />);` , { import : { module : 'htm/preact' , export : '*' } } )
51+ ) . toBe ( 'import * as html from "htm/preact";\nhtml`<div/>`;' ) ;
52+ } ) ;
53+
54+ test ( 'no import without JSX' , ( ) => {
55+ expect (
56+ compile ( `false;` , { import : 'htm/preact' } )
57+ ) . toBe ( 'false;' ) ;
58+ } ) ;
59+ } ) ;
60+
1761 describe ( 'elements and text' , ( ) => {
1862 test ( 'single named element' , ( ) => {
1963 expect (
0 commit comments