Skip to content

named import prefix#362

Merged
Perryvw merged 3 commits intoTypeScriptToLua:ts-to-lua-astfrom
TheLartians:prefix-import-identifiers
Jan 26, 2019
Merged

named import prefix#362
Perryvw merged 3 commits intoTypeScriptToLua:ts-to-lua-astfrom
TheLartians:prefix-import-identifiers

Conversation

@TheLartians
Copy link
Copy Markdown
Contributor

Prevent global shadowing by adding an tstl prefix to imported modules when using named imports.
Example below.

import {printer} from "./print";
declare let print;
print("test"); // errors as print has been overridden by named import 

@TheLartians TheLartians changed the title prefix import identifiers named import prefix Jan 26, 2019
return tstl.createDoStatement(this.transformStatements(block.statements), undefined, block);
}

public tstlIdentifier(name: 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.

Having doubts if this should be a function. It would probably be better to just format the string inside the import declaration function, since that is the only place it's used anyway

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.

Ok, I moved the method into a local arrow function. I still like the function as it is more readable and maintainable imo.

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.

Was thinking more along the lines of const importName = "__TSTL_" + path.basename(importPath) but this is okay too

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.

Yeah that does make more sense when used only here. On the other hand wouldn't it be nice to have some common prefix for all tstl auxiliary variables?

@Perryvw Perryvw merged commit 10f884a into TypeScriptToLua:ts-to-lua-ast Jan 26, 2019
@TheLartians TheLartians deleted the prefix-import-identifiers branch February 17, 2019 18:18
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