Browse Source

tools: change var to const in ./doc/json

PR-URL: https://github.com/nodejs/node/pull/13732
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Refael Ackermann <refack@gmail.com>
v6
Ruben Bridgewater 8 years ago
committed by Refael Ackermann
parent
commit
461049f8e9
No known key found for this signature in database GPG Key ID: CD704BD80FDDDB64
  1. 56
      tools/doc/json.js

56
tools/doc/json.js

@ -30,7 +30,7 @@ const common = require('./common.js');
const marked = require('marked'); const marked = require('marked');
// customized heading without id attribute // customized heading without id attribute
var renderer = new marked.Renderer(); const renderer = new marked.Renderer();
renderer.heading = function(text, level) { renderer.heading = function(text, level) {
return '<h' + level + '>' + text + '</h' + level + '>\n'; return '<h' + level + '>' + text + '</h' + level + '>\n';
}; };
@ -39,14 +39,14 @@ marked.setOptions({
}); });
function doJSON(input, filename, cb) { function doJSON(input, filename, cb) {
var root = {source: filename}; const root = {source: filename};
var stack = [root]; const stack = [root];
var depth = 0; var depth = 0;
var current = root; var current = root;
var state = null; var state = null;
var lexed = marked.lexer(input); const lexed = marked.lexer(input);
lexed.forEach(function(tok) { lexed.forEach(function(tok) {
var type = tok.type; const type = tok.type;
var text = tok.text; var text = tok.text;
// <!-- type = module --> // <!-- type = module -->
@ -223,14 +223,14 @@ function doJSON(input, filename, cb) {
// default: 'false' } ] } ] // default: 'false' } ] } ]
function processList(section) { function processList(section) {
var list = section.list; const list = section.list;
var values = []; const values = [];
var current; var current;
var stack = []; const stack = [];
// for now, *just* build the heirarchical list // for now, *just* build the heirarchical list
list.forEach(function(tok) { list.forEach(function(tok) {
var type = tok.type; const type = tok.type;
if (type === 'space') return; if (type === 'space') return;
if (type === 'list_item_start' || type === 'loose_item_start') { if (type === 'list_item_start' || type === 'loose_item_start') {
var n = {}; var n = {};
@ -329,7 +329,7 @@ function parseSignature(text, sig) {
params = params[1]; params = params[1];
params = params.split(/,/); params = params.split(/,/);
var optionalLevel = 0; var optionalLevel = 0;
var optionalCharDict = {'[': 1, ' ': 0, ']': -1}; const optionalCharDict = {'[': 1, ' ': 0, ']': -1};
params.forEach(function(p, i) { params.forEach(function(p, i) {
p = p.trim(); p = p.trim();
if (!p) return; if (!p) return;
@ -351,7 +351,7 @@ function parseSignature(text, sig) {
} }
p = p.substring(0, pos + 1); p = p.substring(0, pos + 1);
var eq = p.indexOf('='); const eq = p.indexOf('=');
if (eq !== -1) { if (eq !== -1) {
def = p.substr(eq + 1); def = p.substr(eq + 1);
p = p.substr(0, eq); p = p.substr(0, eq);
@ -381,8 +381,8 @@ function parseListItem(item) {
// text = text.replace(/^(Argument|Param)s?\s*:?\s*/i, ''); // text = text.replace(/^(Argument|Param)s?\s*:?\s*/i, '');
text = text.replace(/^, /, '').trim(); text = text.replace(/^, /, '').trim();
var retExpr = /^returns?\s*:?\s*/i; const retExpr = /^returns?\s*:?\s*/i;
var ret = text.match(retExpr); const ret = text.match(retExpr);
if (ret) { if (ret) {
item.name = 'return'; item.name = 'return';
text = text.replace(retExpr, ''); text = text.replace(retExpr, '');
@ -396,24 +396,24 @@ function parseListItem(item) {
} }
text = text.trim(); text = text.trim();
var defaultExpr = /\(default\s*[:=]?\s*['"`]?([^, '"`]*)['"`]?\)/i; const defaultExpr = /\(default\s*[:=]?\s*['"`]?([^, '"`]*)['"`]?\)/i;
var def = text.match(defaultExpr); const def = text.match(defaultExpr);
if (def) { if (def) {
item.default = def[1]; item.default = def[1];
text = text.replace(defaultExpr, ''); text = text.replace(defaultExpr, '');
} }
text = text.trim(); text = text.trim();
var typeExpr = /^\{([^}]+)\}/; const typeExpr = /^\{([^}]+)\}/;
var type = text.match(typeExpr); const type = text.match(typeExpr);
if (type) { if (type) {
item.type = type[1]; item.type = type[1];
text = text.replace(typeExpr, ''); text = text.replace(typeExpr, '');
} }
text = text.trim(); text = text.trim();
var optExpr = /^Optional\.|(?:, )?Optional$/; const optExpr = /^Optional\.|(?:, )?Optional$/;
var optional = text.match(optExpr); const optional = text.match(optExpr);
if (optional) { if (optional) {
item.optional = true; item.optional = true;
text = text.replace(optExpr, ''); text = text.replace(optExpr, '');
@ -556,19 +556,19 @@ function deepCopy_(src) {
// these parse out the contents of an H# tag // these parse out the contents of an H# tag
var eventExpr = /^Event(?::|\s)+['"]?([^"']+).*$/i; const eventExpr = /^Event(?::|\s)+['"]?([^"']+).*$/i;
var classExpr = /^Class:\s*([^ ]+).*$/i; const classExpr = /^Class:\s*([^ ]+).*$/i;
var propExpr = /^[^.]+\.([^ .()]+)\s*$/; const propExpr = /^[^.]+\.([^ .()]+)\s*$/;
var braceExpr = /^[^.[]+(\[[^\]]+\])\s*$/; const braceExpr = /^[^.[]+(\[[^\]]+\])\s*$/;
var classMethExpr = /^class\s*method\s*:?[^.]+\.([^ .()]+)\([^)]*\)\s*$/i; const classMethExpr = /^class\s*method\s*:?[^.]+\.([^ .()]+)\([^)]*\)\s*$/i;
var methExpr = /^(?:[^.]+\.)?([^ .()]+)\([^)]*\)\s*$/; const methExpr = /^(?:[^.]+\.)?([^ .()]+)\([^)]*\)\s*$/;
var newExpr = /^new ([A-Z][a-zA-Z]+)\([^)]*\)\s*$/; const newExpr = /^new ([A-Z][a-zA-Z]+)\([^)]*\)\s*$/;
var paramExpr = /\((.*)\);?$/; var paramExpr = /\((.*)\);?$/;
function newSection(tok) { function newSection(tok) {
var section = {}; const section = {};
// infer the type from the text. // infer the type from the text.
var text = section.textRaw = tok.text; const text = section.textRaw = tok.text;
if (text.match(eventExpr)) { if (text.match(eventExpr)) {
section.type = 'event'; section.type = 'event';
section.name = text.replace(eventExpr, '$1'); section.name = text.replace(eventExpr, '$1');

Loading…
Cancel
Save