Skip to content
This repository has been archived by the owner on Mar 23, 2018. It is now read-only.

Commit

Permalink
use setAttribute from yo-yoify@4
Browse files Browse the repository at this point in the history
  • Loading branch information
goto-bus-stop committed Sep 30, 2017
1 parent 06b3886 commit 7dab806
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 44 deletions.
19 changes: 0 additions & 19 deletions addDynamicAttributeHelper.js

This file was deleted.

6 changes: 2 additions & 4 deletions index.js
Expand Up @@ -117,9 +117,6 @@ module.exports = (babel) => {
)]
)

// 230ish bytes after uglify
const addDynamicAttributeHelper = babel.template(`(${require('./addDynamicAttributeHelper')})`)

const addDynamicAttribute = (helperId, id, attr, value) =>
t.callExpression(helperId, [id, attr, value])

Expand Down Expand Up @@ -322,6 +319,7 @@ module.exports = (babel) => {
},
exit (path) {
const appendChildModule = this.opts.appendChildModule || 'yo-yoify/lib/appendChild'
const setAttributeModule = this.opts.setAttributeModule || 'yo-yoify/lib/setAttribute'

if (this.appendChildId.used) {
path.scope.push({
Expand All @@ -332,7 +330,7 @@ module.exports = (babel) => {
if (this.setAttributeId.used) {
path.scope.push({
id: this.setAttributeId,
init: addDynamicAttributeHelper().expression
init: t.callExpression(t.identifier('require'), [t.stringLiteral(setAttributeModule)])
})
}
if (this.svgNamespaceId.used) {
Expand Down
21 changes: 1 addition & 20 deletions test/fixtures/dynamicAttr.expected.js
Expand Up @@ -2,26 +2,7 @@ var _halp,
_str,
_lol,
_abc,
_setAttribute = function setAttribute(el, attr, value) {
if (typeof attr == 'object') {
for (var i in attr) if (attr.hasOwnProperty(i)) {
setAttribute(el, i, attr[i]);
}

return;
}

if (!attr) return;
if (attr == 'className') attr = 'class';
if (attr == 'htmlFor') attr = 'for';

if (attr.slice(0, 2) == 'on') {
el[attr] = value;
} else {
if (value === true) value = attr;
el.setAttribute(attr, value);
}
};
_setAttribute = require('yo-yoify/lib/setAttribute');

var handler = isTouchDevice ? 'ontouchstart' : 'onmousedown';

Expand Down
7 changes: 6 additions & 1 deletion test/run.js
Expand Up @@ -25,7 +25,12 @@ test('interpolate objects', (t) => {
className: 'abc', // an attribute with a different property name
id: 'def', // a normal attribute
}
const context = { document, props, output: '' }
const context = {
document,
props,
require,
output: ''
}

vm.runInNewContext(src, context)
const str = context.output.outerHTML
Expand Down

0 comments on commit 7dab806

Please sign in to comment.