Skip to content

typeof improvements - #625

Merged
tomblind merged 3 commits into
masterfrom
feature/typeof-improvements
Jun 6, 2019
Merged

typeof improvements#625
tomblind merged 3 commits into
masterfrom
feature/typeof-improvements

Conversation

@tomblind

@tomblind tomblind commented Jun 6, 2019

Copy link
Copy Markdown
Collaborator

closes #613
fixes #612

typeof is now transpiled into a lib function, except in cases where it is directly compared to a string literal, in which case lua's type() is used and the literal is changed (if needed).

Comment thread src/LuaTransformer.ts Outdated
Comment thread test/unit/typechecking.spec.ts Outdated
const code = `
let val = ${expression};
if (typeof val ${operator} "${compareTo}") {
return "TRUE";

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 looks a little odd, any reason you don't just return typeof val ${operator} "${compareTo}"?

Comment thread src/LuaTransformer.ts
Comment thread src/LuaTransformer.ts
case ts.SyntaxKind.SlashToken:
case ts.SyntaxKind.PercentToken:
case ts.SyntaxKind.PercentToken: {
const lhs = this.transformExpression(expression.left);

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 we calculate these in here at all, instead of inside transformBinaryOperation? Seems like a historic thing that's probably not relevant anymore?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

transformBinaryOperation expects already transformed expressions, because it is sometimes given manually constructed ones (like from compound assignments)

@tomblind
tomblind merged commit 2835c51 into master Jun 6, 2019
@tomblind
tomblind deleted the feature/typeof-improvements branch June 6, 2019 19:49
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.

Optimize typeof comparisions typeof nil should be undefined

2 participants