Microsoft/TypeScript

commonjs export binding produces invalid code for increment/decrement in PrefixUnaryExpression

オープン

#35,879 opened on 2019/12/27

 (0 件のコメント) (0 件のリアクション) (0 人の担当者)TypeScript (13,395 件のフォーク)batch import
BugDomain: JS EmitHelp Wanted

Repository metrics

Stars
 (108,860 個のスター)
PR merge metrics
 (PR metrics pending)

説明

TypeScript Version: 3.7.2

Search Terms: export increment decrement syntax error

Code

// @module: commonjs
let foo = 1;
export { foo };
while (!--foo) { }

Expected behavior:

while (!(exports.foo = --foo)) { }

Actual behavior:

Because the module-transform uses onSubstituteNode, it doesn't use the auto-parenthesizing that's done by the factory API.

while (!exports.foo = --foo) { } // SyntaxError: `!exports.foo` is no valid assignment target

Playground Link: https://www.typescriptlang.org/play/?target=99&module=1&ssl=3&ssc=19&pln=1&pc=1#code/DYUwLgBAZg9jEF4IEYDcAoEAPADjATpAN7RwQC+GA7gBYCWoEAFAIQC0bsMAlBCeUA

Related Issues: #33044

コントリビューターガイド