@teleporthq/teleport-plugin-react-styled-components
Advanced tools
Comparing version 0.32.0-alpha.0 to 0.32.0
@@ -37,3 +37,3 @@ import { createReactStyledComponentsPlugin } from '../src' | ||
expect(chunks.length).toBe(2) | ||
expect(chunks.length).toBe(3) | ||
expect(declaration.callee.name).toBe('variant') | ||
@@ -40,0 +40,0 @@ expect(declaration.arguments[0].properties.length).toBe(2) |
@@ -40,3 +40,3 @@ "use strict"; | ||
if (f) throw new TypeError("Generator is already executing."); | ||
while (_) try { | ||
while (g && (g = 0, op[0] && (_ = 0)), _) try { | ||
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; | ||
@@ -100,4 +100,3 @@ if (y = 0, t) op = [op[0] & 2, t.value]; | ||
teleport_shared_1.UIDLUtils.traverseElements(node, function (element) { | ||
var _a; | ||
var key = element.key, elementType = element.elementType, referencedStyles = element.referencedStyles, dependency = element.dependency, style = element.style, _b = element.attrs, attrs = _b === void 0 ? {} : _b; | ||
var key = element.key, elementType = element.elementType, referencedStyles = element.referencedStyles, dependency = element.dependency, style = element.style, _a = element.attrs, attrs = _a === void 0 ? {} : _a; | ||
var propsReferred = new Set(); | ||
@@ -114,9 +113,5 @@ var componentStyleReferences = new Set(); | ||
} | ||
if (Object.keys(style || {}).length === 0 && | ||
Object.keys(referencedStyles || {}).length === 0) { | ||
return; | ||
} | ||
var root = jsxNodesLookup[key]; | ||
var className = teleport_shared_1.StringUtils.dashCaseToUpperCamelCase(key); | ||
if (style && Object.keys(style).length > 0) { | ||
if (style) { | ||
/* Styled components might create an element that | ||
@@ -137,3 +132,3 @@ clashes with native element (Text, View, Image, etc.) */ | ||
} | ||
if (referencedStyles && ((_a = Object.keys(referencedStyles)) === null || _a === void 0 ? void 0 : _a.length) > 0) { | ||
if (referencedStyles) { | ||
Object.values(referencedStyles).forEach(function (styleRef) { | ||
@@ -184,4 +179,3 @@ var _a; | ||
if (styleRef.content.content.type === 'static') { | ||
componentStyleReferences.add(constants_1.componentVariantPropPrefix); | ||
teleport_plugin_common_1.ASTUtils.addAttributeToJSXTag(root, constants_1.componentVariantPropKey, styleRef.content.content.content); | ||
teleport_plugin_common_1.ASTUtils.addAttributeToJSXTag(root, 'className', styleRef.content.content.content); | ||
} | ||
@@ -188,0 +182,0 @@ if (styleRef.content.content.type === 'dynamic' && |
@@ -40,3 +40,3 @@ "use strict"; | ||
if (f) throw new TypeError("Generator is already executing."); | ||
while (_) try { | ||
while (g && (g = 0, op[0] && (_ = 0)), _) try { | ||
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; | ||
@@ -76,5 +76,4 @@ if (y = 0, t) op = [op[0] & 2, t.value]; | ||
_a = uidl.styleSetDefinitions, styleSetDefinitions = _a === void 0 ? {} : _a, _b = uidl.designLanguage, _c = _b === void 0 ? {} : _b, _d = _c.tokens, tokens = _d === void 0 ? {} : _d; | ||
if (Object.keys(styleSetDefinitions).length === 0 && Object.keys(tokens).length === 0) { | ||
return [2 /*return*/, structure]; | ||
} | ||
uidl.outputOptions = uidl.outputOptions || {}; | ||
uidl.outputOptions.fileName = fileName; | ||
tokensMap = Object.keys(tokens || {}).reduce(function (acc, key) { | ||
@@ -114,4 +113,2 @@ var style = tokens[key]; | ||
} | ||
uidl.outputOptions = uidl.outputOptions || {}; | ||
uidl.outputOptions.fileName = fileName; | ||
return [2 /*return*/, structure]; | ||
@@ -118,0 +115,0 @@ }); |
@@ -65,3 +65,3 @@ "use strict"; | ||
return types.variableDeclaration('const', [ | ||
types.variableDeclarator(types.identifier(name), types.callExpression(types.callExpression(types.identifier('styled'), [types.stringLiteral(elementType)]), expressionArguments)), | ||
types.variableDeclarator(types.identifier(name), types.callExpression(types.callExpression(types.identifier('styled'), [types.stringLiteral(elementType)]), expressionArguments.length > 0 ? expressionArguments : [types.objectExpression([])])), | ||
]); | ||
@@ -82,3 +82,3 @@ }; | ||
if (style.type === 'dynamic' && style.content.referenceType === 'state') { | ||
throw new teleport_types_1.PluginStyledComponent("Error running transformDynamicStyles in reactStyledComponentsPlugin. \n Unsupported styleValue.content.referenceType value ".concat(style.content.referenceType)); | ||
throw new teleport_types_1.PluginStyledComponent("Error running transformDynamicStyles in reactStyledComponentsPlugin.\n Unsupported styleValue.content.referenceType value ".concat(style.content.referenceType)); | ||
} | ||
@@ -85,0 +85,0 @@ if (style.type === 'dynamic' && style.content.referenceType === 'prop') { |
@@ -16,3 +16,3 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
if (f) throw new TypeError("Generator is already executing."); | ||
while (_) try { | ||
while (g && (g = 0, op[0] && (_ = 0)), _) try { | ||
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; | ||
@@ -73,4 +73,3 @@ if (y = 0, t) op = [op[0] & 2, t.value]; | ||
UIDLUtils.traverseElements(node, function (element) { | ||
var _a; | ||
var key = element.key, elementType = element.elementType, referencedStyles = element.referencedStyles, dependency = element.dependency, style = element.style, _b = element.attrs, attrs = _b === void 0 ? {} : _b; | ||
var key = element.key, elementType = element.elementType, referencedStyles = element.referencedStyles, dependency = element.dependency, style = element.style, _a = element.attrs, attrs = _a === void 0 ? {} : _a; | ||
var propsReferred = new Set(); | ||
@@ -87,9 +86,5 @@ var componentStyleReferences = new Set(); | ||
} | ||
if (Object.keys(style || {}).length === 0 && | ||
Object.keys(referencedStyles || {}).length === 0) { | ||
return; | ||
} | ||
var root = jsxNodesLookup[key]; | ||
var className = StringUtils.dashCaseToUpperCamelCase(key); | ||
if (style && Object.keys(style).length > 0) { | ||
if (style) { | ||
/* Styled components might create an element that | ||
@@ -110,3 +105,3 @@ clashes with native element (Text, View, Image, etc.) */ | ||
} | ||
if (referencedStyles && ((_a = Object.keys(referencedStyles)) === null || _a === void 0 ? void 0 : _a.length) > 0) { | ||
if (referencedStyles) { | ||
Object.values(referencedStyles).forEach(function (styleRef) { | ||
@@ -157,4 +152,3 @@ var _a; | ||
if (styleRef.content.content.type === 'static') { | ||
componentStyleReferences.add(componentVariantPropPrefix); | ||
ASTUtils.addAttributeToJSXTag(root, componentVariantPropKey, styleRef.content.content.content); | ||
ASTUtils.addAttributeToJSXTag(root, 'className', styleRef.content.content.content); | ||
} | ||
@@ -161,0 +155,0 @@ if (styleRef.content.content.type === 'dynamic' && |
@@ -16,3 +16,3 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
if (f) throw new TypeError("Generator is already executing."); | ||
while (_) try { | ||
while (g && (g = 0, op[0] && (_ = 0)), _) try { | ||
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; | ||
@@ -50,5 +50,4 @@ if (y = 0, t) op = [op[0] & 2, t.value]; | ||
_a = uidl.styleSetDefinitions, styleSetDefinitions = _a === void 0 ? {} : _a, _b = uidl.designLanguage, _c = _b === void 0 ? {} : _b, _d = _c.tokens, tokens = _d === void 0 ? {} : _d; | ||
if (Object.keys(styleSetDefinitions).length === 0 && Object.keys(tokens).length === 0) { | ||
return [2 /*return*/, structure]; | ||
} | ||
uidl.outputOptions = uidl.outputOptions || {}; | ||
uidl.outputOptions.fileName = fileName; | ||
tokensMap = Object.keys(tokens || {}).reduce(function (acc, key) { | ||
@@ -88,4 +87,2 @@ var style = tokens[key]; | ||
} | ||
uidl.outputOptions = uidl.outputOptions || {}; | ||
uidl.outputOptions.fileName = fileName; | ||
return [2 /*return*/, structure]; | ||
@@ -92,0 +89,0 @@ }); |
@@ -39,3 +39,3 @@ var __assign = (this && this.__assign) || function () { | ||
return types.variableDeclaration('const', [ | ||
types.variableDeclarator(types.identifier(name), types.callExpression(types.callExpression(types.identifier('styled'), [types.stringLiteral(elementType)]), expressionArguments)), | ||
types.variableDeclarator(types.identifier(name), types.callExpression(types.callExpression(types.identifier('styled'), [types.stringLiteral(elementType)]), expressionArguments.length > 0 ? expressionArguments : [types.objectExpression([])])), | ||
]); | ||
@@ -55,3 +55,3 @@ }; | ||
if (style.type === 'dynamic' && style.content.referenceType === 'state') { | ||
throw new PluginStyledComponent("Error running transformDynamicStyles in reactStyledComponentsPlugin. \n Unsupported styleValue.content.referenceType value ".concat(style.content.referenceType)); | ||
throw new PluginStyledComponent("Error running transformDynamicStyles in reactStyledComponentsPlugin.\n Unsupported styleValue.content.referenceType value ".concat(style.content.referenceType)); | ||
} | ||
@@ -58,0 +58,0 @@ if (style.type === 'dynamic' && style.content.referenceType === 'prop') { |
{ | ||
"name": "@teleporthq/teleport-plugin-react-styled-components", | ||
"version": "0.32.0-alpha.0", | ||
"version": "0.32.0", | ||
"description": "A plugin for injecting the styles through styled-components inside React components", | ||
@@ -28,7 +28,7 @@ "author": "teleportHQ", | ||
"@babel/types": "^7.5.5", | ||
"@teleporthq/teleport-plugin-common": "^0.32.0-alpha.0", | ||
"@teleporthq/teleport-shared": "^0.32.0-alpha.0", | ||
"@teleporthq/teleport-types": "^0.32.0-alpha.0" | ||
"@teleporthq/teleport-plugin-common": "^0.32.0", | ||
"@teleporthq/teleport-shared": "^0.32.0", | ||
"@teleporthq/teleport-types": "^0.32.0" | ||
}, | ||
"gitHead": "de47527436cc4f1d00f241718fbdfdb86e616e3b" | ||
"gitHead": "08e6b6b0a6328cdbf86891871be39a377450a084" | ||
} |
@@ -87,13 +87,6 @@ import * as types from '@babel/types' | ||
if ( | ||
Object.keys(style || {}).length === 0 && | ||
Object.keys(referencedStyles || {}).length === 0 | ||
) { | ||
return | ||
} | ||
const root = jsxNodesLookup[key] | ||
let className = StringUtils.dashCaseToUpperCamelCase(key) | ||
if (style && Object.keys(style).length > 0) { | ||
if (style) { | ||
/* Styled components might create an element that | ||
@@ -118,3 +111,3 @@ clashes with native element (Text, View, Image, etc.) */ | ||
if (referencedStyles && Object.keys(referencedStyles)?.length > 0) { | ||
if (referencedStyles) { | ||
Object.values(referencedStyles).forEach((styleRef) => { | ||
@@ -176,8 +169,3 @@ switch (styleRef.content?.mapType) { | ||
if (styleRef.content.content.type === 'static') { | ||
componentStyleReferences.add(componentVariantPropPrefix) | ||
ASTUtils.addAttributeToJSXTag( | ||
root, | ||
componentVariantPropKey, | ||
styleRef.content.content.content | ||
) | ||
ASTUtils.addAttributeToJSXTag(root, 'className', styleRef.content.content.content) | ||
} | ||
@@ -211,3 +199,3 @@ | ||
/* | ||
Changing the default value of the prop. | ||
Changing the default value of the prop. | ||
When forceScoping is enabled the classnames change. So, we need to change the default prop too. | ||
@@ -214,0 +202,0 @@ */ |
@@ -22,6 +22,6 @@ import * as types from '@babel/types' | ||
const { styleSetDefinitions = {}, designLanguage: { tokens = {} } = {} } = uidl | ||
if (Object.keys(styleSetDefinitions).length === 0 && Object.keys(tokens).length === 0) { | ||
return structure | ||
} | ||
uidl.outputOptions = uidl.outputOptions || {} | ||
uidl.outputOptions.fileName = fileName | ||
const tokensMap: Record<string, string | number> = Object.keys(tokens || {}).reduce( | ||
@@ -79,5 +79,2 @@ (acc: Record<string, string | number>, key: string) => { | ||
uidl.outputOptions = uidl.outputOptions || {} | ||
uidl.outputOptions.fileName = fileName | ||
return structure | ||
@@ -84,0 +81,0 @@ } |
@@ -61,3 +61,3 @@ import * as types from '@babel/types' | ||
types.callExpression(types.identifier('styled'), [types.stringLiteral(elementType)]), | ||
expressionArguments | ||
expressionArguments.length > 0 ? expressionArguments : [types.objectExpression([])] | ||
) | ||
@@ -96,3 +96,3 @@ ), | ||
if (style.type === 'dynamic' && style.content.referenceType === 'state') { | ||
throw new PluginStyledComponent(`Error running transformDynamicStyles in reactStyledComponentsPlugin. | ||
throw new PluginStyledComponent(`Error running transformDynamicStyles in reactStyledComponentsPlugin. | ||
Unsupported styleValue.content.referenceType value ${style.content.referenceType}`) | ||
@@ -99,0 +99,0 @@ } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
193075
2028