babel-plugin-styled-components
Advanced tools
Comparing version 1.9.4 to 1.9.5-0
@@ -24,10 +24,2 @@ "use strict"; | ||
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread(); } | ||
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance"); } | ||
function _iterableToArray(iter) { if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter); } | ||
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } } | ||
function _default(_ref) { | ||
@@ -38,26 +30,2 @@ var t = _ref.types; | ||
visitor: { | ||
// These visitors insert newly generated code and missing import/require statements | ||
Program: { | ||
enter(path, state) { | ||
state.required = false; | ||
state.items = []; | ||
}, | ||
exit(path, state) { | ||
var _path$node$body; | ||
var oldLength = path.node.body.length; | ||
(_path$node$body = path.node.body).push.apply(_path$node$body, _toConsumableArray(state.items)); | ||
var newLength = path.node.body.length; | ||
for (var i = 0; i < newLength - oldLength; i++) { | ||
// Queue all inserted items for revisiting so that tagged templates are transpiled | ||
path.requeue(path.get('body')[oldLength + i]); | ||
} | ||
} | ||
}, | ||
JSXAttribute(path, state) { | ||
@@ -64,0 +32,0 @@ (0, _transpileCssProp.default)(t)(path, state); |
@@ -8,2 +8,4 @@ "use strict"; | ||
var _helperModuleImports = require("@babel/helper-module-imports"); | ||
var _options = require("../utils/options"); | ||
@@ -32,16 +34,17 @@ | ||
if (!(0, _options.useCssProp)(state)) return; | ||
if (path.node.name.name !== 'css') return; // Insert require('styled-components') if it doesn't exist yet | ||
if (path.node.name.name !== 'css') return; | ||
var program = state.file.path; // state.customImportName is passed through from styled-components/macro if it's used | ||
// since the macro also inserts the import | ||
var bindings = path.findParent(function (p) { | ||
return p.type === 'Program'; | ||
}).scope.bindings; | ||
var importName = state.customImportName; // Insert import if it doesn't exist yet | ||
if (!state.required) { | ||
if (!bindings.styled) { | ||
state.items.push(t.importDeclaration([t.importDefaultSpecifier(t.identifier('styled'))], t.stringLiteral('styled-components'))); | ||
} | ||
var bindings = program.scope.bindings; | ||
state.required = true; | ||
if (!importName || !bindings[importName.name]) { | ||
importName = (0, _helperModuleImports.addDefault)(path, 'styled-components', { | ||
nameHint: importName ? importName.name : 'styled' | ||
}); | ||
} | ||
if (!state.customImportName) state.customImportName = importName; | ||
var elem = path.parentPath; | ||
@@ -52,3 +55,3 @@ var name = getName(elem.node.name, t); | ||
})); | ||
var styled = t.callExpression(t.identifier('styled'), [/^[a-z]/.test(name) ? t.stringLiteral(name) : t.identifier(name)]); | ||
var styled = t.callExpression(importName, [/^[a-z]/.test(name) ? t.stringLiteral(name) : t.identifier(name)]); | ||
var css; | ||
@@ -108,4 +111,7 @@ | ||
return acc; | ||
}, []); | ||
state.items.push(t.variableDeclaration('var', [t.variableDeclarator(id, t.taggedTemplateExpression(styled, css))])); | ||
}, []); // Add the tagged template expression and then requeue the newly added node | ||
// so Babel runs over it again | ||
var length = program.node.body.push(t.variableDeclaration('var', [t.variableDeclarator(id, t.taggedTemplateExpression(styled, css))])); | ||
program.requeue(program.get('body')[length - 1]); | ||
}; | ||
@@ -112,0 +118,0 @@ }; |
{ | ||
"version": "1.9.4", | ||
"version": "1.9.5-0", | ||
"name": "babel-plugin-styled-components", | ||
@@ -30,2 +30,3 @@ "description": "Improve the debugging experience and add server-side rendering support to styled-components", | ||
"@babel/helper-annotate-as-pure": "^7.0.0", | ||
"@babel/helper-module-imports": "^7.0.0", | ||
"babel-plugin-syntax-jsx": "^6.18.0", | ||
@@ -32,0 +33,0 @@ "lodash": "^4.17.10" |
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
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
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
36300
5
708
2
+ Added@babel/code-frame@7.26.2(transitive)
+ Added@babel/generator@7.26.2(transitive)
+ Added@babel/helper-module-imports@7.25.9(transitive)
+ Added@babel/parser@7.26.2(transitive)
+ Added@babel/template@7.25.9(transitive)
+ Added@babel/traverse@7.25.9(transitive)
+ Added@jridgewell/gen-mapping@0.3.5(transitive)
+ Added@jridgewell/resolve-uri@3.1.2(transitive)
+ Added@jridgewell/set-array@1.2.1(transitive)
+ Added@jridgewell/sourcemap-codec@1.5.0(transitive)
+ Added@jridgewell/trace-mapping@0.3.25(transitive)
+ Addeddebug@4.3.7(transitive)
+ Addedglobals@11.12.0(transitive)
+ Addedjsesc@3.0.2(transitive)
+ Addedms@2.1.3(transitive)