google / google/closure-compiler

Multi-line comment before else-if throws Parse error

Open
#3,494 3 comments 0 reactions 0 assignees View on GitHub
internal-issue-created triage-done
Dominant language
JavaScript
Stars
7.7k
Forks
1.2k
Avg merge
2d 12h
Merged PRs (30d)
6

Description

**Tested with**: closure compiler v20190929, also happens on [closure-compiler.appspot.com](https://closure-compiler.appspot.com/home#code%3D%252F%252F%2520%253D%253DClosureCompiler%253D%253D%250A%252F%252F%2520%2540compilation_level%2520SIMPLE_OPTIMIZATIONS%250A%252F%252F%2520%2540output_file_name%2520default.js%250A%252F%252F%2520%253D%253D%252FClosureCompiler%253D%253D%250A%250A%252F%252F%2520ADD%2520YOUR%2520CODE%2520HERE%250A%2520%2520%2520%2520function%2520getClassFacts(node%252C%2520staticProperties)%2520%257B%250A%2520%2520%2520%2520%2520%2520if%2520(ts.some(staticProperties))%2520facts%2520%257C%253D%25201%250A%2520%2520%2520%2520%2520%2520%252F*%2520HasStaticInitializedProperties%2520*%252F%250A%2520%2520%2520%2520%2520%2520%253B%250A%2520%2520%2520%2520%2520%2520if%2520(isExportOfNamespace(node))%2520facts%2520%257C%253D%25208%250A%2520%2520%2520%2520%2520%2520%252F*%2520IsExportOfNamespace%2520*%252F%250A%2520%2520%2520%2520%2520%2520%253Belse%2520if%2520(isDefaultExternalModuleExport(node))%2520facts%2520%257C%253D%252032%250A%2520%2520%2520%2520%2520%2520%252F*%2520IsDefaultExternalExport%2520*%252F%250A%2520%2520%2520%2520%2520%2520%253B%250A%2520%2520%2520%2520%2520%2520return%2520facts%253B%250A%2520%2520%2520%2520%257D%250A)

Came across this while running closure compiler on some generated code. The following results in a parser error:

```javascript
function getClassFacts(node, staticProperties) {
if (ts.some(staticProperties)) facts |= 1
/* HasStaticInitializedProperties */
;
if (isExportOfNamespace(node)) facts |= 8
/* IsExportOfNamespace */
;else if (isDefaultExternalModuleExport(node)) facts |= 32
/* IsDefaultExternalExport */
;
return facts;
}
```

This produces the following error (`java -jar closure-compiler-v20190929.jar --compilation_level SIMPLE --js input.js --js_output_file output.js`):

```
JSC_PARSE_ERROR: Parse error. '}' expected at line 8 character 7
;else if (isDefaultExternalModuleExport(node)) facts |= 32
^
```

Browsers and almost all parsers on https://astexplorer.net seem accept this code. Also, it only seems to happen when there is an `else if` after the `if`.

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.