google / google/closure-compiler

Types mismatch in Document.prototype.documentElement externs

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

Description

The following JS input
```js
new DOMParser()
.parseFromString(``, "image/svg+xml")
.documentElement
.width
.baseVal
```

compiles into this under advanced optimizations
```js
new DOMParser()
.parseFromString(``, "image/svg+xml")
.documentElement
.width
.g
```

The `baseVal` property gets minified and the following warning is printed `WARNING - [JSC_INEXISTENT_PROPERTY] Property width never defined on HTMLHtmlElement`.

As per externs, `DOMParser.prototype.parseFromString` return type is `Document`
https://github.com/google/closure-compiler/blob/7ff6e25843097791416d1544c88dc8711f6be64a/externs/browser/gecko_xml.js#L73, whose `documentElement` property type is indeed `HTMLHtmlElement` https://github.com/google/closure-compiler/blob/7ff6e25843097791416d1544c88dc8711f6be64a/externs/browser/w3c_dom1.js#L339

But in case when parsing SVG the `documentElement` property refers to an element of type `SVGSVGElement`, which is correctly covered with externs https://github.com/google/closure-compiler/blob/7ff6e25843097791416d1544c88dc8711f6be64a/contrib/externs/svg.js#L6555

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.