Socket
Socket
Sign inDemoInstall

@babel/template

Package Overview
Dependencies
16
Maintainers
4
Versions
78
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 7.18.10 to 7.20.7

lib/builder.js.map

18

lib/builder.js

@@ -7,13 +7,8 @@ "use strict";

exports.default = createTemplateBuilder;
var _options = require("./options");
var _string = require("./string");
var _literal = require("./literal");
const NO_PLACEHOLDER = (0, _options.validate)({
placeholderPattern: false
});
function createTemplateBuilder(formatter, defaultOpts) {

@@ -29,3 +24,2 @@ const templateFnCache = new WeakMap();

let builder = templateFnCache.get(tpl);
if (!builder) {

@@ -35,3 +29,2 @@ builder = (0, _literal.default)(formatter, tpl, cachedOpts);

}
return extendedTrace(builder(args));

@@ -42,3 +35,2 @@ } else if (typeof tpl === "object" && tpl) {

}
throw new Error(`Unexpected template param ${typeof tpl}`);

@@ -52,3 +44,2 @@ }, {

let builder = templateAstCache.get(tpl);
if (!builder) {

@@ -58,6 +49,4 @@ builder = (0, _literal.default)(formatter, tpl, (0, _options.merge)(cachedOpts, NO_PLACEHOLDER));

}
return builder(args)();
}
throw new Error(`Unexpected template param ${typeof tpl}`);

@@ -67,6 +56,4 @@ }

}
function extendedTrace(fn) {
let rootStack = "";
try {

@@ -79,3 +66,2 @@ throw new Error();

}
return arg => {

@@ -89,2 +75,4 @@ try {

};
}
}
//# sourceMappingURL=builder.js.map

@@ -7,9 +7,6 @@ "use strict";

exports.statements = exports.statement = exports.smart = exports.program = exports.expression = void 0;
var _t = require("@babel/types");
const {
assertExpressionStatement
} = _t;
function makeStatementFormatter(fn) {

@@ -24,3 +21,2 @@ return {

}
const smart = makeStatementFormatter(body => {

@@ -40,7 +36,5 @@ if (body.length > 1) {

}
if (body.length > 1) {
throw new Error("Found multiple statements but wanted one");
}
return body[0];

@@ -55,3 +49,2 @@ });

}
if (expression.unwrap(ast).start === 0) {

@@ -75,2 +68,4 @@ throw new Error("Parse result included parens.");

};
exports.program = program;
exports.program = program;
//# sourceMappingURL=formatters.js.map

@@ -7,7 +7,4 @@ "use strict";

exports.statements = exports.statement = exports.smart = exports.program = exports.expression = exports.default = void 0;
var formatters = require("./formatters");
var _builder = require("./builder");
const smart = (0, _builder.default)(formatters.smart);

@@ -23,3 +20,2 @@ exports.smart = smart;

exports.program = program;
var _default = Object.assign(smart.bind(undefined), {

@@ -33,3 +29,4 @@ smart,

});
exports.default = _default;
exports.default = _default;
//# sourceMappingURL=index.js.map

@@ -7,9 +7,5 @@ "use strict";

exports.default = literalTemplate;
var _options = require("./options");
var _parse = require("./parse");
var _populate = require("./populate");
function literalTemplate(formatter, tpl, opts) {

@@ -27,3 +23,2 @@ const {

const replacements = (0, _options.normalizeReplacements)(arg);
if (replacements) {

@@ -36,3 +31,2 @@ Object.keys(replacements).forEach(key => {

}
return formatter.unwrap((0, _populate.default)(metadata, replacements ? Object.assign(replacements, defaultReplacements) : defaultReplacements));

@@ -42,3 +36,2 @@ };

}
function buildLiteralData(formatter, tpl, opts) {

@@ -49,3 +42,2 @@ let names;

let prefix = "";
do {

@@ -64,3 +56,2 @@ prefix += "$";

} while (metadata.placeholders.some(placeholder => placeholder.isDuplicate && nameSet.has(placeholder.name)));
return {

@@ -71,7 +62,5 @@ metadata,

}
function buildTemplateCode(tpl, prefix) {
const names = [];
let code = tpl[0];
for (let i = 1; i < tpl.length; i++) {

@@ -82,3 +71,2 @@ const value = `${prefix}${i - 1}`;

}
return {

@@ -88,2 +76,4 @@ names,

};
}
}
//# sourceMappingURL=literal.js.map

@@ -10,3 +10,2 @@ "use strict";

const _excluded = ["placeholderWhitelist", "placeholderPattern", "preserveComments", "syntacticPlaceholders"];
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }

@@ -29,3 +28,2 @@

}
function validate(opts) {

@@ -35,32 +33,25 @@ if (opts != null && typeof opts !== "object") {

}
const _ref = opts || {},
{
placeholderWhitelist,
placeholderPattern,
preserveComments,
syntacticPlaceholders
} = _ref,
parser = _objectWithoutPropertiesLoose(_ref, _excluded);
{
placeholderWhitelist,
placeholderPattern,
preserveComments,
syntacticPlaceholders
} = _ref,
parser = _objectWithoutPropertiesLoose(_ref, _excluded);
if (placeholderWhitelist != null && !(placeholderWhitelist instanceof Set)) {
throw new Error("'.placeholderWhitelist' must be a Set, null, or undefined");
}
if (placeholderPattern != null && !(placeholderPattern instanceof RegExp) && placeholderPattern !== false) {
throw new Error("'.placeholderPattern' must be a RegExp, false, null, or undefined");
}
if (preserveComments != null && typeof preserveComments !== "boolean") {
throw new Error("'.preserveComments' must be a boolean, null, or undefined");
}
if (syntacticPlaceholders != null && typeof syntacticPlaceholders !== "boolean") {
throw new Error("'.syntacticPlaceholders' must be a boolean, null, or undefined");
}
if (syntacticPlaceholders === true && (placeholderWhitelist != null || placeholderPattern != null)) {
throw new Error("'.placeholderWhitelist' and '.placeholderPattern' aren't compatible" + " with '.syntacticPlaceholders: true'");
}
return {

@@ -74,3 +65,2 @@ parser,

}
function normalizeReplacements(replacements) {

@@ -85,4 +75,5 @@ if (Array.isArray(replacements)) {

}
throw new Error("Template replacements must be an array, object, null, or undefined");
}
throw new Error("Template replacements must be an array, object, null, or undefined");
}
//# sourceMappingURL=options.js.map

