Skip to content

Index as argument name #2

@remcohaszing

Description

@remcohaszing

Currently custom imports require a name. This name must then be places into two places: as an option to moduleToFunction and as an argument to the function constructor.

const importName = '__import__'
const ast = parse(source, { ecmaVersion: 'latest', sourceType: 'module' })
// 1. Utility option
moduleToFunction(ast, { importName })
const transformed = generate(ast)
// 2. Function constructor
const fn = new AsyncFunction(importName, transformed)

It might be nice if the custom import can be taken from the arguments object, so the user doesn’t have to specify the importName argument for the function constructor.

- const importName = '__import__'
  const ast = parse(source, { ecmaVersion: 'latest', sourceType: 'module' })
  // 1. Utility option
- moduleToFunction(ast, { importName })
+ moduleToFunction(ast, { importName: 0 })
  const transformed = generate(ast)
  // 2. Function constructor
- const fn = new AsyncFunction(importName, transformed)
+ const fn = new AsyncFunction(transformed)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions