|
| 1 | +/* Generated by `npm run build`, do not edit! */ |
| 2 | + |
| 3 | +"use strict" |
| 4 | + |
| 5 | +var skipWhiteSpace = /(?:\s|\/\/.*|\/\*[^]*?\*\/)*/g |
| 6 | + |
| 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") |
| 35 | + } |
| 36 | + }) |
| 37 | + |
| 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) } |
| 42 | + |
| 43 | + var node = this.startNode() |
| 44 | + var expr = this.parseExpression() |
| 45 | + return this.parseExpressionStatement(node, expr) |
| 46 | + } |
| 47 | + }) |
| 48 | + } |
| 49 | + return acorn |
| 50 | +} |
0 commit comments