google / google/closure-compiler

Exporting a result of destructuring yields an internal compiler error

Open
#2,930 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
7.7k
Forks
1.2k
Avg merge
2d 12h
Merged PRs (30d)
6

Description

Compiling the following with --process_common_js_modules:
```
const { bar } = {};
console.log(bar);
module.exports = bar;
```
results in:
```
java.lang.RuntimeException: INTERNAL COMPILER ERROR.

The nameNode for Var bar @ NAME bar 1 [length: 3] [source_file: experimental/users/cyriln/js/a.js] must be a descendant of one of: [PARAM_LIST, FUNCTION, VAR, CATCH, CONST, CLASS, LET, IMPORT]
Node(NAME bar): experimental/users/cyriln/js/a.js:2:12
console.log(bar);
Parent(CALL): experimental/users/cyriln/js/a.js:2:0
console.log(bar);

Node(SCRIPT): experimental/users/cyriln/js/a.js:1:0
const { bar } = {};
Parent(ROOT): [source unknown]

at com.google.common.base.Preconditions.checkState(Preconditions.java:828)
at com.google.javascript.jscomp.AbstractVar.declarationType(AbstractVar.java:229)
at com.google.javascript.jscomp.AbstractVar.isParam(AbstractVar.java:184)
at com.google.javascript.jscomp.ProcessCommonJSModules$RewriteModule.maybeUpdateName(ProcessCommonJSModules.java:1549)
at com.google.javascript.jscomp.ProcessCommonJSModules$RewriteModule.visit(ProcessCommonJSModules.java:1233)
```

But this is valid code.

Note that no error condition is triggered is `bar` is not assigned to `module.exports`.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.