babel-plugin-estrela
Advanced tools
Comparing version 0.11.1 to 0.11.2
@@ -5,3 +5,3 @@ { | ||
"author": "Eduardo Rosostolato", | ||
"version": "0.11.1", | ||
"version": "0.11.2", | ||
"license": "MIT", | ||
@@ -8,0 +8,0 @@ "main": "dist/index.js", |
@@ -43,3 +43,3 @@ import { NodePath, types as t } from '@babel/core'; | ||
} else { | ||
tmpl = path.scope.generateUidIdentifier('_tmpl'); | ||
tmpl = path.scope.generateUidIdentifier('_tmpl$'); | ||
const template = t.callExpression(state.template, [ | ||
@@ -60,3 +60,3 @@ t.stringLiteral(result.template), | ||
function createProps(props: Record<string, any>): t.ObjectExpression { | ||
const result: t.ObjectProperty[] = []; | ||
const result: (t.ObjectProperty | t.SpreadElement)[] = []; | ||
for (const prop in props) { | ||
@@ -70,23 +70,25 @@ let value = props[prop]; | ||
} | ||
if (typeof value === 'object' && !t.isNode(value)) { | ||
value = createProps(props[prop]); | ||
if (typeof value === 'object' && value !== null && !t.isNode(value)) { | ||
value = createProps(value); | ||
} | ||
if (typeof value !== 'object') { | ||
if (typeof value === 'string') { | ||
value = t.stringLiteral(value); | ||
} | ||
if (typeof value === 'number') { | ||
value = t.numericLiteral(value); | ||
} | ||
if (typeof value === 'boolean') { | ||
value = t.booleanLiteral(value); | ||
} | ||
if (typeof value === null) { | ||
value = t.nullLiteral(); | ||
} | ||
if (typeof value === 'undefined') { | ||
value = t.identifier('undefined'); | ||
} | ||
if (typeof value === 'string') { | ||
value = t.stringLiteral(value); | ||
} | ||
result.push(t.objectProperty(t.stringLiteral(prop), value)); | ||
if (typeof value === 'number') { | ||
value = t.numericLiteral(value); | ||
} | ||
if (typeof value === 'boolean') { | ||
value = t.booleanLiteral(value); | ||
} | ||
if (value === undefined) { | ||
value = t.tsUndefinedKeyword(); | ||
} | ||
if (value === null) { | ||
value = t.nullLiteral(); | ||
} | ||
if (prop === '_$spread$') { | ||
result.push(t.spreadElement(value)); | ||
} else { | ||
result.push(t.objectProperty(t.stringLiteral(prop), value)); | ||
} | ||
} | ||
@@ -134,2 +136,4 @@ return t.objectExpression(result); | ||
} | ||
} else if (attribute.isJSXSpreadAttribute()) { | ||
props['_$spread$'] = attribute.get('argument').node; | ||
} else { | ||
@@ -136,0 +140,0 @@ throw new Error('Unsupported attribute type'); |
@@ -8,5 +8,5 @@ import { NodePath, types as t } from '@babel/core'; | ||
path.state = { | ||
h: path.scope.generateUidIdentifier('h'), | ||
h: path.scope.generateUidIdentifier('h$'), | ||
template: path.scope.generateUidIdentifier('template$'), | ||
tmplDeclaration: t.variableDeclaration('const', []), | ||
template: path.scope.generateUidIdentifier('template'), | ||
} as State; | ||
@@ -13,0 +13,0 @@ }, |
Sorry, the diff of this file is too big to display
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
171662
4773