Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

babel-plugin-transform-jsx-to-html

Package Overview
Dependencies
Maintainers
2
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

babel-plugin-transform-jsx-to-html - npm Package Compare versions

Comparing version 0.1.0 to 0.2.0

es/index.js

9

lib/index.js

@@ -9,4 +9,6 @@ "use strict";

var KEY_FOR_ATTRS = '__attrs';
var TEMP_KEY_PREFIX = '__key_';
module.exports = function () {
var keyIndex = 0;
return {

@@ -21,2 +23,9 @@ visitor: {

if (!t.react.isCompatTag(tagName)) {
// This plugin may transform a normal child to be an array, which cause key validation in createElement failed.
// So add a key for each child in non production env, to prevent key validation warning.
if (process.env.NODE_ENV !== 'production') {
var keyAttr = t.jsxAttribute(t.jsxIdentifier('key'), t.stringLiteral(TEMP_KEY_PREFIX + keyIndex++));
openingPath.node.attributes.unshift(keyAttr);
}
return;

@@ -23,0 +32,0 @@ }

2

package.json
{
"name": "babel-plugin-transform-jsx-to-html",
"version": "0.1.0",
"version": "0.2.0",
"description": "Transform JSX to HTML.",

@@ -5,0 +5,0 @@ "license": "BSD-3-Clause",

@@ -44,3 +44,5 @@ const jsxToHtmlPlugin = require('../index');

__html: "<div>"
}, createElement(View, null), {
}, createElement(View, {
key: "__key_0"
}), {
__html: "</div>"

@@ -50,2 +52,18 @@ }];`);

it('tansform with component already have key', () => {
expect(getTransfromCode(`
<div>
<View key="view_1" />
</div>
`)).toBe(`var _createElement;
[{
__html: "<div>"
}, createElement(View, (_createElement = {
key: "__key_0"
}, _createElement["key"] = "view_1", _createElement)), {
__html: "</div>"
}];`);
});
it('tansform component with children', () => {

@@ -57,3 +75,5 @@ expect(getTransfromCode(`

</View>
`)).toBe(`createElement(View, null, [{
`)).toBe(`createElement(View, {
key: "__key_0"
}, [{
__html: "<div>a</div>"

@@ -155,2 +175,2 @@ }], [{

});
});
});

@@ -6,4 +6,7 @@ const esutils = require('esutils');

const KEY_FOR_ATTRS = '__attrs';
const TEMP_KEY_PREFIX = '__key_';
module.exports = function() {
let keyIndex = 0;
return {

@@ -18,2 +21,9 @@ visitor: {

if (!t.react.isCompatTag(tagName)) {
// This plugin may transform a normal child to be an array, which cause key validation in createElement failed.
// So add a key for each child in non production env, to prevent key validation warning.
if (process.env.NODE_ENV !== 'production') {
const keyAttr = t.jsxAttribute(t.jsxIdentifier('key'), t.stringLiteral(TEMP_KEY_PREFIX + keyIndex ++));
openingPath.node.attributes.unshift(keyAttr);
}
return;

@@ -20,0 +30,0 @@ }

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