Skip to content

Commit bdff308

Browse files
committed
Bring in JSDOM in order to make the babel plugin actually work without a browser runtime
1 parent b6c30e7 commit bdff308

2 files changed

Lines changed: 10 additions & 2 deletions

File tree

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,5 +48,8 @@
4848
"jest": "^23.4.2",
4949
"microbundle": "^0.6.0",
5050
"preact": "^8.2.9"
51+
},
52+
"dependencies": {
53+
"jsdom": "^11.12.0"
5154
}
5255
}

src/babel.mjs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
import htm from './index.mjs';
1+
import { JSDOM } from 'jsdom';
2+
const before = global.document;
3+
global.document = new JSDOM().window.document;
4+
const htm = require('htm');
5+
global.document = before;
26

37
// htm() uses the HTML parser, which serializes attribute values.
48
// this is a problem, because composite values here can be made up
@@ -19,7 +23,7 @@ export default function htmBabelPlugin({ types: t }, options = {}) {
1923
const pragma = options.pragma===false ? false : dottedIdentifier(options.pragma || 'h');
2024

2125
const inlineVNodes = options.monomorphic || pragma===false;
22-
26+
2327
function dottedIdentifier(keypath) {
2428
const path = keypath.split('.');
2529
let out;
@@ -96,6 +100,7 @@ export default function htmBabelPlugin({ types: t }, options = {}) {
96100
if (matches) tag = currentExpressions[matches[1]];
97101
else tag = t.stringLiteral(tag);
98102
}
103+
99104
//const propsNode = props==null || Object.keys(props).length===0 ? t.nullLiteral() : t.objectExpression(
100105
const propsNode = t.objectExpression(
101106
Object.keys(props).map(key => {

0 commit comments

Comments
 (0)