Skip to content

Commit

Permalink
fix: tsc error #10
Browse files Browse the repository at this point in the history
  • Loading branch information
cxtom committed Apr 17, 2019
1 parent 55df5b6 commit e2e9793
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 25 deletions.
3 changes: 2 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ import hash from 'hash-sum';
import {Project} from 'ts-morph';

import * as emitter from './emitter';
import {Ts2phpOptions, CompilerState} from './types';
import {CompilerState} from './types';
import {setState} from './state';
import buildInPlugins from './features/index';
import {transform} from './transformer';
import {Ts2phpOptions} from '../types/index';

const defaultOptions = {
showDiagnostics: true,
Expand Down
2 changes: 1 addition & 1 deletion src/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* @author cxtom(cxtom2008@gmail.com)
*/

import {ErrorInfo} from './types';
import {ErrorInfo} from '../types/index';

let globalState;

Expand Down
22 changes: 1 addition & 21 deletions src/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@

import ts from 'typescript';
import {Ts2phpOptions, ErrorInfo} from '../types/index';

interface moduleInfo {
name: string;
Expand All @@ -9,31 +10,10 @@ interface moduleInfo {
fileName?: string;
}

export interface Ts2phpOptions {
modules?: {
[name: string]: moduleInfo
},
namespace?: string;
plugins?: {emit: Function}[];
source?: string;
filePath?: string;
emitHeader?: boolean;
showDiagnostics?: boolean;
getNamespace?: () => string;
getModulePath?: (name: string, module?: ts.ResolvedModuleFull) => string;
getModuleNamespace?: (name: string, module?: ts.ResolvedModuleFull) => string;
tsConfig?: object,
customTransformers?: ts.TransformerFactory<ts.SourceFile | ts.Bundle>[]
}

export interface CompilerState extends Ts2phpOptions {
errors: ErrorInfo[],
typeChecker: ts.TypeChecker,
helpers: {},
sourceFile?: ts.SourceFile
}

export interface ErrorInfo {
code: number;
msg: string;
}
4 changes: 2 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
"compilerOptions": {
/* Basic Options */
"target": "es6", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017','ES2018' or 'ESNEXT'. */
"module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */
"module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */
"lib": ["es2015"], /* Specify library files to be included in the compilation. */
// "allowJs": true, /* Allow javascript files to be compiled. */
// "checkJs": true, /* Report errors in .js files. */
// "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */
// "declaration": true, /* Generates corresponding '.d.ts' file. */
// "declaration": true, /* Generates corresponding '.d.ts' file. */
// "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */
// "sourceMap": true, /* Generates corresponding '.map' file. */
// "outFile": "./dist/index.js", /* Concatenate and emit output to single file. */
Expand Down
36 changes: 36 additions & 0 deletions types/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@

import ts from 'typescript';

declare function date(x: string, t?: number): string;

declare function strftime(a: string, b: number | string): string;
Expand Down Expand Up @@ -37,3 +39,37 @@ declare const PHP_URL_PASS = 5;
declare const PHP_URL_PATH = 6;
declare const PHP_URL_QUERY = 7;
declare const PHP_URL_FRAGMENT = 8;

interface moduleInfo {
name: string;
path: string;
namespace: string | false;
required?: boolean;
fileName?: string;
}

export interface ErrorInfo {
code: number;
msg: string;
}
export interface Ts2phpOptions {
modules?: {
[name: string]: moduleInfo
},
namespace?: string;
plugins?: {emit: Function}[];
source?: string;
filePath?: string;
emitHeader?: boolean;
showDiagnostics?: boolean;
getNamespace?: () => string;
getModulePath?: (name: string, module?: ts.ResolvedModuleFull) => string;
getModuleNamespace?: (name: string, module?: ts.ResolvedModuleFull) => string;
tsConfig?: object,
customTransformers?: ts.TransformerFactory<ts.SourceFile | ts.Bundle>[]
}

export function compile(filePath: string, options?: Ts2phpOptions): {
phpCode: string;
errors: ErrorInfo[]
}

0 comments on commit e2e9793

Please sign in to comment.