Skip to content

Export default and export equals#670

Merged
Perryvw merged 25 commits intoTypeScriptToLua:masterfrom
hazzard993:default-exports
Jul 28, 2019
Merged

Export default and export equals#670
Perryvw merged 25 commits intoTypeScriptToLua:masterfrom
hazzard993:default-exports

Conversation

@hazzard993
Copy link
Copy Markdown
Contributor

Closes #606

As far as I know this PR should make TypeScriptToLua support all import and export statements. This doesn't include call expression import() (Promise).

Highlighted below are the new statements that can be written.

+ import defaultExport from "module-name";
  import * as name from "module-name";
  import { export } from "module-name";
  import { export as alias } from "module-name";
  import { export1 , export2 } from "module-name";
  import { foo , bar } from "module-name/path/to/specific/un-exported/file";
  import { export1 , export2 as alias2 , [...] } from "module-name";
+ import defaultExport, { export [ , [...] ] } from "module-name";
+ import defaultExport, * as name from "module-name";
  import "module-name";
  
  // Exporting individual features
  export let name1, name2, …, nameN; // also var, const
  export let name1 = …, name2 = …, …, nameN; // also var, const
  export function functionName(){...}
  export class ClassName {...}
  
  // Export list
  export { name1, name2, …, nameN };
  
  // Renaming exports
  export { variable1 as name1, variable2 as name2, …, nameN };
  
  // Exporting destructured assignments with renaming
  export const { name1, name2: bar } = o;
  
  // Default exports
+ export default expression;
+ export default function (…) { … }
+ export default function name1(…) { … }
+ export default class { … }
+ export default class Class { … }
+ export { name1 as default, … };
  
  // Aggregating modules
  export * from …;
  export { name1, name2, …, nameN } from …;
  export { import1 as name1, import2 as name2, …, nameN } from …;
+ export { default } from …;

  // Export only one value
+ export = 5;

Moved some path resolving logic over to tsHelper to allow it to be used by testing utilities. Using this I've made a new utility to functionally test module imports and exports.

@Perryvw Perryvw requested a review from ark120202 July 17, 2019 08:00
Copy link
Copy Markdown
Member

@Perryvw Perryvw left a comment

Choose a reason for hiding this comment

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

This is a little more than I expected, I'll continue reviewing later.

@codecov
Copy link
Copy Markdown

codecov bot commented Jul 20, 2019

Codecov Report

Merging #670 into master will increase coverage by 0.13%.
The diff coverage is 95.7%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #670      +/-   ##
==========================================
+ Coverage   94.13%   94.26%   +0.13%     
==========================================
  Files          16       16              
  Lines        4091     4133      +42     
  Branches      937      947      +10     
==========================================
+ Hits         3851     3896      +45     
+ Misses        206      203       -3     
  Partials       34       34
Impacted Files Coverage Δ
src/TSTLErrors.ts 88.17% <ø> (-0.49%) ⬇️
src/LuaTransformer.ts 95.89% <95.04%> (+0.13%) ⬆️
src/TSHelper.ts 94.7% <97.61%> (+0.45%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 26d7338...8932f1c. Read the comment docs.

}
}

protected getAbsoluteImportPath(relativePath: string): string {
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.

Any reason you moved these? I think they were located correctly in this file.

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.

I mainly moved them to tsHelper as it was logic that transpileAndExecuteProjectReturningMainExport needed.

The methods were not available to convert TypeScript path strings to Lua import and export path strings without constructing a LuaTransformer only to convert a string using those methods.

@Perryvw Perryvw merged commit 2c47c3b into TypeScriptToLua:master Jul 28, 2019
@hazzard993 hazzard993 deleted the default-exports branch July 29, 2019 23:47
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.

Support default imports/exports

3 participants