Skip to content

[compiler] IfExpressions generating undefined instead of null #40

@wcjohnson

Description

@wcjohnson

Problem

[email protected]:

x = if a:
  if b: c
const x = a ? b ? c : void 0 : null;

If a is false, x === null, but if a is true and b is false, x === undefined; this is inconsistent with the defined behavior of IfExpressions which is to produce null when the alternate is omitted.

Cause

This:
https://github.com/lightscript/babel-plugin-lightscript/blob/eb650acf69a17f0e4af9ce10a4c1bdeacec1e9e7/src/index.js#L504
which leads to this:
https://github.com/babel/babel/blob/1e55653ac173c3a59f403a7b5269cf6d143d32d9/packages/babel-traverse/src/path/replacement.js#L195
which leads to this:
https://github.com/babel/babel/blob/master/packages/babel-types/src/converters.js#L47

Babel's algorithm for converting statements to expressions produces undefined by default.

Resolution

It is probably necessary to recapitulate this algorithm inside the lsc transform and make sure it makes nulls here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions