@locker/ast-lib-maker
Advanced tools
Comparing version 0.18.15 to 0.18.16
@@ -9,17 +9,13 @@ /*! | ||
}); | ||
var shared = require('@locker/shared'); | ||
const ASTERISK_CHARACTER = '*'; | ||
const DOCUMENT_ALIASES = [`${ASTERISK_CHARACTER}.ownerDocument`, 'document']; | ||
const WINDOW_ALIASES = ['document.defaultView', 'frames', 'globalThis', 'parent', 'self', 'top', 'window']; | ||
function dehydratedPatternStartsWith(dehydratedPattern, searchString) { | ||
return dehydratedPattern.startsWith(`${searchString}.`); | ||
} | ||
function dehydratedPatternStartsWithByAliases(dehydratedPattern, aliases) { | ||
for (let i = 0, { | ||
length | ||
} = aliases; i < length; i += 1) { | ||
length | ||
} = aliases; i < length; i += 1) { | ||
if (dehydratedPatternStartsWith(dehydratedPattern, aliases[i])) { | ||
@@ -29,23 +25,17 @@ return true; | ||
} | ||
return false; | ||
} | ||
function dehydratedPatternTail(dehydratedPattern) { | ||
return dehydratedPattern.slice(dehydratedPattern.indexOf('.') + 1); | ||
} | ||
function dehydratePattern(pattern) { | ||
return pattern.join('.'); | ||
} | ||
function expandPattern(dehydratedPattern) { | ||
const expandedPatterns = []; // Exit early for patterns starting with '*.'. | ||
const expandedPatterns = []; | ||
// Exit early for patterns starting with '*.'. | ||
if (dehydratedPatternStartsWith(dehydratedPattern, ASTERISK_CHARACTER)) { | ||
return expandedPatterns; | ||
} | ||
const dehydratedPatterns = [dehydratedPattern]; | ||
const push = otherDehydratedPattern => { | ||
@@ -57,36 +47,29 @@ if (!dehydratedPatterns.includes(otherDehydratedPattern)) { | ||
}; | ||
const pushAliases = (aliases, pathTail) => { | ||
for (let i = 0, { | ||
length | ||
} = aliases; i < length; i += 1) { | ||
length | ||
} = aliases; i < length; i += 1) { | ||
push(`${aliases[i]}.${pathTail}`); | ||
} | ||
}; | ||
const topLevelPath = isWindowStringPattern(dehydratedPattern) ? dehydratedPatternTail(dehydratedPattern) : dehydratedPattern; // Expand patterns with a top-level identifier. | ||
push(topLevelPath); // Expand patterns with other `window` aliases. | ||
pushAliases(WINDOW_ALIASES, topLevelPath); // Expand patterns with other `document` aliases. | ||
const topLevelPath = isWindowStringPattern(dehydratedPattern) ? dehydratedPatternTail(dehydratedPattern) : dehydratedPattern; | ||
// Expand patterns with a top-level identifier. | ||
push(topLevelPath); | ||
// Expand patterns with other `window` aliases. | ||
pushAliases(WINDOW_ALIASES, topLevelPath); | ||
// Expand patterns with other `document` aliases. | ||
if (isDocumentStringPattern(topLevelPath)) { | ||
pushAliases(DOCUMENT_ALIASES, dehydratedPatternTail(topLevelPath)); | ||
} | ||
return expandedPatterns; | ||
} | ||
function isDocumentStringPattern(dehydratedPattern) { | ||
return dehydratedPatternStartsWithByAliases(dehydratedPattern, DOCUMENT_ALIASES); | ||
} | ||
function isWindowStringPattern(dehydratedPattern) { | ||
return dehydratedPatternStartsWithByAliases(dehydratedPattern, WINDOW_ALIASES); | ||
} | ||
function rehydratePattern(dehydratedPattern) { | ||
return dehydratedPattern.split('.'); | ||
} | ||
const baseLib = { | ||
@@ -113,36 +96,29 @@ /** | ||
const expandedPatterns = []; | ||
for (let i = 0, { | ||
length | ||
} = dehydratedPatterns; i < length; i += 1) { | ||
length | ||
} = dehydratedPatterns; i < length; i += 1) { | ||
expandedPatterns.push(rehydratePattern(dehydratedPatterns[i])); | ||
} | ||
for (let i = 0, { | ||
length | ||
} = dehydratedPatterns; i < length; i += 1) { | ||
const patterns = expandPattern(dehydratedPatterns[i]); // eslint-disable-next-line @typescript-eslint/naming-convention | ||
length | ||
} = dehydratedPatterns; i < length; i += 1) { | ||
const patterns = expandPattern(dehydratedPatterns[i]); | ||
// eslint-disable-next-line @typescript-eslint/naming-convention | ||
for (let j = 0, { | ||
length: length_j | ||
} = patterns; j < length_j; j += 1) { | ||
length: length_j | ||
} = patterns; j < length_j; j += 1) { | ||
expandedPatterns.push(patterns[j]); | ||
} | ||
} | ||
return expandedPatterns; | ||
}, | ||
getIdentifierName(node) { | ||
return node.name; | ||
}, | ||
getParent(node) { | ||
return node.parent; | ||
}, | ||
getType(node) { | ||
return node.type; | ||
}, | ||
isMatchableNode(node) { | ||
@@ -153,6 +129,4 @@ if (node) { | ||
} | ||
return false; | ||
}, | ||
isNodeByAsteriskOrName(node, name) { | ||
@@ -162,6 +136,4 @@ if (this.isMatchableNode(node)) { | ||
} | ||
return false; | ||
}, | ||
isNonComputedMemberExpressionNode(node) { | ||
@@ -171,17 +143,14 @@ if (node) { | ||
} | ||
return false; | ||
}, | ||
match(identifier, patterns) { | ||
expandedLoop: for (let i = 0, { | ||
length | ||
} = patterns; i < length; i += 1) { | ||
const pattern = patterns[i]; // Skip fast for mismatched identifiers. | ||
length | ||
} = patterns; i < length; i += 1) { | ||
const pattern = patterns[i]; | ||
// Skip fast for mismatched identifiers. | ||
if (!this.isNodeByAsteriskOrName(identifier, pattern[0])) { | ||
continue; | ||
} // Match and exit early for non-member identifier matches. | ||
} | ||
// Match and exit early for non-member identifier matches. | ||
if (pattern.length === 1) { | ||
@@ -194,14 +163,12 @@ return { | ||
} | ||
let currentNode = identifier; // eslint-disable-next-line @typescript-eslint/naming-convention | ||
let currentNode = identifier; | ||
// eslint-disable-next-line @typescript-eslint/naming-convention | ||
for (let j = 0, { | ||
length: length_j | ||
} = pattern; j < length_j; j += 1) { | ||
currentNode = this.getParent(currentNode); // Skip for unexpected nodes. | ||
length: length_j | ||
} = pattern; j < length_j; j += 1) { | ||
currentNode = this.getParent(currentNode); | ||
// Skip for unexpected nodes. | ||
if (!this.isNonComputedMemberExpressionNode(currentNode)) { | ||
continue expandedLoop; | ||
} | ||
const { | ||
@@ -212,26 +179,23 @@ object, | ||
let matchedByPreviousAsterisk = false; | ||
if (this.isMatchableNode(object)) { | ||
// Skip for mismatched object identifiers. | ||
if (!this.isNodeByAsteriskOrName(object, pattern[j])) { | ||
matchedByPreviousAsterisk = pattern[j - 1] === ASTERISK_CHARACTER; // istanbul ignore else: currently unreachable via tests | ||
matchedByPreviousAsterisk = pattern[j - 1] === ASTERISK_CHARACTER; | ||
// istanbul ignore else: currently unreachable via tests | ||
if (!matchedByPreviousAsterisk) { | ||
continue expandedLoop; | ||
} | ||
} // istanbul ignore else: currently unreachable via tests | ||
} | ||
// istanbul ignore else: currently unreachable via tests | ||
if (!matchedByPreviousAsterisk) { | ||
j += 1; | ||
} | ||
} // Skip nodes that aren't part of a property chain. | ||
} | ||
// Skip nodes that aren't part of a property chain. | ||
else if (!this.isNonComputedMemberExpressionNode(object)) { | ||
continue expandedLoop; | ||
} // Skip for mismatched property identifiers. | ||
} | ||
// Skip for mismatched property identifiers. | ||
if (!this.isNodeByAsteriskOrName(property, pattern[j])) { | ||
matchedByPreviousAsterisk = pattern[j - 1] === ASTERISK_CHARACTER; | ||
if (!matchedByPreviousAsterisk) { | ||
@@ -241,9 +205,7 @@ continue expandedLoop; | ||
} | ||
if (matchedByPreviousAsterisk) { | ||
j -= 1; | ||
} | ||
} // If we've made it this far it's a match! | ||
} | ||
// If we've made it this far it's a match! | ||
return { | ||
@@ -255,14 +217,10 @@ identifier, | ||
} | ||
return undefined; | ||
}, | ||
matchAll(identifiers, patterns) { | ||
const matches = []; | ||
for (let i = 0, { | ||
length | ||
} = identifiers; i < length; i += 1) { | ||
length | ||
} = identifiers; i < length; i += 1) { | ||
const matchData = this.match(identifiers[i], patterns); | ||
if (matchData) { | ||
@@ -272,13 +230,9 @@ matches.push(matchData); | ||
} | ||
return matches; | ||
} | ||
}; | ||
function createLib(overrides) { | ||
return shared.ObjectAssign({}, baseLib, overrides); | ||
} | ||
exports.createLib = createLib; | ||
/*! version: 0.18.15 */ | ||
/*! version: 0.18.16 */ |
@@ -8,11 +8,9 @@ /*! | ||
const WINDOW_ALIASES = ['document.defaultView', 'frames', 'globalThis', 'parent', 'self', 'top', 'window']; | ||
function dehydratedPatternStartsWith(dehydratedPattern, searchString) { | ||
return dehydratedPattern.startsWith(`${searchString}.`); | ||
} | ||
function dehydratedPatternStartsWithByAliases(dehydratedPattern, aliases) { | ||
for (let i = 0, { | ||
length | ||
} = aliases; i < length; i += 1) { | ||
length | ||
} = aliases; i < length; i += 1) { | ||
if (dehydratedPatternStartsWith(dehydratedPattern, aliases[i])) { | ||
@@ -22,23 +20,17 @@ return true; | ||
} | ||
return false; | ||
} | ||
function dehydratedPatternTail(dehydratedPattern) { | ||
return dehydratedPattern.slice(dehydratedPattern.indexOf('.') + 1); | ||
} | ||
function dehydratePattern(pattern) { | ||
return pattern.join('.'); | ||
} | ||
function expandPattern(dehydratedPattern) { | ||
const expandedPatterns = []; // Exit early for patterns starting with '*.'. | ||
const expandedPatterns = []; | ||
// Exit early for patterns starting with '*.'. | ||
if (dehydratedPatternStartsWith(dehydratedPattern, ASTERISK_CHARACTER)) { | ||
return expandedPatterns; | ||
} | ||
const dehydratedPatterns = [dehydratedPattern]; | ||
const push = otherDehydratedPattern => { | ||
@@ -50,36 +42,29 @@ if (!dehydratedPatterns.includes(otherDehydratedPattern)) { | ||
}; | ||
const pushAliases = (aliases, pathTail) => { | ||
for (let i = 0, { | ||
length | ||
} = aliases; i < length; i += 1) { | ||
length | ||
} = aliases; i < length; i += 1) { | ||
push(`${aliases[i]}.${pathTail}`); | ||
} | ||
}; | ||
const topLevelPath = isWindowStringPattern(dehydratedPattern) ? dehydratedPatternTail(dehydratedPattern) : dehydratedPattern; // Expand patterns with a top-level identifier. | ||
push(topLevelPath); // Expand patterns with other `window` aliases. | ||
pushAliases(WINDOW_ALIASES, topLevelPath); // Expand patterns with other `document` aliases. | ||
const topLevelPath = isWindowStringPattern(dehydratedPattern) ? dehydratedPatternTail(dehydratedPattern) : dehydratedPattern; | ||
// Expand patterns with a top-level identifier. | ||
push(topLevelPath); | ||
// Expand patterns with other `window` aliases. | ||
pushAliases(WINDOW_ALIASES, topLevelPath); | ||
// Expand patterns with other `document` aliases. | ||
if (isDocumentStringPattern(topLevelPath)) { | ||
pushAliases(DOCUMENT_ALIASES, dehydratedPatternTail(topLevelPath)); | ||
} | ||
return expandedPatterns; | ||
} | ||
function isDocumentStringPattern(dehydratedPattern) { | ||
return dehydratedPatternStartsWithByAliases(dehydratedPattern, DOCUMENT_ALIASES); | ||
} | ||
function isWindowStringPattern(dehydratedPattern) { | ||
return dehydratedPatternStartsWithByAliases(dehydratedPattern, WINDOW_ALIASES); | ||
} | ||
function rehydratePattern(dehydratedPattern) { | ||
return dehydratedPattern.split('.'); | ||
} | ||
const baseLib = { | ||
@@ -106,36 +91,29 @@ /** | ||
const expandedPatterns = []; | ||
for (let i = 0, { | ||
length | ||
} = dehydratedPatterns; i < length; i += 1) { | ||
length | ||
} = dehydratedPatterns; i < length; i += 1) { | ||
expandedPatterns.push(rehydratePattern(dehydratedPatterns[i])); | ||
} | ||
for (let i = 0, { | ||
length | ||
} = dehydratedPatterns; i < length; i += 1) { | ||
const patterns = expandPattern(dehydratedPatterns[i]); // eslint-disable-next-line @typescript-eslint/naming-convention | ||
length | ||
} = dehydratedPatterns; i < length; i += 1) { | ||
const patterns = expandPattern(dehydratedPatterns[i]); | ||
// eslint-disable-next-line @typescript-eslint/naming-convention | ||
for (let j = 0, { | ||
length: length_j | ||
} = patterns; j < length_j; j += 1) { | ||
length: length_j | ||
} = patterns; j < length_j; j += 1) { | ||
expandedPatterns.push(patterns[j]); | ||
} | ||
} | ||
return expandedPatterns; | ||
}, | ||
getIdentifierName(node) { | ||
return node.name; | ||
}, | ||
getParent(node) { | ||
return node.parent; | ||
}, | ||
getType(node) { | ||
return node.type; | ||
}, | ||
isMatchableNode(node) { | ||
@@ -146,6 +124,4 @@ if (node) { | ||
} | ||
return false; | ||
}, | ||
isNodeByAsteriskOrName(node, name) { | ||
@@ -155,6 +131,4 @@ if (this.isMatchableNode(node)) { | ||
} | ||
return false; | ||
}, | ||
isNonComputedMemberExpressionNode(node) { | ||
@@ -164,17 +138,14 @@ if (node) { | ||
} | ||
return false; | ||
}, | ||
match(identifier, patterns) { | ||
expandedLoop: for (let i = 0, { | ||
length | ||
} = patterns; i < length; i += 1) { | ||
const pattern = patterns[i]; // Skip fast for mismatched identifiers. | ||
length | ||
} = patterns; i < length; i += 1) { | ||
const pattern = patterns[i]; | ||
// Skip fast for mismatched identifiers. | ||
if (!this.isNodeByAsteriskOrName(identifier, pattern[0])) { | ||
continue; | ||
} // Match and exit early for non-member identifier matches. | ||
} | ||
// Match and exit early for non-member identifier matches. | ||
if (pattern.length === 1) { | ||
@@ -187,14 +158,12 @@ return { | ||
} | ||
let currentNode = identifier; // eslint-disable-next-line @typescript-eslint/naming-convention | ||
let currentNode = identifier; | ||
// eslint-disable-next-line @typescript-eslint/naming-convention | ||
for (let j = 0, { | ||
length: length_j | ||
} = pattern; j < length_j; j += 1) { | ||
currentNode = this.getParent(currentNode); // Skip for unexpected nodes. | ||
length: length_j | ||
} = pattern; j < length_j; j += 1) { | ||
currentNode = this.getParent(currentNode); | ||
// Skip for unexpected nodes. | ||
if (!this.isNonComputedMemberExpressionNode(currentNode)) { | ||
continue expandedLoop; | ||
} | ||
const { | ||
@@ -205,26 +174,23 @@ object, | ||
let matchedByPreviousAsterisk = false; | ||
if (this.isMatchableNode(object)) { | ||
// Skip for mismatched object identifiers. | ||
if (!this.isNodeByAsteriskOrName(object, pattern[j])) { | ||
matchedByPreviousAsterisk = pattern[j - 1] === ASTERISK_CHARACTER; // istanbul ignore else: currently unreachable via tests | ||
matchedByPreviousAsterisk = pattern[j - 1] === ASTERISK_CHARACTER; | ||
// istanbul ignore else: currently unreachable via tests | ||
if (!matchedByPreviousAsterisk) { | ||
continue expandedLoop; | ||
} | ||
} // istanbul ignore else: currently unreachable via tests | ||
} | ||
// istanbul ignore else: currently unreachable via tests | ||
if (!matchedByPreviousAsterisk) { | ||
j += 1; | ||
} | ||
} // Skip nodes that aren't part of a property chain. | ||
} | ||
// Skip nodes that aren't part of a property chain. | ||
else if (!this.isNonComputedMemberExpressionNode(object)) { | ||
continue expandedLoop; | ||
} // Skip for mismatched property identifiers. | ||
} | ||
// Skip for mismatched property identifiers. | ||
if (!this.isNodeByAsteriskOrName(property, pattern[j])) { | ||
matchedByPreviousAsterisk = pattern[j - 1] === ASTERISK_CHARACTER; | ||
if (!matchedByPreviousAsterisk) { | ||
@@ -234,9 +200,7 @@ continue expandedLoop; | ||
} | ||
if (matchedByPreviousAsterisk) { | ||
j -= 1; | ||
} | ||
} // If we've made it this far it's a match! | ||
} | ||
// If we've made it this far it's a match! | ||
return { | ||
@@ -248,14 +212,10 @@ identifier, | ||
} | ||
return undefined; | ||
}, | ||
matchAll(identifiers, patterns) { | ||
const matches = []; | ||
for (let i = 0, { | ||
length | ||
} = identifiers; i < length; i += 1) { | ||
length | ||
} = identifiers; i < length; i += 1) { | ||
const matchData = this.match(identifiers[i], patterns); | ||
if (matchData) { | ||
@@ -265,13 +225,9 @@ matches.push(matchData); | ||
} | ||
return matches; | ||
} | ||
}; | ||
function createLib(overrides) { | ||
return ObjectAssign({}, baseLib, overrides); | ||
} | ||
export { createLib }; | ||
/*! version: 0.18.15 */ | ||
/*! version: 0.18.16 */ |
{ | ||
"name": "@locker/ast-lib-maker", | ||
"version": "0.18.15", | ||
"version": "0.18.16", | ||
"license": "SEE LICENSE IN LICENSE.txt", | ||
@@ -15,3 +15,2 @@ "author": "Salesforce UI Security Team", | ||
"sideEffects": false, | ||
"typings": "types/index.d.ts", | ||
"publishConfig": { | ||
@@ -21,9 +20,9 @@ "access": "public" | ||
"scripts": { | ||
"build": "tsc --project tsconfig.types.json && rollup --config .rolluprc.cjs", | ||
"build": "rollup --config .rolluprc.cjs", | ||
"build:dev": "cross-env NODE_ENV=development yarn build", | ||
"clean": "locker-trash dist/ types/", | ||
"clean": "locker-trash dist/", | ||
"test": "yarn build && jest" | ||
}, | ||
"dependencies": { | ||
"@locker/shared": "0.18.15" | ||
"@locker/shared": "0.18.16" | ||
}, | ||
@@ -35,5 +34,4 @@ "devDependencies": { | ||
"dist/", | ||
"types/", | ||
"LICENSE.txt" | ||
] | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
25476
572
7
+ Added@locker/shared@0.18.16(transitive)
- Removed@locker/shared@0.18.15(transitive)
Updated@locker/shared@0.18.16