mirror of
https://github.com/ritz078/transform.git
synced 2026-11-22 00:54:01 +03:00
fixes #26
This commit is contained in:
1 parent
60ad63eb9e
commit
050a2eeb87
5 files changed
+16
-15
No files matched your search
+8
-2
@@ -4,6 +4,8 @@ import immutablePropsPlugin from "../utils/babel-plugin-js-to-immutable-prop-typ
|
||||
import Layout from "../components/Layout";
|
||||
import { transform } from "babel-standalone";
|
||||
import defaultText from "../utils/dummy-json";
|
||||
import { toValidJSON } from "../utils/json-to-ts-flow";
|
||||
import merge from "lodash/merge"
|
||||
|
||||
import ConversionPanel from "../components/ConversionPanel";
|
||||
|
||||
@@ -13,9 +15,13 @@ export default class Main extends PureComponent {
|
||||
};
|
||||
|
||||
getTransformedValue = newValue => {
|
||||
newValue = "const propTypes = " + newValue;
|
||||
let x = JSON.parse(toValidJSON(newValue))
|
||||
if (typeof x !== "object" || Array.isArray(x)) {
|
||||
x = merge({}, ...x)
|
||||
}
|
||||
x = "const propTypes = " + JSON.stringify(x);
|
||||
const plugin = this.state.isImmutable ? immutablePropsPlugin : propsPlugin;
|
||||
const { code } = transform(newValue, {
|
||||
const { code } = transform(x, {
|
||||
presets: ["es2015"],
|
||||
plugins: [plugin]
|
||||
});
|
||||
|
||||
@@ -4,15 +4,14 @@ import { Json2dts, toValidJSON } from "../utils/json-to-ts-flow";
|
||||
import Layout from "../components/Layout";
|
||||
import ConversionPanel from "../components/ConversionPanel";
|
||||
import defaultText from "../utils/dummy-json";
|
||||
import merge from "lodash/merge";
|
||||
|
||||
export default class Json2Ts extends PureComponent {
|
||||
getTransformedValue = newValue => {
|
||||
const converter = new Json2dts();
|
||||
let text2Obj = JSON.parse(toValidJSON(newValue));
|
||||
if (typeof text2Obj !== "object" || Array.isArray(text2Obj)) {
|
||||
throw new Error(
|
||||
"Pass a valid JSON Object. Arrays are not acceptable even though they are valid JSON."
|
||||
);
|
||||
text2Obj = merge({}, ...text2Obj)
|
||||
}
|
||||
converter.parse(text2Obj, "props");
|
||||
return converter.getCode(true);
|
||||
|
||||
@@ -3,15 +3,13 @@ import { Json2dts, toValidJSON } from "../utils/json-to-rust-serde";
|
||||
import Layout from "../components/Layout";
|
||||
import ConversionPanel from "../components/ConversionPanel";
|
||||
import defaultText from "../utils/dummy-json";
|
||||
|
||||
import merge from "lodash/merge"
|
||||
export default class Json2Ts extends PureComponent {
|
||||
getTransformedValue = newValue => {
|
||||
const converter = new Json2dts();
|
||||
let text2Obj = JSON.parse(toValidJSON(newValue));
|
||||
if (typeof text2Obj !== "object" || Array.isArray(text2Obj)) {
|
||||
throw new Error(
|
||||
"Pass a valid JSON Object. Arrays are not acceptable even though they are valid JSON."
|
||||
);
|
||||
text2Obj = merge({}, ...text2Obj)
|
||||
}
|
||||
converter.parse(text2Obj, "RootJson");
|
||||
|
||||
|
||||
@@ -3,15 +3,14 @@ import { Json2dts, toValidJSON } from "../utils/json-to-scala-case-class";
|
||||
import Layout from "../components/Layout";
|
||||
import ConversionPanel from "../components/ConversionPanel";
|
||||
import defaultText from "../utils/dummy-json";
|
||||
import merge from "lodash/merge"
|
||||
|
||||
export default class Json2Ts extends PureComponent {
|
||||
getTransformedValue = newValue => {
|
||||
const converter = new Json2dts();
|
||||
let text2Obj = JSON.parse(toValidJSON(newValue));
|
||||
if (typeof text2Obj !== "object" || Array.isArray(text2Obj)) {
|
||||
throw new Error(
|
||||
"Pass a valid JSON Object. Arrays are not acceptable even though they are valid JSON."
|
||||
);
|
||||
text2Obj = merge({}, ...text2Obj)
|
||||
}
|
||||
converter.parse(text2Obj, "RootJson");
|
||||
|
||||
|
||||
@@ -4,15 +4,14 @@ import { Json2dts, toValidJSON } from "../utils/json-to-ts-flow";
|
||||
import Layout from "../components/Layout";
|
||||
import ConversionPanel from "../components/ConversionPanel";
|
||||
import defaultText from "../utils/dummy-json";
|
||||
import merge from "lodash/merge"
|
||||
|
||||
export default class Json2Ts extends PureComponent {
|
||||
getTransformedValue = newValue => {
|
||||
const converter = new Json2dts();
|
||||
let text2Obj = JSON.parse(toValidJSON(newValue));
|
||||
if (typeof text2Obj !== "object" || Array.isArray(text2Obj)) {
|
||||
throw new Error(
|
||||
"Pass a valid JSON Object. Arrays are not acceptable even though they are valid JSON."
|
||||
);
|
||||
text2Obj = merge({}, ...text2Obj)
|
||||
}
|
||||
converter.parse(text2Obj, "RootJson");
|
||||
return converter.getCode();
|
||||
|
||||
Reference in new issue
Block a user