Skip to content

Commit

Permalink
NPM neverending discussion
Browse files Browse the repository at this point in the history
More info here:

- npm/npm#3055
- yarnpkg/yarn#2875
  • Loading branch information
fcsonline committed May 16, 2017
1 parent ccb8e4c commit 38fbf08
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/node_modules

# build
/lib
#/lib

# log
*.log
Expand Down
42 changes: 42 additions & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
'use strict';

Object.defineProperty(exports, "__esModule", {
value: true
});

exports.default = function (_ref) {
var t = _ref.types;

var defaultPrefix = 'data-qa';
var defaultDebugProperty = 'qa';

var prefix = void 0;
var componentAttr = void 0;

var visitor = {
Program: function Program(path, state) {
if (state.opts.prefix) {
prefix = 'data-' + state.opts.prefix;
} else {
prefix = defaultPrefix;
}
componentAttr = prefix + '-component';
},
JSXOpeningElement: function JSXOpeningElement(path, state) {
var attributes = path.container.openingElement.attributes;
var newAttributes = [];

if (state.file && state.file.opts) {
var source = state.file.opts.sourceFileName.replace(/\/index.jsx$/, '').replace(/.jsx$/, '');

newAttributes.push(t.jSXAttribute(t.jSXIdentifier(componentAttr), t.jSXExpressionContainer(t.logicalExpression('&&', t.memberExpression(t.identifier('__DEBUG'), t.identifier(defaultDebugProperty)), t.stringLiteral(source)))));
}

attributes.push.apply(attributes, newAttributes);
}
};

return {
visitor: visitor
};
};

0 comments on commit 38fbf08

Please sign in to comment.