Skip to content

Ineffective Parsing of Modern JavaScript Syntax in TypeScript to JavaScript Conversion #64

@thomasbuilds

Description

@thomasbuilds

The TypeScript to JavaScript parser struggles with modern syntax, such as optional chaining, leading to suboptimal code generation. For example, when processing the with-auth example in lib/Context.js, selecting JavaScript output instead of TypeScript results in complex and unnecessary code like the _optionalChain function:

 function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }import { createContext, useContext, } from "solid-js";
import { useLocation, createAsync, useAction } from "@solidjs/router";
import { querySession, logout } from ".";

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