babel-plugin-emotion
Advanced tools
Comparing version 10.0.29 to 10.0.33
# babel-plugin-emotion | ||
## 10.0.33 | ||
### Patch Changes | ||
- [`b9f8ae3`](https://github.com/emotion-js/emotion/commit/b9f8ae3f6e18b0569376b9ed62e9d09d141adff8) [#1829](https://github.com/emotion-js/emotion/pull/1829) Thanks [@Andarist](https://github.com/Andarist)! - Skip appending source maps & labels to Babel-transpiled tagged template expressions. | ||
## 10.0.29 | ||
@@ -4,0 +10,0 @@ |
@@ -438,2 +438,51 @@ 'use strict'; | ||
return null; | ||
} // this is only used to prevent appending strings/expressions to arguments incorectly | ||
// we could push them to found array expressions, as we do it for TS-transpile output ¯\_(ツ)_/¯ | ||
// it seems overly complicated though - mainly because we'd also have to check against existing stuff of a particular type (source maps & labels) | ||
// considering Babel double-transpilation as a valid use case seems rather far-fetched | ||
function isTaggedTemplateTranspiledByBabel(path) { | ||
if (path.node.arguments.length === 0) { | ||
return false; | ||
} | ||
var firstArgPath = path.get('arguments')[0]; | ||
if (!firstArgPath.isCallExpression() || !firstArgPath.get('callee').isIdentifier()) { | ||
return false; | ||
} | ||
var calleeName = firstArgPath.node.callee.name; | ||
if (!calleeName.includes('templateObject')) { | ||
return false; | ||
} | ||
var bindingPath = path.scope.getBinding(calleeName).path; | ||
if (!bindingPath.isFunction()) { | ||
return false; | ||
} | ||
var functionBody = bindingPath.get('body.body'); | ||
if (!functionBody[0].isVariableDeclaration()) { | ||
return false; | ||
} | ||
var declarationInit = functionBody[0].get('declarations')[0].get('init'); | ||
if (!declarationInit.isCallExpression()) { | ||
return false; | ||
} | ||
var declarationInitArguments = declarationInit.get('arguments'); | ||
if (declarationInitArguments.length === 0 || declarationInitArguments.length > 2 || declarationInitArguments.some(function (argPath) { | ||
return !argPath.isArrayExpression(); | ||
})) { | ||
return false; | ||
} | ||
return true; | ||
} | ||
@@ -459,3 +508,3 @@ | ||
}); | ||
} else { | ||
} else if (!isTaggedTemplateTranspiledByBabel(path)) { | ||
args.push(t.stringLiteral(string)); | ||
@@ -574,3 +623,3 @@ } | ||
}); | ||
} else { | ||
} else if (!isTaggedTemplateTranspiledByBabel(path)) { | ||
path.node.arguments.push(sourceMapConditional); | ||
@@ -577,0 +626,0 @@ } |
@@ -201,2 +201,20 @@ "use strict"; | ||
function isTaggedTemplateTranspiledByBabel(path) { | ||
if (0 === path.node.arguments.length) return !1; | ||
var firstArgPath = path.get("arguments")[0]; | ||
if (!firstArgPath.isCallExpression() || !firstArgPath.get("callee").isIdentifier()) return !1; | ||
var calleeName = firstArgPath.node.callee.name; | ||
if (!calleeName.includes("templateObject")) return !1; | ||
var bindingPath = path.scope.getBinding(calleeName).path; | ||
if (!bindingPath.isFunction()) return !1; | ||
var functionBody = bindingPath.get("body.body"); | ||
if (!functionBody[0].isVariableDeclaration()) return !1; | ||
var declarationInit = functionBody[0].get("declarations")[0].get("init"); | ||
if (!declarationInit.isCallExpression()) return !1; | ||
var declarationInitArguments = declarationInit.get("arguments"); | ||
return !(0 === declarationInitArguments.length || declarationInitArguments.length > 2 || declarationInitArguments.some(function(argPath) { | ||
return !argPath.isArrayExpression(); | ||
})); | ||
} | ||
var appendStringToArguments = function(path, string, t) { | ||
@@ -210,3 +228,3 @@ if (string) { | ||
lastElement.replaceWith(t.stringLiteral(lastElement.node.value + string)); | ||
}) : args.push(t.stringLiteral(string)); | ||
}) : isTaggedTemplateTranspiledByBabel(path) || args.push(t.stringLiteral(string)); | ||
} | ||
@@ -270,3 +288,3 @@ } | ||
}); | ||
} else path.node.arguments.push(sourceMapConditional); | ||
} else isTaggedTemplateTranspiledByBabel(path) || path.node.arguments.push(sourceMapConditional); | ||
} | ||
@@ -273,0 +291,0 @@ } |
@@ -432,2 +432,51 @@ import nodePath from 'path'; | ||
return null; | ||
} // this is only used to prevent appending strings/expressions to arguments incorectly | ||
// we could push them to found array expressions, as we do it for TS-transpile output ¯\_(ツ)_/¯ | ||
// it seems overly complicated though - mainly because we'd also have to check against existing stuff of a particular type (source maps & labels) | ||
// considering Babel double-transpilation as a valid use case seems rather far-fetched | ||
function isTaggedTemplateTranspiledByBabel(path) { | ||
if (path.node.arguments.length === 0) { | ||
return false; | ||
} | ||
var firstArgPath = path.get('arguments')[0]; | ||
if (!firstArgPath.isCallExpression() || !firstArgPath.get('callee').isIdentifier()) { | ||
return false; | ||
} | ||
var calleeName = firstArgPath.node.callee.name; | ||
if (!calleeName.includes('templateObject')) { | ||
return false; | ||
} | ||
var bindingPath = path.scope.getBinding(calleeName).path; | ||
if (!bindingPath.isFunction()) { | ||
return false; | ||
} | ||
var functionBody = bindingPath.get('body.body'); | ||
if (!functionBody[0].isVariableDeclaration()) { | ||
return false; | ||
} | ||
var declarationInit = functionBody[0].get('declarations')[0].get('init'); | ||
if (!declarationInit.isCallExpression()) { | ||
return false; | ||
} | ||
var declarationInitArguments = declarationInit.get('arguments'); | ||
if (declarationInitArguments.length === 0 || declarationInitArguments.length > 2 || declarationInitArguments.some(function (argPath) { | ||
return !argPath.isArrayExpression(); | ||
})) { | ||
return false; | ||
} | ||
return true; | ||
} | ||
@@ -453,3 +502,3 @@ | ||
}); | ||
} else { | ||
} else if (!isTaggedTemplateTranspiledByBabel(path)) { | ||
args.push(t.stringLiteral(string)); | ||
@@ -568,3 +617,3 @@ } | ||
}); | ||
} else { | ||
} else if (!isTaggedTemplateTranspiledByBabel(path)) { | ||
path.node.arguments.push(sourceMapConditional); | ||
@@ -571,0 +620,0 @@ } |
{ | ||
"name": "babel-plugin-emotion", | ||
"version": "10.0.29", | ||
"version": "10.0.33", | ||
"description": "A recommended babel preprocessing plugin for emotion, The Next Generation of CSS-in-JS.", | ||
@@ -5,0 +5,0 @@ "main": "dist/babel-plugin-emotion.cjs.js", |
// @flow | ||
import { getTypeScriptMakeTemplateObjectPath } from './ts-output-utils' | ||
import { | ||
getTypeScriptMakeTemplateObjectPath, | ||
isTaggedTemplateTranspiledByBabel | ||
} from './transpiled-output-utils' | ||
@@ -22,3 +25,3 @@ export const appendStringToArguments = (path: *, string: string, t: *) => { | ||
}) | ||
} else { | ||
} else if (!isTaggedTemplateTranspiledByBabel(path)) { | ||
args.push(t.stringLiteral(string)) | ||
@@ -25,0 +28,0 @@ } |
@@ -9,3 +9,6 @@ // @flow | ||
import { appendStringToArguments, joinStringLiterals } from './strings' | ||
import { getTypeScriptMakeTemplateObjectPath } from './ts-output-utils' | ||
import { | ||
getTypeScriptMakeTemplateObjectPath, | ||
isTaggedTemplateTranspiledByBabel | ||
} from './transpiled-output-utils' | ||
@@ -166,3 +169,3 @@ const CSS_OBJECT_STRINGIFIED_ERROR = | ||
}) | ||
} else { | ||
} else if (!isTaggedTemplateTranspiledByBabel(path)) { | ||
path.node.arguments.push(sourceMapConditional) | ||
@@ -169,0 +172,0 @@ } |
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
159193
3500