mirror of
https://github.com/bendtherules/ts-transformer-visualizer.git
synced 2026-08-18 22:01:45 +00:00
CodeOutput - Add component to show stringified AST, has versions for initial and current AST
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
import React from "react";
|
||||
import { connect } from "react-redux";
|
||||
import * as ts from "typescript";
|
||||
|
||||
import { AppState } from "../../store";
|
||||
|
||||
interface CodeOutputProps {
|
||||
sourceFile?: ts.SourceFile;
|
||||
}
|
||||
|
||||
function CodeOutput(props: CodeOutputProps) {
|
||||
const { sourceFile } = props;
|
||||
if (sourceFile === undefined) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const printer = ts.createPrinter();
|
||||
const codeString = printer.printFile(sourceFile);
|
||||
|
||||
return <div>{codeString}</div>;
|
||||
}
|
||||
|
||||
type CodeOutputStateProps = CodeOutputProps;
|
||||
|
||||
const mapStateToPropsForInitial = (state: AppState): CodeOutputStateProps => ({
|
||||
sourceFile: state.sourceFiles.inititalSourceFile
|
||||
});
|
||||
const mapStateToPropsForCurrent = (state: AppState): CodeOutputStateProps => ({
|
||||
sourceFile: state.sourceFiles.currentSourceFile
|
||||
});
|
||||
|
||||
const CodeOutputForInitial = connect(mapStateToPropsForInitial)(CodeOutput);
|
||||
const CodeOutputForCurrent = connect(mapStateToPropsForCurrent)(CodeOutput);
|
||||
|
||||
export {
|
||||
CodeOutputForInitial,
|
||||
CodeOutputForCurrent,
|
||||
CodeOutput as CodeOutputUnconnected,
|
||||
CodeOutputProps
|
||||
};
|
||||
@@ -0,0 +1 @@
|
||||
export * from "./CodeOutput";
|
||||
Reference in New Issue
Block a user