Socket
Socket
Sign inDemoInstall

babel-plugin-emotion

Package Overview
Dependencies
Maintainers
3
Versions
90
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

babel-plugin-emotion - npm Package Compare versions

Comparing version 10.0.20 to 10.0.21

src/utils/checks.js

6

CHANGELOG.md
# babel-plugin-emotion
## 10.0.21
### Patch Changes
- [0eafebb5](https://github.com/emotion-js/emotion/commit/0eafebb5119212897f81084f63a807c02b0012fc) [#1538](https://github.com/emotion-js/emotion/pull/1538) Thanks [@Andarist](https://github.com/Andarist)! - Push source maps & labels to cooked/raw arrays in TS-transpiled tagged template expressions
## 10.0.20

@@ -4,0 +10,0 @@

43

dist/babel-plugin-emotion.cjs.dev.js

@@ -423,14 +423,30 @@ 'use strict';

var appendStringToExpressions = function appendStringToExpressions(expressions, string, t) {
function isTaggedTemplateExpressionTranspiledByTypeScript(path) {
if (path.node.arguments.length !== 1) {
return false;
}
var argPath = path.get('arguments')[0];
return argPath.isLogicalExpression() && argPath.get('left').isIdentifier() && argPath.node.left.name.includes('templateObject') && argPath.get('right').isAssignmentExpression() && argPath.get('right').get('right').isCallExpression() && argPath.get('right').get('right').get('callee').isIdentifier() && argPath.node.right.right.callee.name.includes('makeTemplateObject') && argPath.node.right.right.arguments.length === 2;
}
var appendStringToArguments = function appendStringToArguments(path, string, t) {
if (!string) {
return expressions;
return;
}
if (t.isStringLiteral(expressions[expressions.length - 1])) {
expressions[expressions.length - 1].value += string;
var args = path.node.arguments;
if (t.isStringLiteral(args[args.length - 1])) {
args[args.length - 1].value += string;
} else if (isTaggedTemplateExpressionTranspiledByTypeScript(path)) {
var makeTemplateObjectCallPath = path.get('arguments')[0].get('right').get('right');
makeTemplateObjectCallPath.get('arguments').forEach(function (argPath) {
var elements = argPath.get('elements');
var lastElement = elements[elements.length - 1];
lastElement.replaceWith(t.stringLiteral(lastElement.node.value + string));
});
} else {
expressions.push(t.stringLiteral(string));
args.push(t.stringLiteral(string));
}
return expressions;
};

@@ -479,7 +495,7 @@ var joinStringLiterals = function joinStringLiterals(expressions, t) {

if (canAppendStrings) {
if (canAppendStrings && shouldLabel) {
var label = getLabelFromPath(path, state, t);
if (label && shouldLabel) {
appendStringToExpressions(path.node.arguments, "label:" + label + ";", t);
if (label) {
appendStringToArguments(path, "label:" + label + ";", t);
}

@@ -528,2 +544,9 @@ }

path.node.arguments[lastIndex] = t.binaryExpression('+', last, sourceMapConditional);
} else if (isTaggedTemplateExpressionTranspiledByTypeScript(path)) {
var makeTemplateObjectCallPath = path.get('arguments')[0].get('right').get('right');
makeTemplateObjectCallPath.get('arguments').forEach(function (argPath) {
var elements = argPath.get('elements');
var lastElement = elements[elements.length - 1];
lastElement.replaceWith(t.binaryExpression('+', lastElement.node, t.cloneNode(sourceMapConditional)));
});
} else {

@@ -530,0 +553,0 @@ path.node.arguments.push(sourceMapConditional);

@@ -195,5 +195,18 @@ "use strict";

var appendStringToExpressions = function(expressions, string, t) {
return string ? (t.isStringLiteral(expressions[expressions.length - 1]) ? expressions[expressions.length - 1].value += string : expressions.push(t.stringLiteral(string)),
expressions) : expressions;
function isTaggedTemplateExpressionTranspiledByTypeScript(path) {
if (1 !== path.node.arguments.length) return !1;
var argPath = path.get("arguments")[0];
return argPath.isLogicalExpression() && argPath.get("left").isIdentifier() && argPath.node.left.name.includes("templateObject") && argPath.get("right").isAssignmentExpression() && argPath.get("right").get("right").isCallExpression() && argPath.get("right").get("right").get("callee").isIdentifier() && argPath.node.right.right.callee.name.includes("makeTemplateObject") && 2 === argPath.node.right.right.arguments.length;
}
var appendStringToArguments = function(path, string, t) {
if (string) {
var args = path.node.arguments;
if (t.isStringLiteral(args[args.length - 1])) args[args.length - 1].value += string; else if (isTaggedTemplateExpressionTranspiledByTypeScript(path)) {
path.get("arguments")[0].get("right").get("right").get("arguments").forEach(function(argPath) {
var elements = argPath.get("elements"), lastElement = elements[elements.length - 1];
lastElement.replaceWith(t.stringLiteral(lastElement.node.value + string));
});
} else args.push(t.stringLiteral(string));
}
}, joinStringLiterals = function(expressions, t) {

@@ -221,5 +234,5 @@ return expressions.reduce(function(finalExpressions, currentExpression, i) {

});
if (canAppendStrings) {
if (canAppendStrings && shouldLabel) {
var label = getLabelFromPath(path, state, t);
label && shouldLabel && appendStringToExpressions(path.node.arguments, "label:" + label + ";", t);
label && appendStringToArguments(path, "label:" + label + ";", t);
}

@@ -243,3 +256,8 @@ var isPure = !0;

var lastIndex = path.node.arguments.length - 1, last = path.node.arguments[lastIndex], sourceMapConditional = createSourceMapConditional(t, t.stringLiteral(""), t.stringLiteral(sourceMap));
t.isStringLiteral(last) ? path.node.arguments[lastIndex] = t.binaryExpression("+", last, sourceMapConditional) : path.node.arguments.push(sourceMapConditional);
if (t.isStringLiteral(last)) path.node.arguments[lastIndex] = t.binaryExpression("+", last, sourceMapConditional); else if (isTaggedTemplateExpressionTranspiledByTypeScript(path)) {
path.get("arguments")[0].get("right").get("right").get("arguments").forEach(function(argPath) {
var elements = argPath.get("elements"), lastElement = elements[elements.length - 1];
lastElement.replaceWith(t.binaryExpression("+", lastElement.node, t.cloneNode(sourceMapConditional)));
});
} else path.node.arguments.push(sourceMapConditional);
}

@@ -246,0 +264,0 @@ return {

@@ -417,14 +417,30 @@ import nodePath from 'path';

var appendStringToExpressions = function appendStringToExpressions(expressions, string, t) {
function isTaggedTemplateExpressionTranspiledByTypeScript(path) {
if (path.node.arguments.length !== 1) {
return false;
}
var argPath = path.get('arguments')[0];
return argPath.isLogicalExpression() && argPath.get('left').isIdentifier() && argPath.node.left.name.includes('templateObject') && argPath.get('right').isAssignmentExpression() && argPath.get('right').get('right').isCallExpression() && argPath.get('right').get('right').get('callee').isIdentifier() && argPath.node.right.right.callee.name.includes('makeTemplateObject') && argPath.node.right.right.arguments.length === 2;
}
var appendStringToArguments = function appendStringToArguments(path, string, t) {
if (!string) {
return expressions;
return;
}
if (t.isStringLiteral(expressions[expressions.length - 1])) {
expressions[expressions.length - 1].value += string;
var args = path.node.arguments;
if (t.isStringLiteral(args[args.length - 1])) {
args[args.length - 1].value += string;
} else if (isTaggedTemplateExpressionTranspiledByTypeScript(path)) {
var makeTemplateObjectCallPath = path.get('arguments')[0].get('right').get('right');
makeTemplateObjectCallPath.get('arguments').forEach(function (argPath) {
var elements = argPath.get('elements');
var lastElement = elements[elements.length - 1];
lastElement.replaceWith(t.stringLiteral(lastElement.node.value + string));
});
} else {
expressions.push(t.stringLiteral(string));
args.push(t.stringLiteral(string));
}
return expressions;
};

@@ -473,7 +489,7 @@ var joinStringLiterals = function joinStringLiterals(expressions, t) {

if (canAppendStrings) {
if (canAppendStrings && shouldLabel) {
var label = getLabelFromPath(path, state, t);
if (label && shouldLabel) {
appendStringToExpressions(path.node.arguments, "label:" + label + ";", t);
if (label) {
appendStringToArguments(path, "label:" + label + ";", t);
}

@@ -522,2 +538,9 @@ }

path.node.arguments[lastIndex] = t.binaryExpression('+', last, sourceMapConditional);
} else if (isTaggedTemplateExpressionTranspiledByTypeScript(path)) {
var makeTemplateObjectCallPath = path.get('arguments')[0].get('right').get('right');
makeTemplateObjectCallPath.get('arguments').forEach(function (argPath) {
var elements = argPath.get('elements');
var lastElement = elements[elements.length - 1];
lastElement.replaceWith(t.binaryExpression('+', lastElement.node, t.cloneNode(sourceMapConditional)));
});
} else {

@@ -524,0 +547,0 @@ path.node.arguments.push(sourceMapConditional);

{
"name": "babel-plugin-emotion",
"version": "10.0.20",
"version": "10.0.21",
"description": "A recommended babel preprocessing plugin for emotion, The Next Generation of CSS-in-JS.",

@@ -42,2 +42,2 @@ "main": "dist/babel-plugin-emotion.cjs.js",

}
}
}

@@ -11,2 +11,2 @@ // @flow

export { getStyledOptions } from './get-styled-options'
export { appendStringToExpressions, joinStringLiterals } from './strings'
export { appendStringToArguments, joinStringLiterals } from './strings'

@@ -1,15 +0,25 @@

export const appendStringToExpressions = (
expressions: Array<*>,
string: string,
t: *
) => {
// @flow
import { isTaggedTemplateExpressionTranspiledByTypeScript } from './checks'
export const appendStringToArguments = (path: *, string: string, t: *) => {
if (!string) {
return expressions
return
}
if (t.isStringLiteral(expressions[expressions.length - 1])) {
expressions[expressions.length - 1].value += string
const args = path.node.arguments
if (t.isStringLiteral(args[args.length - 1])) {
args[args.length - 1].value += string
} else if (isTaggedTemplateExpressionTranspiledByTypeScript(path)) {
const makeTemplateObjectCallPath = path
.get('arguments')[0]
.get('right')
.get('right')
makeTemplateObjectCallPath.get('arguments').forEach(argPath => {
const elements = argPath.get('elements')
const lastElement = elements[elements.length - 1]
lastElement.replaceWith(t.stringLiteral(lastElement.node.value + string))
})
} else {
expressions.push(t.stringLiteral(string))
args.push(t.stringLiteral(string))
}
return expressions
}

@@ -16,0 +26,0 @@

@@ -8,3 +8,4 @@ // @flow

import { simplifyObject } from './object-to-string'
import { appendStringToExpressions, joinStringLiterals } from './strings'
import { appendStringToArguments, joinStringLiterals } from './strings'
import { isTaggedTemplateExpressionTranspiledByTypeScript } from './checks'

@@ -53,6 +54,6 @@ function createSourceMapConditional(t, production, development) {

if (canAppendStrings) {
if (canAppendStrings && shouldLabel) {
const label = getLabelFromPath(path, state, t)
if (label && shouldLabel) {
appendStringToExpressions(path.node.arguments, `label:${label};`, t)
if (label) {
appendStringToArguments(path, `label:${label};`, t)
}

@@ -119,2 +120,19 @@ }

)
} else if (isTaggedTemplateExpressionTranspiledByTypeScript(path)) {
const makeTemplateObjectCallPath = path
.get('arguments')[0]
.get('right')
.get('right')
makeTemplateObjectCallPath.get('arguments').forEach(argPath => {
const elements = argPath.get('elements')
const lastElement = elements[elements.length - 1]
lastElement.replaceWith(
t.binaryExpression(
'+',
lastElement.node,
t.cloneNode(sourceMapConditional)
)
)
})
} else {

@@ -121,0 +139,0 @@ path.node.arguments.push(sourceMapConditional)

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