Skip to content

devlato/proposal-from-import

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 

Repository files navigation

proposal-from-import

Proposal for Python-like import syntax extension

Example

from 'module' import defaultExport;
from 'module' import { export1, export2 [, ...] };
from 'module' import defaultExport, { export1, export2 [, ...] };
from 'module' import defaultExport, { export1 as alias1, export2 as alias2 [, ...] };
from 'module' import defaultExport, { export1, export2 as alias2 [, ...] };
from 'module' import defaultExport, * as moduleName;

Motivation

The specification says that currently proposed syntax means static code import. The actual module code is being imported before any code runs. This approach gives ample possibilities for performing static checking. That's why advanced autocompletion features are possible. But with current syntax it's not convinient to use the autocompletion features at all. Until user typed a module name, a text editor cannot deduct what to complete. So developer has to type at least import from 'module' and start typing braces after import word then to get autocompletion running. It doesn't feel so much convenient. The Python-like syntax from 'module' import ... feels more organic way to import using autocompletion. So here comes this proposal to add support for this syntax too. The examples provided below show the main difference.

In this first example a developer has to type everything else before actually typing exported field names to get autocompletiong running.

import { Component } from 'react';

In the second example a developer could just type an import statement in an organic left-to-right way. An editor will be able to identify the module name even before typing an opening brace, so autocompletion will run when expected.

from 'react' import { Component };

So... you want this instead of import ... from?

No. The proposal offers this syntax as an alternative to import ... from syntax, but not as a replacement. The semantics of this syntactical extension is totally the same as of usual import ... from.