WIP - add extractor, generate snippet_data
This commit is contained in:
4
node_modules/acorn-dynamic-import/src/index.js
generated
vendored
Normal file
4
node_modules/acorn-dynamic-import/src/index.js
generated
vendored
Normal file
@ -0,0 +1,4 @@
|
||||
import * as acorn from 'acorn';
|
||||
import inject from './inject';
|
||||
|
||||
export default inject(acorn);
|
||||
52
node_modules/acorn-dynamic-import/src/inject.js
generated
vendored
Normal file
52
node_modules/acorn-dynamic-import/src/inject.js
generated
vendored
Normal file
@ -0,0 +1,52 @@
|
||||
/* 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;
|
||||
}
|
||||
12
node_modules/acorn-dynamic-import/src/walk.js
generated
vendored
Normal file
12
node_modules/acorn-dynamic-import/src/walk.js
generated
vendored
Normal file
@ -0,0 +1,12 @@
|
||||
import * as walk from 'acorn/dist/walk';
|
||||
import { DynamicImportKey } from './inject';
|
||||
|
||||
export function inject(injectableWalk) {
|
||||
return Object.assign({}, injectableWalk, {
|
||||
base: Object.assign({}, injectableWalk.base, {
|
||||
[DynamicImportKey]() {},
|
||||
}),
|
||||
});
|
||||
}
|
||||
|
||||
export default inject(walk);
|
||||
Reference in New Issue
Block a user