Closed
Description
Simple example:
add.ts
export default function add(a: i32, b: i32): i32 {
return a + b;
}
main.ts
import add from './add';
export function getValue(): i32 {
return add(40, 2);
}
Currently both default import and default export syntax are a syntax error. In JS, this is mostly just syntax sugar over a named export called "default", so I think the expected behavior is reasonably straightforward.
I can try taking this on. Some initial thoughts on the steps/details:
- Add support for
import {default as foo} from './foo';
andexport {foo as default};
so the other syntaxes can be tested individually. - Extend
ImportStatement
to have a default-imported name and make it behave likeimport {default as foo}
. - Add a new
CommonFlags.EXPORT_DEFAULT
and mark it onexport default function
andexport default class
statements. I think these are technically live bindings for the class/function name, if specified, but maybe AssemblyScript should/does disallow overwriting classes and functions anyway? - Add a new statement type
ExportDefaultStatement
forexport default [expression];
. Hopefully this can be implemented similarly toexport const
.
Does that sound reasonable?