Skip to content

Commit 48ae6e6

Browse files
Updated to ES6 syntax
1 parent 2971bbe commit 48ae6e6

51 files changed

Lines changed: 1174 additions & 1185 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.eslintrc.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ extends:
99
- modular/style
1010
- modular/browser
1111
- modular/node
12-
- modular/es5
12+
- modular/es6
1313

1414
globals:
1515
Promise: false

lib/bundle.js

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
"use strict";
22

3-
var $Ref = require("./ref"),
4-
Pointer = require("./pointer"),
5-
url = require("./util/url");
3+
const $Ref = require("./ref");
4+
const Pointer = require("./pointer");
5+
const url = require("./util/url");
66

77
module.exports = bundle;
88

@@ -18,7 +18,7 @@ function bundle (parser, options) {
1818
// console.log('Bundling $ref pointers in %s', parser.$refs._root$Ref.path);
1919

2020
// Build an inventory of all $ref pointers in the JSON Schema
21-
var inventory = [];
21+
let inventory = [];
2222
crawl(parser, "schema", parser.$refs._root$Ref.path + "#", "#", 0, inventory, parser.$refs, options);
2323

2424
// Remap all $ref pointers
@@ -37,7 +37,7 @@ function bundle (parser, options) {
3737
* @param {$RefParserOptions} options
3838
*/
3939
function crawl (parent, key, path, pathFromRoot, indirections, inventory, $refs, options) {
40-
var obj = key === null ? parent : parent[key];
40+
let obj = key === null ? parent : parent[key];
4141

4242
if (obj && typeof obj === "object") {
4343
if ($Ref.isAllowed$Ref(obj)) {
@@ -47,8 +47,8 @@ function crawl (parent, key, path, pathFromRoot, indirections, inventory, $refs,
4747
// Crawl the object in a specific order that's optimized for bundling.
4848
// This is important because it determines how `pathFromRoot` gets built,
4949
// which later determines which keys get dereferenced and which ones get remapped
50-
var keys = Object.keys(obj)
51-
.sort(function (a, b) {
50+
let keys = Object.keys(obj)
51+
.sort((a, b) => {
5252
// Most people will expect references to be bundled into the the "definitions" property,
5353
// so we always crawl that property first, if it exists.
5454
if (a === "definitions") {
@@ -64,10 +64,10 @@ function crawl (parent, key, path, pathFromRoot, indirections, inventory, $refs,
6464
}
6565
});
6666

67-
keys.forEach(function (key) {
68-
var keyPath = Pointer.join(path, key);
69-
var keyPathFromRoot = Pointer.join(pathFromRoot, key);
70-
var value = obj[key];
67+
keys.forEach((key) => {
68+
let keyPath = Pointer.join(path, key);
69+
let keyPathFromRoot = Pointer.join(pathFromRoot, key);
70+
let value = obj[key];
7171

7272
if ($Ref.isAllowed$Ref(value)) {
7373
inventory$Ref(obj, key, path, keyPathFromRoot, indirections, inventory, $refs, options);
@@ -93,17 +93,17 @@ function crawl (parent, key, path, pathFromRoot, indirections, inventory, $refs,
9393
* @param {$RefParserOptions} options
9494
*/
9595
function inventory$Ref ($refParent, $refKey, path, pathFromRoot, indirections, inventory, $refs, options) {
96-
var $ref = $refKey === null ? $refParent : $refParent[$refKey];
97-
var $refPath = url.resolve(path, $ref.$ref);
98-
var pointer = $refs._resolve($refPath, options);
99-
var depth = Pointer.parse(pathFromRoot).length;
100-
var file = url.stripHash(pointer.path);
101-
var hash = url.getHash(pointer.path);
102-
var external = file !== $refs._root$Ref.path;
103-
var extended = $Ref.isExtended$Ref($ref);
96+
let $ref = $refKey === null ? $refParent : $refParent[$refKey];
97+
let $refPath = url.resolve(path, $ref.$ref);
98+
let pointer = $refs._resolve($refPath, options);
99+
let depth = Pointer.parse(pathFromRoot).length;
100+
let file = url.stripHash(pointer.path);
101+
let hash = url.getHash(pointer.path);
102+
let external = file !== $refs._root$Ref.path;
103+
let extended = $Ref.isExtended$Ref($ref);
104104
indirections += pointer.indirections;
105105

106-
var existingEntry = findInInventory(inventory, $refParent, $refKey);
106+
let existingEntry = findInInventory(inventory, $refParent, $refKey);
107107
if (existingEntry) {
108108
// This $Ref has already been inventoried, so we don't need to process it again
109109
if (depth < existingEntry.depth || indirections < existingEntry.indirections) {
@@ -115,18 +115,18 @@ function inventory$Ref ($refParent, $refKey, path, pathFromRoot, indirections, i
115115
}
116116

117117
inventory.push({
118-
$ref: $ref, // The JSON Reference (e.g. {$ref: string})
118+
$ref, // The JSON Reference (e.g. {$ref: string})
119119
parent: $refParent, // The object that contains this $ref pointer
120120
key: $refKey, // The key in `parent` that is the $ref pointer
121-
pathFromRoot: pathFromRoot, // The path to the $ref pointer, from the JSON Schema root
122-
depth: depth, // How far from the JSON Schema root is this $ref pointer?
123-
file: file, // The file that the $ref pointer resolves to
124-
hash: hash, // The hash within `file` that the $ref pointer resolves to
121+
pathFromRoot, // The path to the $ref pointer, from the JSON Schema root
122+
depth, // How far from the JSON Schema root is this $ref pointer?
123+
file, // The file that the $ref pointer resolves to
124+
hash, // The hash within `file` that the $ref pointer resolves to
125125
value: pointer.value, // The resolved value of the $ref pointer
126126
circular: pointer.circular, // Is this $ref pointer DIRECTLY circular? (i.e. it references itself)
127-
extended: extended, // Does this $ref extend its resolved value? (i.e. it has extra properties, in addition to "$ref")
128-
external: external, // Does this $ref pointer point to a file other than the main JSON Schema file?
129-
indirections: indirections, // The number of indirect references that were traversed to resolve the value
127+
extended, // Does this $ref extend its resolved value? (i.e. it has extra properties, in addition to "$ref")
128+
external, // Does this $ref pointer point to a file other than the main JSON Schema file?
129+
indirections, // The number of indirect references that were traversed to resolve the value
130130
});
131131

132132
// Recursively crawl the resolved value
@@ -158,7 +158,7 @@ function inventory$Ref ($refParent, $refKey, path, pathFromRoot, indirections, i
158158
*/
159159
function remap (inventory) {
160160
// Group & sort all the $ref pointers, so they're in the order that we need to dereference/remap them
161-
inventory.sort(function (a, b) {
161+
inventory.sort((a, b) => {
162162
if (a.file !== b.file) {
163163
// Group all the $refs that point to the same file
164164
return a.file < b.file ? -1 : +1;
@@ -186,8 +186,8 @@ function remap (inventory) {
186186
else {
187187
// Determine how far each $ref is from the "definitions" property.
188188
// Most people will expect references to be bundled into the the "definitions" property if possible.
189-
var aDefinitionsIndex = a.pathFromRoot.lastIndexOf("/definitions");
190-
var bDefinitionsIndex = b.pathFromRoot.lastIndexOf("/definitions");
189+
let aDefinitionsIndex = a.pathFromRoot.lastIndexOf("/definitions");
190+
let bDefinitionsIndex = b.pathFromRoot.lastIndexOf("/definitions");
191191

192192
if (aDefinitionsIndex !== bDefinitionsIndex) {
193193
// Give higher priority to the $ref that's closer to the "definitions" property
@@ -200,8 +200,8 @@ function remap (inventory) {
200200
}
201201
});
202202

203-
var file, hash, pathFromRoot;
204-
inventory.forEach(function (entry) {
203+
let file, hash, pathFromRoot;
204+
inventory.forEach((entry) => {
205205
// console.log('Re-mapping $ref pointer "%s" at %s', entry.$ref.$ref, entry.pathFromRoot);
206206

207207
if (!entry.external) {
@@ -240,15 +240,15 @@ function remap (inventory) {
240240
* TODO
241241
*/
242242
function findInInventory (inventory, $refParent, $refKey) {
243-
for (var i = 0; i < inventory.length; i++) {
244-
var existingEntry = inventory[i];
243+
for (let i = 0; i < inventory.length; i++) {
244+
let existingEntry = inventory[i];
245245
if (existingEntry.parent === $refParent && existingEntry.key === $refKey) {
246246
return existingEntry;
247247
}
248248
}
249249
}
250250

251251
function removeFromInventory (inventory, entry) {
252-
var index = inventory.indexOf(entry);
252+
let index = inventory.indexOf(entry);
253253
inventory.splice(index, 1);
254254
}

0 commit comments

Comments
 (0)