Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trouble with "export async function"? #136

Closed
lll000111 opened this issue Mar 4, 2019 · 3 comments
Closed

Trouble with "export async function"? #136

lll000111 opened this issue Mar 4, 2019 · 3 comments

Comments

@lll000111
Copy link

lll000111 commented Mar 4, 2019

Output

I'll just show errors for one file. There are several. but the location always is an export async function line.

mha@mint-virtual-machine ~/Projects/one.moddable/DEVICE $ mcconfig -d -m -p lin
# xsc module-importer.xsb
# xsc instance.xsb
.../one.core/lib/module-importer.js:34: error: invalid export identifier!
.../one.core/lib/module-importer.js:42: error: missing ;!
.../one.core/lib/module-importer.js:62: error: missing ;!
### 3 error(s)
# xsc microdata-to-id-hash.xsb
/home/mha/Projects/moddable/build/tmp/lin/debug/mc/DEVICE/makefile:315: recipe for target '/home/mha/Projects/moddable/build/tmp/lin/debug/mc/DEVICE/modules/module-importer.xsb' failed
make: *** [/home/mha/Projects/moddable/build/tmp/lin/debug/mc/DEVICE/modules/module-importer.xsb] Error 22
make: *** Waiting for unfinished jobs....
...

Code

In module-importer, starting from line 34:

...
// NEXT LINE: #34
export async function createObjects(WriteStorage, {
  moduleName,
  version = '1.0',
  code
}) {
  let clobResult;

  try {
    clobResult = await WriteStorage.storeUTF8Clob(code);
  } catch (err) {
    err.stack += new Error().stack;
    throw err;
  }

  if (clobResult.status === CREATION_STATUS.EXISTS) {
    MessageBus.send('log', `Code CLOB ${clobResult.hash} already exists`);
  }

  const module = {
    type: 'Module',
    name: '@module/' + moduleName.replace(/\.js$/, ''),
    provides: [],
    requires: extractRequires(code),
    version,
    code: clobResult.hash
  };

  try {
    return await WriteStorage.storeVersionedObject(module);
  } catch (err) {
    err.stack += new Error().stack;
    throw err;
  }
}
@lll000111
Copy link
Author

lll000111 commented Mar 5, 2019

It indeed looks like this particular syntax causes problems.

Workaround

I removed the export from those functions and do an extra export {theFunction}; at the end of the file. Those errors have stopped showing up.

Instead of

export async function myFunc () {
   ...
}

I now write

async function myFunc () {
   ...
}

export {myFunc};

@phoddie
Copy link
Collaborator

phoddie commented Mar 7, 2019

Thank you for the detailed report. A fix will be available in the coming days.

@lll000111
Copy link
Author

Fixed in 5f92352

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants