-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
40 lines (34 loc) · 1.01 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
'use strict';
const tt = require('acorn').tokTypes;
module.exports = function(Parser) {
return class extends Parser {
// based on the source code acorn
parseImport(node, exports) {
this.next();
if (this.type === tt.string) {
node.specifiers = [];
node.source = super.parseExprAtom();
} else {
node.specifiers = super.parseImportSpecifiers();
if (this.value === '=') {
this.next();
const expr = this.parseExpression();
if (
expr.type !== 'CallExpression' ||
expr.arguments.length !== 1 ||
expr.arguments[0].type !== 'Literal'
) {
this.unexpected();
}
node.source = expr.arguments[0];
} else {
this.expectContextual('from');
node.source =
this.type === tt.string ? this.parseExprAtom() : this.unexpected();
}
}
this.semicolon();
return this.finishNode(node, 'ImportDeclaration');
}
};
};