Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 2 additions & 0 deletions src/compiler/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ export interface Ast {
css: Style;
instance: Script;
module: Script;
firstError?: any;
}

export interface Warning {
Expand Down Expand Up @@ -170,6 +171,7 @@ export interface CompileOptions {
export interface ParserOptions {
filename?: string;
customElement?: boolean;
errorMode?: 'throw' | 'warn' | 'loose';
}

export interface Visitor {
Expand Down
15 changes: 12 additions & 3 deletions src/compiler/parse/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export class Parser {
readonly template: string;
readonly filename?: string;
readonly customElement: boolean;
private readonly isLooseParsing: boolean;

index = 0;
stack: TemplateNode[] = [];
Expand All @@ -27,6 +28,7 @@ export class Parser {
css: Style[] = [];
js: Script[] = [];
meta_tags = {};
firstError?: any;
last_auto_closed_tag?: LastAutoClosedTag;

constructor(template: string, options: ParserOptions) {
Expand All @@ -37,6 +39,7 @@ export class Parser {
this.template = template.replace(/\s+$/, '');
this.filename = options.filename;
this.customElement = options.customElement;
this.isLooseParsing = options.errorMode === 'loose';

this.html = {
start: null,
Expand Down Expand Up @@ -98,13 +101,18 @@ export class Parser {
}

error({ code, message }: { code: string; message: string }, index = this.index) {
error(message, {
const errorProps = {
name: 'ParseError',
code,
source: this.template,
start: index,
filename: this.filename
});
};
if (this.isLooseParsing) {
this.firstError = this.firstError || errorProps;
} else {
error(message, errorProps);
}
}

eat(str: string, required?: boolean, error?: { code: string, message: string }) {
Expand Down Expand Up @@ -238,6 +246,7 @@ export default function parse(
html: parser.html,
css: parser.css[0],
instance: instance_scripts[0],
module: module_scripts[0]
module: module_scripts[0],
firstError: parser.firstError
};
}