babel-plugin-htm
Advanced tools
Comparing version 2.0.0 to 2.1.0
@@ -5,2 +5,3 @@ function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; } | ||
function objectWithoutProperties (obj, exclude) { var target = {}; for (var k in obj) if (Object.prototype.hasOwnProperty.call(obj, k) && exclude.indexOf(k) === -1) target[k] = obj[k]; return target; } | ||
/** | ||
@@ -23,2 +24,3 @@ * @param {Babel} babel | ||
var inlineVNodes = options.monomorphic || pragma === false; | ||
var symbol = Symbol(); | ||
@@ -75,4 +77,30 @@ function dottedIdentifier(keypath) { | ||
function flatten(props, result) { | ||
if ( result === void 0 ) result = []; | ||
var head = props[symbol]; | ||
var rest = objectWithoutProperties( props, [symbol] ); | ||
var tail = rest; | ||
if (head) { head.forEach(function (obj) { | ||
flatten(obj, result); | ||
}); } | ||
if (Object.keys(tail).length > 0) { | ||
result.push(tail); | ||
} | ||
return result; | ||
} | ||
function spreadNode(args, state) { | ||
// 'Object.assign({}, x)', can be collapsed to 'x'. | ||
if (args.length > 0 && t.isNode(args[0])) { | ||
args.unshift({}); | ||
} // 'Object.assign(x)', can be collapsed to 'x'. | ||
if (args.length === 1) { | ||
return propsNode(args[0]); | ||
} // 'Object.assign({}, x)', can be collapsed to 'x'. | ||
if (args.length === 2 && !t.isNode(args[0]) && Object.keys(args[0]).length === 0) { | ||
@@ -87,3 +115,2 @@ return propsNode(args[1]); | ||
function propsNode(props) { | ||
if (props == null) { return t.nullLiteral(); } | ||
return t.isNode(props) ? props : t.objectExpression(Object.keys(props).map(function (key) { | ||
@@ -118,3 +145,3 @@ var value = props[key]; | ||
var newTag = typeof tag === 'string' ? t.stringLiteral(tag) : tag; | ||
var newProps = !Array.isArray(props) ? propsNode(props) : spreadNode(props, state); | ||
var newProps = props ? spreadNode(flatten(props), state) : t.nullLiteral(); | ||
var newChildren = t.arrayExpression(children.map(childMapper)); | ||
@@ -142,6 +169,7 @@ return createVNode(newTag, newProps, newChildren); | ||
Object.assign = function () { | ||
var obj; | ||
var objs = [], len = arguments.length; | ||
while ( len-- ) objs[ len ] = arguments[ len ]; | ||
return objs; | ||
return ( obj = {}, obj[symbol] = objs, obj ); | ||
}; | ||
@@ -169,3 +197,4 @@ | ||
var tree = treeify(statics, expr); | ||
path.replaceWith(transform(tree, state)); | ||
var node = !Array.isArray(tree) ? transform(tree, state) : t.arrayExpression(tree.map(function (root) { return transform(root, state); })); | ||
path.replaceWith(node); | ||
} | ||
@@ -172,0 +201,0 @@ } |
{ | ||
"name": "babel-plugin-htm", | ||
"version": "2.0.0", | ||
"version": "2.1.0", | ||
"description": "Babel plugin to compile htm's Tagged Template syntax to hyperscript or inline VNodes.", | ||
@@ -35,4 +35,4 @@ "main": "dist/babel-plugin-htm.js", | ||
"devDependencies": { | ||
"microbundle": "^0.8.3" | ||
"microbundle": "^0.10.1" | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
16888
313
0