Skip to content

Commit 9350da7

Browse files
committed
add support to acorn_loose
1 parent 924f9ea commit 9350da7

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

inject.js

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,12 @@ var XHTMLEntities = require('./xhtml');
55
var hexNumber = /^[\da-fA-F]+$/;
66
var decimalNumber = /^\d+$/;
77

8-
module.exports = function(acorn) {
8+
module.exports = function(acorn, injectable) {
9+
if (!injectable) {
10+
injectable = acorn;
11+
acorn = require('acorn');
12+
}
13+
914
var tt = acorn.tokTypes;
1015
var tc = acorn.tokContexts;
1116

@@ -368,7 +373,7 @@ module.exports = function(acorn) {
368373
return this.jsx_parseElementAt(startPos, startLoc);
369374
};
370375

371-
acorn.plugins.jsx = function(instance, opts) {
376+
var toInject = function(instance, opts) {
372377
if (!opts) {
373378
return;
374379
}
@@ -438,5 +443,17 @@ module.exports = function(acorn) {
438443
});
439444
};
440445

441-
return acorn;
446+
['pluginsLoose', 'plugins'].forEach(function(key) {
447+
if (injectable[key] && !injectable[key].jsx) {
448+
injectable[key].jsx = toInject;
449+
return;
450+
}
451+
452+
if (acorn[key] && !acorn[key].jsx) {
453+
acorn[key].jsx = toInject;
454+
return;
455+
}
456+
});
457+
458+
return injectable;
442459
};

0 commit comments

Comments
 (0)