Skip to content

Commit 757302b

Browse files
hazzard993ark120202
authored andcommitted
Avoid exporting anonymous identifiers (#756)
* Avoid exporting anonymous identifiers * Use existing test for anonymous destructuring * Remove TODO for issue 32656 with test filter * Update test/unit/destructuring.spec.ts Co-Authored-By: ark120202 <ark120202@gmail.com> * Update test/unit/destructuring.spec.ts Co-Authored-By: ark120202 <ark120202@gmail.com>
1 parent 3373e4a commit 757302b

File tree

3 files changed

+12
-10
lines changed

3 files changed

+12
-10
lines changed

src/LuaAST.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -829,6 +829,7 @@ export function createMethodCallExpression(
829829

830830
export interface Identifier extends Expression {
831831
kind: SyntaxKind.Identifier;
832+
exportable: boolean;
832833
text: string;
833834
originalName?: string;
834835
symbolId?: SymbolId;
@@ -846,6 +847,7 @@ export function createIdentifier(
846847
parent?: Node
847848
): Identifier {
848849
const expression = createNode(SyntaxKind.Identifier, tsOriginal, parent) as Identifier;
850+
expression.exportable = true;
849851
expression.text = text;
850852
expression.symbolId = symbolId;
851853
expression.originalName = originalName;
@@ -858,6 +860,7 @@ export function cloneIdentifier(identifier: Identifier, tsOriginal?: ts.Node): I
858860

859861
export function createAnonymousIdentifier(tsOriginal?: ts.Node, parent?: Node): Identifier {
860862
const expression = createNode(SyntaxKind.Identifier, tsOriginal, parent) as Identifier;
863+
expression.exportable = false;
861864
expression.text = "____";
862865
return expression;
863866
}

src/LuaTransformer.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5480,6 +5480,10 @@ export class LuaTransformer {
54805480
identifier: tstl.Identifier,
54815481
exportScope?: ts.SourceFile | ts.ModuleDeclaration
54825482
): tstl.AssignmentLeftHandSideExpression {
5483+
if (!identifier.exportable) {
5484+
return identifier;
5485+
}
5486+
54835487
const exportTable =
54845488
exportScope && ts.isModuleDeclaration(exportScope)
54855489
? this.createModuleLocalNameIdentifier(exportScope)

test/unit/destructuring.spec.ts

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -51,16 +51,11 @@ test.each(testCases)("in variable declaration (%p)", ({ binding, value }) => {
5151
`.expectToMatchJsResult();
5252
});
5353

54-
// TODO: https://github.com/TypeScriptToLua/TypeScriptToLua/issues/695
55-
// TODO: https://github.com/microsoft/TypeScript/issues/32656
56-
test.each(testCases.filter(x => x.binding !== "[x, , y]" && x.binding !== "{ x, ...rest }"))(
57-
"in exported variable declaration (%p)",
58-
({ binding, value }) => {
59-
util.testModule`
60-
export const ${binding} = ${value};
61-
`.expectToMatchJsResult();
62-
}
63-
);
54+
test.each(testCases)("in exported variable declaration (%p)", ({ binding, value }) => {
55+
util.testModule`
56+
export const ${binding} = ${value};
57+
`.expectToMatchJsResult();
58+
});
6459

6560
const assignmentTestCases = [
6661
...testCases,

0 commit comments

Comments
 (0)