Skip to content

Commit 948f71b

Browse files
authored
Added optional chaining unsupported diagnostic (#966)
1 parent 6ac1980 commit 948f71b

3 files changed

Lines changed: 16 additions & 1 deletion

File tree

src/transformation/utils/diagnostics.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,3 +177,5 @@ export const annotationDeprecated = createWarningDiagnosticFactory(
177177
`'@${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. ` +
178178
`See https://typescripttolua.github.io/docs/advanced/compiler-annotations#${kind.toLowerCase()} for more information.`
179179
);
180+
181+
export const optionalChainingNotSupported = createErrorDiagnosticFactory("Optional chaining is not supported yet.");

src/transformation/visitors/access.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import * as lua from "../../LuaAST";
33
import { transformBuiltinPropertyAccessExpression } from "../builtins";
44
import { FunctionVisitor, TransformationContext } from "../context";
55
import { AnnotationKind, getTypeAnnotations } from "../utils/annotations";
6-
import { invalidMultiReturnAccess } from "../utils/diagnostics";
6+
import { invalidMultiReturnAccess, optionalChainingNotSupported } from "../utils/diagnostics";
77
import { addToNumericExpression } from "../utils/lua-ast";
88
import { LuaLibFeature, transformLuaLibFunction } from "../utils/lualib";
99
import { isArrayType, isNumberType, isStringType } from "../utils/typescript";
@@ -63,6 +63,10 @@ export const transformPropertyAccessExpression: FunctionVisitor<ts.PropertyAcces
6363
expression,
6464
context
6565
) => {
66+
if (ts.isOptionalChain(expression)) {
67+
context.diagnostics.push(optionalChainingNotSupported(expression));
68+
}
69+
6670
const constEnumValue = tryGetConstEnumValue(context, expression);
6771
if (constEnumValue) {
6872
return constEnumValue;

test/unit/optionalChaining.spec.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { optionalChainingNotSupported } from "../../src/transformation/utils/diagnostics";
2+
import * as util from "../util";
3+
4+
test("Diagnostic optional chaining is not supported yet", () => {
5+
util.testFunction`
6+
let func = (value: number) => value != 0 ? {value} : undefined;
7+
return func(1)?.value;
8+
`.expectToHaveDiagnostics([optionalChainingNotSupported.code]);
9+
});

0 commit comments

Comments
 (0)