Skip to content

Refactor transpilation pipeline#885

Merged
Perryvw merged 8 commits intoTypeScriptToLua:masterfrom
ark120202:refactor-transpilation-pipeline
Jul 13, 2020
Merged

Refactor transpilation pipeline#885
Perryvw merged 8 commits intoTypeScriptToLua:masterfrom
ark120202:refactor-transpilation-pipeline

Conversation

@ark120202
Copy link
Copy Markdown
Contributor

@ark120202 ark120202 commented May 23, 2020

That's a preparation for #432 and #653. The outline of changes done:

  • Added a Transpiler class, which should be used instead of transpile. The reason for making it a class is that it also would take care of the emitted files state. That would be useful since with New module resolution and Compilation structure #432 we don't want to emit all referenced .lua files every single cycle.
  • Unlike transpile, Transpiler takes care of both transpiling and emitting. This is needed, because some emitted files may have no known sources (we actually already have that with bundle files), so a concept of TranspiledFile doesn't work here.
  • Since we can't use a structured TranspiledFile concept there, we'll either have to return a list of generic { fileName, text } objects or take writeFile callback. I have chosen the second approach to be symmetric with program.emit.

Changelog:

  • In preparation for some new features, few public APIs have been changed:
    • High-level APIs that read input files from the file system (transpileFiles and transpileProject) now write transpiled files by default. This behavior can be changed by providing a writeFile callback, similarly to TypeScript's program.emit.
    • transpile and emitTranspiledFiles functions have been replaced with the Transpiler class. See documentation for usage examples.
  • Fixed declarationDir option not being respected.

const file = util
.testFunction(code)
.setOptions({ inlineSourceMap: true })
.disableSemanticCheck() // TS5053: Option 'sourceMap' cannot be specified with option 'inlineSourceMap'.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couldn't we just add sourceMap: false to the setOptions call?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

file.luaSourceMap (which is used for comparison with inlined source map content) is parsed from generated .map file. Previously it did work because TranspiledFile.sourceMap property existed even without sourceMap: true option

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add this reasoning to the comment here? (ie 'We need the source map to compare to for the test')


const configFileName = path.resolve(__dirname, "src/lualib/tsconfig.json");
const { emitResult, diagnostics } = tstl.transpileProject(configFileName);
emitResult.forEach(({ name, text }) => ts.sys.writeFile(name, text));
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is no longer emitted? Doesn't this break lualib inlining?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

transpileProject now emits files itself (unless writeFile callback parameter is provided)

@ark120202 ark120202 marked this pull request as ready for review July 13, 2020 18:50
@Perryvw Perryvw merged commit 404ab4e into TypeScriptToLua:master Jul 13, 2020
@ark120202 ark120202 deleted the refactor-transpilation-pipeline branch July 16, 2020 02:21
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

Successfully merging this pull request may close these issues.

2 participants