@@ -7,9 +7,5 @@ "use strict";

exports.default = parseAndBuildMetadata;
var _t = require("@babel/types");
var _parser = require("@babel/parser");
var _codeFrame = require("@babel/code-frame");
const {

@@ -29,3 +25,2 @@ isCallExpression,

const PATTERN = /^[_$A-Z0-9]+$/;
function parseAndBuildMetadata(formatter, code, opts) {

@@ -66,8 +61,5 @@ const {

}
function placeholderVisitorHandler(node, ancestors, state) {
var _state$placeholderWhi;
let name;
if (isPlaceholder(node)) {

@@ -91,7 +83,5 @@ if (state.syntacticPlaceholders === false) {

}
if (!state.isLegacyRef.value && (state.placeholderPattern != null || state.placeholderWhitelist != null)) {
throw new Error("'.placeholderWhitelist' and '.placeholderPattern' aren't compatible" + " with '.syntacticPlaceholders: true'");
}
if (state.isLegacyRef.value && (state.placeholderPattern === false || !(state.placeholderPattern || PATTERN).test(name)) && !((_state$placeholderWhi = state.placeholderWhitelist) != null && _state$placeholderWhi.has(name))) {

@@ -107,3 +97,2 @@ return;

let type;
if (isStringLiteral(node) || isPlaceholder(node, {

@@ -123,3 +112,2 @@ expectedNode: "StringLiteral"

}
const {

@@ -137,6 +125,4 @@ placeholders,

}
function resolveAncestors(ast, ancestors) {
let parent = ast;
for (let i = 0; i < ancestors.length - 1; i++) {

@@ -147,3 +133,2 @@ const {

} = ancestors[i];
if (index === undefined) {

@@ -155,3 +140,2 @@ parent = parent[key];

}
const {

@@ -167,10 +151,7 @@ key,

}
function parseWithCodeFrame(code, parserOpts, syntacticPlaceholders) {
const plugins = (parserOpts.plugins || []).slice();
if (syntacticPlaceholders !== false) {
plugins.push("placeholders");
}
parserOpts = Object.assign({

@@ -183,3 +164,2 @@ allowReturnOutsideFunction: true,

});
try {

@@ -189,3 +169,2 @@ return (0, _parser.parse)(code, parserOpts);

const loc = err.loc;
if (loc) {

@@ -197,5 +176,6 @@ err.message += "\n" + (0, _codeFrame.codeFrameColumns)(code, {

}
throw err;
}
}
}
//# sourceMappingURL=parse.js.map

@@ -7,5 +7,3 @@ "use strict";

exports.default = populatePlaceholders;
var _t = require("@babel/types");
const {

@@ -22,6 +20,4 @@ blockStatement,

} = _t;
function populatePlaceholders(metadata, replacements) {
const ast = cloneNode(metadata.ast);
if (replacements) {

@@ -54,3 +50,2 @@ metadata.placeholders.forEach(placeholder => {

}
function applyReplacement(placeholder, ast, replacement) {

@@ -64,3 +59,2 @@ if (placeholder.isDuplicate) {

}
const {

@@ -71,3 +65,2 @@ parent,

} = placeholder.resolve(ast);
if (placeholder.type === "string") {

@@ -77,3 +70,2 @@ if (typeof replacement === "string") {

}
if (!replacement || !isStringLiteral(replacement)) {

@@ -98,3 +90,2 @@ throw new Error("Expected string substitution");

}
if (!isStatement(replacement)) {

@@ -109,3 +100,2 @@ replacement = expressionStatement(replacement);

}
if (index === undefined) throw new Error("Assertion failure.");

@@ -116,3 +106,2 @@ } else {

}
if (Array.isArray(replacement)) {

@@ -122,3 +111,2 @@ throw new Error("Cannot replace single expression with an array.");

}
if (index === undefined) {

@@ -129,3 +117,2 @@ validate(parent, key, replacement);

const items = parent[key].slice();
if (placeholder.type === "statement" || placeholder.type === "param") {

@@ -142,6 +129,7 @@ if (replacement == null) {

}
validate(parent, key, items);
parent[key] = items;
}
}
}
//# sourceMappingURL=populate.js.map

@@ -7,9 +7,5 @@ "use strict";

exports.default = stringTemplate;
var _options = require("./options");
var _parse = require("./parse");
var _populate = require("./populate");
function stringTemplate(formatter, code, opts) {

@@ -23,2 +19,4 @@ code = formatter.code(code);

};
}
}
//# sourceMappingURL=string.js.map
{
"name": "@babel/template",
"version": "7.18.10",
"version": "7.20.7",
"description": "Generate an AST from a string template.",

@@ -20,4 +20,4 @@ "author": "The Babel Team (https://babel.dev/team)",

"@babel/code-frame": "^7.18.6",
"@babel/parser": "^7.18.10",
"@babel/types": "^7.18.10"
"@babel/parser": "^7.20.7",
"@babel/types": "^7.20.7"
},

@@ -24,0 +24,0 @@ "engines": {

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc