Skip to content

getHtmlTagDefinition does not return tag definition if given tag name is constructor, toString, etc... #52224

@sosukesuzuki

Description

@sosukesuzuki

Which @angular/* package(s) are the source of the bug?

compiler

Is this a regression?

No

Description

getHtmlTagDefinition returns a tag definition for given HTML tag name. If given tag name is unknown, it should return default tag definition new HtmlTagDefinition({canSelfClose: true}).

However, it does not return the default tag definition for some tag names(constructor, toString, etc...), this is because the table of tag definitions is defined as a JavaScript object.

Code example:
import * as ac from "@angular/compiler";

const KNOWN_TAG_DIV = "div";
const UNKNOWN_TAG_FOO = "foo";
const UNKNOWN_TAG_CONSTRUCTOR = "constructor";
const UNKNOWN_TAG_TOSTRING = "toString";

console.log(ac.getHtmlTagDefinition(KNOWN_TAG_DIV));
// HtmlTagDefinition {
//   closedByChildren: {},
//   closedByParent: false,
//   isVoid: false,
//   implicitNamespacePrefix: null,
//   contentType: 2,
//   ignoreFirstLf: false,
//   preventNamespaceInheritance: false,
//   canSelfClose: false
// }

console.log(ac.getHtmlTagDefinition(UNKNOWN_TAG_FOO));
// HtmlTagDefinition {
//   closedByChildren: {},
//   closedByParent: false,
//   isVoid: false,
//   implicitNamespacePrefix: null,
//   contentType: 2,
//   ignoreFirstLf: false,
//   preventNamespaceInheritance: false,
//   canSelfClose: true
// }

console.log(ac.getHtmlTagDefinition(UNKNOWN_TAG_CONSTRUCTOR));
// [Function: Object]

console.log(ac.getHtmlTagDefinition(UNKNOWN_TAG_TOSTRING));
// [Function: toString]

Please provide a link to a minimal reproduction of the bug

https://github.com/sosukesuzuki/angular-get-html-tag-definition-bug

Please provide the exception or error you saw

// N/A

Please provide the environment you discovered this bug in (run ng version)

{
  "@angular/compiler": "^16.2.9"
}

Anything else?

This is from prettier/prettier#15511

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions