Skip to content

Commit 69f12a9

Browse files
committed
Update acorn-import-meta to v0.3.0.
1 parent f3ed507 commit 69f12a9

File tree

3 files changed

+46
-41
lines changed

3 files changed

+46
-41
lines changed

build.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,4 @@ function compile (name, output) { // eslint-disable-line no-unused-vars
1717
fs.writeFileSync(path.join(__dirname, output), HEADER + result.code, 'utf8')
1818
}
1919

20-
compile('acorn-import-meta/inject', './lib/import-meta/index.js')
20+
compile('acorn-import-meta', './lib/import-meta/index.js')

lib/import-meta/index.js

Lines changed: 44 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -2,49 +2,54 @@
22

33
"use strict"
44

5+
var tt = require("acorn").tokTypes
6+
57
var skipWhiteSpace = /(?:\s|\/\/.*|\/\*[^]*?\*\/)*/g
68

7-
module.exports = function (acorn) {
8-
var tt = acorn.tokTypes
9-
10-
var nextTokenIsDot = function (parser) {
11-
skipWhiteSpace.lastIndex = parser.pos
12-
var skip = skipWhiteSpace.exec(parser.input)
13-
var next = parser.pos + skip[0].length
14-
return parser.input.slice(next, next + 1) === "."
15-
}
16-
17-
acorn.plugins.importMeta = function (instance) {
18-
19-
instance.extend("parseExprAtom", function (superF) {
20-
return function(refDestructuringErrors) {
21-
if (this.type !== tt._import || !nextTokenIsDot(this)) { return superF.call(this, refDestructuringErrors) }
22-
23-
if (!this.options.allowImportExportEverywhere && !this.inModule) {
24-
this.raise(this.start, "'import' and 'export' may appear only with 'sourceType: module'")
25-
}
26-
27-
var node = this.startNode()
28-
node.meta = this.parseIdent(true)
29-
this.expect(tt.dot)
30-
node.property = this.parseIdent(true)
31-
if (node.property.name !== "meta") {
32-
this.raiseRecoverable(node.property.start, "The only valid meta property for import is import.meta")
33-
}
34-
return this.finishNode(node, "MetaProperty")
9+
var nextTokenIsDot = function (parser) {
10+
skipWhiteSpace.lastIndex = parser.pos
11+
var skip = skipWhiteSpace.exec(parser.input)
12+
var next = parser.pos + skip[0].length
13+
return parser.input.slice(next, next + 1) === "."
14+
}
15+
16+
module.exports = function(Parser) {
17+
return (function (Parser) {
18+
function anonymous () {
19+
Parser.apply(this, arguments);
20+
}
21+
22+
if ( Parser ) anonymous.__proto__ = Parser;
23+
anonymous.prototype = Object.create( Parser && Parser.prototype );
24+
anonymous.prototype.constructor = anonymous;
25+
26+
anonymous.prototype.parseExprAtom = function parseExprAtom (refDestructuringErrors) {
27+
if (this.type !== tt._import || !nextTokenIsDot(this)) { return Parser.prototype.parseExprAtom.call(this, refDestructuringErrors) }
28+
29+
if (!this.options.allowImportExportEverywhere && !this.inModule) {
30+
this.raise(this.start, "'import' and 'export' may appear only with 'sourceType: module'")
3531
}
36-
})
3732

38-
instance.extend("parseStatement", function (superF) {
39-
return function(declaration, topLevel, exports) {
40-
if (this.type !== tt._import) { return superF.call(this, declaration, topLevel, exports) }
41-
if (!nextTokenIsDot(this)) { return superF.call(this, declaration, topLevel, exports) }
33+
var node = this.startNode()
34+
node.meta = this.parseIdent(true)
35+
this.expect(tt.dot)
36+
node.property = this.parseIdent(true)
37+
if (node.property.name !== "meta") {
38+
this.raiseRecoverable(node.property.start, "The only valid meta property for import is import.meta")
39+
}
40+
return this.finishNode(node, "MetaProperty")
41+
};
4242

43-
var node = this.startNode()
44-
var expr = this.parseExpression()
45-
return this.parseExpressionStatement(node, expr)
43+
anonymous.prototype.parseStatement = function parseStatement (context, topLevel, exports) {
44+
if (this.type !== tt._import || !nextTokenIsDot(this)) {
45+
return Parser.prototype.parseStatement.call(this, context, topLevel, exports)
4646
}
47-
})
48-
}
49-
return acorn
47+
48+
var node = this.startNode()
49+
var expr = this.parseExpression()
50+
return this.parseExpressionStatement(node, expr)
51+
};
52+
53+
return anonymous;
54+
}(Parser))
5055
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"xtend": "^4.0.1"
1414
},
1515
"devDependencies": {
16-
"acorn-import-meta": "^0.2.1",
16+
"acorn-import-meta": "^0.3.0",
1717
"buble": "^0.19.3",
1818
"mkdirp": "^0.5.1",
1919
"standard": "^11.0.1",

0 commit comments

Comments
 (0)