Skip to content

JS backend: Python _ discard variable in destructuring not declared #326

@ldayton

Description

@ldayton

Summary

Python's _ discard pattern in tuple unpacking is transpiled to JS destructuring without declaring _, producing a ReferenceError at runtime.

Reproduction

Source Python:

token_type, _ = self._lex_peek_operator()

Transpiled JS:

[token_type, _] = this._lex_peek_operator();

_ is never declared with let/const, so this fails with ReferenceError: _ is not defined.

Expected JS (option A — empty slot):

[token_type, ] = this._lex_peek_operator();

Expected JS (option B — declare throwaway):

let _;
[token_type, _] = this._lex_peek_operator();

Impact

2 instances in the Parable transpilation, both in _parse_simple_pipeline. Causes a crash when parsing any pipeline expression.

Discovered via ldayton/Parable#413.

Metadata

Metadata

Assignees

No one assigned

    Labels

    backendbugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions