Skip to content

Bunch of bugfixes#176

Merged
lolleko merged 21 commits intomasterfrom
feature/glua-target
Sep 4, 2018
Merged

Bunch of bugfixes#176
lolleko merged 21 commits intomasterfrom
feature/glua-target

Conversation

@lolleko
Copy link
Copy Markdown
Member

@lolleko lolleko commented Aug 20, 2018

EDIT: At first this was suposed to add support for glua (garrysmode lua).

Turns out we can just use the JIT lua target instead if we leave the module handling to the user via gmods include functions.

This PR contains a bunch of fixes, of bugs that I encountered while testing the transpiler with gmod lua.

  • LuaTarget options is no longet case sensitive
  • Added Array.concat
  • Added support for spread element (Array.push(...antoherArray))
  • Added Exception if !MetaExtension or !Extension class is instantiated via new
  • Filter imports of MetaExtension or Extension classes
  • Fixed issue where GetAccessors would not be detected if used inside a class e.g: this.Something with something being a get accessor
  • Improved performance of Array.push by using a numeric loop

@Janne252
Copy link
Copy Markdown
Contributor

Is targeting a video game variant of Lua within the scope of this project? I feel like this could fit better as a plugin for this library. I don't know if plugins have ever been discussed for this project, but I'd imagine a plugin could for example inherit one of the "standard" targets (5.1, 5.2, etc.) and become active if the plugin's target identifier is used in transpilation args.

@lolleko
Copy link
Copy Markdown
Member Author

lolleko commented Aug 21, 2018

We were discussing that aswell. I think, as long as we dont have a plugin architecture it is fine having this in here. Mainly because i dont want to maintain a fork, while there is still a lot of work to do here. Also glua is probably one of the most used lua dialects out there.

Typescript also has support for jsx (angular, react ....) built-in which is similiar to our situation with videogame versions of lua.

#179

@lolleko lolleko changed the title glua target Bunch of bugfixes Aug 30, 2018
@lolleko lolleko requested a review from Perryvw August 30, 2018 11:17
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.

Looks good but I really dont like the lualib hacky stuff and disabling of ts-lint. We could either solve it in this PR or merge and definitely have to revisit it later.


const imports = node.importClause.namedBindings;

const reqKeyword = this.getRequireKeyword();
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.

Abbreviation goes against our coding style.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I forgot to remove that whole getRequireKeyword function. It was used to replace require with include should I keep it or remove it?

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.

Keep it if it serves a purpose, otherwise remove it.


imports.elements.forEach(element => {
const filteredElements = imports.elements.filter(e => {
const decs = tsHelper.getCustomDecorators(this.checker.getTypeAtLocation(e), this.checker);
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.

abbreviation

@@ -0,0 +1,24 @@
/* tslint:disable */
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.

Why is this disabled here? I think we should be linting these files.

for (let i = 0; i < args.length; i++) {
const arg = args[i];
// Hack because we don't have an isArray function
if (pcall(() => (arg as any[]).length) && type(arg) !== "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.

Ew, there must be a better way to do this, or maybe we should just do some assumptions here.

Copy link
Copy Markdown
Member Author

@lolleko lolleko Aug 30, 2018

Choose a reason for hiding this comment

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

Cant really make assumptions here a type(arg) == "table" check won't work since you are allowed to pass objects to concat.

Only other solution I could think of is iterating the table with pairs and checking if each key is a number, I didn't choose that variant for performance reasons.

function __TS__ArrayPush<T>(arr: T[], ...items: T[]): number {
for (const item of items) {
arr[arr.length] = item;
/* tslint:disable */
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.

We shouldn't be disabling linting like this. Instead we should just transpile for ... of using a numeric loop to solve it at that level.

Copy link
Copy Markdown
Member Author

@lolleko lolleko Aug 30, 2018

Choose a reason for hiding this comment

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

Not really in the scope of this PR.
We could also just disable the for...of rule in our tslint config, I'm not a big fan of that rule anyway.

@lolleko lolleko merged commit ac5cfd1 into master Sep 4, 2018
@lolleko lolleko deleted the feature/glua-target branch September 4, 2018 15:09
@lolleko lolleko mentioned this pull request Sep 5, 2018
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.

3 participants