This repository has been archived on 2024-07-27. You can view files and clone it, but cannot push or open issues or pull requests.
keksAccountGUI/node_modulesOLD/acorn-dynamic-import/src/inject.js

53 lines
1.4 KiB
JavaScript
Raw Normal View History

2019-08-11 18:48:02 +00:00
/* eslint-disable no-underscore-dangle */
export const DynamicImportKey = 'Import';
export default function injectDynamicImport(acorn) {
const tt = acorn.tokTypes;
// NOTE: This allows `yield import()` to parse correctly.
tt._import.startsExpr = true;
function parseDynamicImport() {
const node = this.startNode();
this.next();
if (this.type !== tt.parenL) {
this.unexpected();
}
return this.finishNode(node, DynamicImportKey);
}
function peekNext() {
return this.input[this.pos];
}
// eslint-disable-next-line no-param-reassign
acorn.plugins.dynamicImport = function dynamicImportPlugin(instance) {
instance.extend('parseStatement', nextMethod => (
function parseStatement(...args) {
const node = this.startNode();
if (this.type === tt._import) {
const nextToken = peekNext.call(this);
if (nextToken === tt.parenL.label) {
const expr = this.parseExpression();
return this.parseExpressionStatement(node, expr);
}
}
return nextMethod.apply(this, args);
}
));
instance.extend('parseExprAtom', nextMethod => (
function parseExprAtom(refDestructuringErrors) {
if (this.type === tt._import) {
return parseDynamicImport.call(this);
}
return nextMethod.call(this, refDestructuringErrors);
}
));
};
return acorn;
}