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
2 changes: 2 additions & 0 deletions src/transformation/utils/diagnostics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,3 +177,5 @@ export const annotationDeprecated = createWarningDiagnosticFactory(
`'@${kind}' is deprecated and will be removed in a future update. Please update your code before upgrading to the next release, otherwise your project will no longer compile. ` +
`See https://typescripttolua.github.io/docs/advanced/compiler-annotations#${kind.toLowerCase()} for more information.`
);

export const optionalChainingNotSupported = createErrorDiagnosticFactory("Optional chaining is not supported yet.");
6 changes: 5 additions & 1 deletion src/transformation/visitors/access.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as lua from "../../LuaAST";
import { transformBuiltinPropertyAccessExpression } from "../builtins";
import { FunctionVisitor, TransformationContext } from "../context";
import { AnnotationKind, getTypeAnnotations } from "../utils/annotations";
import { invalidMultiReturnAccess } from "../utils/diagnostics";
import { invalidMultiReturnAccess, optionalChainingNotSupported } from "../utils/diagnostics";
import { addToNumericExpression } from "../utils/lua-ast";
import { LuaLibFeature, transformLuaLibFunction } from "../utils/lualib";
import { isArrayType, isNumberType, isStringType } from "../utils/typescript";
Expand Down Expand Up @@ -63,6 +63,10 @@ export const transformPropertyAccessExpression: FunctionVisitor<ts.PropertyAcces
expression,
context
) => {
if (ts.isOptionalChain(expression)) {
context.diagnostics.push(optionalChainingNotSupported(expression));
}

const constEnumValue = tryGetConstEnumValue(context, expression);
if (constEnumValue) {
return constEnumValue;
Expand Down
9 changes: 9 additions & 0 deletions test/unit/optionalChaining.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { optionalChainingNotSupported } from "../../src/transformation/utils/diagnostics";
import * as util from "../util";

test("Diagnostic optional chaining is not supported yet", () => {
util.testFunction`
let func = (value: number) => value != 0 ? {value} : undefined;
return func(1)?.value;
`.expectToHaveDiagnostics([optionalChainingNotSupported.code]);
});