How to use the acorn-dynamic-import/lib/inject function in acorn-dynamic-import

To help you get started, we’ve selected a few acorn-dynamic-import examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github SevInf / heiss / src / server / parseModule.ts View on Github external
import * as acorn from 'acorn';
import injectDynamicImportPlugin from 'acorn-dynamic-import/lib/inject';
import injectImportMetaPlugin from 'acorn-import-meta/inject';
import { Program } from 'estree';

const parse = injectImportMetaPlugin(injectDynamicImportPlugin(acorn)).parse;

export function parseModule(source: string): Program {
    return parse(source, {
        sourceType: 'module',
        plugins: {
            dynamicImport: true,
            importMeta: true
        }
    });
}