1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-14 22:34:59 +00:00
serenity/Libraries/LibJS/Tests/operators/ternary-basic.js
Linus Groh 0974991d05 LibJS: Don't treat '?.' followed by decimal digit as QuestionMarkPeriod
From the spec: https://tc39.es/ecma262/#sec-punctuators

    OptionalChainingPunctuator ::
        ?. [lookahead ∉ DecimalDigit]

We were missing the lookahead and therefore incorrectly treating any
'?.' as TokenType::QuestionMarkPeriod.

Fixes #4409.
2020-12-14 22:25:46 +01:00

20 lines
531 B
JavaScript

test("basic functionality", () => {
const x = 1;
expect(x === 1 ? true : false).toBeTrue();
expect(x ? x : 0).toBe(x);
expect(1 < 2 ? true : false).toBeTrue();
expect(0 ? 1 : 1 ? 10 : 20).toBe(10);
expect(0 ? (1 ? 1 : 10) : 20).toBe(20);
});
test("object values", () => {
const o = {};
o.f = true;
expect(o.f ? true : false).toBeTrue();
expect(1 ? o.f : null).toBeTrue();
});
test("issue #4409, '?.' followed by decimal digit", () => {
expect("return false?.1:.2").toEvalTo(0.2);
});