Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/LuaAST.ts
Original file line number Diff line number Diff line change
Expand Up @@ -829,6 +829,7 @@ export function createMethodCallExpression(

export interface Identifier extends Expression {
kind: SyntaxKind.Identifier;
exportable: boolean;
text: string;
originalName?: string;
symbolId?: SymbolId;
Expand All @@ -846,6 +847,7 @@ export function createIdentifier(
parent?: Node
): Identifier {
const expression = createNode(SyntaxKind.Identifier, tsOriginal, parent) as Identifier;
expression.exportable = true;
expression.text = text;
expression.symbolId = symbolId;
expression.originalName = originalName;
Expand All @@ -858,6 +860,7 @@ export function cloneIdentifier(identifier: Identifier, tsOriginal?: ts.Node): I

export function createAnonymousIdentifier(tsOriginal?: ts.Node, parent?: Node): Identifier {
const expression = createNode(SyntaxKind.Identifier, tsOriginal, parent) as Identifier;
expression.exportable = false;
expression.text = "____";
return expression;
}
Expand Down
4 changes: 4 additions & 0 deletions src/LuaTransformer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5480,6 +5480,10 @@ export class LuaTransformer {
identifier: tstl.Identifier,
exportScope?: ts.SourceFile | ts.ModuleDeclaration
): tstl.AssignmentLeftHandSideExpression {
if (!identifier.exportable) {
return identifier;
}

const exportTable =
exportScope && ts.isModuleDeclaration(exportScope)
? this.createModuleLocalNameIdentifier(exportScope)
Expand Down
15 changes: 5 additions & 10 deletions test/unit/destructuring.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,11 @@ test.each(testCases)("in variable declaration (%p)", ({ binding, value }) => {
`.expectToMatchJsResult();
});

// TODO: https://github.com/TypeScriptToLua/TypeScriptToLua/issues/695
// TODO: https://github.com/microsoft/TypeScript/issues/32656
test.each(testCases.filter(x => x.binding !== "[x, , y]" && x.binding !== "{ x, ...rest }"))(
"in exported variable declaration (%p)",
({ binding, value }) => {
util.testModule`
export const ${binding} = ${value};
`.expectToMatchJsResult();
}
);
test.each(testCases)("in exported variable declaration (%p)", ({ binding, value }) => {
util.testModule`
export const ${binding} = ${value};
`.expectToMatchJsResult();
});

const assignmentTestCases = [
...testCases,
Expand Down