Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

babel-plugin-estrela

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

babel-plugin-estrela - npm Package Compare versions

Comparing version 0.2.0 to 0.2.1

797

dist/index.js

@@ -1,444 +0,447 @@

(() => {
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
}) : x)(function(x) {
if (typeof require !== "undefined")
return require.apply(this, arguments);
throw new Error('Dynamic require of "' + x + '" is not supported');
});
var __commonJS = (cb, mod) => function __require2() {
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod));
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __commonJS = (cb, mod) => function __require() {
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
};
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
// ../../node_modules/@babel/helper-annotate-as-pure/lib/index.js
var require_lib = __commonJS({
"../../node_modules/@babel/helper-annotate-as-pure/lib/index.js"(exports) {
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = annotateAsPure3;
var _t = __require("@babel/types");
var {
addComment
} = _t;
var PURE_ANNOTATION = "#__PURE__";
var isPureAnnotated = ({
leadingComments
}) => !!leadingComments && leadingComments.some((comment) => /[@#]__PURE__/.test(comment.value));
function annotateAsPure3(pathOrNode) {
const node = pathOrNode["node"] || pathOrNode;
if (isPureAnnotated(node)) {
return;
}
addComment(node, "leading", PURE_ANNOTATION);
// ../../node_modules/@babel/helper-annotate-as-pure/lib/index.js
var require_lib = __commonJS({
"../../node_modules/@babel/helper-annotate-as-pure/lib/index.js"(exports) {
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = annotateAsPure3;
var _t = require("@babel/types");
var {
addComment
} = _t;
var PURE_ANNOTATION = "#__PURE__";
var isPureAnnotated = ({
leadingComments
}) => !!leadingComments && leadingComments.some((comment) => /[@#]__PURE__/.test(comment.value));
function annotateAsPure3(pathOrNode) {
const node = pathOrNode["node"] || pathOrNode;
if (isPureAnnotated(node)) {
return;
}
addComment(node, "leading", PURE_ANNOTATION);
}
});
}
});
// src/index.ts
var t4 = __toESM(__require("@babel/types"));
// src/index.ts
var src_exports = {};
__export(src_exports, {
default: () => src_default
});
module.exports = __toCommonJS(src_exports);
var t4 = __toESM(require("@babel/types"));
// src/functional.transform.ts
var import_helper_annotate_as_pure = __toESM(require_lib());
var t = __toESM(__require("@babel/types"));
function functional_transform_default() {
const visitor2 = {
CallExpression(path, state) {
var _a, _b;
if (path.get("callee").isIdentifier({ name: "getState" })) {
const param = path.node.arguments[0];
let object = null;
let prop = null;
if (t.isIdentifier(param)) {
const scopeNode = path.scope.getBindingIdentifier(param.name);
if (state.states.includes(scopeNode)) {
object = t.identifier("_$");
prop = param.name;
}
if (state.props.includes(scopeNode)) {
// src/functional.transform.ts
var import_helper_annotate_as_pure = __toESM(require_lib());
var t = __toESM(require("@babel/types"));
function functional_transform_default() {
const visitor2 = {
CallExpression(path, state) {
var _a, _b;
if (path.get("callee").isIdentifier({ name: "getState" })) {
const param = path.node.arguments[0];
let object = null;
let prop = null;
if (t.isIdentifier(param)) {
const scopeNode = path.scope.getBindingIdentifier(param.name);
if (state.states.includes(scopeNode)) {
object = t.identifier("_$");
prop = param.name;
}
if (state.props.includes(scopeNode)) {
object = state.propsParam;
prop = param.name;
}
} else if (isMemberExpression2(param)) {
const member = param;
if (t.isIdentifier(member.object)) {
const scopeNode = path.scope.getBindingIdentifier(member.object.name);
if (state.propsParam === scopeNode) {
object = state.propsParam;
prop = param.name;
prop = (_b = (_a = member.property) == null ? void 0 : _a.name) != null ? _b : "0";
}
} else if (isMemberExpression2(param)) {
const member = param;
if (t.isIdentifier(member.object)) {
const scopeNode = path.scope.getBindingIdentifier(member.object.name);
if (state.propsParam === scopeNode) {
object = state.propsParam;
prop = (_b = (_a = member.property) == null ? void 0 : _a.name) != null ? _b : "0";
}
}
}
if (object && prop) {
path.skip();
path.node.arguments = [object, t.stringLiteral(prop)];
}
}
},
Identifier(path, state) {
const scopeNode = path.scope.getBindingIdentifier(path.node.name);
if (scopeNode === path.node || path.parentPath.isMemberExpression({ property: path.node })) {
return;
}
if (state.states.includes(scopeNode)) {
path.replaceWith(t.memberExpression(t.identifier("_$"), path.node));
if (object && prop) {
path.skip();
path.node.arguments = [object, t.stringLiteral(prop)];
}
if (state.props.includes(scopeNode)) {
path.replaceWith(t.memberExpression(t.cloneNode(state.propsParam), path.node));
path.skip();
}
},
JSXExpressionContainer(path, state) {
}
},
Identifier(path, state) {
const scopeNode = path.scope.getBindingIdentifier(path.node.name);
if (scopeNode === path.node || path.parentPath.isMemberExpression({ property: path.node })) {
return;
}
if (state.states.includes(scopeNode)) {
path.replaceWith(t.memberExpression(t.identifier("_$"), path.node));
path.skip();
const expPath = path.get("expression");
if (expPath.isFunction() || expPath.isCallExpression() && expPath.get("callee").isIdentifier({ name: "getState" })) {
path.traverse(visitor2, state);
} else if (t.isExpression(path.node.expression)) {
const selectors = getSelectors(path, state);
if (selectors.length > 0) {
const arrow = t.arrowFunctionExpression(selectors.map((x) => x.param), path.node.expression);
const array = t.arrayExpression([
...selectors.map((x) => x.sel),
arrow
]);
const expression = t.jsxExpressionContainer(array);
path.replaceWith(t.inherits(expression, path.node));
}
}
if (state.props.includes(scopeNode)) {
path.replaceWith(t.memberExpression(t.cloneNode(state.propsParam), path.node));
path.skip();
}
},
JSXExpressionContainer(path, state) {
path.skip();
const expPath = path.get("expression");
if (expPath.isFunction() || expPath.isCallExpression() && expPath.get("callee").isIdentifier({ name: "getState" })) {
path.traverse(visitor2, state);
} else if (t.isExpression(path.node.expression)) {
const selectors = getSelectors(path, state);
if (selectors.length > 0) {
const arrow = t.arrowFunctionExpression(selectors.map((x) => x.param), path.node.expression);
const array = t.arrayExpression([
...selectors.map((x) => x.sel),
arrow
]);
const expression = t.jsxExpressionContainer(array);
path.replaceWith(t.inherits(expression, path.node));
}
},
VariableDeclaration(path, state) {
if (path.node.kind === "let") {
const nodes = path.node.declarations.reduce((acc, declaration) => {
if (t.isIdentifier(declaration.id)) {
state.states.push(declaration.id);
if (declaration.init) {
const left = t.memberExpression(t.identifier("_$"), declaration.id);
const assignment = t.assignmentExpression("=", left, declaration.init);
acc.push(assignment);
}
}
},
VariableDeclaration(path, state) {
if (path.node.kind === "let") {
const nodes = path.node.declarations.reduce((acc, declaration) => {
if (t.isIdentifier(declaration.id)) {
state.states.push(declaration.id);
if (declaration.init) {
const left = t.memberExpression(t.identifier("_$"), declaration.id);
const assignment = t.assignmentExpression("=", left, declaration.init);
acc.push(assignment);
}
return acc;
}, []);
path.replaceWithMultiple(nodes);
}
return acc;
}, []);
path.replaceWithMultiple(nodes);
}
}
};
return {
Function(path) {
var _a, _b, _c;
let funcName;
let returnValue = null;
if (t.isVariableDeclarator(path.parent)) {
funcName = t.isIdentifier(path.parent.id) ? path.parent.id.name : "";
} else {
funcName = t.isFunctionDeclaration(path.node) ? (_b = (_a = path.node.id) == null ? void 0 : _a.name) != null ? _b : "" : "";
}
if (!funcName[0] || funcName[0] !== funcName[0].toUpperCase()) {
return;
}
if (t.isBlockStatement(path.node.body)) {
for (const node of path.node.body.body) {
if (t.isReturnStatement(node)) {
returnValue = (_c = node.argument) != null ? _c : null;
}
}
} else {
returnValue = path.node.body;
}
};
return {
Function(path) {
var _a, _b, _c;
let funcName;
let returnValue = null;
if (t.isVariableDeclarator(path.parent)) {
funcName = t.isIdentifier(path.parent.id) ? path.parent.id.name : "";
} else {
funcName = t.isFunctionDeclaration(path.node) ? (_b = (_a = path.node.id) == null ? void 0 : _a.name) != null ? _b : "" : "";
if (t.isJSXElement(returnValue) || t.isJSXFragment(returnValue)) {
const param = path.node.params[0];
const props = [];
let propsParam = t.identifier("_props");
const body = path.get("body");
if (body.isBlockStatement()) {
const callExp = t.callExpression(t.identifier("_$$"), []);
const declaration = t.variableDeclarator(t.identifier("_$"), callExp);
body.unshiftContainer("body", t.variableDeclaration("const", [declaration]));
(0, import_helper_annotate_as_pure.default)(callExp);
}
if (!funcName[0] || funcName[0] !== funcName[0].toUpperCase()) {
return;
if (t.isIdentifier(param)) {
propsParam = param;
}
if (t.isBlockStatement(path.node.body)) {
for (const node of path.node.body.body) {
if (t.isReturnStatement(node)) {
returnValue = (_c = node.argument) != null ? _c : null;
if (t.isObjectPattern(param)) {
for (const prop of param.properties) {
if (t.isObjectProperty(prop) && t.isIdentifier(prop.value)) {
props.push(prop.value);
}
}
} else {
returnValue = path.node.body;
}
if (t.isJSXElement(returnValue) || t.isJSXFragment(returnValue)) {
const param = path.node.params[0];
const props = [];
let propsParam = t.identifier("_props");
const body = path.get("body");
if (body.isBlockStatement()) {
const callExp = t.callExpression(t.identifier("_$$"), []);
const declaration = t.variableDeclarator(t.identifier("_$"), callExp);
body.unshiftContainer("body", t.variableDeclaration("const", [declaration]));
(0, import_helper_annotate_as_pure.default)(callExp);
}
if (t.isIdentifier(param)) {
propsParam = param;
}
if (t.isObjectPattern(param)) {
for (const prop of param.properties) {
if (t.isObjectProperty(prop) && t.isIdentifier(prop.value)) {
props.push(prop.value);
}
if (t.isRestElement(prop) && t.isIdentifier(prop.argument)) {
propsParam = prop.argument;
}
if (t.isRestElement(prop) && t.isIdentifier(prop.argument)) {
propsParam = prop.argument;
}
}
path.skip();
path.node.params[0] = propsParam;
body.traverse(visitor2, { propsParam, props, states: [] });
}
path.skip();
path.node.params[0] = propsParam;
body.traverse(visitor2, { propsParam, props, states: [] });
}
};
}
function getSelectors(path, state) {
let id = 0;
const node = path.node;
const selectors = [];
path.traverse({
Function(path2) {
if (path2.parent === node) {
path2.skip();
}
},
Identifier(path2) {
let sel;
const scopeNode = path2.scope.getBindingIdentifier(path2.node.name);
if (state.states.includes(scopeNode)) {
sel = t.memberExpression(t.memberExpression(t.identifier("_$"), t.identifier("$")), path2.node);
} else if (state.props.includes(scopeNode)) {
sel = t.memberExpression(t.memberExpression(t.cloneNode(state.propsParam), t.identifier("$")), path2.node);
} else if (t.isNodesEquivalent(state.propsParam, path2.node)) {
if (isMemberExpression2(path2.parent)) {
const parent = t.cloneNode(path2.parent);
parent.object = t.memberExpression(path2.node, t.identifier("$"));
sel = parent;
} else {
sel = t.memberExpression(path2.node, t.identifier("$"));
}
}
};
}
function getSelectors(path, state) {
let id = 0;
const node = path.node;
const selectors = [];
path.traverse({
Function(path2) {
if (path2.parent === node) {
path2.skip();
}
},
Identifier(path2) {
let sel;
const scopeNode = path2.scope.getBindingIdentifier(path2.node.name);
if (state.states.includes(scopeNode)) {
sel = t.memberExpression(t.memberExpression(t.identifier("_$"), t.identifier("$")), path2.node);
} else if (state.props.includes(scopeNode)) {
sel = t.memberExpression(t.memberExpression(t.cloneNode(state.propsParam), t.identifier("$")), path2.node);
} else if (t.isNodesEquivalent(state.propsParam, path2.node)) {
if (isMemberExpression2(path2.parent)) {
const parent = t.cloneNode(path2.parent);
parent.object = t.memberExpression(path2.node, t.identifier("$"));
sel = parent;
} else {
return;
sel = t.memberExpression(path2.node, t.identifier("$"));
}
const name = t.isMemberExpression(sel) && t.isIdentifier(sel.property) ? sel.property.name : String(id++);
const param = path2.scope.generateUidIdentifier(name);
let selector = selectors.find((selector2) => t.isNodesEquivalent(selector2.sel, sel));
if (!selector) {
selector = { sel, param };
selectors.push(selector);
}
path2.replaceWith(selector.param);
} else {
return;
}
});
return selectors;
}
function isMemberExpression2(node) {
return !!node && (t.isMemberExpression(node) || t.isOptionalMemberExpression(node));
}
const name = t.isMemberExpression(sel) && t.isIdentifier(sel.property) ? sel.property.name : String(id++);
const param = path2.scope.generateUidIdentifier(name);
let selector = selectors.find((selector2) => t.isNodesEquivalent(selector2.sel, sel));
if (!selector) {
selector = { sel, param };
selectors.push(selector);
}
path2.replaceWith(selector.param);
}
});
return selectors;
}
function isMemberExpression2(node) {
return !!node && (t.isMemberExpression(node) || t.isOptionalMemberExpression(node));
}
// src/jsx.transform.ts
var import_helper_annotate_as_pure2 = __toESM(require_lib());
var t2 = __toESM(__require("@babel/types"));
function visitor() {
return {
JSXAttribute(path) {
if (t2.isJSXElement(path.node.value)) {
path.node.value = t2.jsxExpressionContainer(path.node.value);
}
},
JSXElement: {
exit(path, file) {
const callExpr = buildCreateElementCall(path, file);
// src/jsx.transform.ts
var import_helper_annotate_as_pure2 = __toESM(require_lib());
var t2 = __toESM(require("@babel/types"));
function visitor() {
return {
JSXAttribute(path) {
if (t2.isJSXElement(path.node.value)) {
path.node.value = t2.jsxExpressionContainer(path.node.value);
}
},
JSXElement: {
exit(path, file) {
const callExpr = buildCreateElementCall(path, file);
path.replaceWith(t2.inherits(callExpr, path.node));
}
},
JSXFragment: {
exit(path, file) {
const callExpr = buildCreateElementFragmentCall(path);
if (callExpr) {
path.replaceWith(t2.inherits(callExpr, path.node));
}
},
JSXFragment: {
exit(path, file) {
const callExpr = buildCreateElementFragmentCall(path);
if (callExpr) {
path.replaceWith(t2.inherits(callExpr, path.node));
}
}
}
};
}
};
}
function buildVirtualNode(args) {
const node = t2.callExpression(t2.identifier("_jsx"), args);
(0, import_helper_annotate_as_pure2.default)(node);
return node;
}
function buildCreateElementCall(path, file) {
const openingPath = path.get("openingElement");
return buildVirtualNode([
getTag(openingPath),
buildCreateElementOpeningElementAttributes(file, openingPath.get("attributes")),
...t2.react.buildChildren(path.node)
]);
}
function buildCreateElementFragmentCall(path) {
return buildVirtualNode([
t2.nullLiteral(),
t2.nullLiteral(),
...t2.react.buildChildren(path.node)
]);
}
function getTag(openingPath) {
const tagExpr = convertJSXIdentifier(openingPath.node.name, openingPath.node);
let tagName;
if (t2.isIdentifier(tagExpr)) {
tagName = tagExpr.name;
} else if (t2.isLiteral(tagExpr)) {
tagName = tagExpr.value;
}
function buildVirtualNode(args) {
const node = t2.callExpression(t2.identifier("_jsx"), args);
(0, import_helper_annotate_as_pure2.default)(node);
return node;
if (t2.react.isCompatTag(tagName)) {
return t2.stringLiteral(tagName);
} else {
return tagExpr;
}
function buildCreateElementCall(path, file) {
const openingPath = path.get("openingElement");
return buildVirtualNode([
getTag(openingPath),
buildCreateElementOpeningElementAttributes(file, openingPath.get("attributes")),
...t2.react.buildChildren(path.node)
]);
}
function buildCreateElementFragmentCall(path) {
return buildVirtualNode([
t2.nullLiteral(),
t2.nullLiteral(),
...t2.react.buildChildren(path.node)
]);
}
function getTag(openingPath) {
const tagExpr = convertJSXIdentifier(openingPath.node.name, openingPath.node);
let tagName;
if (t2.isIdentifier(tagExpr)) {
tagName = tagExpr.name;
} else if (t2.isLiteral(tagExpr)) {
tagName = tagExpr.value;
}
if (t2.react.isCompatTag(tagName)) {
return t2.stringLiteral(tagName);
}
function convertJSXIdentifier(node, parent) {
if (t2.isJSXIdentifier(node)) {
if (node.name === "this" && t2.isReferenced(node, parent)) {
return t2.thisExpression();
} else if (t2.isValidIdentifier(node.name, false)) {
node.type = "Identifier";
} else {
return tagExpr;
return t2.stringLiteral(node.name);
}
} else if (t2.isJSXMemberExpression(node)) {
return t2.memberExpression(convertJSXIdentifier(node.object, node), convertJSXIdentifier(node.property, node));
} else if (t2.isJSXNamespacedName(node)) {
return t2.stringLiteral(`${node.namespace.name}:${node.name.name}`);
}
function convertJSXIdentifier(node, parent) {
if (t2.isJSXIdentifier(node)) {
if (node.name === "this" && t2.isReferenced(node, parent)) {
return t2.thisExpression();
} else if (t2.isValidIdentifier(node.name, false)) {
node.type = "Identifier";
} else {
return t2.stringLiteral(node.name);
}
} else if (t2.isJSXMemberExpression(node)) {
return t2.memberExpression(convertJSXIdentifier(node.object, node), convertJSXIdentifier(node.property, node));
} else if (t2.isJSXNamespacedName(node)) {
return t2.stringLiteral(`${node.namespace.name}:${node.name.name}`);
}
return node;
}
function convertAttributeValue(node) {
if (t2.isJSXExpressionContainer(node)) {
return node.expression;
} else {
return node;
}
function convertAttributeValue(node) {
if (t2.isJSXExpressionContainer(node)) {
return node.expression;
}
function accumulateAttribute(array, attribute) {
var _a;
if (t2.isJSXSpreadAttribute(attribute.node)) {
const arg = attribute.node.argument;
if (t2.isObjectExpression(arg)) {
array.push(...arg.properties);
} else {
return node;
array.push(t2.spreadElement(arg));
}
}
function accumulateAttribute(array, attribute) {
var _a;
if (t2.isJSXSpreadAttribute(attribute.node)) {
const arg = attribute.node.argument;
if (t2.isObjectExpression(arg)) {
array.push(...arg.properties);
} else {
array.push(t2.spreadElement(arg));
}
return array;
}
const value = convertAttributeValue(attribute.node.name.name !== "key" ? attribute.node.value || t2.booleanLiteral(true) : attribute.node.value);
if (attribute.node.name.name === "key" && value === null) {
throw attribute.buildCodeFrameError('Please provide an explicit key value. Using "key" as a shorthand for "key={true}" is not allowed.');
}
if (t2.isStringLiteral(value) && !t2.isJSXExpressionContainer(attribute.node.value)) {
value.value = value.value.replace(/\n\s+/g, " ");
(_a = value.extra) == null ? true : delete _a.raw;
}
if (t2.isJSXNamespacedName(attribute.node.name)) {
attribute.node.name = t2.stringLiteral(attribute.node.name.namespace.name + ":" + attribute.node.name.name.name);
} else if (t2.isValidIdentifier(attribute.node.name.name, false)) {
attribute.node.name.type = "Identifier";
} else {
attribute.node.name = t2.stringLiteral(attribute.node.name.name);
}
array.push(t2.inherits(t2.objectProperty(attribute.node.name, value), attribute.node));
return array;
}
function buildCreateElementOpeningElementAttributes(file, attribs) {
const objs = [];
const props = attribs.reduce(accumulateAttribute, []);
objs.push(t2.objectExpression(props));
if (!objs.length) {
return t2.nullLiteral();
}
if (objs.length === 1) {
return objs[0];
}
if (!t2.isObjectExpression(objs[0])) {
objs.unshift(t2.objectExpression([]));
}
const helper = file.addHelper("extends");
return t2.callExpression(helper, objs);
const value = convertAttributeValue(attribute.node.name.name !== "key" ? attribute.node.value || t2.booleanLiteral(true) : attribute.node.value);
if (attribute.node.name.name === "key" && value === null) {
throw attribute.buildCodeFrameError('Please provide an explicit key value. Using "key" as a shorthand for "key={true}" is not allowed.');
}
var jsx_transform_default = visitor;
// src/styled.transform.ts
var t3 = __toESM(__require("@babel/types"));
var import_postcss = __toESM(__require("postcss"));
var import_postcss_nested = __toESM(__require("postcss-nested"));
var import_postcss_prefix_selector = __toESM(__require("postcss-prefix-selector"));
var import_autoprefixer = __toESM(__require("autoprefixer"));
function styled_transform_default() {
return {
TaggedTemplateExpression(path) {
const tagPath = path.get("tag");
const isStyledComponent = tagPath.isCallExpression() && tagPath.get("callee").isIdentifier({ name: "styled" });
if (isStyledComponent) {
const css = path.get("quasi").get("quasis").map((quasi) => {
var _a;
return (_a = quasi.node.value.cooked) != null ? _a : quasi.node.value.raw;
}).join(`/*$$*/`);
const styleId = generateStyleId();
const processedQuasis = processCss(css, styleId).split(`/*$$*/`).map((str) => t3.templateElement({ raw: str, cooked: str }));
path.node.quasi.quasis = [
t3.templateElement({ raw: "", cooked: "" }),
...processedQuasis
];
path.node.quasi.expressions = [
t3.stringLiteral(styleId),
...path.node.quasi.expressions
];
path.skip();
}
}
};
if (t2.isStringLiteral(value) && !t2.isJSXExpressionContainer(attribute.node.value)) {
value.value = value.value.replace(/\n\s+/g, " ");
(_a = value.extra) == null ? true : delete _a.raw;
}
function generateStyleId() {
return Math.random().toString(36).slice(2, 7);
if (t2.isJSXNamespacedName(attribute.node.name)) {
attribute.node.name = t2.stringLiteral(attribute.node.name.namespace.name + ":" + attribute.node.name.name.name);
} else if (t2.isValidIdentifier(attribute.node.name.name, false)) {
attribute.node.name.type = "Identifier";
} else {
attribute.node.name = t2.stringLiteral(attribute.node.name.name);
}
function processCss(css, hostId) {
return (0, import_postcss.default)([
(0, import_autoprefixer.default)(),
(0, import_postcss_nested.default)(),
(0, import_postcss_prefix_selector.default)({
transform: (_, selector) => `${selector}[_${hostId}]`
})
]).process(css).css;
array.push(t2.inherits(t2.objectProperty(attribute.node.name, value), attribute.node));
return array;
}
function buildCreateElementOpeningElementAttributes(file, attribs) {
const objs = [];
const props = attribs.reduce(accumulateAttribute, []);
objs.push(t2.objectExpression(props));
if (!objs.length) {
return t2.nullLiteral();
}
if (objs.length === 1) {
return objs[0];
}
if (!t2.isObjectExpression(objs[0])) {
objs.unshift(t2.objectExpression([]));
}
const helper = file.addHelper("extends");
return t2.callExpression(helper, objs);
}
var jsx_transform_default = visitor;
// src/index.ts
function src_default() {
return {
name: "babel-plugin-estrela",
manipulateOptions(opts, parserOpts) {
parserOpts.plugins.push("jsx");
},
visitor: {
Program(path) {
const imports = createImport({
h: "_jsx",
createProxyState: "_$$"
}, "estrela/internal");
path.unshiftContainer("body", imports);
path.traverse(functional_transform_default());
path.traverse(jsx_transform_default());
path.traverse(styled_transform_default());
}
// src/styled.transform.ts
var t3 = __toESM(require("@babel/types"));
var import_postcss = __toESM(require("postcss"));
var import_postcss_nested = __toESM(require("postcss-nested"));
var import_postcss_prefix_selector = __toESM(require("postcss-prefix-selector"));
var import_autoprefixer = __toESM(require("autoprefixer"));
function styled_transform_default() {
return {
TaggedTemplateExpression(path) {
const tagPath = path.get("tag");
const isStyledComponent = tagPath.isCallExpression() && tagPath.get("callee").isIdentifier({ name: "styled" });
if (isStyledComponent) {
const css = path.get("quasi").get("quasis").map((quasi) => {
var _a;
return (_a = quasi.node.value.cooked) != null ? _a : quasi.node.value.raw;
}).join(`/*$$*/`);
const styleId = generateStyleId();
const processedQuasis = processCss(css, styleId).split(`/*$$*/`).map((str) => t3.templateElement({ raw: str, cooked: str }));
path.node.quasi.quasis = [
t3.templateElement({ raw: "", cooked: "" }),
...processedQuasis
];
path.node.quasi.expressions = [
t3.stringLiteral(styleId),
...path.node.quasi.expressions
];
path.skip();
}
};
}
function createImport(props, from) {
const imports = Object.entries(props).map(([prop, alias]) => {
const local = t4.identifier(alias);
const imported = t4.identifier(prop);
return t4.importSpecifier(local, imported);
});
const importSource = t4.stringLiteral(from);
return t4.importDeclaration(imports, importSource);
}
})();
}
};
}
function generateStyleId() {
return Math.random().toString(36).slice(2, 7);
}
function processCss(css, hostId) {
return (0, import_postcss.default)([
(0, import_autoprefixer.default)(),
(0, import_postcss_nested.default)(),
(0, import_postcss_prefix_selector.default)({
transform: (_, selector) => `${selector}[_${hostId}]`
})
]).process(css).css;
}
// src/index.ts
function src_default() {
return {
name: "babel-plugin-estrela",
manipulateOptions(opts, parserOpts) {
parserOpts.plugins.push("jsx");
},
visitor: {
Program(path) {
const imports = createImport({
h: "_jsx",
createProxyState: "_$$"
}, "estrela/internal");
path.unshiftContainer("body", imports);
path.traverse(functional_transform_default());
path.traverse(jsx_transform_default());
path.traverse(styled_transform_default());
}
}
};
}
function createImport(props, from) {
const imports = Object.entries(props).map(([prop, alias]) => {
const local = t4.identifier(alias);
const imported = t4.identifier(prop);
return t4.importSpecifier(local, imported);
});
const importSource = t4.stringLiteral(from);
return t4.importDeclaration(imports, importSource);
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {});

@@ -5,2 +5,3 @@ {

"outfile": "dist/index.js",
"platform": "node",
"external": [

@@ -7,0 +8,0 @@ "@babel/core",

{
"name": "babel-plugin-estrela",
"version": "0.2.0",
"version": "0.2.1",
"description": "A babel plugin to process estrela jsx/tsx files",

@@ -5,0 +5,0 @@ "main": "dist/index.js",

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc