New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

babel-plugin-flask-urls

Package Overview
Dependencies
Maintainers
2
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

babel-plugin-flask-urls - npm Package Compare versions

Comparing version

to
0.1.0

50

lib/plugin.js

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

const buildFunc = template.expression('FUNC.bind(null, RULE, BASE)');
const buildFuncMock = template.expression('FUNC.bind(null, ENDPOINT)');
const importPrefix = opts.importPrefix || 'flask-url';
const builderImportLocation = opts.builderImportLocation || 'flask-urls';
const urlMap = opts.urlMap || {};
const mock = opts.mock;
const basePath = opts.basePath || '';

@@ -46,23 +48,41 @@ const importRegex = new RegExp("^".concat(importPrefix, ":(.+)$"));

const importName = path.node.specifiers[0].local.name;
const data = urlMap[endpoint];
let builderFuncId = this.builderFuncId;
if (!data) {
throw path.get('source').buildCodeFrameError("".concat(importPrefix, " imports must reference a valid flask endpoint"));
if (builderFuncId) {
builderFuncId = t.cloneDeep(builderFuncId);
}
let builderFuncId = this.builderFuncId;
let variable;
if (builderFuncId) {
builderFuncId = t.cloneDeep(builderFuncId);
if (mock) {
if (!builderFuncId) {
builderFuncId = this.builderFuncId = (0, _helperModuleImports.addNamed)(path, 'mockFlaskURL', builderImportLocation, {
nameHint: 'mockFlaskURL'
});
}
variable = t.variableDeclarator(t.identifier(importName), buildFuncMock({
FUNC: builderFuncId,
ENDPOINT: t.stringLiteral(endpoint)
}));
} else {
builderFuncId = this.builderFuncId = (0, _helperModuleImports.addDefault)(path, builderImportLocation, {
nameHint: 'buildFlaskURL'
});
const data = urlMap[endpoint];
if (!data) {
throw path.get('source').buildCodeFrameError("".concat(importPrefix, " imports must reference a valid flask endpoint"));
}
if (!builderFuncId) {
builderFuncId = this.builderFuncId = (0, _helperModuleImports.addDefault)(path, builderImportLocation, {
nameHint: 'buildFlaskURL'
});
}
variable = t.variableDeclarator(t.identifier(importName), buildFunc({
FUNC: builderFuncId,
RULE: t.valueToNode(data),
BASE: t.stringLiteral(basePath)
}));
}
const variable = t.variableDeclarator(t.identifier(importName), buildFunc({
FUNC: builderFuncId,
RULE: t.valueToNode(data),
BASE: t.stringLiteral(basePath)
}));
path.replaceWith({

@@ -74,3 +94,3 @@ type: 'VariableDeclaration',

type: 'CommentBlock',
value: " flask url builder for '".concat(endpoint, "' ")
value: " ".concat(mock ? 'mocked ' : '', "flask url builder for '").concat(endpoint, "' ")
}]

@@ -77,0 +97,0 @@ });

{
"name": "babel-plugin-flask-urls",
"version": "0.0.2",
"version": "0.1.0",
"description": "Adds support for importing Flask routing rules to generate URLs client-side.",

@@ -38,3 +38,3 @@ "main": "lib/plugin.js",

},
"gitHead": "c1e3c573af44772f594c51414a3237313d2abc16"
"gitHead": "03768d31e4adcfc1f3efa282778762450b73a233"
}