Skip to content

Commit 209f7ec

Browse files
committed
add support to acorn_loose
1 parent 05852d8 commit 209f7ec

File tree

2 files changed

+23
-6
lines changed

2 files changed

+23
-6
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

@@ -359,7 +364,7 @@ module.exports = function(acorn) {
359364
return this.jsx_parseElementAt(startPos, startLoc);
360365
};
361366

362-
acorn.plugins.jsx = function(instance, opts) {
367+
var toInject = function(instance, opts) {
363368
if (!opts) {
364369
return;
365370
}
@@ -429,5 +434,17 @@ module.exports = function(acorn) {
429434
});
430435
};
431436

432-
return acorn;
437+
['pluginsLoose', 'plugins'].forEach(function(key) {
438+
if (injectable[key] && !injectable[key].jsx) {
439+
injectable[key].jsx = toInject;
440+
return;
441+
}
442+
443+
if (acorn[key] && !acorn[key].jsx) {
444+
acorn[key].jsx = toInject;
445+
return;
446+
}
447+
});
448+
449+
return injectable;
433450
};

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@
1919
"test": "node test/run.js"
2020
},
2121
"dependencies": {
22-
"acorn": "^3.0.4"
22+
"acorn": "^4.0.2"
2323
},
2424
"devDependencies": {
25-
"chai": "^3.0.0",
26-
"mocha": "^2.2.5"
25+
"chai": "^3.5.0",
26+
"mocha": "^3.0.2"
2727
}
2828
}

0 commit comments

Comments
 (0)