Microsoft/TypeScript

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

Open

#35,879 建立於 2019年12月27日

在 GitHub 查看
 (0 留言) (0 反應) (0 負責人)TypeScript (6,726 fork)batch import
BugDomain: JS EmitHelp Wanted

倉庫指標

Star
 (48,455 star)
PR 合併指標
 (平均合併 6天 17小時) (30 天內合併 9 個 PR)

描述

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

貢獻者指南