aabtop / reify

Reify lets you embed a customized TypeScript runtime within a C++ application.
MIT License
6 stars 0 forks source link

Enable module scripts via support for es2015 modules. #2

Closed aabtop closed 4 years ago

aabtop commented 4 years ago

This is kind of a no-brainer issue, it's just a matter of time/priority.

The TypeScript compiler supports various different module settings, one of which is 'es2015'. By supporting this, we would enable scripts to be defined in separate files which is good for two reasons:

1) Script code can be reused. 2) Reused code can be cached and also v8-snapshotted, improving startup time.

aabtop commented 4 years ago

To be clear, this is probably going to imply a change in two areas:

1) The TS compiler will need to have the ability to load external files, in order to open *.d.ts declaration files. 2) We will need to add hooks to V8 somewhere to enable it to load external files (as part of the "import" implementation). Luckily, it seems like V8 will have already dealt with all the module management complexity.

aabtop commented 4 years ago

I think it may also be necessary to import the reify interface as a module at the beginning of each input script as well, otherwise external TypeScript tools (e.g. like IDE error checkers/linters) won't know about the definitions.

aabtop commented 4 years ago

Yet another reason to get this implemented is so that we can have proper line numbers in generated error messages. As is, we're just prepending code to the beginning of the user's input.

aabtop commented 4 years ago

Okay, with 656ae8c18c42ea5d3d4414e42b544d0250de257e, support for modules is added to both the TypeScript compiler and the V8 runtime environment, so the main thrust of this issue is now resolved.

That said, support still needs to be added for actually defining and implementing a model for loading externally referenced user modules, which is now captured in issue #6 , so I will close this issue.