From 4bd3ce58851b0cd332b9d46d56e4e42795636984 Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Mon, 12 Jan 2015 08:45:35 -0800 Subject: Moved "use strict" to top of modules. --- js/lib/blocks.js | 22 ++-------------------- js/lib/common.js | 5 ++--- js/lib/from-code-point.js | 4 ++-- js/lib/html5-entities.js | 3 ++- js/lib/index.js | 4 ++-- js/lib/inlines.js | 33 ++------------------------------- 6 files changed, 12 insertions(+), 59 deletions(-) diff --git a/js/lib/blocks.js b/js/lib/blocks.js index d184b51..7d24406 100644 --- a/js/lib/blocks.js +++ b/js/lib/blocks.js @@ -1,3 +1,5 @@ +"use strict"; + var Node = require('./node'); var unescapeString = require('./common').unescapeString; @@ -37,7 +39,6 @@ var reLineEnding = /\r\n|\n|\r/; // Returns true if string contains only space characters. var isBlank = function(s) { - "use strict"; return !(reNonSpace.test(s)); }; @@ -45,8 +46,6 @@ var tabSpaces = [' ', ' ', ' ', ' ']; // Convert tabs to spaces on each line using a 4-space tab stop. var detabLine = function(text) { - "use strict"; - var start = 0; var offset; var lastStop = 0; @@ -65,7 +64,6 @@ var detabLine = function(text) { // Attempt to match a regex in string s at offset offset. // Return index of match or -1. var matchAt = function(re, s, offset) { - "use strict"; var res = s.slice(offset).match(re); if (res) { return offset + res.index; @@ -76,7 +74,6 @@ var matchAt = function(re, s, offset) { // destructively trip final blank lines in an array of strings var stripFinalBlankLines = function(lns) { - "use strict"; var i = lns.length - 1; while (!reNonSpace.test(lns[i])) { lns.pop(); @@ -90,7 +87,6 @@ var stripFinalBlankLines = function(lns) { // Returns true if parent block can contain child block. var canContain = function(parent_type, child_type) { - "use strict"; return ( parent_type === 'Document' || parent_type === 'BlockQuote' || parent_type === 'Item' || @@ -99,7 +95,6 @@ var canContain = function(parent_type, child_type) { // Returns true if block type can accept lines of text. var acceptsLines = function(block_type) { - "use strict"; return ( block_type === 'Paragraph' || block_type === 'IndentedCode' || block_type === 'FencedCode' ); @@ -108,7 +103,6 @@ var acceptsLines = function(block_type) { // Returns true if block ends with a blank line, descending if needed // into lists and sublists. var endsWithBlankLine = function(block) { - "use strict"; while (block) { if (block.last_line_blank) { return true; @@ -127,7 +121,6 @@ var endsWithBlankLine = function(block) { // all the lists. (This is used to implement the "two blank lines // break of of all lists" feature.) var breakOutOfLists = function(block, line_number) { - "use strict"; var b = block; var last_list = null; do { @@ -150,7 +143,6 @@ var breakOutOfLists = function(block, line_number) { // Add a line to the block at the tip. We assume the tip // can accept lines -- that check should be done before calling this. var addLine = function(ln, offset) { - "use strict"; var s = ln.slice(offset); if (!(this.tip.open)) { throw { msg: "Attempted to add line (" + ln + ") to closed container." }; @@ -162,7 +154,6 @@ var addLine = function(ln, offset) { // accept children, close and finalize it and try its parent, // and so on til we find a block that can accept children. var addChild = function(tag, line_number, offset) { - "use strict"; while (!canContain(this.tip.t, tag)) { this.finalize(this.tip, line_number - 1); } @@ -179,7 +170,6 @@ var addChild = function(tag, line_number, offset) { // Parse a list marker and return data on the marker (type, // start, delimiter, bullet character, padding) or null. var parseListMarker = function(ln, offset) { - "use strict"; var rest = ln.slice(offset); var match; var spaces_after_marker; @@ -220,7 +210,6 @@ var parseListMarker = function(ln, offset) { // with the same delimiter and bullet character. This is used // in agglomerating list items into lists. var listsMatch = function(list_data, item_data) { - "use strict"; return (list_data.type === item_data.type && list_data.delimiter === item_data.delimiter && list_data.bullet_char === item_data.bullet_char); @@ -230,8 +219,6 @@ var listsMatch = function(list_data, item_data) { // We parse markdown text by calling this on each line of input, // then finalizing the document. var incorporateLine = function(ln, line_number) { - "use strict"; - var all_matched = true; var first_nonspace; var offset = 0; @@ -570,7 +557,6 @@ var incorporateLine = function(ln, line_number) { // of paragraphs for reference definitions. Reset the tip to the // parent of the closed block. var finalize = function(block, line_number) { - "use strict"; var pos; // don't do anything if the block is already closed if (!block.open) { @@ -654,7 +640,6 @@ var finalize = function(block, line_number) { // Walk through a block & children recursively, parsing string content // into inline content where appropriate. Returns new object. var processInlines = function(block) { - "use strict"; var node, event; var walker = block.walker(); while ((event = walker.next())) { @@ -667,7 +652,6 @@ var processInlines = function(block) { }; var Document = function() { - "use strict"; var doc = new Node('Document', [[1, 1], [0, 0]]); doc.string_content = undefined; doc.strings = []; @@ -676,7 +660,6 @@ var Document = function() { // The main parsing function. Returns a parsed document AST. var parse = function(input) { - "use strict"; this.doc = Document(); this.tip = this.doc; this.refmap = {}; @@ -705,7 +688,6 @@ var parse = function(input) { // The DocParser object. function DocParser(options){ - "use strict"; return { doc: Document(), tip: this.doc, diff --git a/js/lib/common.js b/js/lib/common.js index 8ba70a8..05640e3 100644 --- a/js/lib/common.js +++ b/js/lib/common.js @@ -1,3 +1,5 @@ +"use strict"; + var entityToChar = require('./html5-entities.js').entityToChar; var ENTITY = "&(?:#x[a-f0-9]{1,8}|#[0-9]{1,8}|[a-z][a-z0-9]{1,31});"; @@ -15,7 +17,6 @@ var reXmlSpecial = new RegExp(XMLSPECIAL, 'g'); var reXmlSpecialOrEntity = new RegExp(ENTITY + '|' + XMLSPECIAL, 'gi'); var unescapeChar = function(s) { - "use strict"; if (s[0] === '\\') { return s[1]; } else { @@ -25,7 +26,6 @@ var unescapeChar = function(s) { // Replace entities and backslash escapes with literal characters. var unescapeString = function(s) { - "use strict"; if (reBackslashOrAmp.test(s)) { return s.replace(reEntityOrEscapedChar, unescapeChar); } else { @@ -34,7 +34,6 @@ var unescapeString = function(s) { }; var normalizeURI = function(uri) { - "use strict"; return encodeURI(unescape(uri)); } diff --git a/js/lib/from-code-point.js b/js/lib/from-code-point.js index 69f53a2..a0557b3 100644 --- a/js/lib/from-code-point.js +++ b/js/lib/from-code-point.js @@ -1,8 +1,9 @@ +"use strict"; + // derived from https://github.com/mathiasbynens/String.fromCodePoint /*! http://mths.be/fromcodepoint v0.2.1 by @mathias */ if (String.fromCodePoint) { module.exports = function (_) { - "use strict"; try { return String.fromCodePoint(_); } catch (e) { @@ -18,7 +19,6 @@ if (String.fromCodePoint) { var stringFromCharCode = String.fromCharCode; var floor = Math.floor; var fromCodePoint = function() { - "use strict"; var MAX_SIZE = 0x4000; var codeUnits = []; var highSurrogate; diff --git a/js/lib/html5-entities.js b/js/lib/html5-entities.js index e0d703c..71e9fe6 100644 --- a/js/lib/html5-entities.js +++ b/js/lib/html5-entities.js @@ -1,3 +1,5 @@ +"use strict"; + var fromCodePoint = require('./from-code-point'); var entities = { @@ -2128,7 +2130,6 @@ var entities = { zwnj: 8204 }; var entityToChar = function(m) { - "use strict"; var isNumeric = /^&#/.test(m); var isHex = /^&#[Xx]/.test(m); var uchar; diff --git a/js/lib/index.js b/js/lib/index.js index 61a128c..d78a5b2 100755 --- a/js/lib/index.js +++ b/js/lib/index.js @@ -1,3 +1,5 @@ +"use strict"; + // commonmark.js - CommomMark in JavaScript // Copyright (C) 2014 John MacFarlane // License: BSD3. @@ -9,8 +11,6 @@ // var renderer = new commonmark.HtmlRenderer(); // console.log(renderer.render(parser.parse('Hello *world*'))); -"use strict"; - module.exports.Node = require('./node'); module.exports.DocParser = require('./blocks'); module.exports.HtmlRenderer = require('./html'); diff --git a/js/lib/inlines.js b/js/lib/inlines.js index 440328a..46e4644 100644 --- a/js/lib/inlines.js +++ b/js/lib/inlines.js @@ -1,3 +1,5 @@ +"use strict"; + var Node = require('./node'); var common = require('./common'); var normalizeURI = common.normalizeURI; @@ -93,14 +95,12 @@ var reMain = /^[^\n`\[\]\\!<&*_]+/m; // Normalize reference label: collapse internal whitespace // to single space, remove leading/trailing whitespace, case fold. var normalizeReference = function(s) { - "use strict"; return s.trim() .replace(/\s+/, ' ') .toUpperCase(); }; var text = function(s) { - "use strict"; var node = new Node('Text'); node.literal = s; return node; @@ -115,7 +115,6 @@ var text = function(s) { // If re matches at current position in the subject, advance // position in subject and return the match; otherwise return null. var match = function(re) { - "use strict"; var m = re.exec(this.subject.slice(this.pos)); if (m) { this.pos += m.index + m[0].length; @@ -128,7 +127,6 @@ var match = function(re) { // Returns the code for the character at the current subject position, or -1 // there are no more characters. var peek = function() { - "use strict"; if (this.pos < this.subject.length) { return this.subject.charCodeAt(this.pos); } else { @@ -138,7 +136,6 @@ var peek = function() { // Parse zero or more space characters, including at most one newline var spnl = function() { - "use strict"; this.match(reSpnl); return 1; }; @@ -150,7 +147,6 @@ var spnl = function() { // Attempt to parse backticks, adding either a backtick code span or a // literal sequence of backticks. var parseBackticks = function(block) { - "use strict"; var ticks = this.match(reTicksHere); if (!ticks) { return 0; @@ -179,7 +175,6 @@ var parseBackticks = function(block) { // character, a hard line break (if the backslash is followed by a newline), // or a literal backslash to the block's children. var parseBackslash = function(block) { - "use strict"; var subj = this.subject, pos = this.pos; var node; @@ -203,7 +198,6 @@ var parseBackslash = function(block) { // Attempt to parse an autolink (URL or email in pointy brackets). var parseAutolink = function(block) { - "use strict"; var m; var dest; var node; @@ -230,7 +224,6 @@ var parseAutolink = function(block) { // Attempt to parse a raw HTML tag. var parseHtmlTag = function(block) { - "use strict"; var m = this.match(reHtmlTag); var node; if (m) { @@ -248,7 +241,6 @@ var parseHtmlTag = function(block) { // they can open and/or close emphasis or strong emphasis. A utility // function for strong/emph parsing. var scanDelims = function(cc) { - "use strict"; var numdelims = 0; var char_before, char_after, cc_after; var startpos = this.pos; @@ -288,8 +280,6 @@ var scanDelims = function(cc) { // Attempt to parse emphasis or strong emphasis. var parseEmphasis = function(cc, block) { - "use strict"; - var res = this.scanDelims(cc); var numdelims = res.numdelims; var startpos = this.pos; @@ -320,7 +310,6 @@ var parseEmphasis = function(cc, block) { }; var removeDelimiter = function(delim) { - "use strict"; if (delim.previous !== null) { delim.previous.next = delim.next; } @@ -333,7 +322,6 @@ var removeDelimiter = function(delim) { }; var processEmphasis = function(block, stack_bottom) { - "use strict"; var opener, closer; var opener_inl, closer_inl; var nextstack, tempstack; @@ -431,7 +419,6 @@ var processEmphasis = function(block, stack_bottom) { // Attempt to parse link title (sans quotes), returning the string // or null if no match. var parseLinkTitle = function() { - "use strict"; var title = this.match(reLinkTitle); if (title) { // chop off quotes from title and unescape: @@ -444,7 +431,6 @@ var parseLinkTitle = function() { // Attempt to parse link destination, returning the string or // null if no match. var parseLinkDestination = function() { - "use strict"; var res = this.match(reLinkDestinationBraces); if (res) { // chop off surrounding <..>: return normalizeURI(unescapeString(res.substr(1, res.length - 2))); @@ -460,15 +446,12 @@ var parseLinkDestination = function() { // Attempt to parse a link label, returning number of characters parsed. var parseLinkLabel = function() { - "use strict"; var m = this.match(reLinkLabel); return m === null ? 0 : m.length; }; // Add open bracket to delimiter stack and add a text node to block's children. var parseOpenBracket = function(block) { - "use strict"; - var startpos = this.pos; this.pos += 1; @@ -496,8 +479,6 @@ var parseOpenBracket = function(block) { // IF next character is [, and ! delimiter to delimiter stack and // add a text node to block's children. Otherwise just add a text node. var parseBang = function(block) { - "use strict"; - var startpos = this.pos; this.pos += 1; if (this.peek() === C_OPEN_BRACKET) { @@ -530,8 +511,6 @@ var parseBang = function(block) { // to block's children. If there is a matching delimiter, // remove it from the delimiter stack. var parseCloseBracket = function(block) { - "use strict"; - var startpos; var is_image; var dest; @@ -658,8 +637,6 @@ var parseCloseBracket = function(block) { // Attempt to parse an entity, return Entity object if successful. var parseEntity = function(block) { - "use strict"; - var m; if ((m = this.match(reEntityHere))) { block.appendChild(text(entityToChar(m))); @@ -672,7 +649,6 @@ var parseEntity = function(block) { // Parse a run of ordinary characters, or a single character with // a special meaning in markdown, as a plain string. var parseString = function(block) { - "use strict"; var m; if ((m = this.match(reMain))) { block.appendChild(text(m)); @@ -685,7 +661,6 @@ var parseString = function(block) { // Parse a newline. If it was preceded by two spaces, return a hard // line break; otherwise a soft line break. var parseNewline = function(block) { - "use strict"; this.pos += 1; // assume we're at a \n // check previous node for trailing spaces var lastc = block.lastChild; @@ -704,7 +679,6 @@ var parseNewline = function(block) { // Attempt to parse a link reference, modifying refmap. var parseReference = function(s, refmap) { - "use strict"; this.subject = s; this.pos = 0; var rawlabel; @@ -765,7 +739,6 @@ var parseReference = function(s, refmap) { // On success, add the result to block's children and return true. // On failure, return false. var parseInline = function(block) { - "use strict"; var res; var c = this.peek(); if (c === -1) { @@ -817,7 +790,6 @@ var parseInline = function(block) { // Parse string_content in block into inline children, // using refmap to resolve references. var parseInlines = function(block, refmap) { - "use strict"; this.subject = block.string_content.trim(); this.pos = 0; this.refmap = refmap || {}; @@ -829,7 +801,6 @@ var parseInlines = function(block, refmap) { // The InlineParser object. function InlineParser(){ - "use strict"; return { subject: '', delimiters: null, // used by parseEmphasis method -- cgit v1.2.3