For AI agents: the complete documentation index is available at /tc39-atlas/en/llms.txt, the full documentation bundle is available at /tc39-atlas/en/llms-full.txt, and this page is available as Markdown at /tc39-atlas/en/proposals/proposal-from-import.md.
  • English
  • from ... import ?

    Proposal details
    Proposal overview

    This proposal addresses the pain of code completion in the current order of import and from, and proposes the inverse syntax from . import . to allow better completion of module specifiers. The proposal also discusses edge cases such as imports without bindings and interaction with module attributes, and raises concerns about grammar growth and ASI-related issues.

    Note

    The README below comes from the upstream repository and may contain outdated stage or status metadata. Use the proposal details above as the current source of truth.

    from ... import ...;

    Champion: Bradley Farias (@bmeck)

    Stage: 0

    Code completion is painful for the current order of import and from. This proposal seeks to add the inverse to make code completion work.

    from "foo" import {bar};

    Explanation

    Status Quo

    import /*code completion here*/

    Could be a string for the module specier, or the list of imported binding.

    • Tools cannot statically determine the list of possible bindings without the specifier, but it hasn't been added to the code yet.
    • Tools can create a good completion by inserting the specifier, but doing so means a programmer needs to reposition the cursor to insert binding names which is the common case of imports.
    import "foo"/*code completion/programmer moves caret here after typing*/
       // ^ code completion caret needs to be here for binding names

    Proposed

    from /*code completion here*/

    Module specifiers are the only thing that could be here to allow better code completion.

    Imports without bindings

    import "a";

    Just for posterity we can add the from prefixed form, even though it is more verbose:

    from "a" import;

    Working with other proposals

    Module attributes

    The position of module attributes would still be at the end.

    from "./foo.json" import foo with type="json"

    Concerns

    • We would be growing the grammar without any new semantics added to the language.
    • We would need to have different [no LineTerminator here] rules in this form of import.
    // allowed currently
    import
    	* as foo
    from
            'foo';

    Due to from needing to be a contextual keyword it needs to avoid problems with ASI and would have a grammar like:

    from [no LineTerminator here] ModuleSpecifier import ImportClause?