Skip to content

Commit

Permalink
[PERF] Reduce install size by removing 'string.prototype.matchall' de…
Browse files Browse the repository at this point in the history
…pendency
  • Loading branch information
matz3 committed Nov 6, 2020
1 parent 7487b02 commit b69d75e
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 243 deletions.
12 changes: 5 additions & 7 deletions lib/validation/ValidationError.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
const chalk = require("chalk");
const escapeStringRegExp = require("escape-string-regexp");
const matchAll = require("string.prototype.matchall");

/**
* Error class for validation of project configuration.
Expand Down Expand Up @@ -140,9 +139,9 @@ class ValidationError extends Error {
let currentIndex;
if (yaml.documentIndex) {
const matchDocumentSeparator = /^---/gm;
const documents = matchAll(yaml.source, matchDocumentSeparator);
let currentDocumentIndex = 0;
for (const document of documents) {
let document;
while ((document = matchDocumentSeparator.exec(yaml.source)) !== null) {
// If the first separator is not at the beginning of the file
// we are already at document index 1
// Using String#trim() to remove any whitespace characters
Expand All @@ -168,8 +167,6 @@ class ValidationError extends Error {
currentSubstring = yaml.source;
}


const matchArrayElement = /(^|\r?\n)([ ]*-[^\r\n]*)/g;
const matchArrayElementIndentation = /([ ]*)-/;

for (let i = 0; i < objectPath.length; i++) {
Expand All @@ -193,11 +190,12 @@ class ValidationError extends Error {
// This currently only works for arrays defined with "-" in multiple lines.
// Arrays using square brackets are not supported.

const matchArrayElement = /(^|\r?\n)([ ]*-[^\r\n]*)/g;
const arrayIndex = parseInt(property);
const arrayIndicators = matchAll(currentSubstring, matchArrayElement);
let a = 0;
let firstIndentation = -1;
for (const match of arrayIndicators) {
let match;
while ((match = matchArrayElement.exec(currentSubstring)) !== null) {
const indentationMatch = match[2].match(matchArrayElementIndentation);
if (!indentationMatch) {
return {line: -1, column: -1};
Expand Down
234 changes: 0 additions & 234 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,7 @@
"read-pkg": "^5.2.0",
"read-pkg-up": "^7.0.1",
"resolve": "^1.18.1",
"semver": "^7.3.2",
"string.prototype.matchall": "^4.0.2"
"semver": "^7.3.2"
},
"devDependencies": {
"ava": "^3.13.0",
Expand Down

0 comments on commit b69d75e

Please sign in to comment.