diff --git a/packages/moon/dist/moon.js b/packages/moon/dist/moon.js index 2f940e88..1b4b4afb 100644 --- a/packages/moon/dist/moon.js +++ b/packages/moon/dist/moon.js @@ -107,7 +107,7 @@ */ function lexError(message, input, index) { - var lexMessage = message + "\n\n"; + var lexMessage = message + "\n\n"; // Show input characters surrounding the source of the error. for (var i = Math.max(0, index - 16); i < Math.min(index + 16, input.length); i++) { lexMessage += input[i]; @@ -189,6 +189,11 @@ // the match and captured groups. var typeExec = typeRE.exec(input); + + if ("development" === "development" && typeExec === null) { + lexError("Lexer expected a valid opening or closing tag.", input, i); + } + var typeMatch = typeExec[0]; var type = typeExec[1]; var attributesText = typeExec[2]; @@ -302,6 +307,7 @@ function parseErrorMessage(message) { + /* istanbul ignore next */ return "development" === "development" ? message : ""; } /** diff --git a/packages/moon/dist/moon.min.js b/packages/moon/dist/moon.min.js index 05356ef6..d410b5fd 100644 --- a/packages/moon/dist/moon.min.js +++ b/packages/moon/dist/moon.min.js @@ -4,4 +4,4 @@ * Released under the MIT License * https://kbrsh.github.io/moon */ -!function(e,t){"undefined"==typeof module?e.Moon=t():module.exports=t()}(this,function(){"use strict";function a(){}function u(e,t){return void 0===e?t:e}var k=/<([\w\d-_]+)([^>]*?)(\/?)>/g,O=/\s*([\w\d-_]*)(?:=(?:("[\w\d-_]*"|'[\w\d-_]*')|{([\w\d-_]*)}))?/g;function t(e){e=e.trim();for(var t=[],n=0;n",n+2),u=e.slice(n+2,a);0,t.push({type:"tagClose",value:u}),n=a+1;continue}if("!"===o&&"-"===e[n+2]&&"-"===e[n+3]){var i=e.indexOf("--\x3e",n+4);0,n=i+3;continue}k.lastIndex=n;for(var l=k.exec(e),c=l[0],s=l[1],f=l[2],m=l[3],v={},p=void 0;null!==(p=O.exec(f));){var d=p[0],y=p[1],h=p[2],x=p[3];0===d.length?O.lastIndex+=1:v[y]=void 0===x?h:x}t.push({type:"tagOpen",value:s,attributes:v,closed:"/"===m}),n+=c.length}else if("{"===r){var g="";for(n+=1;n]*?)(\/?)>/g,O=/\s*([\w\d-_]*)(?:=(?:("[\w\d-_]*"|'[\w\d-_]*')|{([\w\d-_]*)}))?/g;function t(e){e=e.trim();for(var t=[],n=0;n",n+2),u=e.slice(n+2,a);0,t.push({type:"tagClose",value:u}),n=a+1;continue}if("!"===o&&"-"===e[n+2]&&"-"===e[n+3]){var i=e.indexOf("--\x3e",n+4);0,n=i+3;continue}k.lastIndex=n;var l=k.exec(e);0;for(var c=l[0],s=l[1],f=l[2],m=l[3],v={},p=void 0;null!==(p=O.exec(f));){var d=p[0],y=p[1],h=p[2],x=p[3];0===d.length?O.lastIndex+=1:v[y]=void 0===x?h:x}t.push({type:"tagOpen",value:s,attributes:v,closed:"/"===m}),n+=c.length}else if("{"===r){var g="";for(n+=1;n { expect(console.error).toBeCalled(); }); +test("lex error from invalid opening tag", () => { + console.error = jest.fn(); + + expect(Array.isArray(lex(" { + console.error = jest.fn(); + + expect(Array.isArray(lex("
{ console.error = jest.fn();