Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
refactor(compiler): use === rather than == in the ml_parser
This is a simple tidy up commit to move to the more specific `===`
comparison operator in the HTML lexer/parser.
  • Loading branch information
petebacondarwin committed Jul 31, 2021
commit a1e9d44f4b39c7ebbf60c0d98dfb69b880d4b157
2 changes: 1 addition & 1 deletion packages/compiler/src/ml_parser/html_tags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export class HtmlTagDefinition implements TagDefinition {

getContentType(prefix?: string): TagContentType {
if (typeof this.contentType === 'object') {
const overrideType = prefix == null ? undefined : this.contentType[prefix];
const overrideType = prefix === undefined ? undefined : this.contentType[prefix];
return overrideType ?? this.contentType.default;
}
return this.contentType;
Expand Down
6 changes: 3 additions & 3 deletions packages/compiler/src/ml_parser/icu_ast_expander.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ class _Expander implements html.Visitor {

visitExpansion(icu: html.Expansion, context: any): any {
this.isExpanded = true;
return icu.type == 'plural' ? _expandPluralForm(icu, this.errors) :
_expandDefaultForm(icu, this.errors);
return icu.type === 'plural' ? _expandPluralForm(icu, this.errors) :
_expandDefaultForm(icu, this.errors);
}

visitExpansionCase(icuCase: html.ExpansionCase, context: any): any {
Expand All @@ -92,7 +92,7 @@ class _Expander implements html.Visitor {
// Plural forms are expanded to `NgPlural` and `NgPluralCase`s
function _expandPluralForm(ast: html.Expansion, errors: ParseError[]): html.Element {
const children = ast.cases.map(c => {
if (PLURAL_CASES.indexOf(c.value) == -1 && !c.value.match(/^=\d+$/)) {
if (PLURAL_CASES.indexOf(c.value) === -1 && !c.value.match(/^=\d+$/)) {
errors.push(new ExpansionError(
c.valueSourceSpan,
`Plural cases should be "=<number>" or one of ${PLURAL_CASES.join(', ')}`));
Expand Down
12 changes: 6 additions & 6 deletions packages/compiler/src/ml_parser/lexer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -881,19 +881,19 @@ function isPrefixEnd(code: number): boolean {
}

function isDigitEntityEnd(code: number): boolean {
return code == chars.$SEMICOLON || code == chars.$EOF || !chars.isAsciiHexDigit(code);
return code === chars.$SEMICOLON || code === chars.$EOF || !chars.isAsciiHexDigit(code);
}

function isNamedEntityEnd(code: number): boolean {
return code == chars.$SEMICOLON || code == chars.$EOF || !chars.isAsciiLetter(code);
return code === chars.$SEMICOLON || code === chars.$EOF || !chars.isAsciiLetter(code);
}

function isExpansionCaseStart(peek: number): boolean {
return peek !== chars.$RBRACE;
}

function compareCharCodeCaseInsensitive(code1: number, code2: number): boolean {
return toUpperCaseCharCode(code1) == toUpperCaseCharCode(code2);
return toUpperCaseCharCode(code1) === toUpperCaseCharCode(code2);
}

function toUpperCaseCharCode(code: number): number {
Expand All @@ -905,9 +905,9 @@ function mergeTextTokens(srcTokens: Token[]): Token[] {
let lastDstToken: Token|undefined = undefined;
for (let i = 0; i < srcTokens.length; i++) {
const token = srcTokens[i];
if ((lastDstToken && lastDstToken.type == TokenType.TEXT && token.type == TokenType.TEXT) ||
(lastDstToken && lastDstToken.type == TokenType.ATTR_VALUE_TEXT &&
token.type == TokenType.ATTR_VALUE_TEXT)) {
if ((lastDstToken && lastDstToken.type === TokenType.TEXT && token.type === TokenType.TEXT) ||
(lastDstToken && lastDstToken.type === TokenType.ATTR_VALUE_TEXT &&
token.type === TokenType.ATTR_VALUE_TEXT)) {
lastDstToken.parts[0]! += token.parts[0];
lastDstToken.sourceSpan.end = token.sourceSpan.end;
} else {
Expand Down
8 changes: 4 additions & 4 deletions packages/compiler/src/ml_parser/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ class _TreeBuilder {
if (this._peek.type === TokenType.EXPANSION_CASE_EXP_END) {
if (lastOnStack(expansionFormStack, TokenType.EXPANSION_CASE_EXP_START)) {
expansionFormStack.pop();
if (expansionFormStack.length == 0) return exp;
if (expansionFormStack.length === 0) return exp;

} else {
this.errors.push(
Expand Down Expand Up @@ -220,9 +220,9 @@ class _TreeBuilder {
const tokens = [token];
const startSpan = token.sourceSpan;
let text = token.parts[0];
if (text.length > 0 && text[0] == '\n') {
if (text.length > 0 && text[0] === '\n') {
const parent = this._getParentElement();
if (parent != null && parent.children.length == 0 &&
if (parent != null && parent.children.length === 0 &&
this.getTagDefinition(parent.name).ignoreFirstLf) {
text = text.substring(1);
tokens[0] = {type: token.type, sourceSpan: token.sourceSpan, parts: [text]} as typeof token;
Expand Down Expand Up @@ -342,7 +342,7 @@ class _TreeBuilder {
let unexpectedCloseTagDetected = false;
for (let stackIndex = this._elementStack.length - 1; stackIndex >= 0; stackIndex--) {
const el = this._elementStack[stackIndex];
if (el.name == fullName) {
if (el.name === fullName) {
// Record the parse span with the element that is being closed. Any elements that are
// removed from the element stack at this point are closed implicitly, so they won't get
// an end source span (as there is no explicit closing element).
Expand Down
2 changes: 1 addition & 1 deletion packages/compiler/src/ml_parser/tags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export function splitNsName(elementName: string): [string|null, string] {

const colonIndex = elementName.indexOf(':', 1);

if (colonIndex == -1) {
if (colonIndex === -1) {
throw new Error(`Unsupported format "${elementName}" expecting ":namespace:name"`);
}

Expand Down