LaravelTest
329 строк · 11.2 Кб
1'use strict';2
3function copyObj(obj, target, overwrite) {4if (!target) { target = {}; }5for (var prop in obj)6{ if (obj.hasOwnProperty(prop) && (overwrite !== false || !target.hasOwnProperty(prop)))7{ target[prop] = obj[prop]; } }8return target9}
10
11// Counts the column offset in a string, taking tabs into account.
12// Used mostly to find indentation.
13function countColumn(string, end, tabSize, startIndex, startValue) {14if (end == null) {15end = string.search(/[^\s\u00a0]/);16if (end == -1) { end = string.length; }17}18for (var i = startIndex || 0, n = startValue || 0;;) {19var nextTab = string.indexOf("\t", i);20if (nextTab < 0 || nextTab >= end)21{ return n + (end - i) }22n += nextTab - i;23n += tabSize - (n % tabSize);24i = nextTab + 1;25}26}
27
28function nothing() {}29
30function createObj(base, props) {31var inst;32if (Object.create) {33inst = Object.create(base);34} else {35nothing.prototype = base;36inst = new nothing();37}38if (props) { copyObj(props, inst); }39return inst40}
41
42// STRING STREAM
43
44// Fed to the mode parsers, provides helper functions to make
45// parsers more succinct.
46
47var StringStream = function(string, tabSize, lineOracle) {48this.pos = this.start = 0;49this.string = string;50this.tabSize = tabSize || 8;51this.lastColumnPos = this.lastColumnValue = 0;52this.lineStart = 0;53this.lineOracle = lineOracle;54};55
56StringStream.prototype.eol = function () {return this.pos >= this.string.length};57StringStream.prototype.sol = function () {return this.pos == this.lineStart};58StringStream.prototype.peek = function () {return this.string.charAt(this.pos) || undefined};59StringStream.prototype.next = function () {60if (this.pos < this.string.length)61{ return this.string.charAt(this.pos++) }62};63StringStream.prototype.eat = function (match) {64var ch = this.string.charAt(this.pos);65var ok;66if (typeof match == "string") { ok = ch == match; }67else { ok = ch && (match.test ? match.test(ch) : match(ch)); }68if (ok) {++this.pos; return ch}69};70StringStream.prototype.eatWhile = function (match) {71var start = this.pos;72while (this.eat(match)){}73return this.pos > start74};75StringStream.prototype.eatSpace = function () {76var start = this.pos;77while (/[\s\u00a0]/.test(this.string.charAt(this.pos))) { ++this.pos; }78return this.pos > start79};80StringStream.prototype.skipToEnd = function () {this.pos = this.string.length;};81StringStream.prototype.skipTo = function (ch) {82var found = this.string.indexOf(ch, this.pos);83if (found > -1) {this.pos = found; return true}84};85StringStream.prototype.backUp = function (n) {this.pos -= n;};86StringStream.prototype.column = function () {87if (this.lastColumnPos < this.start) {88this.lastColumnValue = countColumn(this.string, this.start, this.tabSize, this.lastColumnPos, this.lastColumnValue);89this.lastColumnPos = this.start;90}91return this.lastColumnValue - (this.lineStart ? countColumn(this.string, this.lineStart, this.tabSize) : 0)92};93StringStream.prototype.indentation = function () {94return countColumn(this.string, null, this.tabSize) -95(this.lineStart ? countColumn(this.string, this.lineStart, this.tabSize) : 0)96};97StringStream.prototype.match = function (pattern, consume, caseInsensitive) {98if (typeof pattern == "string") {99var cased = function (str) { return caseInsensitive ? str.toLowerCase() : str; };100var substr = this.string.substr(this.pos, pattern.length);101if (cased(substr) == cased(pattern)) {102if (consume !== false) { this.pos += pattern.length; }103return true104}105} else {106var match = this.string.slice(this.pos).match(pattern);107if (match && match.index > 0) { return null }108if (match && consume !== false) { this.pos += match[0].length; }109return match110}111};112StringStream.prototype.current = function (){return this.string.slice(this.start, this.pos)};113StringStream.prototype.hideFirstChars = function (n, inner) {114this.lineStart += n;115try { return inner() }116finally { this.lineStart -= n; }117};118StringStream.prototype.lookAhead = function (n) {119var oracle = this.lineOracle;120return oracle && oracle.lookAhead(n)121};122StringStream.prototype.baseToken = function () {123var oracle = this.lineOracle;124return oracle && oracle.baseToken(this.pos)125};126
127// Known modes, by name and by MIME
128var modes = {}, mimeModes = {};129
130// Extra arguments are stored as the mode's dependencies, which is
131// used by (legacy) mechanisms like loadmode.js to automatically
132// load a mode. (Preferred mechanism is the require/define calls.)
133function defineMode(name, mode) {134if (arguments.length > 2)135{ mode.dependencies = Array.prototype.slice.call(arguments, 2); }136modes[name] = mode;137}
138
139function defineMIME(mime, spec) {140mimeModes[mime] = spec;141}
142
143// Given a MIME type, a {name, ...options} config object, or a name
144// string, return a mode config object.
145function resolveMode(spec) {146if (typeof spec == "string" && mimeModes.hasOwnProperty(spec)) {147spec = mimeModes[spec];148} else if (spec && typeof spec.name == "string" && mimeModes.hasOwnProperty(spec.name)) {149var found = mimeModes[spec.name];150if (typeof found == "string") { found = {name: found}; }151spec = createObj(found, spec);152spec.name = found.name;153} else if (typeof spec == "string" && /^[\w\-]+\/[\w\-]+\+xml$/.test(spec)) {154return resolveMode("application/xml")155} else if (typeof spec == "string" && /^[\w\-]+\/[\w\-]+\+json$/.test(spec)) {156return resolveMode("application/json")157}158if (typeof spec == "string") { return {name: spec} }159else { return spec || {name: "null"} }160}
161
162// Given a mode spec (anything that resolveMode accepts), find and
163// initialize an actual mode object.
164function getMode(options, spec) {165spec = resolveMode(spec);166var mfactory = modes[spec.name];167if (!mfactory) { return getMode(options, "text/plain") }168var modeObj = mfactory(options, spec);169if (modeExtensions.hasOwnProperty(spec.name)) {170var exts = modeExtensions[spec.name];171for (var prop in exts) {172if (!exts.hasOwnProperty(prop)) { continue }173if (modeObj.hasOwnProperty(prop)) { modeObj["_" + prop] = modeObj[prop]; }174modeObj[prop] = exts[prop];175}176}177modeObj.name = spec.name;178if (spec.helperType) { modeObj.helperType = spec.helperType; }179if (spec.modeProps) { for (var prop$1 in spec.modeProps)180{ modeObj[prop$1] = spec.modeProps[prop$1]; } }181
182return modeObj183}
184
185// This can be used to attach properties to mode objects from
186// outside the actual mode definition.
187var modeExtensions = {};188function extendMode(mode, properties) {189var exts = modeExtensions.hasOwnProperty(mode) ? modeExtensions[mode] : (modeExtensions[mode] = {});190copyObj(properties, exts);191}
192
193function copyState(mode, state) {194if (state === true) { return state }195if (mode.copyState) { return mode.copyState(state) }196var nstate = {};197for (var n in state) {198var val = state[n];199if (val instanceof Array) { val = val.concat([]); }200nstate[n] = val;201}202return nstate203}
204
205// Given a mode and a state (for that mode), find the inner mode and
206// state at the position that the state refers to.
207function innerMode(mode, state) {208var info;209while (mode.innerMode) {210info = mode.innerMode(state);211if (!info || info.mode == mode) { break }212state = info.state;213mode = info.mode;214}215return info || {mode: mode, state: state}216}
217
218function startState(mode, a1, a2) {219return mode.startState ? mode.startState(a1, a2) : true220}
221
222var modeMethods = {223__proto__: null,224modes: modes,225mimeModes: mimeModes,226defineMode: defineMode,227defineMIME: defineMIME,228resolveMode: resolveMode,229getMode: getMode,230modeExtensions: modeExtensions,231extendMode: extendMode,232copyState: copyState,233innerMode: innerMode,234startState: startState235};236
237// Copy StringStream and mode methods into exports (CodeMirror) object.
238exports.StringStream = StringStream;239exports.countColumn = countColumn;240for (var exported in modeMethods) { exports[exported] = modeMethods[exported]; }241
242// Shim library CodeMirror with the minimal CodeMirror defined above.
243require.cache[require.resolve("../../lib/codemirror")] = require.cache[require.resolve("./runmode.node")];244require.cache[require.resolve("../../addon/runmode/runmode")] = require.cache[require.resolve("./runmode.node")];245
246// Minimal default mode.
247exports.defineMode("null", function () { return ({token: function (stream) { return stream.skipToEnd(); }}); });248exports.defineMIME("text/plain", "null");249
250exports.registerHelper = exports.registerGlobalHelper = Math.min;251exports.splitLines = function(string) { return string.split(/\r?\n|\r/) };252
253exports.defaults = { indentUnit: 2 };254
255// CodeMirror, copyright (c) by Marijn Haverbeke and others
256// Distributed under an MIT license: https://codemirror.net/LICENSE
257
258(function(mod) {259if (typeof exports == "object" && typeof module == "object") // CommonJS260{ mod(require("../../lib/codemirror")); }261else if (typeof define == "function" && define.amd) // AMD262{ define(["../../lib/codemirror"], mod); }263else // Plain browser env264{ mod(CodeMirror); }265})(function(CodeMirror) {266
267CodeMirror.runMode = function(string, modespec, callback, options) {268var mode = CodeMirror.getMode(CodeMirror.defaults, modespec);269var tabSize = (options && options.tabSize) || CodeMirror.defaults.tabSize;270
271// Create a tokenizing callback function if passed-in callback is a DOM element.272if (callback.appendChild) {273var ie = /MSIE \d/.test(navigator.userAgent);274var ie_lt9 = ie && (document.documentMode == null || document.documentMode < 9);275var node = callback, col = 0;276node.innerHTML = "";277callback = function(text, style) {278if (text == "\n") {279// Emitting LF or CRLF on IE8 or earlier results in an incorrect display.280// Emitting a carriage return makes everything ok.281node.appendChild(document.createTextNode(ie_lt9 ? '\r' : text));282col = 0;283return;284}285var content = "";286// replace tabs287for (var pos = 0;;) {288var idx = text.indexOf("\t", pos);289if (idx == -1) {290content += text.slice(pos);291col += text.length - pos;292break;293} else {294col += idx - pos;295content += text.slice(pos, idx);296var size = tabSize - col % tabSize;297col += size;298for (var i = 0; i < size; ++i) { content += " "; }299pos = idx + 1;300}301}302// Create a node with token style and append it to the callback DOM element.303if (style) {304var sp = node.appendChild(document.createElement("span"));305sp.className = "cm-" + style.replace(/ +/g, " cm-");306sp.appendChild(document.createTextNode(content));307} else {308node.appendChild(document.createTextNode(content));309}310};311}312
313var lines = CodeMirror.splitLines(string), state = (options && options.state) || CodeMirror.startState(mode);314for (var i = 0, e = lines.length; i < e; ++i) {315if (i) { callback("\n"); }316var stream = new CodeMirror.StringStream(lines[i], null, {317lookAhead: function(n) { return lines[i + n] },318baseToken: function() {}319});320if (!stream.string && mode.blankLine) { mode.blankLine(state); }321while (!stream.eol()) {322var style = mode.token(stream, state);323callback(stream.current(), style, i, stream.start, state, mode);324stream.start = stream.pos;325}326}327};328
329});330