Skip to content

Commit

Permalink
add support to acorn_loose
Browse files Browse the repository at this point in the history
  • Loading branch information
sergioramos committed Jun 20, 2017
1 parent 924f9ea commit 9350da7
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions inject.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@ var XHTMLEntities = require('./xhtml');
var hexNumber = /^[\da-fA-F]+$/;
var decimalNumber = /^\d+$/;

module.exports = function(acorn) {
module.exports = function(acorn, injectable) {
if (!injectable) {
injectable = acorn;
acorn = require('acorn');
}

var tt = acorn.tokTypes;
var tc = acorn.tokContexts;

Expand Down Expand Up @@ -368,7 +373,7 @@ module.exports = function(acorn) {
return this.jsx_parseElementAt(startPos, startLoc);
};

acorn.plugins.jsx = function(instance, opts) {
var toInject = function(instance, opts) {
if (!opts) {
return;
}
Expand Down Expand Up @@ -438,5 +443,17 @@ module.exports = function(acorn) {
});
};

return acorn;
['pluginsLoose', 'plugins'].forEach(function(key) {
if (injectable[key] && !injectable[key].jsx) {
injectable[key].jsx = toInject;
return;
}

if (acorn[key] && !acorn[key].jsx) {
acorn[key].jsx = toInject;
return;
}
});

return injectable;
};

0 comments on commit 9350da7

Please sign in to comment.