From 01db59ee36b55675d32eeac4bcb4814345f328c5 Mon Sep 17 00:00:00 2001 From: Marijn Haverbeke Date: Wed, 11 Sep 2019 08:35:11 +0200 Subject: [PATCH] Fix issue in previous patch Issue #266 --- dist/angulartemplate.js | 321 +++++++++++++++++++++------------------- dist/html.js | 63 +++++--- dist/javascript.js | 10 +- src/html_util.js | 6 +- 4 files changed, 223 insertions(+), 177 deletions(-) diff --git a/dist/angulartemplate.js b/dist/angulartemplate.js index dfc627d..1c49ea0 100644 --- a/dist/angulartemplate.js +++ b/dist/angulartemplate.js @@ -16,7 +16,7 @@ 2, 10, -1, {"name":"tag"}, 3, "atom", /^\&(?:(?![\;\n\t ]).)*\;/, -1, [1, "\n", /^(?:(?!\&|\<|\{\{).)+/], -1], - [1, 18, 5], + [1, 16, 5], ["}}", -1], [""; proto.fold = "xml"; + contextInfo(proto); CodeMirror$1.defineMode("google-angular-template", function (conf, modeConf) { return new AngularTemplateMode(conf, modeConf); }); diff --git a/dist/html.js b/dist/html.js index bdadc18..304d652 100644 --- a/dist/html.js +++ b/dist/html.js @@ -21,7 +21,7 @@ [/^(?:\<\!doctype|\<\!DOCTYPE)(?![a-zA-Z\-\.0-9_])/, 7], [[0, /^(?!\>)/, /^[^]/], 7, ">", -1], - [2, 16, 9, {"name":"openTag"}], + [2, 14, 9, {"name":"openTag"}], [3, "tag", "/>", -1, [7, "selfClosing"], 10, 3, "tag", ">", 11], @@ -30,32 +30,33 @@ /^(?=\<\/)/, 12], [[7, "matchingTag"], 13, 0, -1], - [3, "tag", "", -1], - [3, "tag", [0, "<", [6, 23]], 17], - [e[0], 17, - 3, "tag", e[1], 18], - [e[0], 18, - 0, 19], - [3, "attribute", e[1], 20, + [2, 21, -1, {"name":"closeTag"}], + [3, "tag", [0, "<", [6, 24]], 15], + [e[0], 15, + 3, "tag", e[1], 16], + [e[0], 16, + 0, 17], + [3, "attribute", e[1], 18, 0, -1], + [e[0], 18, + "=", 19, + 0, 20], + [e[0], 19, + 2, 25, 20, {"name":"attributeValue","token":"string"}], [e[0], 20, - "=", 21, - 0, 22], - [e[0], 21, - 2, 24, 22, {"name":"attributeValue","token":"string"}], + 0, 17], + [3, "tag", "", -1], + [e[0], 24, "/", -1], - ["\"", 25, - "'", 26, + ["\"", 26, + "'", 27, /^(?:(?![\n\t \>]).)*/, -1], - [[0, /^(?!\")/, /^[^]/], 25, + [[0, /^(?!\")/, /^[^]/], 26, "\"", -1], - [[0, /^(?!\')/, /^[^]/], 26, + [[0, /^(?!\')/, /^[^]/], 27, "'", -1] ]; var start = 0; @@ -104,6 +105,25 @@ return 0 } + function contextInfo(proto) { + proto.xmlCurrentTag = function (state) { + var cx = state.context; + if (!cx || (cx.name != "openTag" || cx.name != "closeTag")) { return null } + var match = /<\/?\s*([\w\-\.]+)/.exec(cx.startLine.slice(cx.startPos)); + return match ? {name: match[1], close: cx.name == "closeTag"} : null + }; + proto.xmlCurrentContext = function (state) { + var context = []; + for (var cx = state.context; cx; cx = cx.parent) { + if (cx.name == "tag") { + var match = /<\/?\s*([\w\-\.]+)/.exec(cx.startLine.slice(cx.startPos)); + if (match) { context.push(match[1]); } + } + } + return context.reverse() + }; + } + var HTMLMode = (function (superclass) { function HTMLMode(conf, modeConf) { superclass.call(this, grammar, {predicates: predicates}); @@ -126,6 +146,7 @@ proto.blockCommentStart = ""; proto.fold = "xml"; + contextInfo(proto); CodeMirror$1.defineMode("google-html", function (conf, modeConf) { return new HTMLMode(conf, modeConf); }); diff --git a/dist/javascript.js b/dist/javascript.js index e9a1832..f3c42af 100644 --- a/dist/javascript.js +++ b/dist/javascript.js @@ -1005,6 +1005,8 @@ * @param {!Stream} stream */ TemplateTokenizer.prototype.backupIfEmbeddedTokenizerOvershot = function backupIfEmbeddedTokenizerOvershot (stream) { + var this$1 = this; + var cur = stream.current(); var searchFrom = 0; while(true) { @@ -1016,7 +1018,7 @@ closingIdx = closingIdx + searchFrom; var amountToBackUp = cur.length - closingIdx; var locationOfEarlyExit = stream.pos - amountToBackUp; - var escaped = this.isEscaped(stream, locationOfEarlyExit); + var escaped = this$1.isEscaped(stream, locationOfEarlyExit); if (!escaped) { // Found a template boundary. Must not consume it. stream.backUp(cur.length - closingIdx); @@ -1055,6 +1057,8 @@ * @param {string|null} templateTag */ TemplateTokenizer.prototype.getModeForTemplateTag = function getModeForTemplateTag (templateTag) { + var this$1 = this; + if (!templateTag) { return null; } @@ -1067,7 +1071,7 @@ // Note: the google-modules build pipeline does not currently support // for/of. for (var i = 0; i < modeSpecs.length; i++) { - var mode = CodeMirror.getMode(this.config, modeSpecs[i]); + var mode = CodeMirror.getMode(this$1.config, modeSpecs[i]); if (mode && mode.name !== 'null') { return mode; } @@ -1139,7 +1143,7 @@ var scopes = ["Block", "FunctionDef", "ArrowFunc", "ForStatement"]; - var JSMode = /*@__PURE__*/(function (superclass) { + var JSMode = (function (superclass) { function JSMode(conf, modeConf) { superclass.call(this, grammar, { predicates: {canInsertSemi: modeConf.requireSemicolons === false ? canInsertSemi : function () { return false; }} diff --git a/src/html_util.js b/src/html_util.js index 10af937..694b7a0 100644 --- a/src/html_util.js +++ b/src/html_util.js @@ -38,15 +38,15 @@ export function indent(state, textAfter, line, config) { export function contextInfo(proto) { proto.xmlCurrentTag = state => { let cx = state.context - if (!cx || (cx.name != "openTag" || cx.name != "closeTag")) return null - let match = /<\/?\s*([\w\-\.]+)/.exec(cx.startLine.slice(cx.startPos)) + if (!cx || (cx.name != "openTag" && cx.name != "closeTag")) return null + let match = /^<\/?\s*([\w\-\.]+)/.exec(cx.startLine.slice(cx.startPos)) return match ? {name: match[1], close: cx.name == "closeTag"} : null } proto.xmlCurrentContext = state => { let context = [] for (let cx = state.context; cx; cx = cx.parent) { if (cx.name == "tag") { - let match = /<\/?\s*([\w\-\.]+)/.exec(cx.startLine.slice(cx.startPos)) + let match = /^<\s*([\w\-\.]+)/.exec(cx.startLine.slice(cx.startPos)) if (match) context.push(match[1]) } }