Skip to content

Refactor: convert to ESM module (.js files) #19719

Closed
@mhegazy

Description

@mhegazy
  • var mod = require('mod'); =>

    • if mod is callable then import mod from 'mod'
    • else mod is not callable the import { a, b } from "mod" and replace mod.a and mod.b
    • namespace import should ever be used?
  • var mod= require('mod').a; => import { a } from "mod";

  • const { a } = require('mod'); => import { a } from "mod";

  • if (__DEV__) { var warning = require('warning'); }

    • disallowed?
    • have two actions? one sync and one async?
  • function f() { var warning = require('warning'); } => async function f() { var warning = await import('warning'); }

    • maybe do nothing here as well
  • module.exports = EventPlugin; => export default EventPlugin;

  • fix imports in other files
  • should we also fix require("mod") to require("mod").default?
  • module.exports.blah = 0 => export const blah = 0

    • should we support this too
      var myModule = module.exports = exports = {};
      myModule.a = 0;
      
    • this is another common pattern in CJS modules that we should consider supporting
    • we already have handling for this in the binder in .js files
  • module.exports = require('mod'); => export * from 'mod';

  • module.exports = {foo: function () { } ... } => export function foo() {} ?

    • is this even common enough to support?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Domain: Refactoringse.g. extract to constant or function, rename symbolFixedA PR has been merged for this issueSuggestionAn idea for TypeScript

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions