fix(compiler): warning prints "WARNING" instead of "ERROR" (#15125)
This commit is contained in:
parent
3c15916e17
commit
3b1956bbf2
|
@ -110,17 +110,18 @@ export class ParseSourceSpan {
|
||||||
|
|
||||||
export enum ParseErrorLevel {
|
export enum ParseErrorLevel {
|
||||||
WARNING,
|
WARNING,
|
||||||
FATAL
|
ERROR,
|
||||||
}
|
}
|
||||||
|
|
||||||
export class ParseError {
|
export class ParseError {
|
||||||
constructor(
|
constructor(
|
||||||
public span: ParseSourceSpan, public msg: string,
|
public span: ParseSourceSpan, public msg: string,
|
||||||
public level: ParseErrorLevel = ParseErrorLevel.FATAL) {}
|
public level: ParseErrorLevel = ParseErrorLevel.ERROR) {}
|
||||||
|
|
||||||
toString(): string {
|
toString(): string {
|
||||||
const ctx = this.span.start.getContext(100, 3);
|
const ctx = this.span.start.getContext(100, 3);
|
||||||
const contextStr = ctx ? ` ("${ctx.before}[ERROR ->]${ctx.after}")` : '';
|
const contextStr =
|
||||||
|
ctx ? ` ("${ctx.before}[${ParseErrorLevel[this.level]} ->]${ctx.after}")` : '';
|
||||||
const details = this.span.details ? `, ${this.span.details}` : '';
|
const details = this.span.details ? `, ${this.span.details}` : '';
|
||||||
return `${this.msg}${contextStr}: ${this.span.start}${details}`;
|
return `${this.msg}${contextStr}: ${this.span.start}${details}`;
|
||||||
}
|
}
|
||||||
|
|
|
@ -161,7 +161,7 @@ export class BindingParser {
|
||||||
this._reportError(
|
this._reportError(
|
||||||
`Assigning animation triggers via @prop="exp" attributes with an expression is invalid.` +
|
`Assigning animation triggers via @prop="exp" attributes with an expression is invalid.` +
|
||||||
` Use property bindings (e.g. [@prop]="exp") or use an attribute without a value (e.g. @prop) instead.`,
|
` Use property bindings (e.g. [@prop]="exp") or use an attribute without a value (e.g. @prop) instead.`,
|
||||||
sourceSpan, ParseErrorLevel.FATAL);
|
sourceSpan, ParseErrorLevel.ERROR);
|
||||||
}
|
}
|
||||||
this._parseAnimation(name, value, sourceSpan, targetMatchableAttrs, targetProps);
|
this._parseAnimation(name, value, sourceSpan, targetMatchableAttrs, targetProps);
|
||||||
} else {
|
} else {
|
||||||
|
@ -366,7 +366,7 @@ export class BindingParser {
|
||||||
|
|
||||||
private _reportError(
|
private _reportError(
|
||||||
message: string, sourceSpan: ParseSourceSpan,
|
message: string, sourceSpan: ParseSourceSpan,
|
||||||
level: ParseErrorLevel = ParseErrorLevel.FATAL) {
|
level: ParseErrorLevel = ParseErrorLevel.ERROR) {
|
||||||
this._targetErrors.push(new ParseError(sourceSpan, message, level));
|
this._targetErrors.push(new ParseError(sourceSpan, message, level));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -405,7 +405,7 @@ export class BindingParser {
|
||||||
const report = isAttr ? this._schemaRegistry.validateAttribute(propName) :
|
const report = isAttr ? this._schemaRegistry.validateAttribute(propName) :
|
||||||
this._schemaRegistry.validateProperty(propName);
|
this._schemaRegistry.validateProperty(propName);
|
||||||
if (report.error) {
|
if (report.error) {
|
||||||
this._reportError(report.msg, sourceSpan, ParseErrorLevel.FATAL);
|
this._reportError(report.msg, sourceSpan, ParseErrorLevel.ERROR);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -98,7 +98,7 @@ export class TemplateParser {
|
||||||
templateUrl: string): {template: TemplateAst[], pipes: CompilePipeSummary[]} {
|
templateUrl: string): {template: TemplateAst[], pipes: CompilePipeSummary[]} {
|
||||||
const result = this.tryParse(component, template, directives, pipes, schemas, templateUrl);
|
const result = this.tryParse(component, template, directives, pipes, schemas, templateUrl);
|
||||||
const warnings = result.errors.filter(error => error.level === ParseErrorLevel.WARNING);
|
const warnings = result.errors.filter(error => error.level === ParseErrorLevel.WARNING);
|
||||||
const errors = result.errors.filter(error => error.level === ParseErrorLevel.FATAL);
|
const errors = result.errors.filter(error => error.level === ParseErrorLevel.ERROR);
|
||||||
|
|
||||||
if (warnings.length > 0) {
|
if (warnings.length > 0) {
|
||||||
this._console.warn(`Template parse warnings:\n${warnings.join('\n')}`);
|
this._console.warn(`Template parse warnings:\n${warnings.join('\n')}`);
|
||||||
|
@ -196,7 +196,7 @@ export class TemplateParser {
|
||||||
} else {
|
} else {
|
||||||
const error = new TemplateParseError(
|
const error = new TemplateParseError(
|
||||||
`Reference "#${name}" is defined several times`, reference.sourceSpan,
|
`Reference "#${name}" is defined several times`, reference.sourceSpan,
|
||||||
ParseErrorLevel.FATAL);
|
ParseErrorLevel.ERROR);
|
||||||
errors.push(error);
|
errors.push(error);
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
|
@ -731,7 +731,7 @@ class TemplateParseVisitor implements html.Visitor {
|
||||||
|
|
||||||
private _reportError(
|
private _reportError(
|
||||||
message: string, sourceSpan: ParseSourceSpan,
|
message: string, sourceSpan: ParseSourceSpan,
|
||||||
level: ParseErrorLevel = ParseErrorLevel.FATAL) {
|
level: ParseErrorLevel = ParseErrorLevel.ERROR) {
|
||||||
this._targetErrors.push(new ParseError(sourceSpan, message, level));
|
this._targetErrors.push(new ParseError(sourceSpan, message, level));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,28 @@
|
||||||
|
/**
|
||||||
|
* @license
|
||||||
|
* Copyright Google Inc. All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Use of this source code is governed by an MIT-style license that can be
|
||||||
|
* found in the LICENSE file at https://angular.io/license
|
||||||
|
*/
|
||||||
|
|
||||||
|
import {ParseError, ParseErrorLevel, ParseLocation, ParseSourceFile, ParseSourceSpan} from '../src/parse_util'
|
||||||
|
|
||||||
|
export function main() {
|
||||||
|
describe(
|
||||||
|
'ParseError',
|
||||||
|
() => {
|
||||||
|
it('should reflect the level in the message', () => {
|
||||||
|
const file = new ParseSourceFile(`foo\nbar\nfoo`, 'url');
|
||||||
|
const start = new ParseLocation(file, 4, 1, 0);
|
||||||
|
const end = new ParseLocation(file, 6, 1, 2);
|
||||||
|
const span = new ParseSourceSpan(start, end);
|
||||||
|
|
||||||
|
const fatal = new ParseError(span, 'fatal', ParseErrorLevel.ERROR);
|
||||||
|
expect(fatal.toString()).toEqual('fatal ("foo\n[ERROR ->]bar\nfoo"): url@1:0');
|
||||||
|
|
||||||
|
const warning = new ParseError(span, 'warning', ParseErrorLevel.WARNING);
|
||||||
|
expect(warning.toString()).toEqual('warning ("foo\n[WARNING ->]bar\nfoo"): url@1:0');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
Loading…
Reference in New Issue