Skip to content

Document and/or fix ES6 Module incompatibilities #2

@yortus

Description

@yortus

Hi @Macmee,

I have another suggestion. Looking at the replacements the hook function makes, I see a few incompatibilities/omissions compared to how 'real' ES6 modules would behave. You've probably already come across the MDN import and export pages, and Axel Rauschmayer eBook. Perhaps you could list which syntax is supported/unsupported in your README.

  • export default X is not the same as module.exports = X. It actually creates an export named 'default'.
  • import X from './X' is not the same as const X = require('./X'), it's more like const X = require('./X').default (but see next point)
  • exported values can be modified by their exporting module, and all import sites will instantly see the updated value. E.g. if module A contains export let x = 1; setTimeout(() => ++x, 1000);, and module B has import {x} from './A', then the x variable in module B will change form 1 to 2 after a second. This allows ES6 modules to support circular references.
  • ES6 imports are hoisted.
  • various ES6 syntaxes appear not to be supported here, e.g.:
    • import {foo as myFoo} from './module'
    • import './module'
    • import * as fs from 'fs'
    • import main, {other, another} from './module'
    • export default (/* absolutely any expression */)
    • export {foo, bar}
    • export {x} from './module'
    • export {x as default} from './module'

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