This repository has been archived by the owner on Jun 12, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
47 lines (39 loc) · 1.63 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
41
42
43
44
45
46
47
"use strict"
const tt = require("acorn").tokTypes
const skipWhiteSpace = /(?:\s|\/\/.*|\/\*[^]*?\*\/)*/g
const nextTokenIsDot = parser => {
skipWhiteSpace.lastIndex = parser.pos
let skip = skipWhiteSpace.exec(parser.input)
let next = parser.pos + skip[0].length
return parser.input.slice(next, next + 1) === "."
}
module.exports = function(Parser) {
return class extends Parser {
parseExprAtom(refDestructuringErrors) {
if (this.type !== tt._import || !nextTokenIsDot(this)) return super.parseExprAtom(refDestructuringErrors)
if (!this.options.allowImportExportEverywhere && !this.inModule) {
this.raise(this.start, "'import' and 'export' may appear only with 'sourceType: module'")
}
let node = this.startNode()
if (this.containsEsc) this.raiseRecoverable(this.start, "Escape sequence in keyword import")
node.meta = this.parseIdent(true)
this.expect(tt.dot)
node.property = this.parseIdent(true)
if (node.property.name !== "meta") {
this.raiseRecoverable(node.property.start, "The only valid meta property for import is import.meta")
}
if (this.containsEsc) {
this.raiseRecoverable(node.property.start, "\"meta\" in import.meta must not contain escape sequences")
}
return this.finishNode(node, "MetaProperty")
}
parseStatement(context, topLevel, exports) {
if (this.type !== tt._import || !nextTokenIsDot(this)) {
return super.parseStatement(context, topLevel, exports)
}
let node = this.startNode()
let expr = this.parseExpression()
return this.parseExpressionStatement(node, expr)
}
}
}